Skip to content

Commit

Permalink
Merge pull request #144 from Team-Shaka/feature/141
Browse files Browse the repository at this point in the history
✨  Feat : 브리핑 수정 API 구현
  • Loading branch information
swa07016 authored Jan 7, 2024
2 parents 9d2c782 + ed38836 commit cbfd0ee
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/briefing/briefing/api/BriefingApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -69,4 +70,29 @@ public CommonResponse<BriefingResponseDTO.BriefingDetailDTO> 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<BriefingResponseDTO.BriefingUpdateDTO> patchBriefingContent(
@PathVariable(name = "id") Long id,
@RequestBody @Valid BriefingRequestDTO.BriefingUpdateDTO request
){

Briefing briefing = briefingCommandService.updateBriefing(id, request);
return CommonResponse.onSuccess(BriefingConverter.toBriefingUpdateDTO(briefing));
}
}
9 changes: 9 additions & 0 deletions src/main/java/briefing/briefing/api/BriefingConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,6 +18,8 @@
import briefing.briefing.domain.repository.BriefingRepository;
import lombok.RequiredArgsConstructor;

import javax.swing.text.html.Option;

@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
19 changes: 19 additions & 0 deletions src/main/java/briefing/briefing/domain/Briefing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import jakarta.persistence.*;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit cbfd0ee

Please sign in to comment.