41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package com.walkguide.service;
|
|
|
|
import com.walkguide.enums.ActivityLogType;
|
|
import com.walkguide.repository.UserRepository;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Map;
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class UserService {
|
|
|
|
private final UserRepository userRepository;
|
|
private final ActivityLogService activityLogService;
|
|
|
|
public Map<String, Object> getProfile(Long userId) {
|
|
var user = userRepository.findById(userId)
|
|
.orElseThrow(() -> new RuntimeException("User tidak ditemukan"));
|
|
return Map.of(
|
|
"id", user.getId(),
|
|
"email", user.getEmail(),
|
|
"displayName", user.getDisplayName() != null ? user.getDisplayName() : "",
|
|
"role", user.getRole(),
|
|
"uniqueUserId", user.getUniqueUserId() != null ? user.getUniqueUserId() : ""
|
|
);
|
|
}
|
|
|
|
public void logWalkGuideStart(Long userId) {
|
|
userRepository.findById(userId).ifPresent(user ->
|
|
activityLogService.createLog(user, ActivityLogType.WALKGUIDE_START,
|
|
"WalkGuide dimulai", null));
|
|
}
|
|
|
|
public void logWalkGuideStop(Long userId) {
|
|
userRepository.findById(userId).ifPresent(user ->
|
|
activityLogService.createLog(user, ActivityLogType.WALKGUIDE_STOP,
|
|
"WalkGuide dihentikan", null));
|
|
}
|
|
}
|