Skip to content

Commit

Permalink
Merge pull request #20 from Ha-dam/feat/19-diaryDetail
Browse files Browse the repository at this point in the history
feat: diary details inquiry API
  • Loading branch information
ziiyouth authored Dec 11, 2023
2 parents 239de94 + 92b085a commit 6e1dbfb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/hadam/hadam/controller/DiaryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ public ResponseEntity<BaseResponse<?>> getMonthlyAllDiaryOld(@RequestParam Long
.body(BaseResponse.of(SuccessCode.OK, diaryService.getMonthlyAllDiaryOld(memberId, year, month)));
}

@GetMapping("/detail/{diaryId}")
public ResponseEntity<BaseResponse<?>> detailDiary(@PathVariable Long diaryId){
return ResponseEntity.status(HttpStatus.OK)
.body(BaseResponse.of(SuccessCode.OK, diaryService.getDetailDiary(diaryId)));
}

}
12 changes: 12 additions & 0 deletions src/main/java/com/hadam/hadam/dto/response/DiaryDetailRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hadam.hadam.dto.response;

public record DiaryDetailRes(
Long id,
String img,
String title,
String date,
String content,
boolean liked

) {
}
19 changes: 15 additions & 4 deletions src/main/java/com/hadam/hadam/service/DiaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.hadam.hadam.domain.DiaryInfo;
import com.hadam.hadam.domain.Member;
import com.hadam.hadam.dto.request.UpdateDiaryReq;
import com.hadam.hadam.dto.response.DiaryDetailRes;
import com.hadam.hadam.dto.response.MonthlyListReq;
import com.hadam.hadam.dto.response.MonthlyRepresentRes;
import com.hadam.hadam.global.error.exception.EntityNotFoundException;
Expand All @@ -16,9 +17,6 @@
import java.util.stream.Collectors;
import java.util.Comparator;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -121,7 +119,6 @@ public List<MonthlyListReq> getMonthlyAllDiaryOld(Long memberId, int year, int m
.collect(Collectors.toList());
}

// TODO : 제목 넣을지에 따라 수정
private String truncateContent(String content) {
int maxLength = 15;
if (content.length() > maxLength) {
Expand All @@ -130,5 +127,19 @@ private String truncateContent(String content) {
return content;
}

@Transactional(readOnly = true)
public DiaryDetailRes getDetailDiary(Long diaryId){
Diary diary = diaryRepository.findByIdOrThrow(diaryId);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy. MM. dd. HH:mm");
return new DiaryDetailRes(
diary.getId(),
diary.getImg(),
diary.getTitle(),
diary.getDate().format(formatter),
diary.getContent(),
diary.isLiked()
);
}


}

0 comments on commit 6e1dbfb

Please sign in to comment.