Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: add user distance api #434

Merged
merged 1 commit into from
Feb 6, 2024
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 @@ -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;
Expand Down Expand Up @@ -66,4 +67,13 @@ public ResponseEntity<UserLevelResponseDto> getUserLevel(@ReqUser User user) {
var response = userLevelService.getUserLevel(user);
return ResponseDto.ok(response);
}

@Operation(summary = "사용자 반경 조회")
@ApiResponse(responseCode = "200", description = "사용자 반경 조회 성공")
@GetMapping("/me/distance")
public ResponseEntity<UserDistanceResponseDto> getUserDistance(@ReqUser User user) {
var response = userService.getUserDistance(user);
return ResponseDto.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE users_level ADD distance INT NOT NULL DEFAULT 0;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading