Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat : 브리핑 수정 API 구현 #144

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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이 진행하겠음
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동의합니다!
관리자 권한 유저에게만 열어줘야 할 것 같습니다.

/**
*
* @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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우선은 서비스 계층에서 이런 형태로 방어적으로 작성해도 무방하다고 생각합니다.
컨트롤러계층에서는 추후 AOP로 PathVariable 존재유무를 검증해도 좋을 것 같습니다.


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);
}
}
Loading