Skip to content

Commit

Permalink
refactor: change memo and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO committed Nov 11, 2024
1 parent 5a0248e commit fbd9786
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public ResponseEntity<DailyResponseResponse> getOneResponseOfDailyQuestion(@Requ
return ResponseEntity.ok().body(dailyResponseResponse);
}

@Operation(summary = "본인이 모든 답변 조회", description = "본인이 작성한 모든 답변을 조회합니다.")
@GetMapping("/response/{localDate}")
@Operation(summary = "날짜별 본인이 모든 답변 조회", description = "localDate에 본인이 작성한 모든 답변을 조회합니다.")
@GetMapping("/response/all/{localDate}")
public ResponseEntity<List<DailyResponseResponse>> getAllResponseOfDailyQuestion(@RequestAttribute("memberId") Long memberId, @PathVariable("localDate") LocalDate localDate) {
List<DailyResponseResponse> dailyResponseResponses = dailyResponseService.getAllResponseOfDailyQuestionInLocalDate(memberId, localDate);
return ResponseEntity.ok().body(dailyResponseResponses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public class DiaryController {

private final DiaryService diaryService;

@Operation(summary = "일기 작성", description = "사용자가 일기를 작성합니다.")
@Operation(summary = "일기 작성", description = "사용자가 일기를 작성합니다. 리스트형태로 여러개를 넣을 수 있습니다.")
@PostMapping
public ResponseEntity<StringTypeMessageResponse> writeDiary(@RequestAttribute("memberId") Long memberId, @RequestBody DiaryWriteRequest diaryWriteRequest) {
diaryService.writeDiary(memberId, diaryWriteRequest);
public ResponseEntity<StringTypeMessageResponse> writeDiary(@RequestAttribute("memberId") Long memberId, @RequestBody List<DiaryWriteRequest> diaryWriteRequests) {
diaryService.writeDiary(memberId, diaryWriteRequests);
return ResponseEntity.status(HttpStatus.CREATED).body(new StringTypeMessageResponse("일기가 작성되었습니다."));
}

@Operation(summary = "유저의 날짜별 작성 일기 조회", description = "localDate에 해당하는 날짜에 사용자가 작성했던 모든 일기를 조회합니다.")
@GetMapping("/{localDate}")
@GetMapping("/all/{localDate}")
public ResponseEntity<List<DiaryReadResponse>> getAllDiary(@RequestAttribute("memberId") Long memberId, @PathVariable("localDate") LocalDate localDate) {
List<DiaryReadResponse> diaryReadResponses = diaryService.getAllDiaryWrittenByMemberInLocalDate(memberId, localDate);
return ResponseEntity.ok().body(diaryReadResponses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public record DiaryReadResponse(
Long diaryId,
LocalDateTime localDateTime,
LocalDateTime writtenDateTime,
Diary.Type type,
String content
) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/gdg/kkia/diary/service/DiaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public class DiaryService {
private final MemberRepository memberRepository;

@Transactional
public void writeDiary(Long memberId, DiaryWriteRequest diaryWriteRequest) {
public void writeDiary(Long memberId, List<DiaryWriteRequest> diaryWriteRequests) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException("id에 해당하는 멤버가 없습니다."));

Diary diary = new Diary(diaryWriteRequest.type(), diaryWriteRequest.content(), member);
diaryRepository.save(diary);
for (DiaryWriteRequest diaryWriteRequest : diaryWriteRequests) {
Diary diary = new Diary(diaryWriteRequest.type(), diaryWriteRequest.content(), member);
diaryRepository.save(diary);
}
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
@Tag(name = "인증", description = "인증 관련 API")
@Tag(name = "회원 관리", description = "회원 관리 관련 API")
public class MemberController {

private final MemberService memberService;
Expand Down

0 comments on commit fbd9786

Please sign in to comment.