Skip to content

Commit

Permalink
[Merge] 임시 저장 일기에 대해 구현되지 않은 부분을 구현
Browse files Browse the repository at this point in the history
[Fix] 임시 저장 일기에 대해 구현되지 않은 부분을 구현
  • Loading branch information
M-ung authored Nov 25, 2024
2 parents 9282741 + 6e78e0e commit 5bec259
Show file tree
Hide file tree
Showing 22 changed files with 308 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-11-26T00:28:54+0900",
date = "2024-11-26T01:10:10+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package moodbuddy.moodbuddy.domain.diary.mapper.draft;

import javax.annotation.processing.Generated;
import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
import org.springframework.stereotype.Component;

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-11-26T01:51:46+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)"
)
@Component
public class DraftDiaryMapperImpl implements DraftDiaryMapper {

@Override
public DiaryResDetailDTO toResDetailDTO(Diary diary) {
if ( diary == null ) {
return null;
}

DiaryResDetailDTO.DiaryResDetailDTOBuilder diaryResDetailDTO = DiaryResDetailDTO.builder();

diaryResDetailDTO.diaryId( diary.getDiaryId() );
diaryResDetailDTO.moodBuddyStatus( diary.getMoodBuddyStatus() );
diaryResDetailDTO.userId( diary.getUserId() );
diaryResDetailDTO.diaryTitle( diary.getDiaryTitle() );
diaryResDetailDTO.diaryDate( diary.getDiaryDate() );
diaryResDetailDTO.diaryContent( diary.getDiaryContent() );
diaryResDetailDTO.diaryWeather( diary.getDiaryWeather() );
diaryResDetailDTO.diaryEmotion( diary.getDiaryEmotion() );
diaryResDetailDTO.diaryStatus( diary.getDiaryStatus() );
diaryResDetailDTO.diarySummary( diary.getDiarySummary() );
diaryResDetailDTO.diarySubject( diary.getDiarySubject() );
diaryResDetailDTO.diaryBookMarkCheck( diary.getDiaryBookMarkCheck() );
diaryResDetailDTO.diaryFont( diary.getDiaryFont() );
diaryResDetailDTO.diaryFontSize( diary.getDiaryFontSize() );

return diaryResDetailDTO.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-11-26T00:28:54+0900",
date = "2024-11-26T01:10:10+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-11-26T00:28:54+0900",
date = "2024-11-26T01:10:10+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)"
)
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DiaryReqDraftSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqUpdateDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DraftDiaryReqSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqSaveDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindAllDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO;
import moodbuddy.moodbuddy.domain.diary.facade.draft.DraftDiaryFacade;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v2/member/draftDiary")
@Tag(name = "Diary", description = "일기 관련 API")
Expand All @@ -22,24 +26,40 @@ public class DraftDiaryApiController {
/** 구현 완료 **/
@PostMapping("/save")
@Operation(summary = "일기 임시 저장", description = "일기를 임시 저장합니다.")
public ResponseEntity<DiaryResDetailDTO> draftSave(@Parameter(description = "임시 저장 일기 정보를 담고 있는 DTO")
public ResponseEntity<DiaryResDetailDTO> save(@Parameter(description = "임시 저장 일기 정보를 담고 있는 DTO")
@RequestBody DiaryReqSaveDTO requestDTO) {
return ResponseEntity.ok().body(draftDiaryFacade.saveDraftDiary(requestDTO));
return ResponseEntity.ok().body(draftDiaryFacade.save(requestDTO));
}

/** 구현 완료 **/
@PostMapping("/update")
@Operation(summary = "임시 저장 일기 -> 일기 저장으로 변경", description = "임시 저장 일기 -> 일기 저장으로 변경합니다.")
public ResponseEntity<DiaryResDetailDTO> update(@Parameter(description = "변경할 일기 정보를 담고 있는 DTO")
@RequestBody DiaryReqUpdateDTO requestDTO) {
return ResponseEntity.ok().body(draftDiaryFacade.update(requestDTO));
}

/** 구현 완료 **/
@GetMapping("/findOne/{diaryId}")
@Operation(summary = "임시 저장 일기 하나 조회", description = "임시 저장 일기 하나를 조회합니다.")
public ResponseEntity<DraftDiaryResDetailDTO> findOneByDiaryId(@Parameter(description = "일기 고유 식별자")
@PathVariable("diaryId") Long diaryId) {
return ResponseEntity.ok().body(draftDiaryFacade.findOneByDiaryId(diaryId));
}

/** 구현 완료 **/
@GetMapping("/findAll")
@Operation(summary = "임시 저장 일기 목록 조회", description = "임시 저장 일기를 모두 조회합니다.")
public ResponseEntity<DiaryResDraftFindAllDTO> draftFindAll() {
return ResponseEntity.ok().body(draftDiaryFacade.draftFindAll());
public ResponseEntity<List<DraftDiaryResFindOneDTO>> findAll() {
return ResponseEntity.ok().body(draftDiaryFacade.findAll());
}

/** 구현 완료 **/
@PostMapping("/selectDelete")
@Operation(summary = "임시 저장 일기 선택 삭제", description = "임시 저장 일기를 선택해서 삭제합니다.")
public ResponseEntity<?> draftSelectDelete(@Parameter(description = "삭제할 임시 저장 일기 고유 식별자를 담고 있는 DTO")
@RequestBody DiaryReqDraftSelectDeleteDTO requestDTO) {
draftDiaryFacade.draftSelectDelete(requestDTO);
public ResponseEntity<?> selectDelete(@Parameter(description = "삭제할 임시 저장 일기 고유 식별자를 담고 있는 DTO")
@RequestBody DraftDiaryReqSelectDeleteDTO requestDTO) {
draftDiaryFacade.selectDelete(requestDTO);
return ResponseEntity.ok().body("임시 저장 일기 선택 삭제 완료.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public class DiaryImageApiController {
public ResponseEntity<CompletableFuture<DiaryImageResURLDTO>> upload(@ModelAttribute CloudReqDTO cloudReqDTO) throws IOException {
return ResponseEntity.ok().body(diaryImageFacade.uploadAndSave(cloudReqDTO));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public record DiaryReqSaveDTO (
DiaryFontSize diaryFontSize,
@Schema(description = "일기 사진 URL 리스트", example = "[이미지 URL, 이미지 URL]")
@Nullable
List<String> diaryImageURLs)
List<String> diaryImageURLs )
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jakarta.validation.constraints.NotNull;
import java.util.List;

public record DiaryReqDraftSelectDeleteDTO (
public record DraftDiaryReqSelectDeleteDTO(
@Schema(description = "삭제하고 싶은 임시 저장 일기 고유 식별자(diaryId)를 담는 List", example = "[1, 2]")
@NotNull List<Long> diaryIdList) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DiaryResDetailDTO {
@Schema(description = "일기 상태", example = "ACTIVE")
private MoodBuddyStatus moodBuddyStatus;

@JsonInclude(JsonInclude.Include.NON_NULL) // 굳이 필요하지 않은 경우가 있음.
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(description = "일기 이미지 List", example = "[이미지 URL, 이미지 URL]")
private List<String> diaryImgList;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package moodbuddy.moodbuddy.domain.diary.dto.response.draft;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryFont;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryFontSize;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus;
import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryWeather;
import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus;
import java.time.LocalDate;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DraftDiaryResDetailDTO {
private Long diaryId;
private Long userId;
private String diaryTitle;
private LocalDate diaryDate;
private String diaryContent;
private DiaryWeather diaryWeather;
private DiaryStatus diaryStatus;
private DiaryFont diaryFont;
private DiaryFontSize diaryFontSize;
private MoodBuddyStatus moodBuddyStatus;

@JsonInclude(JsonInclude.Include.NON_NULL)
private List<String> diaryImgList;

public DraftDiaryResDetailDTO(Long diaryId, Long userId, String diaryTitle, LocalDate diaryDate, String diaryContent, DiaryWeather diaryWeather, DiaryStatus diaryStatus, DiaryFont diaryFont, DiaryFontSize diaryFontSize, MoodBuddyStatus moodBuddyStatus) {
this.diaryId = diaryId;
this.userId = userId;
this.diaryTitle = diaryTitle;
this.diaryDate = diaryDate;
this.diaryContent = diaryContent;
this.diaryWeather = diaryWeather;
this.diaryStatus = diaryStatus;
this.diaryFont = diaryFont;
this.diaryFontSize = diaryFontSize;
this.moodBuddyStatus = moodBuddyStatus;
this.diaryImgList = List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import java.time.LocalDate;

public record DiaryResDraftFindOneDTO(
public record DraftDiaryResFindOneDTO(
@Schema(description = "일기 고유 식별자(diaryId)", example = "1")
Long diaryId,
@Schema(description = "사용자 고유 식별자(userId)", example = "2")
Long userId,
@Schema(description = "일기 날짜", example = "2023-07-02T15:30:00")
LocalDate diaryDate,
@Schema(description = "일기 상태(DRAFT, PUBLISHED)", example = "DRAFT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.RequiredArgsConstructor;
import moodbuddy.moodbuddy.domain.bookMark.service.BookMarkService;
import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.domain.image.DiaryImage;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqSaveDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqUpdateDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
Expand All @@ -16,9 +15,7 @@
import moodbuddy.moodbuddy.global.common.util.JwtUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package moodbuddy.moodbuddy.domain.diary.facade.draft;

import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DiaryReqDraftSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqUpdateDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DraftDiaryReqSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqSaveDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindAllDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO;

import java.util.List;

public interface DraftDiaryFacade {
DiaryResDetailDTO saveDraftDiary(DiaryReqSaveDTO requestDTO);
DiaryResDraftFindAllDTO draftFindAll();
void draftSelectDelete(DiaryReqDraftSelectDeleteDTO requestDTO);
DiaryResDetailDTO save(DiaryReqSaveDTO requestDTO);
DiaryResDetailDTO update(DiaryReqUpdateDTO requestDTO);
List<DraftDiaryResFindOneDTO> findAll();
void selectDelete(DraftDiaryReqSelectDeleteDTO requestDTO);
DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,75 @@

import lombok.RequiredArgsConstructor;
import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DiaryReqDraftSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqUpdateDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.draft.DraftDiaryReqSelectDeleteDTO;
import moodbuddy.moodbuddy.domain.diary.dto.request.DiaryReqSaveDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindAllDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO;
import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO;
import moodbuddy.moodbuddy.domain.diary.mapper.DiaryMapper;
import moodbuddy.moodbuddy.domain.diary.mapper.draft.DraftDiaryMapper;
import moodbuddy.moodbuddy.domain.diary.service.DiaryService;
import moodbuddy.moodbuddy.domain.diary.service.draft.DraftDiaryService;
import moodbuddy.moodbuddy.domain.diary.service.image.DiaryImageService;
import moodbuddy.moodbuddy.global.common.elasticSearch.diary.service.DiaryDocumentService;
import moodbuddy.moodbuddy.global.common.gpt.service.GptService;
import moodbuddy.moodbuddy.global.common.util.JwtUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DraftDiaryFacadeImpl implements DraftDiaryFacade {
private final DraftDiaryService draftDiaryService;
private final DiaryMapper diaryMapper;
private final DiaryDocumentService diaryDocumentService;
private final DiaryImageService diaryImageService;
private final GptService gptService;
private final DraftDiaryMapper draftDiaryMapper;

@Override
@Transactional
public DiaryResDetailDTO save(DiaryReqSaveDTO requestDTO) {
final Long userId = JwtUtil.getUserId();
Diary diary = draftDiaryService.save(requestDTO, userId);
if(requestDTO.diaryImageURLs() != null) {
diaryImageService.saveAll(requestDTO.diaryImageURLs(), diary.getDiaryId());
}
return draftDiaryMapper.toResDetailDTO(diary);
}

//TODO 이미지 관리 해결해야 함.
@Override
@Transactional
public DiaryResDetailDTO saveDraftDiary(DiaryReqSaveDTO requestDTO) {
public DiaryResDetailDTO update(DiaryReqUpdateDTO requestDTO) {
final Long userId = JwtUtil.getUserId();
Diary diary = draftDiaryService.draftSave(requestDTO, userId);
return diaryMapper.toResDetailDTO(diary);
Diary diary = draftDiaryService.update(requestDTO, gptService.analyzeDiaryContent(requestDTO.diaryContent()), userId);
diaryImageService.deleteAll(diary.getDiaryId());
if(requestDTO.newImageURLs() != null) {
diaryImageService.saveAll(requestDTO.newImageURLs(), diary.getDiaryId());
}
diaryDocumentService.save(diary);
return draftDiaryMapper.toResDetailDTO(diary);
}

@Override
public DiaryResDraftFindAllDTO draftFindAll() {
public List<DraftDiaryResFindOneDTO> findAll() {
final Long userId = JwtUtil.getUserId();
return draftDiaryService.draftFindAll(userId);
return draftDiaryService.findAll(userId);
}

@Override
@Transactional
public void draftSelectDelete(DiaryReqDraftSelectDeleteDTO requestDTO) {
public void selectDelete(DraftDiaryReqSelectDeleteDTO requestDTO) {
final Long userId = JwtUtil.getUserId();
draftDiaryService.selectDelete(requestDTO, userId);
}

@Override
public DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId) {
final Long userId = JwtUtil.getUserId();
draftDiaryService.draftSelectDelete(requestDTO, userId);
return draftDiaryService.findOneByDiaryId(diaryId, userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package moodbuddy.moodbuddy.domain.diary.mapper.draft;

import moodbuddy.moodbuddy.domain.diary.domain.Diary;
import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring")
public interface DraftDiaryMapper {
DraftDiaryMapper INSTANCE = Mappers.getMapper(DraftDiaryMapper.class);

@Mapping(source = "diaryId", target = "diaryId")
@Mapping(source = "moodBuddyStatus", target = "moodBuddyStatus")
DiaryResDetailDTO toResDetailDTO(Diary diary);
}
Loading

0 comments on commit 5bec259

Please sign in to comment.