Skip to content

Commit c34364b

Browse files
authored
Dev > Main 브랜치 병합
1. 프로젝트 상세 조회시 조회수를 1씩 증가하는 기능 구현 후 통합테스트 실행하였습니다. 2. 공지사항 조회시 조회수를 1씩 증가하는 기능 구현 후 통합테스트 실행하였습니다.
2 parents dc0468b + 3f7404d commit c34364b

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

src/main/java/hs/kr/backend/devpals/domain/notice/entity/NoticeEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public void update(String title, String content) {
3737
this.content = content;
3838
}
3939

40+
public void increaseViewCount() { this.viewCount++;}
41+
4042
public static NoticeEntity fromDTO(NoticeDTO noticeDto) {
4143
return NoticeEntity.builder()
4244
.id(noticeDto.getId())

src/main/java/hs/kr/backend/devpals/domain/notice/service/NoticeService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ public ResponseEntity<ApiResponse<NoticeListResponse>> getNotices(String keyword
6464
return ResponseEntity.ok(new ApiResponse<>(true, "공지사항 전체 목록 가져오기 성공", response));
6565
}
6666

67-
@Transactional(readOnly = true)
67+
@Transactional
6868
public ResponseEntity<ApiResponse<NoticeDetailResponse>> getNotice(Long noticeId) {
6969
NoticeEntity notice = noticeRepository.findById(noticeId).orElse(null);
7070
if (notice == null) {
7171
return ResponseEntity.ok(new ApiResponse<>(false, "공지사항글이 존재하지 않습니다", null));
7272
}
7373

74+
notice.increaseViewCount();
75+
7476
Optional<NoticeEntity> prev = noticeRepository.findFirstByIdLessThanOrderByIdDesc(noticeId);
7577
Optional<NoticeEntity> next = noticeRepository.findFirstByIdGreaterThanOrderByIdAsc(noticeId);
7678

src/main/java/hs/kr/backend/devpals/domain/project/controller/ProjectController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ public ResponseEntity<ApiResponse<ProjectAllDto>> createProject(
137137
)
138138
public ResponseEntity<ApiResponse<ProjectAllDto>> getProjectList(
139139
@PathVariable Long projectId) {
140-
return projectService.getProjectList(projectId);
140+
return projectService.getProjectDetail(projectId);
141141
}
142142
}

src/main/java/hs/kr/backend/devpals/domain/project/entity/ProjectEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ public void updateIsDone(boolean isDone) {
135135
public void increaseWarning() {
136136
this.warning++;
137137
}
138+
139+
public void increaseView() {this.views++;}
138140
}

src/main/java/hs/kr/backend/devpals/domain/project/service/ProjectService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,17 @@ public ResponseEntity<ApiResponse<ProjectAllDto>> projectSignup(ProjectAllDto re
142142

143143
// 특정 프로젝트 조회
144144
@Transactional
145-
public ResponseEntity<ApiResponse<ProjectAllDto>> getProjectList(Long projectId) {
146-
ProjectAllDto project = projectAllCache.get(projectId);
147-
if (project == null) {
148-
throw new CustomException(ErrorException.PROJECT_NOT_FOUND);
149-
}
150-
return ResponseEntity.ok(new ApiResponse<>(true, "프로젝트 상세 내용조회 성공", project));
145+
public ResponseEntity<ApiResponse<ProjectAllDto>> getProjectDetail(Long projectId) {
146+
ProjectEntity project = projectRepository.findById(projectId)
147+
.orElseThrow(() -> new CustomException(ErrorException.PROJECT_NOT_FOUND));
148+
149+
project.increaseView();
150+
151+
ProjectAllDto dto = convertToDto(project);
152+
153+
projectAllCache.put(projectId, dto);
154+
155+
return ResponseEntity.ok(new ApiResponse<>(true, "프로젝트 상세 정보입니다.", dto));
151156
}
152157

153158
public ResponseEntity<ApiResponse<List<ProjectAuthoredResponse>>> getMyProject(String token) {

0 commit comments

Comments
 (0)