Skip to content

Commit

Permalink
REFACTORING : 마감 임박 게시글 반환 방식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseungL committed Aug 9, 2024
1 parent 3db7e1f commit 19ecc5d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public ResponseEntity<ApiResponse<PostTotalPagingResponse>> pagingSupportPost(
@RequestParam(defaultValue = "") List<String> category, // 카테고리
@RequestParam(defaultValue = "ing") String status
) {
// 응답에 이미지 포함 시키기
return ApiResponse.success(GET_SUPPORT_POST_PAGING_SUCCESS, supportService.pagingSupportPost(page-1, q, category, status));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SupportRecord extends BaseTimeEntity {
@Column(nullable = false)
private int amount;

@Column(name = "deleted_at") // 삭제 시각 저장
@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public interface SupportImageRepository extends JpaRepository<SupportImage, Long

default SupportImage findFirstImageBySupportPostIdOrDefault(Long supportPostId) {
List<SupportImage> images = findImagesBySupportPostId(supportPostId);
return images.isEmpty() ? null : images.get(0); // Get the first image or null if empty
return images.isEmpty() ? null : images.get(0);
}

// Soft Delete 시 한방 쿼리 용
@Modifying
@Query("UPDATE SupportImage si SET si.deletedAt = :deletedAt WHERE si.id IN (:ids)")
void softDeleteByIds(@Param("ids") List<Long> ids, @Param("deletedAt") LocalDateTime deletedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import java.util.Optional;

public interface SupportPostRepository extends JpaRepository<SupportPost, Long> {
/**
* 한방 쿼리: Fetch Join
*/
@Query("SELECT s FROM SupportPost s " +
"JOIN FETCH s.member m " +
"LEFT JOIN FETCH s.images i " +
Expand Down Expand Up @@ -51,11 +48,6 @@ Page<SupportPost> findByCategoryAndSearchAndSupportPostStatusWithImages(@Param("
"ORDER BY sp.expirationDate ASC")
List<SupportPost> findByExpirationDateWithinSevenDays(@Param("pending") SupportPostStatus pending, @Param("inProgress") SupportPostStatus inProgress);



// IN 절보다 AND
// List<SupportPost> findAllBySupportPostStatusIn(List<SupportPostStatus> statuses);
// JPQL을 사용하여 PENDING 또는 IN_PROGRESS 상태의 SupportPost를 찾는 메서드
@Query("SELECT sp FROM SupportPost sp WHERE sp.supportPostStatus = com.fledge.fledgeserver.support.entity.SupportPostStatus.PENDING " +
"OR sp.supportPostStatus = com.fledge.fledgeserver.support.entity.SupportPostStatus.IN_PROGRESS")
List<SupportPost> findAllBySupportPostStatusOr();
Expand Down

0 comments on commit 19ecc5d

Please sign in to comment.