diff --git a/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/controller/UserController.java b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/controller/UserController.java index b35a841e..23ab9858 100644 --- a/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/controller/UserController.java +++ b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/controller/UserController.java @@ -2,6 +2,7 @@ import com.depromeet.common.dto.ResponseDto; import com.depromeet.domains.user.dto.request.NicknameChangeDto; +import com.depromeet.domains.user.dto.response.UserDistanceResponseDto; import com.depromeet.domains.user.dto.response.UserLevelResponseDto; import com.depromeet.domains.user.dto.response.UserResponseDto; import com.depromeet.domains.user.service.UserLevelService; @@ -66,4 +67,13 @@ public ResponseEntity getUserLevel(@ReqUser User user) { var response = userLevelService.getUserLevel(user); return ResponseDto.ok(response); } + + @Operation(summary = "사용자 반경 조회") + @ApiResponse(responseCode = "200", description = "사용자 반경 조회 성공") + @GetMapping("/me/distance") + public ResponseEntity getUserDistance(@ReqUser User user) { + var response = userService.getUserDistance(user); + return ResponseDto.ok(response); + } + } diff --git a/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/dto/response/UserDistanceResponseDto.java b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/dto/response/UserDistanceResponseDto.java new file mode 100644 index 00000000..5aeee89f --- /dev/null +++ b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/dto/response/UserDistanceResponseDto.java @@ -0,0 +1,14 @@ +package com.depromeet.domains.user.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class UserDistanceResponseDto { + @Schema(description = "사용자 지정 거리", example = "600") + private Integer distance; +} diff --git a/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/service/UserService.java b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/service/UserService.java index d6a02ffc..4b3c37c0 100644 --- a/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/service/UserService.java +++ b/backend/streetdrop-api/src/main/java/com/depromeet/domains/user/service/UserService.java @@ -1,7 +1,9 @@ package com.depromeet.domains.user.service; +import com.depromeet.domains.user.dto.response.UserDistanceResponseDto; import com.depromeet.domains.user.dto.response.UserResponseDto; import com.depromeet.domains.user.repository.DefaultNickNameRepository; +import com.depromeet.domains.user.repository.UserLevelRepository; import com.depromeet.domains.user.repository.UserRepository; import com.depromeet.user.User; import com.depromeet.user.vo.MusicApp; @@ -17,7 +19,7 @@ public class UserService { public static final long USER_LEVEL_ID = 1L; private final UserRepository userRepository; private final DefaultNickNameRepository defaultNickNameRepository; - + private final UserLevelRepository userLevelRepository; @Transactional(readOnly = true) public User getOrCreateUser(String nickname) { return userRepository.findUserByNickname(nickname) @@ -68,4 +70,13 @@ public UserResponseDto changeMusicApp(User user, MusicApp musicApp) { userRepository.save(user); return new UserResponseDto(user); } + + @Transactional(readOnly = true) + public UserDistanceResponseDto getUserDistance(User user) { + var defaultDistance = 600; + var userLevelId = user.getUserLevelId(); + return userLevelRepository.findById(userLevelId) + .map(userLevel -> new UserDistanceResponseDto(userLevel.getDistance())) + .orElseGet(() -> new UserDistanceResponseDto(defaultDistance)); + } } diff --git a/backend/streetdrop-api/src/main/resources/db/migration/V20240206__add_distance_to_users_level.sql b/backend/streetdrop-api/src/main/resources/db/migration/V20240206__add_distance_to_users_level.sql new file mode 100644 index 00000000..bc84aed3 --- /dev/null +++ b/backend/streetdrop-api/src/main/resources/db/migration/V20240206__add_distance_to_users_level.sql @@ -0,0 +1 @@ +ALTER TABLE users_level ADD distance INT NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/backend/streetdrop-domain/src/main/java/com/depromeet/user/UserLevel.java b/backend/streetdrop-domain/src/main/java/com/depromeet/user/UserLevel.java index 777dca98..cc331d7e 100644 --- a/backend/streetdrop-domain/src/main/java/com/depromeet/user/UserLevel.java +++ b/backend/streetdrop-domain/src/main/java/com/depromeet/user/UserLevel.java @@ -25,10 +25,14 @@ public class UserLevel { @Column(nullable = false) private String image; + @Column(nullable = false) + private Integer distance; + @Builder - public UserLevel(String name, String description, String image) { + public UserLevel(String name, String description, String image, Integer distance) { this.name = name; this.description = description; this.image = image; + this.distance = distance; } }