Skip to content

Commit

Permalink
feat : get news notice number api
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Nov 12, 2024
1 parent fc0084c commit eef9586
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wable.www.WableServer.api.notification.controller;

import com.wable.www.WableServer.api.comment.dto.request.CommentPostRequestDto;
import com.wable.www.WableServer.api.notification.dto.response.NewsNoticeCountResponseDto;
import com.wable.www.WableServer.api.notification.service.InfoNotificationCommandService;
import com.wable.www.WableServer.api.notification.service.InfoNotificationQueryService;
import com.wable.www.WableServer.common.response.ApiResponse;
Expand Down Expand Up @@ -55,4 +56,11 @@ public ResponseEntity<ApiResponse<Object>> postWeekDoneInfoNotification() {
infoNotificationCommandService.postWeekDoneInfoNotification();
return ApiResponse.success(POST_WEEKDONE_INFONOTIFICATION_SUCCESS);
}

@GetMapping("information/number")
@Operation(summary = "뉴스와 공지사항 개수 반환 API", description = "NewsNoticeNumber")
public ResponseEntity<ApiResponse<NewsNoticeCountResponseDto>> getNewsNoticeNumber() {
return ApiResponse.success(NEWS_NOTICE_NUMBER_SUCCESS, infoNotificationQueryService.getNewsNoticeNumber());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wable.www.WableServer.api.notification.dto.response;

public record NewsNoticeCountResponseDto(
int newsNumber,
int noticeNumber
) {
public static NewsNoticeCountResponseDto of(int newsNumber, int noticeNumber) {
return new NewsNoticeCountResponseDto(
newsNumber,
noticeNumber
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.wable.www.WableServer.api.member.repository.MemberRepository;
import com.wable.www.WableServer.api.notification.domain.InfoNotification;
import com.wable.www.WableServer.api.notification.dto.response.InfoNotificationAllResponseDto;
import com.wable.www.WableServer.api.notification.dto.response.NewsNoticeCountResponseDto;
import com.wable.www.WableServer.api.notification.repository.InfoNotificationRepository;
import com.wable.www.WableServer.api.notification.repository.NewsRepository;
import com.wable.www.WableServer.api.notification.repository.NoticeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
Expand All @@ -24,6 +27,8 @@ public class InfoNotificationQueryService {

private final InfoNotificationRepository infoNotificationRepository;
private final MemberRepository memberRepository;
private final NewsRepository newsRepository;
private final NoticeRepository noticeRepository;

public List<InfoNotificationAllResponseDto> getInfoNotifications(Long memberId, Long cursor) {
Member member = memberRepository.findMemberByIdOrThrow(memberId);
Expand All @@ -43,4 +48,10 @@ public List<InfoNotificationAllResponseDto> getInfoNotifications(Long memberId,
)).collect(Collectors.toList());
}

public NewsNoticeCountResponseDto getNewsNoticeNumber() {
int newsNumber = (int) newsRepository.count();
int noticeNumber = (int) noticeRepository.count();

return NewsNoticeCountResponseDto.of(newsNumber, noticeNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public enum SuccessStatus {
POST_WEEKDONE_INFONOTIFICATION_SUCCESS(HttpStatus.CREATED,"한 주 종료 정보 노티 생성 완료"),
NEWS_ALL_SUCCESS(HttpStatus.OK, "뉴스 목록 조회 성공"),
NOTICE_ALL_SUCCESS(HttpStatus.OK, "공지사항 목록 조회 성공"),

NEWS_NOTICE_NUMBER_SUCCESS(HttpStatus.OK, "뉴스, 공지사항 개수 조회 성공"),
/**
* report
*/
Expand Down

0 comments on commit eef9586

Please sign in to comment.