From 14ef110d6de6c38c4892473a45a2da7b8af15468 Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Sat, 16 Sep 2023 20:39:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?docs:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=8D=94=EB=AF=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/import.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/import.sql b/src/main/resources/import.sql index c881458..5bb0d6b 100644 --- a/src/main/resources/import.sql +++ b/src/main/resources/import.sql @@ -54,7 +54,7 @@ INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modif INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(3, '의정부 튼튼어린이병원, 심질환 환아 감시 하이카디플러스 도입', '내용', 0, null, 'NEWS', '2023-08-20', '2023-08-20'); INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(4, '[2023.09.17 마감] 하이카디 체험단 모집', '내용', 1, '첨부파일', 'NECESSARY', '2023-09-08', '2023-09-08'); INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(5, '하이카디 갤럭시A13 연동 방법', '내용', 0, '첨부파일', 'DATA', '2023-09-08', '2023-09-08'); -INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(6, '[2023.09.15 마감] 하이카디플러스 소개 및 설명회 참여 인원 모집', '내용', 1, 'https://hicardi.s3.ap-northeast-2.amazonaws.com/notice1.svg', 'NECESSARY', '2023-09-09', '2023-09-09'); +INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(6, '[2023.09.15 마감] 하이카디플러스 소개 및 설명회 참여 인원 모집', 'https://hicardi.s3.ap-northeast-2.amazonaws.com/notice1.svg' , 1, 'hicardi_seminar.jpg(1.8MB)', 'NECESSARY', '2023-09-09', '2023-09-09'); INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(7, '하이카디 패치 사용법', '내용', 0, '첨부파일', 'DATA', '2023-09-09', '2023-09-09'); INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(8, '하이카디 갤럭시A13 연동 방법', '내용', 0, '첨부파일', 'DATA', '2023-09-09', '2023-09-09'); INSERT INTO Notice(id, title, content, istop, file, category, createdDate, modifiedDate) VALUES(9, '하이카디 패치 사용법', '내용', 0, '첨부파일', 'DATA', '2023-09-10', '2023-09-10'); From 1992c82e2e81b1353b792e6cfed285b2c5c73d59 Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Sat, 16 Sep 2023 20:39:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notice/dto/response/NoticeGetResponseDto.java | 4 ++-- .../java/com/teamA/hicardi/domain/notice/entity/Notice.java | 3 +++ .../hicardi/domain/notice/repository/NoticeRepository.java | 4 ++++ .../teamA/hicardi/domain/notice/service/NoticeService.java | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/teamA/hicardi/domain/notice/dto/response/NoticeGetResponseDto.java b/src/main/java/com/teamA/hicardi/domain/notice/dto/response/NoticeGetResponseDto.java index 15680ef..5741a98 100644 --- a/src/main/java/com/teamA/hicardi/domain/notice/dto/response/NoticeGetResponseDto.java +++ b/src/main/java/com/teamA/hicardi/domain/notice/dto/response/NoticeGetResponseDto.java @@ -4,9 +4,9 @@ import com.teamA.hicardi.domain.notice.entity.Notice; -public record NoticeGetResponseDto(Long id, String category, String title, String content, String file, Boolean isTop, LocalDate createdDate) { +public record NoticeGetResponseDto(Long id, String category, String title, String content, String file, Boolean isTop, LocalDate createdDate, int views) { public static NoticeGetResponseDto from(Notice notice) { - return new NoticeGetResponseDto(notice.getId(), notice.getCategory().getDesc(), notice.getTitle(), notice.getContent(), notice.getFile(), notice.getIsTop(), notice.getCreatedDate().toLocalDate()); + return new NoticeGetResponseDto(notice.getId(), notice.getCategory().getDesc(), notice.getTitle(), notice.getContent(), notice.getFile(), notice.getIsTop(), notice.getCreatedDate().toLocalDate(), notice.getViews()); } } diff --git a/src/main/java/com/teamA/hicardi/domain/notice/entity/Notice.java b/src/main/java/com/teamA/hicardi/domain/notice/entity/Notice.java index 534e0b4..82fe84d 100644 --- a/src/main/java/com/teamA/hicardi/domain/notice/entity/Notice.java +++ b/src/main/java/com/teamA/hicardi/domain/notice/entity/Notice.java @@ -29,4 +29,7 @@ public class Notice extends BaseTimeEntity { @Enumerated(EnumType.STRING) private NoticeCategory category; + @Column(columnDefinition = "Integer default 1") + private int views; + } diff --git a/src/main/java/com/teamA/hicardi/domain/notice/repository/NoticeRepository.java b/src/main/java/com/teamA/hicardi/domain/notice/repository/NoticeRepository.java index f256d98..de83d17 100644 --- a/src/main/java/com/teamA/hicardi/domain/notice/repository/NoticeRepository.java +++ b/src/main/java/com/teamA/hicardi/domain/notice/repository/NoticeRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import com.teamA.hicardi.domain.notice.entity.Notice; import com.teamA.hicardi.domain.notice.entity.NoticeCategory; @@ -27,4 +28,7 @@ public interface NoticeRepository extends JpaRepository { @Query("SELECT n FROM Notice n WHERE n.id > :noticeId ORDER BY n.id LIMIT 1") Notice findNextNotice(@Param("noticeId") Long noticeId); + @Modifying + @Query("update Notice n set n.views = n.views + 1 where n.id = :noticeId") + void updateView(@Param("noticeId") Long noticeId); } diff --git a/src/main/java/com/teamA/hicardi/domain/notice/service/NoticeService.java b/src/main/java/com/teamA/hicardi/domain/notice/service/NoticeService.java index 4ea1b94..0a20b21 100644 --- a/src/main/java/com/teamA/hicardi/domain/notice/service/NoticeService.java +++ b/src/main/java/com/teamA/hicardi/domain/notice/service/NoticeService.java @@ -48,6 +48,8 @@ public List getNotice(Long noticeId) { Notice notice = noticeRepository.findById(noticeId) .orElseThrow(() -> new BusinessException(ErrorCode.NOTICE_NOT_FOUND)); + noticeRepository.updateView(noticeId); + Notice previousNotice = noticeRepository.findPreviousNotice(noticeId); Notice nextNotice = noticeRepository.findNextNotice(noticeId);