Skip to content

Commit e429a00

Browse files
Merge pull request #612 from Podo-Store/develop
[FIX] 공연 소식 api 수정
2 parents b5c529a + 9d23604 commit e429a00

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/main/java/PodoeMarket/podoemarket/common/repository/PerformanceRepository.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public interface PerformanceRepository extends JpaRepository<PerformanceEntity,L
1919
SELECT p FROM PerformanceEntity p
2020
WHERE p.startDate <= :today
2121
AND p.endDate >= :today
22-
AND (:isUsed IS NULL OR p.isUsed = :isUsed)
22+
AND (
23+
(:isUsed = true AND p.isUsed = true)
24+
OR (:isUsed = false)
25+
OR (:isUsed IS NULL)
26+
)
2327
ORDER BY p.startDate DESC
2428
""")
2529
Page<PerformanceEntity> findOngoing(
@@ -31,7 +35,11 @@ Page<PerformanceEntity> findOngoing(
3135
@Query("""
3236
SELECT p FROM PerformanceEntity p
3337
WHERE p.startDate > :today
34-
AND (:isUsed IS NULL OR p.isUsed = :isUsed)
38+
AND (
39+
(:isUsed = true AND p.isUsed = true)
40+
OR (:isUsed = false)
41+
OR (:isUsed IS NULL)
42+
)
3543
ORDER BY p.startDate DESC
3644
""")
3745
Page<PerformanceEntity> findUpcoming(
@@ -43,7 +51,11 @@ Page<PerformanceEntity> findUpcoming(
4351
@Query("""
4452
SELECT p FROM PerformanceEntity p
4553
WHERE p.endDate < :today
46-
AND (:isUsed IS NULL OR p.isUsed = :isUsed)
54+
AND (
55+
(:isUsed = true AND p.isUsed = true)
56+
OR (:isUsed = false)
57+
OR (:isUsed IS NULL)
58+
)
4759
ORDER BY p.startDate DESC
4860
""")
4961
Page<PerformanceEntity> findPast(

src/main/java/PodoeMarket/podoemarket/performance/controller/PerformanceController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ public ResponseEntity<?> getPastPerformanceMain(@AuthenticationPrincipal UserEnt
118118
}
119119

120120
@GetMapping("/")
121-
public ResponseEntity<?> getPerformanceList(@RequestParam PerformanceStatus status,
121+
public ResponseEntity<?> getPerformanceList(@AuthenticationPrincipal UserEntity userInfo,
122+
@RequestParam PerformanceStatus status,
122123
@RequestParam(required = false) Boolean isUsed,
123124
@RequestParam(value = "page", defaultValue = "0") int page) {
124125
try {
125-
final List<PerformanceStatusResponseDTO.PerformanceListDTO> resDTO = performanceService.getPerformanceList(status, isUsed, page, 20).getContent();
126+
final List<PerformanceStatusResponseDTO.PerformanceListDTO> resDTO = performanceService.getPerformanceList(userInfo, status, isUsed, page, 20).getContent();
126127

127128
return ResponseEntity.ok().body(resDTO);
128129
} catch (Exception e) {

src/main/java/PodoeMarket/podoemarket/performance/dto/response/PerformanceStatusResponseDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ public static class PerformanceListDTO {
3030
private LocalDate startDate;
3131
private LocalDate endDate;
3232
private Boolean isUsed;
33+
private Boolean isOwner;
34+
private String link;
3335
}
3436
}

src/main/java/PodoeMarket/podoemarket/performance/service/PerformanceService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public List<PerformanceMainResponseDTO> getStatusPerformanceMain(PerformanceStat
215215
}
216216
}
217217

218-
public Page<PerformanceStatusResponseDTO.PerformanceListDTO> getPerformanceList(PerformanceStatus status, Boolean isUsed, int page, int pageSize) {
218+
public Page<PerformanceStatusResponseDTO.PerformanceListDTO> getPerformanceList(UserEntity userInfo, PerformanceStatus status, Boolean isUsed, int page, int pageSize) {
219219
try {
220220
LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul"));
221221
Pageable pageable = PageRequest.of(page, pageSize, Sort.by("startDate").descending());
@@ -234,7 +234,7 @@ public Page<PerformanceStatusResponseDTO.PerformanceListDTO> getPerformanceList(
234234
default -> throw new IllegalArgumentException("잘못된 공연 상태입니다.");
235235
}
236236

237-
return result.map(this::getStatusListDTO);
237+
return result.map(p -> getStatusListDTO(p, userInfo));
238238
} catch (Exception e) {
239239
throw e;
240240
}
@@ -364,11 +364,13 @@ private PerformanceMainResponseDTO getMainStatusListDTO(PerformanceEntity perfor
364364
.build();
365365
}
366366

367-
private PerformanceStatusResponseDTO.PerformanceListDTO getStatusListDTO(PerformanceEntity p) {
367+
private PerformanceStatusResponseDTO.PerformanceListDTO getStatusListDTO(PerformanceEntity p, UserEntity userInfo) {
368368
String posterPath = p.getPosterPath() != null
369369
? bucketURL + URLEncoder.encode(p.getPosterPath(), StandardCharsets.UTF_8)
370370
: "";
371371

372+
boolean isOwner = userInfo != null && p.getUser() != null && p.getUser().getId().equals(userInfo.getId());
373+
372374
return PerformanceStatusResponseDTO.PerformanceListDTO.builder()
373375
.id(p.getId())
374376
.posterPath(posterPath)
@@ -377,6 +379,8 @@ private PerformanceStatusResponseDTO.PerformanceListDTO getStatusListDTO(Perform
377379
.startDate(p.getStartDate())
378380
.endDate(p.getEndDate())
379381
.isUsed(p.getIsUsed())
382+
.isOwner(isOwner)
383+
.link(p.getLink())
380384
.build();
381385
}
382386
}

0 commit comments

Comments
 (0)