diff --git a/build.gradle b/build.gradle index faf1b31b..7079f567 100644 --- a/build.gradle +++ b/build.gradle @@ -97,10 +97,6 @@ dependencies { // slack implementation 'com.github.maricn:logback-slack-appender:1.4.0' - // Elasticsearch - implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch' - // implementation 'org.springframework.data:spring-data-elasticsearch:4.2.2' - // actuator implementation 'org.springframework.boot:spring-boot-starter-actuator' diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java index e04ce225..a645f80c 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/DiaryMapperImpl.java @@ -7,7 +7,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-26T00:28:54+0900", + date = "2024-11-26T02:00:56+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapperImpl.java new file mode 100644 index 00000000..95fb5761 --- /dev/null +++ b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapperImpl.java @@ -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-26T02:00:56+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(); + } +} diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java index 6c06581d..6139a873 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/diary/mapper/image/DiaryImageMapperImpl.java @@ -6,7 +6,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-26T00:28:54+0900", + date = "2024-11-26T02:00:56+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java b/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java index 68420dcb..bd47fe69 100644 --- a/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java +++ b/src/main/generated/moodbuddy/moodbuddy/domain/quddyTI/mapper/QuddyTIMapperImpl.java @@ -8,7 +8,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-11-26T00:28:54+0900", + date = "2024-11-26T02:00:56+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 17.0.13 (Homebrew)" ) @Component diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/draft/DraftDiaryApiController.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/draft/DraftDiaryApiController.java index 92134027..dc3d61c2 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/draft/DraftDiaryApiController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/draft/DraftDiaryApiController.java @@ -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") @@ -22,24 +26,40 @@ public class DraftDiaryApiController { /** 구현 완료 **/ @PostMapping("/save") @Operation(summary = "일기 임시 저장", description = "일기를 임시 저장합니다.") - public ResponseEntity draftSave(@Parameter(description = "임시 저장 일기 정보를 담고 있는 DTO") + public ResponseEntity 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 update(@Parameter(description = "변경할 일기 정보를 담고 있는 DTO") + @RequestBody DiaryReqUpdateDTO requestDTO) { + return ResponseEntity.ok().body(draftDiaryFacade.update(requestDTO)); + } + + /** 구현 완료 **/ + @GetMapping("/findOne/{diaryId}") + @Operation(summary = "임시 저장 일기 하나 조회", description = "임시 저장 일기 하나를 조회합니다.") + public ResponseEntity findOneByDiaryId(@Parameter(description = "일기 고유 식별자") + @PathVariable("diaryId") Long diaryId) { + return ResponseEntity.ok().body(draftDiaryFacade.findOneByDiaryId(diaryId)); } /** 구현 완료 **/ @GetMapping("/findAll") @Operation(summary = "임시 저장 일기 목록 조회", description = "임시 저장 일기를 모두 조회합니다.") - public ResponseEntity draftFindAll() { - return ResponseEntity.ok().body(draftDiaryFacade.draftFindAll()); + public ResponseEntity> 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("임시 저장 일기 선택 삭제 완료."); } } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/emotion/DiaryEmotionApiController.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/emotion/DiaryEmotionApiController.java index 9511c472..66eff3bc 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/emotion/DiaryEmotionApiController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/emotion/DiaryEmotionApiController.java @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/api/v1/member/diary") +@RequestMapping("/api/v2/member/diary") @Tag(name = "Diary", description = "일기 감정 관련 API") @RequiredArgsConstructor public class DiaryEmotionApiController { diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/image/DiaryImageApiController.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/image/DiaryImageApiController.java index d65aa30e..7dfe3523 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/image/DiaryImageApiController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/controller/image/DiaryImageApiController.java @@ -24,4 +24,4 @@ public class DiaryImageApiController { public ResponseEntity> upload(@ModelAttribute CloudReqDTO cloudReqDTO) throws IOException { return ResponseEntity.ok().body(diaryImageFacade.uploadAndSave(cloudReqDTO)); } -} +} \ No newline at end of file diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/DiaryReqSaveDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/DiaryReqSaveDTO.java index bb2910a2..3f19816a 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/DiaryReqSaveDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/DiaryReqSaveDTO.java @@ -24,6 +24,6 @@ public record DiaryReqSaveDTO ( DiaryFontSize diaryFontSize, @Schema(description = "일기 사진 URL 리스트", example = "[이미지 URL, 이미지 URL]") @Nullable - List diaryImageURLs) + List diaryImageURLs ) { } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DiaryReqDraftSelectDeleteDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DraftDiaryReqSelectDeleteDTO.java similarity index 88% rename from src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DiaryReqDraftSelectDeleteDTO.java rename to src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DraftDiaryReqSelectDeleteDTO.java index c4b381b9..0090e5f9 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DiaryReqDraftSelectDeleteDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/request/draft/DraftDiaryReqSelectDeleteDTO.java @@ -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 diaryIdList) { } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/DiaryResDetailDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/DiaryResDetailDTO.java index dc317912..2eaae1fa 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/DiaryResDetailDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/DiaryResDetailDTO.java @@ -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 diaryImgList; diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindAllDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindAllDTO.java deleted file mode 100644 index fcc66a4d..00000000 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindAllDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package moodbuddy.moodbuddy.domain.diary.dto.response.draft; - -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.List; - -public record DiaryResDraftFindAllDTO ( - @Schema(description = "임시 저장 일기 DTO를 담고 있는 List") - List diaryResDraftFindOneList -){ -} diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResDetailDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResDetailDTO.java new file mode 100644 index 00000000..eeca994c --- /dev/null +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResDetailDTO.java @@ -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 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(); + } +} \ No newline at end of file diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindOneDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResFindOneDTO.java similarity index 79% rename from src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindOneDTO.java rename to src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResFindOneDTO.java index 5ccc3110..38c7e4ad 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DiaryResDraftFindOneDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/dto/response/draft/DraftDiaryResFindOneDTO.java @@ -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") diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/DiaryFacadeImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/DiaryFacadeImpl.java index cd387f91..60100ddc 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/DiaryFacadeImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/DiaryFacadeImpl.java @@ -3,29 +3,24 @@ 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; import moodbuddy.moodbuddy.domain.diary.mapper.DiaryMapper; import moodbuddy.moodbuddy.domain.diary.service.image.DiaryImageService; import moodbuddy.moodbuddy.domain.diary.service.DiaryService; -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.service.DiaryDocumentService; import moodbuddy.moodbuddy.domain.user.service.UserService; 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.time.LocalDate; -import java.util.List; @Component @RequiredArgsConstructor @Transactional(readOnly = true) public class DiaryFacadeImpl implements DiaryFacade { private final DiaryService diaryService; - private final DiaryDocumentService diaryDocumentService; private final DiaryImageService diaryImageService; private final BookMarkService bookMarkService; private final UserService userService; @@ -42,7 +37,7 @@ public DiaryResDetailDTO save(DiaryReqSaveDTO requestDTO) { if(requestDTO.diaryImageURLs() != null) { diaryImageService.saveAll(requestDTO.diaryImageURLs(), diary.getDiaryId()); } - diaryDocumentService.save(diary); +// diaryDocumentService.save(diary); checkTodayDiary(requestDTO.diaryDate(), userId, false); return diaryMapper.toResDetailDTO(diary); } @@ -56,7 +51,7 @@ public DiaryResDetailDTO update(DiaryReqUpdateDTO requestDTO) { if(requestDTO.newImageURLs() != null) { diaryImageService.saveAll(requestDTO.newImageURLs(), diary.getDiaryId()); } - diaryDocumentService.save(diary); +// diaryDocumentService.save(diary); return diaryMapper.toResDetailDTO(diary); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacade.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacade.java index f641e333..836a4784 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacade.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacade.java @@ -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 findAll(); + void selectDelete(DraftDiaryReqSelectDeleteDTO requestDTO); + DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacadeImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacadeImpl.java index 5d7d9f01..a8cad039 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacadeImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/facade/draft/DraftDiaryFacadeImpl.java @@ -2,42 +2,70 @@ 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.mapper.DiaryMapper; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO; +import moodbuddy.moodbuddy.domain.diary.mapper.draft.DraftDiaryMapper; import moodbuddy.moodbuddy.domain.diary.service.draft.DraftDiaryService; +import moodbuddy.moodbuddy.domain.diary.service.image.DiaryImageService; +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 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()); + } + return draftDiaryMapper.toResDetailDTO(diary); } @Override - public DiaryResDraftFindAllDTO draftFindAll() { + public List 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); } } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapper.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapper.java new file mode 100644 index 00000000..1c04de72 --- /dev/null +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/mapper/draft/DraftDiaryMapper.java @@ -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); +} diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/DiaryRepositoryImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/DiaryRepositoryImpl.java index dbce6789..9f24f0e2 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/DiaryRepositoryImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/DiaryRepositoryImpl.java @@ -3,6 +3,7 @@ import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; +import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus; import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO; import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; import java.util.List; @@ -35,12 +36,14 @@ public DiaryResDetailDTO findOneByDiaryId(Long diaryId) { diary.moodBuddyStatus )) .from(diary) - .where(diary.diaryId.eq(diaryId).and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))) + .where(diary.diaryId.eq(diaryId) + .and(diary.diaryStatus.eq(DiaryStatus.PUBLISHED)) + .and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))) .fetchOne(); List diaryImgList = queryFactory.select(diaryImage.diaryImgURL) .from(diaryImage) - .where(diaryImage.diaryId.eq(diaryId)) + .where(diaryImage.diaryId.eq(diaryId).and(diaryImage.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))) .fetch(); diaryResDetailDTO.setDiaryImgList(diaryImgList); diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepository.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepository.java index 31ac4d25..a5e34caf 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepository.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepository.java @@ -5,8 +5,11 @@ import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; import org.springframework.data.jpa.repository.JpaRepository; +import java.time.LocalDate; +import java.util.List; import java.util.Optional; public interface DraftDiaryRepository extends JpaRepository, DraftDiaryRepositoryCustom { Optional findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(Long diaryId, DiaryStatus diaryStatus, MoodBuddyStatus moodBuddyStatus); + List findAllByDiaryDateAndUserIdAndDiaryStatus(LocalDate diaryDate, Long userId, DiaryStatus diaryStatus); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryCustom.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryCustom.java index 5dc49d97..ebc553b4 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryCustom.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryCustom.java @@ -1,7 +1,11 @@ package moodbuddy.moodbuddy.domain.diary.repository.draft; -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 DraftDiaryRepositoryCustom { - DiaryResDraftFindAllDTO draftFindAllByUserId(Long userId); + List findAllByUserId(Long userId); + DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryImpl.java index 5f761133..5dd6d02e 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/repository/draft/DraftDiaryRepositoryImpl.java @@ -4,12 +4,14 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus; -import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindAllDTO; -import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DiaryResDraftFindOneDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.DiaryResDetailDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO; import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; import java.util.List; import java.util.stream.Collectors; import static moodbuddy.moodbuddy.domain.diary.domain.QDiary.diary; +import static moodbuddy.moodbuddy.domain.diary.domain.image.QDiaryImage.diaryImage; public class DraftDiaryRepositoryImpl implements DraftDiaryRepositoryCustom { private final JPAQueryFactory queryFactory; @@ -19,11 +21,10 @@ public DraftDiaryRepositoryImpl(EntityManager em) { } @Override - public DiaryResDraftFindAllDTO draftFindAllByUserId(Long userId) { - List draftList = queryFactory - .select(Projections.constructor(DiaryResDraftFindOneDTO.class, + public List findAllByUserId(Long userId) { + List result = queryFactory + .select(Projections.constructor(DraftDiaryResFindOneDTO.class, diary.diaryId, - diary.userId, diary.diaryDate, diary.diaryStatus )) @@ -32,9 +33,41 @@ public DiaryResDraftFindAllDTO draftFindAllByUserId(Long userId) { .and(diary.diaryStatus.eq(DiaryStatus.DRAFT).and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE)))) .fetch() .stream() - .map(d -> new DiaryResDraftFindOneDTO(d.diaryId(), d.userId(), d.diaryDate(), d.diaryStatus())) + .map(d -> new DraftDiaryResFindOneDTO(d.diaryId(), d.diaryDate(), d.diaryStatus())) .collect(Collectors.toList()); - return new DiaryResDraftFindAllDTO(draftList); + return result; + } + + @Override + public DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId) { + System.out.println("======"); + System.out.println(diaryId); + DraftDiaryResDetailDTO result = queryFactory.select(Projections.constructor(DraftDiaryResDetailDTO.class, + diary.diaryId, + diary.userId, + diary.diaryTitle, + diary.diaryDate, + diary.diaryContent, + diary.diaryWeather, + diary.diaryStatus, + diary.diaryFont, + diary.diaryFontSize, + diary.moodBuddyStatus + )) + .from(diary) + .where(diary.diaryId.eq(diaryId) + .and(diary.diaryStatus.eq(DiaryStatus.DRAFT)) + .and(diary.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))) + .fetchOne(); + + List diaryImgList = queryFactory.select(diaryImage.diaryImgURL) + .from(diaryImage) + .where(diaryImage.diaryId.eq(diaryId).and(diaryImage.moodBuddyStatus.eq(MoodBuddyStatus.ACTIVE))) + .fetch(); + + result.setDiaryImgList(diaryImgList); + + return result; } } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryService.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryService.java index 65ad5685..ce09fede 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryService.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryService.java @@ -1,17 +1,25 @@ package moodbuddy.moodbuddy.domain.diary.service.draft; 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.draft.DiaryResDraftFindAllDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResDetailDTO; +import moodbuddy.moodbuddy.domain.diary.dto.response.draft.DraftDiaryResFindOneDTO; +import java.util.List; +import java.util.Map; public interface DraftDiaryService { // 일기 임시 저장 - Diary draftSave(DiaryReqSaveDTO diaryReqSaveDTO, final Long userId); + Diary save(DiaryReqSaveDTO diaryReqSaveDTO, final Long userId); + + Diary update(DiaryReqUpdateDTO requestDTO, Map stringStringMap, final Long userId); // 일기 임시 저장 날짜 조회 - DiaryResDraftFindAllDTO draftFindAll(final Long userId); + List findAll(final Long userId); // 일기 임시 저장 선택 삭제 - void draftSelectDelete(DiaryReqDraftSelectDeleteDTO requestDTO, final Long userId); -} + void selectDelete(DraftDiaryReqSelectDeleteDTO requestDTO, final Long userId); + + DraftDiaryResDetailDTO findOneByDiaryId(final Long diaryId, final Long userId); +} \ No newline at end of file diff --git a/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryServiceImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryServiceImpl.java index 8d1de88b..3f76aaa5 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryServiceImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/diary/service/draft/DraftDiaryServiceImpl.java @@ -3,15 +3,24 @@ import lombok.RequiredArgsConstructor; import moodbuddy.moodbuddy.domain.diary.domain.Diary; import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus; -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.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.repository.draft.DraftDiaryRepository; import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; +import moodbuddy.moodbuddy.global.common.exception.ErrorCode; +import moodbuddy.moodbuddy.global.common.exception.diary.DiaryNoAccessException; import moodbuddy.moodbuddy.global.common.exception.diary.DiaryNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; + +import static moodbuddy.moodbuddy.global.common.exception.ErrorCode.NOT_FOUND_DIARY; import static moodbuddy.moodbuddy.global.common.exception.ErrorCode.NOT_FOUND_DRAFT_DIARY; @Service @@ -22,27 +31,54 @@ public class DraftDiaryServiceImpl implements DraftDiaryService { @Override @Transactional - public Diary draftSave(DiaryReqSaveDTO requestDTO, final Long userId) { + public Diary save(DiaryReqSaveDTO requestDTO, final Long userId) { return draftDiaryRepository.save((Diary.ofDraft( requestDTO, userId))); } @Override - public DiaryResDraftFindAllDTO draftFindAll(final Long userId) { - return draftDiaryRepository.draftFindAllByUserId(userId); + public Diary update(DiaryReqUpdateDTO requestDTO, Map gptResults, Long userId) { + Diary findDiary = getDraftDiaryById(requestDTO.diaryId()); + validateDiaryAccess(findDiary, userId); + findDiary.updateDiary(requestDTO, gptResults); + deleteTodayDraftDiaries(requestDTO.diaryDate(), userId); + return findDiary; + } + + @Override + public List findAll(final Long userId) { + return draftDiaryRepository.findAllByUserId(userId); } @Override @Transactional - public void draftSelectDelete(DiaryReqDraftSelectDeleteDTO requestDTO, Long userId) { + public void selectDelete(DraftDiaryReqSelectDeleteDTO requestDTO, Long userId) { requestDTO.diaryIdList().forEach(diaryId -> getDraftDiaryById(diaryId).updateMoodBuddyStatus(MoodBuddyStatus.DIS_ACTIVE) ); } + @Override + public DraftDiaryResDetailDTO findOneByDiaryId(Long diaryId, Long userId) { + final Diary findDiary = getDraftDiaryById(diaryId); + validateDiaryAccess(findDiary, userId); + return draftDiaryRepository.findOneByDiaryId(diaryId); + } + + private void deleteTodayDraftDiaries(LocalDate diaryDate, Long userId) { + draftDiaryRepository.findAllByDiaryDateAndUserIdAndDiaryStatus(diaryDate, userId, DiaryStatus.DRAFT) + .forEach(draftDiary -> draftDiary.updateMoodBuddyStatus(MoodBuddyStatus.DIS_ACTIVE)); + } + private Diary getDraftDiaryById(Long diaryId) { return draftDiaryRepository.findByDiaryIdAndDiaryStatusAndMoodBuddyStatus(diaryId, DiaryStatus.DRAFT, MoodBuddyStatus.ACTIVE) .orElseThrow(() -> new DiaryNotFoundException(NOT_FOUND_DRAFT_DIARY)); } + + private void validateDiaryAccess(Diary findDiary, Long userId) { + if (!findDiary.getUserId().equals(userId)) { + throw new DiaryNoAccessException(ErrorCode.NO_ACCESS_DIARY); + } + } } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/letter/controller/LetterApiController.java b/src/main/java/moodbuddy/moodbuddy/domain/letter/controller/LetterApiController.java index e9b76c3a..5796aef4 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/letter/controller/LetterApiController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/letter/controller/LetterApiController.java @@ -21,7 +21,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/member/letter") +@RequestMapping("/api/v2/member/letter") @Tag(name = "letter-controller", description = "Letter API") public class LetterApiController { diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/controller/OAuthController.java b/src/main/java/moodbuddy/moodbuddy/domain/user/controller/OAuthController.java index 0ae385e4..2d09a645 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/controller/OAuthController.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/controller/OAuthController.java @@ -15,7 +15,7 @@ @Slf4j @RestController @RequiredArgsConstructor -@RequestMapping("api/v1/user") +@RequestMapping("api/v2/user") public class OAuthController { private final KakaoService kakaoService; diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqLoginDTO.java b/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqLoginDTO.java index 1454f7a9..188fe738 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqLoginDTO.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/dto/request/UserReqLoginDTO.java @@ -10,5 +10,5 @@ @NoArgsConstructor public class UserReqLoginDTO { @Schema(description = "임시로 사용할 자체 로그인이기 때문에 kakaoId 으로만 로그인이 가능하게 한다.", example = "12342") - private Long userId; + private Long kakaoId; } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/repository/UserRepository.java b/src/main/java/moodbuddy/moodbuddy/domain/user/repository/UserRepository.java index a967e366..ebdc9433 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/repository/UserRepository.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/repository/UserRepository.java @@ -24,6 +24,8 @@ public interface UserRepository extends JpaRepository { @Query("select u from User u where u.userId = :userId") Optional findByUserIdWithPessimisticLock(@Param("userId") Long userId); + @Query("select u from User u where u.kakaoId = :kakaoId") + Optional findByKakaoId(@Param("kakaoId") Long kakaoId); // @Modifying // @Transactional // @Query("update User u set u.userCurDiaryNums = :curDiaryNums where u.userId = :userId") @@ -32,11 +34,11 @@ public interface UserRepository extends JpaRepository { // @Modifying // @Transactional // @Query("update User u set u.userLastDiaryNums = :curDiaryNums where u.userId = :userId") + // void updateLastDiaryNumsById(@Param("userId") Long userId, @Param("curDiaryNums") Integer curDiaryNums); @Modifying @Transactional @Query("update User u set u.letterAlarm = :letterAlarm where u.userId = :userId") void updateLetterAlarmByUserId(@Param("userId") Long userId, @Param("letterAlarm") boolean letterAlarm); - } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java index 44d907ee..2bf7dc31 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserService.java @@ -61,4 +61,5 @@ public interface UserService { UserResLoginDTO login(UserReqLoginDTO userReqLoginDTO); UserResSaveDTO save(UserReqSaveDTO userReqSaveDTO); User getUserById(Long userId); + User getUserByKakaoId(Long kakaoId); } diff --git a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java index 64ffd960..43892c5f 100644 --- a/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java +++ b/src/main/java/moodbuddy/moodbuddy/domain/user/service/UserServiceImpl.java @@ -522,7 +522,7 @@ public void setUserCheckTodayDairy(Long userId, Boolean check) { /** 테스트를 위한 임시 자체 로그인 **/ @Override public UserResLoginDTO login(UserReqLoginDTO userReqLoginDTO) { - return UserMapper.toUserResLoginDTO(getUserById(userReqLoginDTO.getUserId())); + return UserMapper.toUserResLoginDTO(getUserByKakaoId(userReqLoginDTO.getKakaoId())); } /** 테스트를 위한 임시 자체 회원가입 **/ @@ -534,7 +534,13 @@ public UserResSaveDTO save(UserReqSaveDTO userReqSaveDTO) { @Override public User getUserById(Long userId) { - return userRepository.findById(userId) + return userRepository.findByUserId(userId) + .orElseThrow(()->new UserNotFoundByUserIdException(ErrorCode.NOT_FOUND_USER)); + } + + @Override + public User getUserByKakaoId(Long kakaoId) { + return userRepository.findByKakaoId(kakaoId) .orElseThrow(()->new UserNotFoundByUserIdException(ErrorCode.NOT_FOUND_USER)); } } \ No newline at end of file diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/config/SecurityConfig.java b/src/main/java/moodbuddy/moodbuddy/global/common/config/SecurityConfig.java index eb092167..dfc1039b 100644 --- a/src/main/java/moodbuddy/moodbuddy/global/common/config/SecurityConfig.java +++ b/src/main/java/moodbuddy/moodbuddy/global/common/config/SecurityConfig.java @@ -31,7 +31,8 @@ public WebSecurityCustomizer webSecurityCustomizer() { .requestMatchers(new AntPathRequestMatcher("/v3/api-docs/**")) .requestMatchers(new AntPathRequestMatcher("/user/sign-up")) .requestMatchers(new AntPathRequestMatcher("/api/healthCheck")) - .requestMatchers(new AntPathRequestMatcher("/user/login"))); + .requestMatchers(new AntPathRequestMatcher("/user/login")) + .requestMatchers(new AntPathRequestMatcher("/test/login"))); } @Bean @@ -44,10 +45,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "http://react-app:3000", "http://localhost:5173", "http://localhost:3000", + "http://localhost:8080", + "http://52.79.54.242:8080", + "http://52.79.54.242:3000", "http://moodbuddy:8080", "https://moodbuddy.site", "http://moodbuddy.site", - "https://neon-cat-f70a98.netlify.app")); + "https://neon-cat-f70a98.netlify.app", + "https://main.d28mm6xwy7gaq8.amplifyapp.com/")); config.setAllowedHeaders(List.of("*")); config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE")); config.setAllowCredentials(true); diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryDocument.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryDocument.java deleted file mode 100644 index 7409a0cb..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryDocument.java +++ /dev/null @@ -1,81 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain; - -import lombok.*; -import moodbuddy.moodbuddy.domain.diary.domain.Diary; -import moodbuddy.moodbuddy.domain.diary.domain.type.DiaryStatus; -import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; -import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.Document; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; -import java.time.LocalDate; - -@Document(indexName = "diary") -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class DiaryDocument { - @Id - private Long id; - - @Field(type = FieldType.Text) - private String diaryTitle; - - @Field(type = FieldType.Date) - private LocalDate diaryDate; - - @Field(type = FieldType.Text) - private String diaryContent; - - @Field(type = FieldType.Keyword) - private String diaryWeather; - - @Field(type = FieldType.Keyword) - private String diaryEmotion; - - @Field(type = FieldType.Keyword) - private String diaryStatus; - - @Field(type = FieldType.Keyword) - private String diarySubject; - - @Field(type = FieldType.Text) - private String diarySummary; - - @Field(type = FieldType.Long) - private Long userId; - - @Field(type = FieldType.Boolean) - private Boolean diaryBookMarkCheck; - - @Field(type = FieldType.Keyword) - private String diaryFont; - - @Field(type = FieldType.Keyword) - private String diaryFontSize; - - @Field(type = FieldType.Keyword) - private MoodBuddyStatus moodBuddyStatus; - - public static DiaryDocument from(Diary diary) { - return DiaryDocument.builder() - .diaryTitle(diary.getDiaryTitle()) - .diaryDate(diary.getDiaryDate()) - .diaryContent(diary.getDiaryContent().toString()) - .diaryWeather(diary.getDiaryWeather().toString()) - .diaryStatus(DiaryStatus.PUBLISHED.toString()) - .diarySummary(diary.getDiarySummary()) - .diarySubject(diary.getDiarySubject().toString()) - .userId(diary.getUserId()) - .diaryBookMarkCheck(false) - .diaryFont(diary.getDiaryFont().toString()) - .diaryFontSize(diary.getDiaryFontSize().toString()) - .moodBuddyStatus(MoodBuddyStatus.ACTIVE) - .build(); - } - - public void updateMoodBuddyStatus(MoodBuddyStatus moodBuddyStatus) { - this.moodBuddyStatus = moodBuddyStatus; - } -} diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryImageDocument.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryImageDocument.java deleted file mode 100644 index 94e7f0fa..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/domain/DiaryImageDocument.java +++ /dev/null @@ -1,24 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain; - -import lombok.*; -import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.Document; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; - -@Document(indexName = "diary_image") -@Getter -@Builder -@AllArgsConstructor -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class DiaryImageDocument { - @Id - private Long id; - - @Field(type = FieldType.Long) - private Long diaryId; // 연결된 Diary ID - - @Field(type = FieldType.Text) - private String diaryImgURL; -} - diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryDocumentRepository.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryDocumentRepository.java deleted file mode 100644 index d5bb101d..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryDocumentRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.repository; - -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain.DiaryDocument; -import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; - -public interface DiaryDocumentRepository extends ElasticsearchRepository { -} diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryImageDocumentRepository.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryImageDocumentRepository.java deleted file mode 100644 index b48047f5..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/repository/DiaryImageDocumentRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.repository; - -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain.DiaryImageDocument; -import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; - -public interface DiaryImageDocumentRepository extends ElasticsearchRepository { -} diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentService.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentService.java deleted file mode 100644 index 0a4d9c0a..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentService.java +++ /dev/null @@ -1,9 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.service; - -import moodbuddy.moodbuddy.domain.diary.domain.Diary; -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain.DiaryDocument; - -public interface DiaryDocumentService { - DiaryDocument save(Diary diary); - void delete(Long diaryId); -} diff --git a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentServiceImpl.java b/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentServiceImpl.java deleted file mode 100644 index 7f6a2245..00000000 --- a/src/main/java/moodbuddy/moodbuddy/global/common/elasticSearch/diary/service/DiaryDocumentServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package moodbuddy.moodbuddy.global.common.elasticSearch.diary.service; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import moodbuddy.moodbuddy.domain.diary.domain.Diary; -import moodbuddy.moodbuddy.global.common.base.MoodBuddyStatus; -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.domain.DiaryDocument; -import moodbuddy.moodbuddy.global.common.elasticSearch.diary.repository.DiaryDocumentRepository; -import moodbuddy.moodbuddy.global.common.exception.diary.DiaryNotFoundException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import static moodbuddy.moodbuddy.global.common.exception.ErrorCode.NOT_FOUND_DIARY; - -@Service -@Transactional(readOnly = true) -@Slf4j -@RequiredArgsConstructor -public class DiaryDocumentServiceImpl implements DiaryDocumentService { - private final DiaryDocumentRepository diaryDocumentRepository; - - @Override - public DiaryDocument save(Diary diary) { - return diaryDocumentRepository.save(DiaryDocument.from(diary)); - } - - @Override - public void delete(Long diaryId) { - findDiaryDocumentById(diaryId).updateMoodBuddyStatus(MoodBuddyStatus.DIS_ACTIVE); - } - - private DiaryDocument findDiaryDocumentById(Long diaryDocumentId) { - return diaryDocumentRepository.findById(diaryDocumentId) - .orElseThrow(() -> new DiaryNotFoundException(NOT_FOUND_DIARY)); - } -}