Skip to content

Commit

Permalink
feat: '프로필 뱃지', 'profileBadge' 용어 통일, 프로필 뱃지 설정 API endpoint 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
redcarrot1 committed Aug 21, 2024
1 parent 7f6c67f commit 0238f9b
Show file tree
Hide file tree
Showing 26 changed files with 197 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public interface AdventureRepository extends JpaRepository<Adventure, Long> {

@Query("SELECT new com.playkuround.playkuroundserver.domain.score.dto.NicknameAndScoreAndBadgeType(a.user.nickname, cast(SUM(a.score) as integer), a.user.representBadge) " +
@Query("SELECT new com.playkuround.playkuroundserver.domain.score.dto.NicknameAndScoreAndBadgeType(a.user.nickname, cast(SUM(a.score) as integer), a.user.profileBadge) " +
"FROM Adventure a " +
"where a.landmark.id=:landmark AND a.createdAt >= :from " +
"GROUP BY a.user.id " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.playkuround.playkuroundserver.domain.badge.api;

import com.playkuround.playkuroundserver.domain.badge.api.request.RepresentationBadgeRequest;
import com.playkuround.playkuroundserver.domain.badge.api.response.BadgeFindResponse;
import com.playkuround.playkuroundserver.domain.badge.application.BadgeService;
import com.playkuround.playkuroundserver.domain.badge.domain.Badge;
import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.domain.badge.exception.BadgeTypeNotFoundException;
import com.playkuround.playkuroundserver.global.common.response.ApiResponse;
import com.playkuround.playkuroundserver.global.security.UserDetailsImpl;
import com.playkuround.playkuroundserver.global.util.ApiUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -44,15 +40,4 @@ public ApiResponse<Boolean> saveTheDreamOfDuckBadge(@AuthenticationPrincipal Use
return ApiUtils.success(response);
}

@PostMapping("/representation")
@Operation(summary = "대표 뱃지 설정", description = "사용자를 대표하는 뱃지를 설정합니다.")
public ApiResponse<Void> setRepresentationBadge(@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody @Valid RepresentationBadgeRequest request) {
BadgeType badgeType = BadgeType.fromString(request.getBadgeType())
.orElseThrow(BadgeTypeNotFoundException::new);

badgeService.representationBadge(userDetails.getUser(), badgeType);
return ApiUtils.success(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
@AllArgsConstructor
public class RepresentationBadgeRequest {
public class ProfileBadgeRequest {

@ValidEnum(enumClass = BadgeType.class, message = "잘못된 badge type 입니다.")
@Schema(description = "설정할 뱃지 타입", example = "ATTENDANCE_CHILDREN_DAY", requiredMode = Schema.RequiredMode.REQUIRED)
private String badgeType;
@Schema(description = "설정할 뱃지 이름", example = "ATTENDANCE_CHILDREN_DAY", requiredMode = Schema.RequiredMode.REQUIRED)
private String profileBadge;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.playkuround.playkuroundserver.domain.badge.domain.Badge;
import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.domain.badge.dto.NewlyRegisteredBadge;
import com.playkuround.playkuroundserver.domain.badge.exception.BadgeNotHaveException;
import com.playkuround.playkuroundserver.domain.common.DateTimeService;
import com.playkuround.playkuroundserver.domain.landmark.domain.Landmark;
import com.playkuround.playkuroundserver.domain.landmark.domain.LandmarkType;
Expand Down Expand Up @@ -124,14 +123,4 @@ public boolean saveManualBadge(String userEmail, BadgeType badgeType, boolean re
return true;
}

@Transactional
public void representationBadge(User user, BadgeType badgeType) {
if (!badgeRepository.existsByUserAndBadgeType(user, badgeType)) {
throw new BadgeNotHaveException();
}

user.updateRepresentBadge(badgeType);
userRepository.save(user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class LandmarkApi {
@Operation(summary = "가장 가까운 랜드마크 찾기",
description = "인식 반경 내에 있는 랜드마크 중 가장 가까운 랜드마크를 반환합니다. " +
"인식 반경에 랜드마크가 없을 경우 아무것도 반환하지 않습니다.")
public ApiResponse<NearestLandmarkResponse> LandmarkFindNear(@RequestParam @Latitude Double latitude,
@RequestParam @Longitude Double longitude) {
public ApiResponse<NearestLandmarkResponse> findNearestLandmark(@RequestParam @Latitude Double latitude,
@RequestParam @Longitude Double longitude) {
Location location = new Location(latitude, longitude);
NearestLandmark nearestLandmark = landmarkFindNearService.findNearestLandmark(location);
return ApiUtils.success(NearestLandmarkResponse.from(nearestLandmark));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class LandmarkHighestScoreUserResponse {
@Schema(description = "최고 점수", example = "294")
private Long score;

@Schema(description = "해당 사용자의 뱃지타입", example = "COLLEGE_OF_ENGINEERING")
private String badgeType;
@Schema(description = "해당 사용자의 프로필 뱃지", example = "COLLEGE_OF_ENGINEERING")
private String profileBadge;

public static LandmarkHighestScoreUserResponse from(LandmarkHighestScoreUser firstUserData) {
String badgeTypeName = firstUserData.badgeType() == null ? null : firstUserData.badgeType().name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Optional<LandmarkHighestScoreUser> findHighestScoreUserByLandmark(Long la
LandmarkHighestScoreUser highestScoreUser = new LandmarkHighestScoreUser(
landmark.getHighestScore(),
firstUser.getNickname(),
firstUser.getRepresentBadge()
firstUser.getProfileBadge()
);
return Optional.of(highestScoreUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setMyRank(int ranking, int score, BadgeType badgeType) {
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class RankList {
private String nickname;
private String badgeType;
private String profileBadge;
private int score;
}

Expand All @@ -45,6 +45,6 @@ public static class RankList {
public static class MyRank {
private int ranking;
private int score;
private String badgeType;
private String profileBadge;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ScoreRankingResponse getRankTop100ByLandmark(User user, Long landmarkId)

RankAndScore rankAndScore = adventureRepository.findMyRankByLandmarkId(user, landmarkId, monthStartDateTime)
.orElseGet(() -> new RankAndScore(0, 0));
response.setMyRank(rankAndScore.ranking(), rankAndScore.score(), user.getRepresentBadge());
response.setMyRank(rankAndScore.ranking(), rankAndScore.score(), user.getProfileBadge());
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ScoreRankingResponse getRankTop100(User user) {
ScoreRankingResponse response = scoreRankService.createScoreRankingResponse(emailBindingNickname);

RankAndScore myRank = getMyRank(user);
response.setMyRank(myRank.ranking(), myRank.score(), user.getRepresentBadge());
response.setMyRank(myRank.ranking(), myRank.score(), user.getProfileBadge());

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.playkuround.playkuroundserver.domain.appversion.application.AppVersionService;
import com.playkuround.playkuroundserver.domain.appversion.domain.OperationSystem;
import com.playkuround.playkuroundserver.domain.badge.api.request.ProfileBadgeRequest;
import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.domain.badge.exception.BadgeTypeNotFoundException;
import com.playkuround.playkuroundserver.domain.systemcheck.application.SystemCheckService;
import com.playkuround.playkuroundserver.domain.user.api.response.UserGameHighestScoreResponse;
import com.playkuround.playkuroundserver.domain.user.api.response.UserNotificationResponse;
Expand All @@ -16,12 +19,10 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -31,8 +32,8 @@
@Tag(name = "User", description = "User API")
public class UserProfileApi {

private final AppVersionService appVersionService;
private final UserProfileService userProfileService;
private final AppVersionService appVersionService;
private final SystemCheckService systemCheckService;

@GetMapping
Expand All @@ -55,6 +56,17 @@ public ApiResponse<Boolean> isAvailableNickname(@RequestParam("nickname") String
return ApiUtils.success(isAvailable);
}

@PostMapping("/profile-badge")
@Operation(summary = "프로필 뱃지 설정", description = "사용자 프로필 뱃지를 설정합니다.")
public ApiResponse<Void> setProfileBadge(@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody @Valid ProfileBadgeRequest request) {
BadgeType badgeType = BadgeType.fromString(request.getProfileBadge())
.orElseThrow(BadgeTypeNotFoundException::new);

userProfileService.setProfileBadge(userDetails.getUser(), badgeType);
return ApiUtils.success(null);
}

@GetMapping("/notification")
@Operation(summary = "유저 알림 얻기",
description = "유저 개인 알림을 얻습니다. 저장된 메시지는 (정상적인) 호출 이후 삭제됩니다.<br>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class UserProfileResponse {
@Schema(description = "학과", example = "컴퓨터공학부", requiredMode = RequiredMode.REQUIRED)
private String major;

@Schema(description = "자신의 토탈 스코어 최고점(점수가 없다면 null 리턴)", example = "1500", requiredMode = RequiredMode.REQUIRED)
@Schema(description = "자신의 토탈 스코어 최고점(점수가 없다면 null 리턴)", example = "1500")
private Long highestScore;

@Schema(description = "자신의 토탈 등수 최고점(등수가 없다면 null 리턴)", example = "13", requiredMode = RequiredMode.REQUIRED)
@Schema(description = "자신의 토탈 등수 최고점(등수가 없다면 null 리턴)", example = "13")
private Long highestRank;

@Schema(description = "출석한 횟수", example = "28", requiredMode = RequiredMode.REQUIRED)
private int attendanceDays;

@Schema(description = "대표 뱃지(대표 뱃지가 없다면 null 리턴)", example = "MONTHLY_RANKING_1", requiredMode = RequiredMode.REQUIRED)
private String badge;
@Schema(description = "프로필 뱃지(프로필 뱃지가 없다면 null 리턴)", example = "MONTHLY_RANKING_1")
private String profileBadge;

public static UserProfileResponse from(User user) {
return UserProfileResponse.builder()
Expand All @@ -41,7 +41,7 @@ public static UserProfileResponse from(User user) {
.attendanceDays(user.getAttendanceDays())
.highestScore(user.getHighestScore() == null ? null : user.getHighestScore().getHighestTotalScore())
.highestRank(user.getHighestScore() == null ? null : user.getHighestScore().getHighestTotalRank())
.badge(user.getRepresentBadge() == null ? null : user.getRepresentBadge().name())
.profileBadge(user.getProfileBadge() == null ? null : user.getProfileBadge().name())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.playkuround.playkuroundserver.domain.user.application;

import com.playkuround.playkuroundserver.domain.badge.dao.BadgeRepository;
import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType;
import com.playkuround.playkuroundserver.domain.badge.exception.BadgeNotHaveException;
import com.playkuround.playkuroundserver.domain.user.dao.UserRepository;
import com.playkuround.playkuroundserver.domain.user.domain.HighestScore;
import com.playkuround.playkuroundserver.domain.user.domain.Notification;
Expand All @@ -19,6 +22,7 @@
public class UserProfileService {

private final UserRepository userRepository;
private final BadgeRepository badgeRepository;
private final Pattern nicknamePattern = Pattern.compile("^[0-9a-zA-Z가-힣]{2,8}$");

@Transactional(readOnly = true)
Expand All @@ -28,6 +32,16 @@ public boolean isAvailableNickname(String nickname) {
!userRepository.existsByNickname(nickname);
}

@Transactional
public void setProfileBadge(User user, BadgeType badgeType) {
if (!badgeRepository.existsByUserAndBadgeType(user, badgeType)) {
throw new BadgeNotHaveException();
}

user.updateProfileBadge(badgeType);
userRepository.save(user);
}

@Transactional(readOnly = true)
public HighestScore getUserGameHighestScore(User user) {
return user.getHighestScore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public TokenDto registerUser(UserRegisterDto userRegisterDto) {
Badge badge = new Badge(user, collageBadgeType);
badgeRepository.save(badge);

user.updateRepresentBadge(collageBadgeType);
user.updateProfileBadge(collageBadgeType);

return userLoginService.login(user.getEmail());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface UserRepository extends JpaRepository<User, Long> {

Optional<User> findByEmail(String email);

@Query("select new com.playkuround.playkuroundserver.domain.user.dto.EmailAndNicknameAndBadge(u.email, u.nickname, u.representBadge) " +
@Query("select new com.playkuround.playkuroundserver.domain.user.dto.EmailAndNicknameAndBadge(u.email, u.nickname, u.profileBadge) " +
"from User u " +
"where u.email in :emails")
List<EmailAndNicknameAndBadge> findNicknameByEmailIn(List<String> emails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class User extends BaseTimeEntity {
private Set<Notification> notification;

@Enumerated(EnumType.STRING)
private BadgeType representBadge;
private BadgeType profileBadge;

private User(String email, String nickname, Major major, Role role) {
this.email = email;
Expand Down Expand Up @@ -79,8 +79,8 @@ public void updateHighestRank(long rank, long score) {
highestScore.updateHighestTotalLank(rank, score);
}

public void updateRepresentBadge(BadgeType badgeType) {
this.representBadge = badgeType;
public void updateProfileBadge(BadgeType badgeType) {
this.profileBadge = badgeType;
}

public HighestScore getHighestScore() {
Expand Down
Loading

0 comments on commit 0238f9b

Please sign in to comment.