Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor: 공고 조회, 공고 카테고리 조회 수정 #186

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading