diff --git a/src/main/java/briefing/briefing/api/BriefingApi.java b/src/main/java/briefing/briefing/api/BriefingApi.java index 73d43af..f9ac02f 100644 --- a/src/main/java/briefing/briefing/api/BriefingApi.java +++ b/src/main/java/briefing/briefing/api/BriefingApi.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Optional; +import jakarta.validation.Valid; import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -69,4 +70,29 @@ public CommonResponse findBriefing( public void createBriefing(@RequestBody final BriefingRequestDTO.BriefingCreate request) { briefingCommandService.createBriefing(request); } + + + /* + * TODO 브리핑 수정 API는 우선적으로 인가 처리를 진행하지 않으나 + * 빠른 시일 내로 브리핑 등록과 함께 인가 처리 예정 + * 즉 유저에게 권한을 부여하는 일련의 과정에 대한 리팩토링이 필요함 이는 CYY1007이 진행하겠음 + */ + + /** + * + * @param id, BriefingResponseDTO.BriefingUpdateDTO + * @return 수정된 값, 요청으로 온 값과 동일 + */ + + @Operation(summary = "03-04Briefing \uD83D\uDCF0 브리핑 내용 수정", description = "") + @Parameter(name = "id", description = "브리핑 아이디", example = "1") + @PatchMapping("/briefings/{id}") + public CommonResponse patchBriefingContent( + @PathVariable(name = "id") Long id, + @RequestBody @Valid BriefingRequestDTO.BriefingUpdateDTO request + ){ + + Briefing briefing = briefingCommandService.updateBriefing(id, request); + return CommonResponse.onSuccess(BriefingConverter.toBriefingUpdateDTO(briefing)); + } } diff --git a/src/main/java/briefing/briefing/api/BriefingConverter.java b/src/main/java/briefing/briefing/api/BriefingConverter.java index 81d7b79..0cffbe8 100644 --- a/src/main/java/briefing/briefing/api/BriefingConverter.java +++ b/src/main/java/briefing/briefing/api/BriefingConverter.java @@ -196,4 +196,13 @@ public static BriefingResponseDTO.BriefingV2PreviewListDTO toBriefingPreviewV2Te .briefings(tempDTOList) .build(); } + + public static BriefingResponseDTO.BriefingUpdateDTO toBriefingUpdateDTO(Briefing briefing){ + return BriefingResponseDTO.BriefingUpdateDTO + .builder() + .title(briefing.getTitle()) + .subTitle(briefing.getSubtitle()) + .content(briefing.getContent()) + .build(); + } } diff --git a/src/main/java/briefing/briefing/application/BriefingCommandService.java b/src/main/java/briefing/briefing/application/BriefingCommandService.java index bcfac21..171e159 100644 --- a/src/main/java/briefing/briefing/application/BriefingCommandService.java +++ b/src/main/java/briefing/briefing/application/BriefingCommandService.java @@ -1,7 +1,10 @@ package briefing.briefing.application; import java.util.List; +import java.util.Optional; +import briefing.exception.ErrorCode; +import briefing.exception.handler.BriefingException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +18,8 @@ import briefing.briefing.domain.repository.BriefingRepository; import lombok.RequiredArgsConstructor; +import javax.swing.text.html.Option; + @Service @Transactional @RequiredArgsConstructor @@ -36,4 +41,13 @@ public void createBriefing(final BriefingRequestDTO.BriefingCreate request) { articles.stream().map(article -> new BriefingArticle(briefing, article)).toList(); briefingArticleRepository.saveAll(briefingArticles); } + + public Briefing updateBriefing(Long id, final BriefingRequestDTO.BriefingUpdateDTO request){ + + Briefing briefing = briefingRepository.findById(id).orElseThrow(() -> new BriefingException(ErrorCode.NOT_FOUND_BRIEFING)); + + briefing.updateBriefing(request.getTitle(),request.getSubTitle(),request.getContent()); + + return briefing; + } } diff --git a/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java b/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java index 794d524..3ca7078 100644 --- a/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java +++ b/src/main/java/briefing/briefing/application/dto/BriefingRequestDTO.java @@ -7,7 +7,10 @@ import briefing.briefing.domain.BriefingType; import briefing.briefing.domain.TimeOfDay; import briefing.chatting.domain.GptModel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; public class BriefingRequestDTO { @@ -36,4 +39,11 @@ public static class BriefingCreate { TimeOfDay timeOfDay = TimeOfDay.MORNING; BriefingType briefingType = BriefingType.KOREA; } + + @Getter + public static class BriefingUpdateDTO{ + String title; + String subTitle; + String content; + } } diff --git a/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java b/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java index 9f4b7bd..48c899d 100644 --- a/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java +++ b/src/main/java/briefing/briefing/application/dto/BriefingResponseDTO.java @@ -125,4 +125,14 @@ public static class BriefingPreviewV2TempDTO { String subtitle; Integer scrapCount; } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class BriefingUpdateDTO{ + String title; + String subTitle; + String content; + } } diff --git a/src/main/java/briefing/briefing/domain/Briefing.java b/src/main/java/briefing/briefing/domain/Briefing.java index e028401..bab2124 100644 --- a/src/main/java/briefing/briefing/domain/Briefing.java +++ b/src/main/java/briefing/briefing/domain/Briefing.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import jakarta.persistence.*; @@ -53,4 +54,22 @@ public class Briefing extends BaseDateTimeEntity { public void setScrapCount(Integer scrapCount) { this.scrapCount = scrapCount; } + + public void setTitle(String title) { + this.title = title; + } + + public void setSubtitle(String subtitle) { + this.subtitle = subtitle; + } + + public void setContent(String content) { + this.content = content; + } + + public void updateBriefing(String title, String subtitle, String content){ + Optional.ofNullable(title).ifPresent(this::setTitle); + Optional.ofNullable(subtitle).ifPresent(this::setSubtitle); + Optional.ofNullable(content).ifPresent(this::setContent); + } }