From 337d1606450d5b534915e87776014a9e12c81420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9A=B0=EB=94=94?= <38103085+EunjiShin@users.noreply.github.com> Date: Sun, 4 Aug 2024 04:09:05 +0900 Subject: [PATCH] =?UTF-8?q?[BSVR-188]=20Level=20up=20=EB=8B=A4=EC=9D=B4?= =?UTF-8?q?=EC=96=BC=EB=A1=9C=EA=B7=B8=EC=9A=A9=20API=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Level에 레벨업 이미지 필드 추가 * feat: 레벨업 다이얼로그 정보 조회 API 추가 * feat: findById를 Optional로 변경 * fix: 유저 후기 개수 카운트 쿼리에 deleteAt is null 조건 추가 * fix: levels info API는 필터 안타게 수정 --- .../common/jwt/JwtAuthenticationFilter.java | 2 +- ...ntroller.java => ReadLevelController.java} | 20 ++++++++++++++++--- .../dto/response/LevelUpDialogInfo.java | 10 ++++++++++ .../depromeet/spot/domain/member/Level.java | 1 + .../jpa/member/entity/LevelEntity.java | 11 +++++++++- .../member/repository/LevelJpaRepository.java | 4 +++- .../repository/LevelRepositoryImpl.java | 5 ++++- .../repository/ReviewJpaRepository.java | 2 +- .../repository/ReviewRepositoryImpl.java | 2 +- .../usecase/port/in/member/LevelUsecase.java | 2 ++ .../usecase/service/level/LevelService.java | 7 +++++++ 11 files changed, 57 insertions(+), 9 deletions(-) rename application/src/main/java/org/depromeet/spot/application/member/controller/{LevelUpTableController.java => ReadLevelController.java} (58%) create mode 100644 application/src/main/java/org/depromeet/spot/application/member/dto/response/LevelUpDialogInfo.java diff --git a/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java b/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java index 01136f05..ede259f9 100644 --- a/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java +++ b/application/src/main/java/org/depromeet/spot/application/common/jwt/JwtAuthenticationFilter.java @@ -36,7 +36,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { "/favicon.ico", "/api/v1/members", "/actuator", - "/api/v1/levelUpConditions", + "/api/v1/levels/info", "/api/v1/baseball-teams", }; diff --git a/application/src/main/java/org/depromeet/spot/application/member/controller/LevelUpTableController.java b/application/src/main/java/org/depromeet/spot/application/member/controller/ReadLevelController.java similarity index 58% rename from application/src/main/java/org/depromeet/spot/application/member/controller/LevelUpTableController.java rename to application/src/main/java/org/depromeet/spot/application/member/controller/ReadLevelController.java index 05796f16..5f91c597 100644 --- a/application/src/main/java/org/depromeet/spot/application/member/controller/LevelUpTableController.java +++ b/application/src/main/java/org/depromeet/spot/application/member/controller/ReadLevelController.java @@ -2,11 +2,17 @@ import java.util.List; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; + +import org.depromeet.spot.application.member.dto.response.LevelUpDialogInfo; import org.depromeet.spot.application.member.dto.response.LevelUpTableResponse; +import org.depromeet.spot.domain.member.Level; import org.depromeet.spot.usecase.port.in.member.LevelUsecase; import org.springframework.http.HttpStatus; 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.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -17,15 +23,23 @@ @RestController @RequiredArgsConstructor @Tag(name = "레벨") -@RequestMapping("/api/v1/levelUpConditions") -public class LevelUpTableController { +@RequestMapping("/api/v1/levels") +public class ReadLevelController { private final LevelUsecase levelUsecase; - @GetMapping + @GetMapping("/info") @ResponseStatus(HttpStatus.OK) @Operation(summary = "레벨업 조건 테이블 조회 API") public List getLevelUpTable() { return levelUsecase.findAllLevels().stream().map(LevelUpTableResponse::from).toList(); } + + @GetMapping("/up/info") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "레벨업 다이얼로그 조회 API") + public LevelUpDialogInfo getLevelUpDialogInfo(@RequestParam @NotNull @Positive int nextLevel) { + Level level = levelUsecase.findLevelUpDialogInfo(nextLevel); + return LevelUpDialogInfo.from(level); + } } diff --git a/application/src/main/java/org/depromeet/spot/application/member/dto/response/LevelUpDialogInfo.java b/application/src/main/java/org/depromeet/spot/application/member/dto/response/LevelUpDialogInfo.java new file mode 100644 index 00000000..4d0a8f72 --- /dev/null +++ b/application/src/main/java/org/depromeet/spot/application/member/dto/response/LevelUpDialogInfo.java @@ -0,0 +1,10 @@ +package org.depromeet.spot.application.member.dto.response; + +import org.depromeet.spot.domain.member.Level; + +public record LevelUpDialogInfo(String title, String levelUpImage) { + + public static LevelUpDialogInfo from(Level level) { + return new LevelUpDialogInfo(level.getTitle(), level.getLevelUpImageUrl()); + } +} diff --git a/domain/src/main/java/org/depromeet/spot/domain/member/Level.java b/domain/src/main/java/org/depromeet/spot/domain/member/Level.java index cb19a3de..b3287c03 100644 --- a/domain/src/main/java/org/depromeet/spot/domain/member/Level.java +++ b/domain/src/main/java/org/depromeet/spot/domain/member/Level.java @@ -34,6 +34,7 @@ public class Level { private final int value; private final String title; private final String mascotImageUrl; + private final String levelUpImageUrl; private final LocalDateTime createdAt; private final LocalDateTime updatedAt; private final LocalDateTime deletedAt; diff --git a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/entity/LevelEntity.java b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/entity/LevelEntity.java index 72541dd7..9d4bbdd4 100644 --- a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/entity/LevelEntity.java +++ b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/entity/LevelEntity.java @@ -25,15 +25,23 @@ public class LevelEntity extends BaseEntity { @Column(name = "mascot_image_url") private String mascotImageUrl; + @Column(name = "level_up_image_url") + private String levelUpImageUrl; + public LevelEntity(Level level) { super(level.getId(), level.getCreatedAt(), level.getUpdatedAt(), level.getDeletedAt()); value = level.getValue(); title = level.getTitle(); mascotImageUrl = level.getMascotImageUrl(); + levelUpImageUrl = level.getLevelUpImageUrl(); } public static LevelEntity from(Level level) { - return new LevelEntity(level.getValue(), level.getTitle(), level.getMascotImageUrl()); + return new LevelEntity( + level.getValue(), + level.getTitle(), + level.getMascotImageUrl(), + level.getLevelUpImageUrl()); } public Level toDomain() { @@ -42,6 +50,7 @@ public Level toDomain() { value, title, mascotImageUrl, + levelUpImageUrl, this.getCreatedAt(), this.getUpdatedAt(), this.getDeletedAt()); diff --git a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelJpaRepository.java b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelJpaRepository.java index a4f29c84..dbb06a58 100644 --- a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelJpaRepository.java +++ b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelJpaRepository.java @@ -1,9 +1,11 @@ package org.depromeet.spot.infrastructure.jpa.member.repository; +import java.util.Optional; + import org.depromeet.spot.infrastructure.jpa.member.entity.LevelEntity; import org.springframework.data.jpa.repository.JpaRepository; public interface LevelJpaRepository extends JpaRepository { - LevelEntity findByValue(int value); + Optional findByValue(int value); } diff --git a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelRepositoryImpl.java b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelRepositoryImpl.java index d3fe74b1..481951b9 100644 --- a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelRepositoryImpl.java +++ b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/member/repository/LevelRepositoryImpl.java @@ -2,6 +2,7 @@ import java.util.List; +import org.depromeet.spot.common.exception.member.MemberException.InvalidLevelException; import org.depromeet.spot.domain.member.Level; import org.depromeet.spot.infrastructure.jpa.member.entity.LevelEntity; import org.depromeet.spot.usecase.port.out.member.LevelRepository; @@ -17,7 +18,9 @@ public class LevelRepositoryImpl implements LevelRepository { @Override public Level findByValue(final int value) { - return levelJpaRepository.findByValue(value).toDomain(); + LevelEntity entity = + levelJpaRepository.findByValue(value).orElseThrow(InvalidLevelException::new); + return entity.toDomain(); } @Override diff --git a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewJpaRepository.java b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewJpaRepository.java index e58c0f80..5c6f6463 100644 --- a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewJpaRepository.java +++ b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewJpaRepository.java @@ -14,7 +14,7 @@ import org.springframework.data.repository.query.Param; public interface ReviewJpaRepository extends JpaRepository { - long countByMemberId(Long memberId); + long countByMemberIdAndDeletedAtIsNull(Long memberId); @Query( "SELECT r FROM ReviewEntity r WHERE r.stadium.id = :stadiumId AND r.block.code = :blockCode " diff --git a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewRepositoryImpl.java b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewRepositoryImpl.java index 69bd15c8..8a723534 100644 --- a/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewRepositoryImpl.java +++ b/infrastructure/src/main/java/org/depromeet/spot/infrastructure/jpa/review/repository/ReviewRepositoryImpl.java @@ -37,7 +37,7 @@ public Optional findById(Long id) { @Override public long countByUserId(Long id) { - return reviewJpaRepository.countByMemberId(id); + return reviewJpaRepository.countByMemberIdAndDeletedAtIsNull(id); } @Override diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/LevelUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/LevelUsecase.java index 2a38fb64..e3dc7cd3 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/LevelUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/LevelUsecase.java @@ -6,4 +6,6 @@ public interface LevelUsecase { List findAllLevels(); + + Level findLevelUpDialogInfo(int nextLevel); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/level/LevelService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/level/LevelService.java index 9f615fba..746a6911 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/level/LevelService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/level/LevelService.java @@ -4,6 +4,7 @@ import org.depromeet.spot.domain.member.Level; import org.depromeet.spot.usecase.port.in.member.LevelUsecase; +import org.depromeet.spot.usecase.port.in.member.ReadLevelUsecase; import org.depromeet.spot.usecase.port.out.member.LevelRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,9 +17,15 @@ public class LevelService implements LevelUsecase { private final LevelRepository levelRepository; + private final ReadLevelUsecase readLevelUsecase; @Override public List findAllLevels() { return levelRepository.findAll(); } + + @Override + public Level findLevelUpDialogInfo(final int nextLevel) { + return readLevelUsecase.findByValue(nextLevel); + } }