Skip to content

Commit

Permalink
[FIX] response수정 및 총 학생회, 단과 대학, 학과 학생회 별 조회될 수 있도록 수정 #31
Browse files Browse the repository at this point in the history
  • Loading branch information
eeddiinn committed Jul 14, 2024
1 parent 14eecb5 commit 52cfbdb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
@AllArgsConstructor
public class NoticeResponseDTO {
private Long id;
private LocalDateTime startTime;
private LocalDateTime endTime;
private LocalDateTime createdAt;
private String title;
private Long likeCount;
private Long saveCount;
private Long viewCount;
private String category;
private String image;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {

@Query("SELECT n FROM Notice n WHERE n.member.universityName = :universityName AND n.member.affiliation.affiliation = :affiliation")
List<Notice> findByMemberUniversityNameAndAffiliationAffiliation(String universityName, String affiliation);

List<Notice> findByMemberUniversityNameAndMemberCollegeDepartmentNameAndMemberAffiliationAffiliation(String universityName, String collegeDepartmentName, String affiliation);

List<Notice> findByMemberUniversityNameAndMemberCollegeDepartmentNameAndMemberDepartmentNameAndMemberAffiliationAffiliation(String universityName, String collegeDepartmentName, String departmentName, String affiliation);
}


Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ public List<NoticeDTO> getUniversityNoticeByUserUniversity() {

String universityName = member.getUniversityName();

List<Notice> universityNotices = noticeRepository.findByMemberUniversityNameAndMemberAffiliationAffiliation(universityName, "총학생회");
List<Notice> universityNotices = noticeRepository.findByMemberUniversityNameAndMemberAffiliationAffiliation(universityName, "총 학생회");
// 최신순 정렬
universityNotices.sort(Comparator.comparing(Notice::getCreatedAt).reversed());

List<NoticeDTO> noticeResponseDTOs = new ArrayList<>();
for (Notice notice : universityNotices) {
Expand All @@ -424,7 +426,7 @@ public List<NoticeDTO> getUniversityNoticeByUserUniversity() {
notice.getNoticeLike(),
notice.getViewCount(),
notice.getCategory(),
image // assuming category is an enum or string
image
);
noticeResponseDTOs.add(noticeDTO);
}
Expand All @@ -442,21 +444,25 @@ public List<NoticeResponseDTO> getCollegeDepartmentNoticeByUserUniversity() {
.orElseThrow(() -> new IllegalArgumentException("Invalid member ID"));

String universityName = member.getUniversityName();
String collegeDepartmentName = member.getCollegeDepartmentName();

List<Notice> universityNotices = noticeRepository.findByMemberUniversityNameAndMemberAffiliationAffiliation(universityName, "단과대학학생회");
List<Notice> universityNotices = noticeRepository.findByMemberUniversityNameAndMemberCollegeDepartmentNameAndMemberAffiliationAffiliation(universityName, collegeDepartmentName, "단과대학 학생회");

// 최신순 정렬
universityNotices.sort(Comparator.comparing(Notice::getCreatedAt).reversed());

List<NoticeResponseDTO> noticeResponseDTOs = universityNotices.stream().map(notice -> new NoticeResponseDTO(
List<NoticeResponseDTO> noticeResponseDTOs = universityNotices.stream().map(notice -> {
String image = notice.getNoticeImages().isEmpty() ? null : notice.getNoticeImages().get(0).getNoticeImage();
return new NoticeResponseDTO(
notice.getId(),
notice.getStartTime(),
notice.getEndTime(),
notice.getCreatedAt(),
notice.getTitle(),
notice.getNoticeLike(),
(long) notice.getSaveNotices().size(),
notice.getCategory()
)).collect(Collectors.toList());



notice.getViewCount(),
notice.getCategory(),
image
);
}).collect(Collectors.toList());
return noticeResponseDTOs;
}

Expand All @@ -468,22 +474,27 @@ public List<NoticeResponseDTO> getDepartmentNoticeByUserUniversity() {
.orElseThrow(() -> new IllegalArgumentException("Invalid member ID"));

String universityName = member.getUniversityName();
String collegeDepartmentName = member.getCollegeDepartmentName();
String departmentName = member.getDepartmentName();

List<Notice> universityNotices = noticeRepository.findByMemberUniversityNameAndMemberAffiliationAffiliation(universityName, "과학생회");
List<Notice> departmentNotices = noticeRepository.findByMemberUniversityNameAndMemberCollegeDepartmentNameAndMemberDepartmentNameAndMemberAffiliationAffiliation(universityName, collegeDepartmentName, departmentName, "학과 학생회");

List<NoticeResponseDTO> noticeResponseDTOs = universityNotices.stream().map(notice -> new NoticeResponseDTO(
// 최신순 정렬
departmentNotices.sort(Comparator.comparing(Notice::getCreatedAt).reversed());

List<NoticeResponseDTO> noticeResponseDTOs = departmentNotices.stream().map(notice -> {
String image = notice.getNoticeImages().isEmpty() ? null : notice.getNoticeImages().get(0).getNoticeImage();
return new NoticeResponseDTO(
notice.getId(),
notice.getStartTime(),
notice.getEndTime(),
notice.getCreatedAt(),
notice.getTitle(),
notice.getNoticeLike(),
(long) notice.getSaveNotices().size(),
notice.getCategory()
)).collect(Collectors.toList());



return noticeResponseDTOs;
notice.getViewCount(),
notice.getCategory(),
image
);
}).collect(Collectors.toList());
return noticeResponseDTOs;
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit 52cfbdb

Please sign in to comment.