Skip to content

Commit

Permalink
♻️ refactor: 공고 조회, 공고 카테고리 조회 수정 (#186)
Browse files Browse the repository at this point in the history
* ♻️ refactor: 공고 조회 Response에 조직 태그 추가

* ♻️ refactor: 공고 카테고리 조회 steam.sort처리 -> JPA 로 변경
  • Loading branch information
seheonnn authored Feb 13, 2024
1 parent 1ecc95e commit b0624dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementCategory;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementStatus;
import com.sponus.sponusbe.domain.announcement.entity.enums.AnnouncementType;
import com.sponus.sponusbe.domain.organization.dto.OrganizationSummaryResponse;

import lombok.Builder;

@Builder
public record AnnouncementDetailResponse(
Long id,
Long writerId,
OrganizationSummaryResponse writer,
String title,
AnnouncementType type,
AnnouncementCategory category,
Expand All @@ -27,9 +28,11 @@ public static AnnouncementDetailResponse from(Announcement announcement) {
.map(AnnouncementImageResponse::from)
.toList();

OrganizationSummaryResponse writer = OrganizationSummaryResponse.from(announcement.getWriter());

return AnnouncementDetailResponse.builder()
.id(announcement.getId())
.writerId(announcement.getWriter().getId())
.writer(writer)
.title(announcement.getTitle())
.type(announcement.getType())
.category(announcement.getCategory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public interface AnnouncementRepository extends JpaRepository<Announcement, Long

List<Announcement> findByStatus(AnnouncementStatus status);

List<Announcement> findByCategoryAndType(AnnouncementCategory category, AnnouncementType type);
List<Announcement> findByCategoryAndTypeOrderByCreatedAtDesc(AnnouncementCategory category, AnnouncementType type);

List<Announcement> findByCategory(AnnouncementCategory category);
List<Announcement> findByCategoryOrderByCreatedAtDesc(AnnouncementCategory category);

List<Announcement> findByType(AnnouncementType type);
List<Announcement> findByTypeOrderByCreatedAtDesc(AnnouncementType type);

@Query("SELECT a FROM Announcement a WHERE a.status='OPENED' ORDER BY a.viewCount DESC LIMIT 10")
List<Announcement> findTop10OrderByViewCountDesc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,26 @@ public List<AnnouncementSummaryResponse> getAnnouncementByCategory(AnnouncementC
// 둘 다 값이 있는 경우
if (category != null && type != null) {
log.info("category & type");
return announcementRepository.findByCategoryAndType(category, type)
return announcementRepository.findByCategoryAndTypeOrderByCreatedAtDesc(category, type)
.stream()
.filter(announcement -> announcement.getStatus() == AnnouncementStatus.OPENED)
.map(AnnouncementSummaryResponse::from)
.sorted(Comparator.comparing(AnnouncementSummaryResponse::getCreatedAt).reversed())
.toList();
}
// category 만 있는 경우
else if (category != null) {
return announcementRepository.findByCategory(category)
return announcementRepository.findByCategoryOrderByCreatedAtDesc(category)
.stream()
.filter(announcement -> announcement.getStatus() == AnnouncementStatus.OPENED)
.map(AnnouncementSummaryResponse::from)
.sorted(Comparator.comparing(AnnouncementSummaryResponse::getCreatedAt).reversed())
.toList();
}
// type 만 있는 경우
else if (type != null) {
return announcementRepository.findByType(type)
return announcementRepository.findByTypeOrderByCreatedAtDesc(type)
.stream()
.filter(announcement -> announcement.getStatus() == AnnouncementStatus.OPENED)
.map(AnnouncementSummaryResponse::from)
.sorted(Comparator.comparing(AnnouncementSummaryResponse::getCreatedAt).reversed())
.toList();
}
// 둘 다 값이 없는 경우, 전체 announcement 반환
Expand Down

0 comments on commit b0624dc

Please sign in to comment.