Skip to content
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

[Refactor] 공지사항 상세 페이지 내용과 파일 응답 수정 #75

Merged
merged 2 commits into from
Sep 16, 2023
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
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ public class Notice extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private NoticeCategory category;

@Column(columnDefinition = "Integer default 1")
private int views;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,4 +28,7 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {
@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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public List<NoticeGetResponseDto> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading