11package com .movelog .domain .news .presentation ;
22
33import com .movelog .domain .news .application .NewsService ;
4+ import com .movelog .domain .news .dto .request .CreateNewsReq ;
45import com .movelog .domain .news .dto .request .NewsHeadLineReq ;
56import com .movelog .domain .news .dto .response .HeadLineRes ;
67import com .movelog .global .config .security .token .CurrentUser ;
78import com .movelog .global .config .security .token .UserPrincipal ;
9+ import com .movelog .global .payload .Message ;
10+ import com .movelog .global .util .ApiResponseUtil ;
811import io .swagger .v3 .oas .annotations .Operation ;
912import io .swagger .v3 .oas .annotations .Parameter ;
13+ import io .swagger .v3 .oas .annotations .media .Content ;
14+ import io .swagger .v3 .oas .annotations .media .Schema ;
1015import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
16+
1117import io .swagger .v3 .oas .annotations .responses .ApiResponses ;
1218import io .swagger .v3 .oas .annotations .tags .Tag ;
1319import lombok .RequiredArgsConstructor ;
1420import lombok .extern .slf4j .Slf4j ;
15- import org .springframework .web .bind .annotation .PostMapping ;
16- import org .springframework .web .bind .annotation .RequestBody ;
17- import org .springframework .web .bind .annotation .RequestMapping ;
18- import org .springframework .web .bind .annotation .RestController ;
21+ import org .springframework .http .ResponseEntity ;
22+ import org .springframework .security .core .annotation .AuthenticationPrincipal ;
23+ import org .springframework .web .ErrorResponse ;
24+ import org .springframework .web .bind .annotation .*;
25+ import org .springframework .web .multipart .MultipartFile ;
1926
2027import java .util .List ;
2128
@@ -30,17 +37,43 @@ public class NewsController {
3037
3138 @ Operation (summary = "뉴스 헤드라인 생성 API" , description = "뉴스 헤드라인을 생성하는 API입니다." )
3239 @ ApiResponses (value = {
33- @ ApiResponse (responseCode = "200" , description = "뉴스 헤드라인 생성 성공" ),
34- @ ApiResponse (responseCode = "400" , description = "뉴스 헤드라인 생성 실패" )
40+ @ ApiResponse (responseCode = "200" , description = "뉴스 헤드라인 생성 성공" ,
41+ content = @ Content (mediaType = "application/json" , schema = @ Schema (implementation = List .class ))),
42+ @ ApiResponse (responseCode = "400" , description = "뉴스 헤드라인 생성 실패" ,
43+ content = @ Content (mediaType = "application/json" , schema = @ Schema (implementation = ErrorResponse .class )))
3544 })
36- @ PostMapping ("/headline" )
37- public List <HeadLineRes > createHeadLine (
38- @ Parameter (description = "Access Token을 입력해주세요." , required = true ) @ CurrentUser UserPrincipal userPrincipal ,
45+ @ PostMapping ("/{keywordId}/headline" )
46+ public ResponseEntity <?> createHeadLine (
47+ @ Parameter (description = "Access Token을 입력해주세요." , required = true ) @ AuthenticationPrincipal UserPrincipal userPrincipal ,
48+ @ Parameter (description = "키워드 ID(동사-명사 쌍에 대한 ID)를 입력해주세요." , required = true ) @ PathVariable Long keywordId ,
3949 @ Parameter (description = "뉴스 헤드라인 생성 요청" , required = true ) @ RequestBody NewsHeadLineReq newsHeadLineReq
4050 ) {
41- return newsService .createHeadLine (userPrincipal , newsHeadLineReq );
51+ List <HeadLineRes > response = newsService .createHeadLine (userPrincipal , keywordId , newsHeadLineReq );
52+ return ResponseEntity .ok (ApiResponseUtil .success (response ));
4253 }
4354
4455
56+ @ Operation (summary = "뉴스 생성 및 저장 API(기존 이미지 기록 기반)" , description = "사용자의 기존 기록 이미지로 뉴스를 생성합니다." )
57+ @ ApiResponses (value = {
58+ @ ApiResponse (responseCode = "200" , description = "뉴스 생성 및 저장 성공" ,
59+ content = @ Content (mediaType = "application/json" , schema = @ Schema (implementation = Message .class ))),
60+ @ ApiResponse (responseCode = "400" , description = "뉴스 생성 및 저장 실패" ,
61+ content = @ Content (mediaType = "application/json" , schema = @ Schema (implementation = ErrorResponse .class )))
62+ })
63+ @ PostMapping ("/{keywordId}" )
64+ public ResponseEntity <?> createNews (
65+ @ Parameter (description = "Access Token을 입력해주세요." , required = true ) @ AuthenticationPrincipal UserPrincipal userPrincipal ,
66+ @ Parameter (description = "키워드 ID(동사-명사 쌍에 대한 ID)를 입력해주세요." , required = true ) @ PathVariable Long keywordId ,
67+ @ Parameter (description = "뉴스 생성 및 저장을 위한 정보를 입력해주세요" , required = true ) @ RequestPart CreateNewsReq createNewsReq ,
68+ @ Parameter (description = "뉴스 이미지를 파일 형식으로 입력해주세요" , required = true ) @ RequestParam (value = "img" , required = false ) MultipartFile img
69+ ) {
70+ newsService .createNews (userPrincipal , keywordId , createNewsReq , img );
71+ return ResponseEntity .ok (ApiResponseUtil .success (Message .builder ().message ("뉴스가 생성되었습니다." ).build ()));
72+ }
73+
74+
75+
76+
77+
4578
4679}
0 commit comments