Skip to content

Commit

Permalink
Refactor/#40 slow type diary retry (#44)
Browse files Browse the repository at this point in the history
* 수정전 commit

* Principal객체사용한 memberId기반 api전체 수정

* refactor : slowtype api principal제외

* refactor:오류수정을 위한 임시파일경로생성

* Update DiaryController.java 오타해결

* refactor 충돌해결
  • Loading branch information
jms0324 authored May 4, 2024
1 parent d2b6f8c commit 8debb90
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public String upload(MultipartFile file) throws IOException {
}

private File convertMultiPartToFile(MultipartFile file) throws IOException {
File convertedFile = new File(file.getOriginalFilename());
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File convertedFile = new File(tempDir,file.getOriginalFilename());
try (FileOutputStream fos = new FileOutputStream(convertedFile)) {
fos.write(file.getBytes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ public DiaryController(DiaryService diaryService,S3UploaderService s3UploaderSer
@PostMapping("/api/diary/content")
public ResponseEntity<ApiResponse<?>> getDiaryContents(@RequestBody DiaryContentRequestDto diaryContentRequestDto) {

Long diaryId = diaryContentRequestDto.getDiaryId();
Long diaryId = diaryContentRequestDto.getDiaryId();

Optional<Diary> diaryOptional = diaryService.findDiaryById(diaryId);
Optional<Diary> diaryOptional = diaryService.findDiaryById(diaryId);

if (diaryOptional.isPresent()) {
if (diaryOptional.isPresent()) {

Diary diary = diaryOptional.get();
// Diary의 Advice 정보를 AdviceResponseDto 객체로 변환
AdviceResponseDto adviceResponseDto = new AdviceResponseDto(
diary.getAdvice().getSpicy_advice(), //여기서 null이 나오면 ?
diary.getAdvice().getKind_advice()
Diary diary = diaryOptional.get();
// Diary의 Advice 정보를 AdviceResponseDto 객체로 변환
AdviceResponseDto adviceResponseDto = new AdviceResponseDto(
diary.getAdvice().getSpicy_advice(), //여기서 null이 나오면 ?
diary.getAdvice().getKind_advice()

);
);


DiaryContentResponseDto responseDto = new DiaryContentResponseDto(
Expand All @@ -78,12 +78,13 @@ public ResponseEntity<ApiResponse<?>> getDiaryContents(@RequestBody DiaryContent
diary.getTitle()
);

return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED, responseDto));
} else {
return ResponseEntity.status(ErrorType.REQUEST_VALIDATION_ERROR.getHttpStatus())
.body(ApiResponse.error(ErrorType.REQUEST_VALIDATION_ERROR));
//diary 가 null 일 경우 요청이상함 반환
}

return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED, responseDto));
} else {
return ResponseEntity.status(ErrorType.REQUEST_VALIDATION_ERROR.getHttpStatus())
.body(ApiResponse.error(ErrorType.REQUEST_VALIDATION_ERROR));
//diary 가 null 일 경우 요청이상함 반환
}

}
/* @PostMapping("/api/diary/list/calendar")
Expand All @@ -104,6 +105,8 @@ public ResponseEntity<ApiResponse<?>> getDiariesByMonth(@RequestBody CurrentDate
Map<String,List<CalenderDiaryResponseDto>> responseMap= Map.of("monthList",diaryDtos);
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED, responseMap));*/



@PostMapping("/api/diary/list/calendar")
public ResponseEntity<ApiResponse<?>> getDiariesByMonth(Principal principal,@RequestBody CurrentDateRequestDto requestDto){
Long memberId= JwtProvider.getUserFromPrincipal(principal);
Expand All @@ -112,16 +115,16 @@ public ResponseEntity<ApiResponse<?>> getDiariesByMonth(Principal principal,@Req
List<Diary> diaries = diaryService.findDiariesByMonthAndMemberId(currentDate, memberId);

if(diaries.isEmpty()){
return ResponseEntity.status(ErrorType.REQUEST_VALIDATION_ERROR.getHttpStatus())
.body(ApiResponse.error(ErrorType.REQUEST_VALIDATION_ERROR, "해당 월에 대한 일기가 존재하지 않습니다."));
}
return ResponseEntity.status(ErrorType.REQUEST_VALIDATION_ERROR.getHttpStatus())
.body(ApiResponse.error(ErrorType.REQUEST_VALIDATION_ERROR, "해당 월에 대한 일기가 존재하지 않습니다."));
}

List<CalenderDiaryResponseDto> diaryDtos=diaries.stream()
.map(diary -> new CalenderDiaryResponseDto(diary.getId(), diary.getTitle(), diary.getWritedAt()))
.collect(Collectors.toList());
List<CalenderDiaryResponseDto> diaryDtos=diaries.stream()
.map(diary -> new CalenderDiaryResponseDto(diary.getId(), diary.getTitle(), diary.getWritedAt()))
.collect(Collectors.toList());

Map<String,List<CalenderDiaryResponseDto>> responseMap= Map.of("monthList",diaryDtos);
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED, responseMap));
Map<String,List<CalenderDiaryResponseDto>> responseMap= Map.of("monthList",diaryDtos);
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED, responseMap));



Expand Down Expand Up @@ -168,15 +171,24 @@ public ResponseEntity<ApiResponse<?>> getDiariesByFeeling( Principal principal,@

}


/* @PostMapping("/api/diary/create/slow")
public ResponseEntity<ApiResponse<?>> createSlowTypeDiary(@RequestPart("imageurl")MultipartFile image,
@RequestPart("diaryTitle") String diaryTitle,
@RequestPart("diaryContent") String diaryContent){
try {
String accessToken = null;
if (authHeader != null && authHeader.startsWith("Bearer ")) {
accessToken = authHeader.substring(7);
}
String imageUrl = s3UploaderService.upload(image);
Long memberId= jwtProvider.getUserFromJwt(accessToken);
Member member= memberService.findByIdOrThrow(memberId);
Diary diary = new Diary();
diary.setTitle(diaryTitle);
diary.setMember(member);
diary.setContent(diaryContent);
diary.setImageurl(imageUrl);
Expand All @@ -185,7 +197,10 @@ public ResponseEntity<ApiResponse<?>> createSlowTypeDiary(@RequestPart("imageurl
return ResponseEntity.ok().body(ApiResponse.success(SuccessType.PROCESS_SUCCESSED,responseDto));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR,"서버 내부 오류"));
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponse.error(ErrorType.INTERNAL_SERVER_ERROR,e.getMessage()));
}
}*/
@PostMapping("/api/diary/create/slow")
Expand Down Expand Up @@ -222,4 +237,4 @@ public ResponseEntity<ApiResponse<?>> createSlowTypeDiary(@RequestHeader(value =



}
}

0 comments on commit 8debb90

Please sign in to comment.