Skip to content

Commit

Permalink
feat : NO.10 메인홈 학과 학생회 공지 리스트로 주기
Browse files Browse the repository at this point in the history
  • Loading branch information
softmoca committed Jul 12, 2024
1 parent ff8b596 commit 700ed62
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sopt.univoice.domain.auth.dto.MemberCreateRequest;
import sopt.univoice.domain.auth.service.AuthService;
import sopt.univoice.domain.notice.dto.GetAllNoticesResponseDTO;
import sopt.univoice.domain.notice.dto.GetUniversityNoticesResponseDTO;
import sopt.univoice.domain.notice.dto.GetMainNoticesResponseDTO;
import sopt.univoice.domain.notice.dto.NoticeCreateRequest;
import sopt.univoice.domain.notice.dto.NoticeSaveDTO;
import sopt.univoice.domain.notice.entity.Notice;
import sopt.univoice.domain.notice.service.NoticeService;
import sopt.univoice.infra.common.dto.SuccessMessage;
import sopt.univoice.infra.common.dto.SuccessStatusResponse;
Expand Down Expand Up @@ -89,21 +86,28 @@ public ResponseEntity<SuccessStatusResponse<Object>> getAllNoticeByUserUniversit

@GetMapping("/university")
public ResponseEntity<SuccessStatusResponse<Object>> getUniversityNoticeByUserUniversity() {
GetUniversityNoticesResponseDTO response = noticeService.getUniversityNoticeByUserUniversity();
GetMainNoticesResponseDTO response = noticeService.getUniversityNoticeByUserUniversity();
return ResponseEntity.status(HttpStatus.OK)
.body(SuccessStatusResponse.of(SuccessMessage.GET_ALL_UNIVERSITY_NOTICE_SUCCESS, response));
}


@GetMapping("/college-department")
public ResponseEntity<SuccessStatusResponse<Object>> getCollegeDepartmentNoticeByUserUniversity() {
GetUniversityNoticesResponseDTO response = noticeService.getCollegeDepartmentNoticeByUserUniversity();
GetMainNoticesResponseDTO response = noticeService.getCollegeDepartmentNoticeByUserUniversity();


return ResponseEntity.status(HttpStatus.OK)
.body(SuccessStatusResponse.of(SuccessMessage.GET_ALL_COLLEGE_NOTICE_SUCCESS, response));
}

@GetMapping("/department")
public ResponseEntity<SuccessStatusResponse<Object>> getDepartmentNoticeByUserUniversity() {
GetMainNoticesResponseDTO response = noticeService.getDepartmentNoticeByUserUniversity();


return ResponseEntity.status(HttpStatus.OK)
.body(SuccessStatusResponse.of(SuccessMessage.GET_ALL_DEPARTMENT_SUCCESS, response));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class GetUniversityNoticesResponseDTO {
public class GetMainNoticesResponseDTO {
private QuickScanResponseDTO quickScans;
private List<NoticeResponseDTO> notices;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sopt.univoice.domain.notice.service;

import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -19,7 +18,6 @@

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -280,7 +278,7 @@ public GetAllNoticesResponseDTO getAllNoticeByUserUniversity() {
}

@Transactional
public GetUniversityNoticesResponseDTO getUniversityNoticeByUserUniversity() {
public GetMainNoticesResponseDTO getUniversityNoticeByUserUniversity() {
Long memberId = principalHandler.getUserIdFromPrincipal();

Member member = authRepository.findById(memberId)
Expand Down Expand Up @@ -315,7 +313,7 @@ public GetUniversityNoticesResponseDTO getUniversityNoticeByUserUniversity() {
departmentCount
);

return new GetUniversityNoticesResponseDTO(quickScans, noticeResponseDTOs);
return new GetMainNoticesResponseDTO(quickScans, noticeResponseDTOs);
}


Expand All @@ -324,7 +322,7 @@ public GetUniversityNoticesResponseDTO getUniversityNoticeByUserUniversity() {


@Transactional
public GetUniversityNoticesResponseDTO getCollegeDepartmentNoticeByUserUniversity() {
public GetMainNoticesResponseDTO getCollegeDepartmentNoticeByUserUniversity() {
Long memberId = principalHandler.getUserIdFromPrincipal();

Member member = authRepository.findById(memberId)
Expand Down Expand Up @@ -359,12 +357,49 @@ public GetUniversityNoticesResponseDTO getCollegeDepartmentNoticeByUserUniversit
departmentCount
);

return new GetUniversityNoticesResponseDTO(quickScans, noticeResponseDTOs);
return new GetMainNoticesResponseDTO(quickScans, noticeResponseDTOs);
}



@Transactional
public GetMainNoticesResponseDTO getDepartmentNoticeByUserUniversity() {
Long memberId = principalHandler.getUserIdFromPrincipal();

Member member = authRepository.findById(memberId)
.orElseThrow(() -> new IllegalArgumentException("Invalid member ID"));

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

long universityNameCount = noticeRepository.countByMemberUniversityNameAndMemberAffiliationAffiliation(universityName, "총학생회");
long collegeDepartmentCount = noticeRepository.countByMemberCollegeDepartmentNameAndMemberAffiliationAffiliation(collegeDepartmentName, "단과대학학생회");
long departmentCount = noticeRepository.countByMemberDepartmentNameAndMemberAffiliationAffiliation(departmentName, "과학생회");

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

List<NoticeResponseDTO> noticeResponseDTOs = universityNotices.stream().map(notice -> new NoticeResponseDTO(
notice.getId(),
notice.getStartTime(),
notice.getEndTime(),
notice.getTitle(),
notice.getNoticeLike(),
(long) notice.getSaveNotices().size(),
notice.getCategory()
)).collect(Collectors.toList());

QuickScanResponseDTO quickScans = new QuickScanResponseDTO(
universityName,
universityNameCount,
collegeDepartmentName,
collegeDepartmentCount,
departmentName,
departmentCount
);

return new GetMainNoticesResponseDTO(quickScans, noticeResponseDTOs);
}



Expand Down

0 comments on commit 700ed62

Please sign in to comment.