Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
Expand All @@ -29,10 +30,15 @@
public class UserController {
private final UserService userService;

@Operation(summary = "회원가입", description = """
새로운 사용자를 등록합니다.

@Operation(
summary = "회원가입",
description =
"""
새로운 사용자를 등록합니다.

✅ 요청 형식:
- **userRequest**: 사용자 정보(JSON) \s
- **image**: 프로필 이미지 파일 (선택)
""")
@PostMapping(
path = "/register",
Expand All @@ -55,4 +61,24 @@ public ResponseEntity<BaseResponse<UserResponse>> registerUser(
return ResponseEntity.status(HttpStatus.CREATED)
.body(BaseResponse.success("회원 가입이 완료되었습니다.", userResponse));
}

@Operation(
summary = "완료 미션 개수 조회",
description =
"""
로그인한 사용자의 완료한 미션 개수를 조회합니다.

✅ 인증 필요: \s
- 이 API는 **JWT 인증이 필요한 API**입니다. \s
- 헤더에 **Authorization: Bearer <AccessToken>**을 포함해주세요.

✅ 동작 방식: \s
- Redis에 캐시된 값이 있으면 해당 값을 반환합니다. \s
- 없을 경우 DB에서 값을 조회한 후 Redis에 저장하고 응답합니다.
""")
@GetMapping("/missions/count")
public ResponseEntity<BaseResponse<Long>> getCompletedMissionCount() {
long count = userService.getCompletedMissionCountForCurrentUser();
return ResponseEntity.ok(BaseResponse.success("완료 미션 개수를 조회했습니다.", count));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public UserResponse register(InfoRequest userRequest, MultipartFile imageFile) {
return userMapper.toResponse(user, getCompletedMission(user.getId()));
}

/**
* 현재 로그인한 사용자의 완료한 미션 개수를 조회하는 메서드
*
* <p>내부적으로 Redis 캐시에 값이 존재하는 경우 이를 사용하고, 존재하지 않으면 DB에서 조회한 뒤 Redis에 저장합니다.
*
* @return 완료한 미션 개수
* @throws CustomException 사용자 정보를 찾을 수 없는 경우 {@link UserErrorCode#USER_NOT_FOUND}
*/
public long getCompletedMissionCountForCurrentUser() {

Long userId = securityUtil.getCurrentUserId();
return getCompletedMission(userId);
}

// Lazy Loading: Redis에 없으면 → DB에서 조회하고 → Redis에 저장
public long getCompletedMission(Long userId) {
String redisKey = "user:completedMission:" + userId;
Expand Down