Skip to content

공지/새소식 조회 기능 구현 #113

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

Merged
merged 3 commits into from
Apr 13, 2025
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
@@ -1,6 +1,7 @@
package com.clip.api.display.controller;

import com.clip.api.display.controller.dto.BannerInfoDto;
import com.clip.api.display.controller.dto.NoticeInfoDto;
import com.clip.api.display.service.DisplayInfoService;
import com.clip.api.docs.display.DisplayInfoDocs;
import com.clip.notice.entity.BannerType;
Expand All @@ -18,4 +19,9 @@ public class DisplayInfoController implements DisplayInfoDocs {
public List<BannerInfoDto> getBanners(final BannerType bannerType) {
return displayInfoService.getBanners(bannerType);
}

@Override
public List<NoticeInfoDto> getNotices() {
return displayInfoService.getNotices();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.clip.api.display.controller.dto;

import com.clip.notice.entity.NoticeType;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class NoticeInfoDto {
private NoticeType noticeType;
private String content;
private String link;

@Builder
public NoticeInfoDto(NoticeType noticeType, String content, String link) {
this.noticeType = noticeType;
this.content = content;
this.link = link;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.clip.api.display.service;

import com.clip.api.display.controller.dto.BannerInfoDto;
import com.clip.api.display.controller.dto.NoticeInfoDto;
import com.clip.infra.aws.s3.S3ImgService;
import com.clip.notice.entity.Banner;
import com.clip.notice.entity.BannerType;
import com.clip.notice.service.BannerDataService;
import com.clip.notice.service.NoticeDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -14,6 +16,7 @@
@RequiredArgsConstructor
public class DisplayInfoService {
private final BannerDataService bannerDataService;
private final NoticeDataService noticeDataService;
private final S3ImgService s3ImgService;

public List<BannerInfoDto> getBanners(final BannerType bannerType) {
Expand All @@ -27,4 +30,14 @@ public List<BannerInfoDto> getBanners(final BannerType bannerType) {
.toList();
}

public List<NoticeInfoDto> getNotices() {
return noticeDataService.findNotices().stream()
.map(notice -> NoticeInfoDto.builder()
.noticeType(notice.getNoticeType())
.content(notice.getContent())
.link(notice.getLink())
.build())
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clip.api.docs.display;

import com.clip.api.display.controller.dto.BannerInfoDto;
import com.clip.api.display.controller.dto.NoticeInfoDto;
import com.clip.notice.entity.BannerType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -35,5 +36,23 @@ public interface DisplayInfoDocs {
@GetMapping("/banners/{bannerType}")
List<BannerInfoDto> getBanners(@PathVariable final BannerType bannerType);

@Operation(
summary = "공지/새소식 조회 API",
description = """
- 홈화면 스낵바에 있는 공지/새소식 조회 API입니다.
- 공지/새소식은 NOTICE, ARTICLE 으로 구분됩니다.
"""
)
@ApiResponse(
responseCode = "200",
description = "조회 성공",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = NoticeInfoDto.class)
)
)
@GetMapping("/notices")
List<NoticeInfoDto> getNotices();


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface NoticeRepository extends JpaRepository<Notice, Long> {
Expand All @@ -19,4 +21,13 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {
@Query("select n from Notice n where n.id = :noticeId")
Optional<Notice> findNotice(Long noticeId);

@Query("""
select n from Notice n
where n.exposureDate <= :exposureDate
and n.isExposure = true
order by n.exposureDate desc
limit 3
""")
List<Notice> findAllNotices(@Param("exposureDate") LocalDate exposureDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
@RequiredArgsConstructor
public class NoticeDataService {
Expand All @@ -24,4 +27,8 @@ public Notice save(Notice notice) {
public void deleteNotice(Long noticeId) {
noticeRepository.deleteNotice(noticeId);
}

public List<Notice> findNotices() {
return noticeRepository.findAllNotices(LocalDate.now());
}
}