-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Docs: 스웨거 설명 수정 - 페널티 사유 -> 페널티 수준 #39 * Feat: 페널티 목록 조회 API - 페널티 목록 조회 API #39 * Feat: 페널티 목록 조회 API 테스트 코드 작성 - 페널티 목록 조회 서비스 테스트 코드 작성 - 페널티 목록 조회 레포지토리 테스트 코드 작성 #39 * Docs: 페널티 목록 조회 API 스웨거 수정 - 페널티 목록 조회 스웨거 수정 #39
- Loading branch information
Showing
11 changed files
with
295 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/kea/enter/enterbe/api/penalty/controller/response/GetPenaltyListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kea.enter.enterbe.api.penalty.controller.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kea.enter.enterbe.domain.penalty.entity.PenaltyLevel; | ||
import kea.enter.enterbe.domain.penalty.entity.PenaltyReason; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class GetPenaltyListResponse { | ||
@Schema(description = "페널티 아이디", example = "1") | ||
private Long penaltyId; | ||
|
||
@Schema(description = "페널티 생성일", example = "2024-07-31") | ||
private String createdAt; | ||
|
||
@Schema(description = "페널티 사유 (TAKE, RETURN, BROKEN, FUEL, ETC)", example = "FUEL") | ||
private PenaltyReason reason; | ||
|
||
@Schema(description = "페널티 수준 (LOW, MEDIUM, HIGH, BLACKLIST)", example = "LOW") | ||
private PenaltyLevel level; | ||
|
||
@Schema(description = "비고", example = "자동차를 박살냈습니다.") | ||
private String etc; | ||
|
||
@Builder | ||
public GetPenaltyListResponse(Long penaltyId, String createdAt, PenaltyReason reason, | ||
PenaltyLevel level, String etc) { | ||
this.penaltyId = penaltyId; | ||
this.createdAt = createdAt; | ||
this.reason = reason; | ||
this.level = level; | ||
this.etc = etc; | ||
} | ||
|
||
public static GetPenaltyListResponse of(Long penaltyId, String createdAt, PenaltyReason reason, | ||
PenaltyLevel level, String etc) { | ||
return GetPenaltyListResponse.builder() | ||
.penaltyId(penaltyId) | ||
.createdAt(createdAt) | ||
.reason(reason) | ||
.level(level) | ||
.etc(etc) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/kea/enter/enterbe/api/penalty/service/AdminPenaltyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package kea.enter.enterbe.api.penalty.service; | ||
|
||
import kea.enter.enterbe.api.penalty.controller.response.GetPenaltyListResponse; | ||
import kea.enter.enterbe.api.penalty.service.dto.GetPenaltyListServiceDto; | ||
import kea.enter.enterbe.api.penalty.service.dto.PostPenaltyServiceDto; | ||
|
||
import java.util.List; | ||
|
||
public interface AdminPenaltyService { | ||
void createPenalty(PostPenaltyServiceDto postPenaltyServiceDto); | ||
List<GetPenaltyListResponse> getPenaltyList(GetPenaltyListServiceDto of); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/kea/enter/enterbe/api/penalty/service/dto/GetPenaltyListServiceDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package kea.enter.enterbe.api.penalty.service.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class GetPenaltyListServiceDto { | ||
private Long memberId; | ||
|
||
@Builder | ||
public GetPenaltyListServiceDto(Long memberId) { | ||
this.memberId = memberId; | ||
} | ||
|
||
public static GetPenaltyListServiceDto of(Long memberId) { | ||
return GetPenaltyListServiceDto.builder() | ||
.memberId(memberId) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/main/java/kea/enter/enterbe/domain/penalty/repository/PenaltyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package kea.enter.enterbe.domain.penalty.repository; | ||
|
||
import kea.enter.enterbe.domain.penalty.entity.Penalty; | ||
import kea.enter.enterbe.domain.penalty.entity.PenaltyState; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface PenaltyRepository extends JpaRepository<Penalty, Long> { | ||
|
||
// 사용자의 페널티 목록을 조회한다 | ||
List<Penalty> findAllByMemberIdAndStateOrderByCreatedAt(Long memberId, PenaltyState state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package kea.enter.enterbe.api.penalty.service; | ||
|
||
import kea.enter.enterbe.IntegrationTestSupport; | ||
import kea.enter.enterbe.api.penalty.controller.response.GetPenaltyListResponse; | ||
import kea.enter.enterbe.api.penalty.service.dto.GetPenaltyListServiceDto; | ||
import kea.enter.enterbe.api.penalty.service.dto.PostPenaltyServiceDto; | ||
import kea.enter.enterbe.domain.member.entity.Member; | ||
import kea.enter.enterbe.domain.member.entity.MemberRole; | ||
|
@@ -13,6 +15,8 @@ | |
import org.junit.jupiter.api.Test; | ||
import java.util.List; | ||
|
||
import static kea.enter.enterbe.domain.penalty.entity.PenaltyLevel.BLACKLIST; | ||
import static kea.enter.enterbe.domain.penalty.entity.PenaltyReason.BROKEN; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.tuple; | ||
|
||
|
@@ -36,8 +40,39 @@ public void postPenalty() throws Exception { | |
); | ||
} | ||
|
||
@DisplayName(value = "사용자의 페널티 목록을 조회한다.") | ||
@Test | ||
public void getPenaltyList() throws Exception { | ||
//given | ||
Member member = memberRepository.save(createMember()); | ||
Long memberId = member.getId(); | ||
|
||
Penalty penalty1 = penaltyRepository.save(createPenalty(member)); | ||
Penalty penalty2 = penaltyRepository.save(createPenalty(member)); | ||
Penalty penalty3 = penaltyRepository.save(createPenalty(member)); | ||
penaltyRepository.saveAll(List.of(penalty1, penalty2, penalty3)); | ||
|
||
GetPenaltyListServiceDto dto = GetPenaltyListServiceDto.of(memberId); | ||
|
||
//when | ||
List<GetPenaltyListResponse> penaltyList = adminPenaltyService.getPenaltyList(dto); | ||
|
||
//then | ||
assertThat(penaltyList).hasSize(3) | ||
.extracting("reason", "level") | ||
.containsExactlyInAnyOrder( | ||
tuple(PenaltyReason.BROKEN, PenaltyLevel.BLACKLIST), | ||
tuple(PenaltyReason.BROKEN, PenaltyLevel.BLACKLIST), | ||
tuple(PenaltyReason.BROKEN, PenaltyLevel.BLACKLIST) | ||
); | ||
} | ||
|
||
private Member createMember() { | ||
return Member.of("1234", "name", "[email protected]", "password", "licenseId", | ||
"licensePassword", true, true, 1, MemberRole.USER, MemberState.ACTIVE); | ||
} | ||
|
||
private Penalty createPenalty(Member member) { | ||
return Penalty.of(member, BROKEN, BLACKLIST, null); | ||
} | ||
} |
Oops, something went wrong.