Skip to content

Commit

Permalink
[BSVR-188] Level up 다이얼로그용 API (#111)
Browse files Browse the repository at this point in the history
* feat: Level에 레벨업 이미지 필드 추가

* feat: 레벨업 다이얼로그 정보 조회 API 추가

* feat: findById를 Optional로 변경

* fix: 유저 후기 개수 카운트 쿼리에 deleteAt is null 조건 추가

* fix: levels info API는 필터 안타게 수정
  • Loading branch information
EunjiShin authored Aug 3, 2024
1 parent efa7284 commit 337d160
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<LevelUpTableResponse> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -42,6 +50,7 @@ public Level toDomain() {
value,
title,
mascotImageUrl,
levelUpImageUrl,
this.getCreatedAt(),
this.getUpdatedAt(),
this.getDeletedAt());
Expand Down
Original file line number Diff line number Diff line change
@@ -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, Long> {

LevelEntity findByValue(int value);
Optional<LevelEntity> findByValue(int value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.data.repository.query.Param;

public interface ReviewJpaRepository extends JpaRepository<ReviewEntity, Long> {
long countByMemberId(Long memberId);
long countByMemberIdAndDeletedAtIsNull(Long memberId);

@Query(
"SELECT r FROM ReviewEntity r WHERE r.stadium.id = :stadiumId AND r.block.code = :blockCode "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Optional<Review> findById(Long id) {

@Override
public long countByUserId(Long id) {
return reviewJpaRepository.countByMemberId(id);
return reviewJpaRepository.countByMemberIdAndDeletedAtIsNull(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface LevelUsecase {
List<Level> findAllLevels();

Level findLevelUpDialogInfo(int nextLevel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,9 +17,15 @@
public class LevelService implements LevelUsecase {

private final LevelRepository levelRepository;
private final ReadLevelUsecase readLevelUsecase;

@Override
public List<Level> findAllLevels() {
return levelRepository.findAll();
}

@Override
public Level findLevelUpDialogInfo(final int nextLevel) {
return readLevelUsecase.findByValue(nextLevel);
}
}

0 comments on commit 337d160

Please sign in to comment.