From 688b3b4221612b2c455e58c3df297c3642077336 Mon Sep 17 00:00:00 2001 From: snacktime Date: Sun, 30 Jun 2024 17:26:27 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20TT-169=20controller=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stateless를 유지 할 수 있는 방향으로 api uri path구조 변경 --- .../script/controller/ScriptController.java | 39 ++++++++++++------- .../controller/SwaggerScriptInterface.java | 15 +++---- .../script/controller/ThemeController.java | 2 +- .../dto/request/ParagraphsRequestDTO.java | 2 +- .../SaveScriptAndSentenceResponseDTO.java | 4 -- .../SaveScriptAndSentencesResponseDTO.java | 4 ++ .../script/service/ScriptSentenceFacade.java | 2 +- .../peech/script/service/ScriptService.java | 4 +- .../peech/user/controller/UserController.java | 2 +- 9 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentenceResponseDTO.java create mode 100644 src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentencesResponseDTO.java diff --git a/src/main/java/com/twentythree/peech/script/controller/ScriptController.java b/src/main/java/com/twentythree/peech/script/controller/ScriptController.java index 08538fb1..cbf39893 100644 --- a/src/main/java/com/twentythree/peech/script/controller/ScriptController.java +++ b/src/main/java/com/twentythree/peech/script/controller/ScriptController.java @@ -4,7 +4,7 @@ import com.twentythree.peech.script.dto.response.ExpectedTimeResponseDTO; import com.twentythree.peech.script.dto.response.MajorScriptsResponseDTO; import com.twentythree.peech.script.dto.response.MinorScriptsResponseDTO; -import com.twentythree.peech.script.dto.response.SaveScriptAndSentenceResponseDTO; +import com.twentythree.peech.script.dto.response.SaveScriptAndSentencesResponseDTO; import com.twentythree.peech.script.service.ScriptSentenceFacade; import com.twentythree.peech.script.service.ScriptService; import io.swagger.v3.oas.annotations.Operation; @@ -18,29 +18,38 @@ public class ScriptController implements SwaggerScriptInterface{ private final ScriptSentenceFacade scriptSentenceFacade; private final ScriptService scriptService; - @Operation(summary = "문단들 입력", description = "버전 생성 및 저장, 대본 저장, 문장 저장.") - @PostMapping("/api/v1/script") - public SaveScriptAndSentenceResponseDTO saveScriptAndSentence(@RequestBody ParagraphsRequestDTO request) { - Long scriptId = scriptSentenceFacade.createScriptAndSentence(request.themeId(), request.paragraphs()); + @Operation(summary = "새로운 대본 생성", + description = "특정 주제를 themeId로 path에 넣고, 스크립트를 문단들로 나누어 RequestBody에 입력하면 새로운 버전, 대본, 문장 생성 및 저장.") + @PostMapping("/api/v1/themes/{themeId}/script") + public SaveScriptAndSentencesResponseDTO saveScriptAndSentences(@PathVariable("themeId") Long themeId, + @RequestBody ParagraphsRequestDTO request) { + Long scriptId = scriptSentenceFacade.createScriptAndSentences(themeId, request.paragraphs()); - return new SaveScriptAndSentenceResponseDTO(scriptId); + return new SaveScriptAndSentencesResponseDTO(scriptId); } - @GetMapping("/api/v1/script") - public ExpectedTimeResponseDTO getScriptAndSentenceExpectedTime(@RequestParam("scriptId") Long scriptId) { + @Operation(summary = "입력한 스크립트에 대한 예상 시간 가져오기", + description = "특정 주제의 스크립트를 themeId, scriptId로 path에 입력하면 전체 예상시간, 문단별 예상시간들을 응답") + @GetMapping("/api/v1/themes/{themeId}/scripts/{scriptId}/time") + public ExpectedTimeResponseDTO getScriptAndParagraphsExpectedTime(@PathVariable("themeId") Long themeId, + @PathVariable("scriptId") Long scriptId) { return scriptSentenceFacade.getScriptAndSentence(scriptId); } + @Operation(summary = "입력(메이저) 대본 가져오기", + description = "특정 주제의 themeId를 path에 넣으면 특정 주제에 대해 입력한(메이저) 스크립트들을 응답한다.") @Override - @GetMapping("/api/v1/script/{themeId}") - public MajorScriptsResponseDTO getMajorScript(@PathVariable("themeId") Long themeId) { - MajorScriptsResponseDTO majorScript = scriptService.getMajorScript(themeId); - return majorScript; + @GetMapping("/api/v1/themes/{themeId}/Scripts/majors") + public MajorScriptsResponseDTO getMajorScripts(@PathVariable("themeId") Long themeId) { + MajorScriptsResponseDTO majorScripts = scriptService.getMajorScripts(themeId); + return majorScripts; } + @Operation(summary = "측정(마이너) 대본 가져오기", + description = "특정 주제의 themeId와 메이저 대본의 버전(majorVersion)을 path에 입력하면 특정주제의 입력대본을 가지고 연습하여 나온 음성 스크립트들을 응답한다.") @Override - @GetMapping("/api/v1/script/{themeId}/{majorVersion}") - public MinorScriptsResponseDTO getMinorScript(@PathVariable("themeId") Long themeId, @PathVariable("majorVersion") Long majorVersion) { - return scriptService.getMinorScript(themeId, majorVersion); + @GetMapping("/api/v1/themes/{themeId}/scripts/{majorVersion}/minors") + public MinorScriptsResponseDTO getMinorScripts(@PathVariable("themeId") Long themeId, @PathVariable("majorVersion") Long majorVersion) { + return scriptService.getMinorScripts(themeId, majorVersion); } } diff --git a/src/main/java/com/twentythree/peech/script/controller/SwaggerScriptInterface.java b/src/main/java/com/twentythree/peech/script/controller/SwaggerScriptInterface.java index 3240f94d..52dea12e 100644 --- a/src/main/java/com/twentythree/peech/script/controller/SwaggerScriptInterface.java +++ b/src/main/java/com/twentythree/peech/script/controller/SwaggerScriptInterface.java @@ -4,27 +4,28 @@ import com.twentythree.peech.script.dto.response.ExpectedTimeResponseDTO; import com.twentythree.peech.script.dto.response.MajorScriptsResponseDTO; import com.twentythree.peech.script.dto.response.MinorScriptsResponseDTO; -import com.twentythree.peech.script.dto.response.SaveScriptAndSentenceResponseDTO; +import com.twentythree.peech.script.dto.response.SaveScriptAndSentencesResponseDTO; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; public interface SwaggerScriptInterface { - @ApiResponse(responseCode = "201", description = "성공", content = {@Content(schema = @Schema(implementation = SaveScriptAndSentenceResponseDTO.class), mediaType = "application/json")}) + @ApiResponse(responseCode = "201", description = "성공", content = {@Content(schema = @Schema(implementation = SaveScriptAndSentencesResponseDTO.class), mediaType = "application/json")}) @ApiResponse(responseCode = "400", description = "실패", content = {@Content(schema = @Schema(implementation = Error.class), mediaType = "application/json")}) - SaveScriptAndSentenceResponseDTO saveScriptAndSentence(@RequestBody ParagraphsRequestDTO request); + SaveScriptAndSentencesResponseDTO saveScriptAndSentences(@PathVariable("themeId") Long themeId, + @RequestBody ParagraphsRequestDTO request); @ApiResponse(responseCode = "200", description = "성공", content = {@Content(schema = @Schema(implementation = ExpectedTimeResponseDTO.class), mediaType = "application/json")}) @ApiResponse(responseCode = "400", description = "실패", content = {@Content(schema = @Schema(implementation = Error.class), mediaType = "application/json")}) - ExpectedTimeResponseDTO getScriptAndSentenceExpectedTime(@RequestParam("scriptId") Long scriptId); + ExpectedTimeResponseDTO getScriptAndParagraphsExpectedTime(@PathVariable("themeId") Long themeId, + @PathVariable("scriptId") Long scriptId); @ApiResponse(responseCode = "200", description = "success", content = {@Content(schema = @Schema(implementation = MajorScriptsResponseDTO.class), mediaType = "application/json")}) - MajorScriptsResponseDTO getMajorScript(@PathVariable Long themeId); + MajorScriptsResponseDTO getMajorScripts(@PathVariable Long themeId); @ApiResponse(responseCode = "200", description = "success", content = {@Content(schema = @Schema(implementation = MajorScriptsResponseDTO.class), mediaType = "application/json")}) - MinorScriptsResponseDTO getMinorScript(@PathVariable Long majorVersion, @PathVariable Long themeId); + MinorScriptsResponseDTO getMinorScripts(@PathVariable Long majorVersion, @PathVariable Long themeId); } diff --git a/src/main/java/com/twentythree/peech/script/controller/ThemeController.java b/src/main/java/com/twentythree/peech/script/controller/ThemeController.java index c70ad41a..0cf482f2 100644 --- a/src/main/java/com/twentythree/peech/script/controller/ThemeController.java +++ b/src/main/java/com/twentythree/peech/script/controller/ThemeController.java @@ -32,7 +32,7 @@ public ThemeIdResponseDTO saveTheme(@RequestBody ThemeTitleRequestDTO request, @ } @Override - @GetMapping("/api/v1/theme") + @GetMapping("/api/v1/themes") public ThemesResponseDTO getThemes(@LoginUserId UserIdDTO userIdDTO) { Long userId = userIdDTO.userId(); diff --git a/src/main/java/com/twentythree/peech/script/dto/request/ParagraphsRequestDTO.java b/src/main/java/com/twentythree/peech/script/dto/request/ParagraphsRequestDTO.java index ccf864d5..865c3441 100644 --- a/src/main/java/com/twentythree/peech/script/dto/request/ParagraphsRequestDTO.java +++ b/src/main/java/com/twentythree/peech/script/dto/request/ParagraphsRequestDTO.java @@ -1,5 +1,5 @@ package com.twentythree.peech.script.dto.request; -public record ParagraphsRequestDTO(Long themeId, String[] paragraphs) { +public record ParagraphsRequestDTO(String[] paragraphs) { } \ No newline at end of file diff --git a/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentenceResponseDTO.java b/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentenceResponseDTO.java deleted file mode 100644 index 037a3d22..00000000 --- a/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentenceResponseDTO.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.twentythree.peech.script.dto.response; - -public record SaveScriptAndSentenceResponseDTO(Long scriptId) { -} diff --git a/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentencesResponseDTO.java b/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentencesResponseDTO.java new file mode 100644 index 00000000..c81e1581 --- /dev/null +++ b/src/main/java/com/twentythree/peech/script/dto/response/SaveScriptAndSentencesResponseDTO.java @@ -0,0 +1,4 @@ +package com.twentythree.peech.script.dto.response; + +public record SaveScriptAndSentencesResponseDTO(Long scriptId) { +} diff --git a/src/main/java/com/twentythree/peech/script/service/ScriptSentenceFacade.java b/src/main/java/com/twentythree/peech/script/service/ScriptSentenceFacade.java index 7e3713f6..3f9a23f4 100644 --- a/src/main/java/com/twentythree/peech/script/service/ScriptSentenceFacade.java +++ b/src/main/java/com/twentythree/peech/script/service/ScriptSentenceFacade.java @@ -17,7 +17,7 @@ public class ScriptSentenceFacade { private final SentenceService sentenceService; @Transactional - public Long createScriptAndSentence(Long themeId, String[] paragraphs) { + public Long createScriptAndSentences(Long themeId, String[] paragraphs) { SaveScriptDTO saveScripDTO = scriptService.saveInputScript(themeId, paragraphs); List sentenceIds = sentenceService.saveInputSentencesByParagraphs(saveScripDTO.scriptEntity(), paragraphs); diff --git a/src/main/java/com/twentythree/peech/script/service/ScriptService.java b/src/main/java/com/twentythree/peech/script/service/ScriptService.java index 9d711d15..1f4df329 100644 --- a/src/main/java/com/twentythree/peech/script/service/ScriptService.java +++ b/src/main/java/com/twentythree/peech/script/service/ScriptService.java @@ -65,7 +65,7 @@ public LocalTime getInputExpectedScriptTime(Long scriptId) { return scriptEntity.getTotalExpectTime(); } - public MajorScriptsResponseDTO getMajorScript(Long themeId) { + public MajorScriptsResponseDTO getMajorScripts(Long themeId) { List scripts = scriptRepository.findMajorScriptByThemeId(themeId); List majorScript = new ArrayList<>(); for (ScriptEntity script : scripts) { @@ -75,7 +75,7 @@ public MajorScriptsResponseDTO getMajorScript(Long themeId) { return new MajorScriptsResponseDTO(majorScript); } - public MinorScriptsResponseDTO getMinorScript(Long themeId, Long majorVersion) { + public MinorScriptsResponseDTO getMinorScripts(Long themeId, Long majorVersion) { List scripts = scriptRepository.findMinorScriptByThemeIdAndMajorVersion(themeId, majorVersion); List minorScripts = new ArrayList<>(); diff --git a/src/main/java/com/twentythree/peech/user/controller/UserController.java b/src/main/java/com/twentythree/peech/user/controller/UserController.java index 819609c9..66ed9d0a 100644 --- a/src/main/java/com/twentythree/peech/user/controller/UserController.java +++ b/src/main/java/com/twentythree/peech/user/controller/UserController.java @@ -17,7 +17,7 @@ public class UserController implements SwaggerUserController{ private final UserService userService; @Operation(summary = "유저 가입", - description = "deviceId를 CreateUserRequestDTO에 담아 요청하면 생성된 UserId를 CreteUserResponseDTO에 담아 응답한다.") + description = "deviceId를 RequestBody에 담아 요청하면 새로운 유저를 생성하고 생성된 UserId를 응답한다.") @Override @PostMapping("api/v1/user") public CreateUserResponseDTO createUser(@RequestBody CreateUserRequestDTO request) { From 88351cc97d55feb8fdad6bd8538afafcb3c32732 Mon Sep 17 00:00:00 2001 From: snacktime Date: Sun, 30 Jun 2024 20:30:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20TT-169=20=EB=8C=80=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=20=EA=B5=AC=EB=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../twentythree/peech/script/controller/ScriptController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/twentythree/peech/script/controller/ScriptController.java b/src/main/java/com/twentythree/peech/script/controller/ScriptController.java index cbf39893..163885f8 100644 --- a/src/main/java/com/twentythree/peech/script/controller/ScriptController.java +++ b/src/main/java/com/twentythree/peech/script/controller/ScriptController.java @@ -39,7 +39,7 @@ public ExpectedTimeResponseDTO getScriptAndParagraphsExpectedTime(@PathVariable( @Operation(summary = "입력(메이저) 대본 가져오기", description = "특정 주제의 themeId를 path에 넣으면 특정 주제에 대해 입력한(메이저) 스크립트들을 응답한다.") @Override - @GetMapping("/api/v1/themes/{themeId}/Scripts/majors") + @GetMapping("/api/v1/themes/{themeId}/scripts/majors") public MajorScriptsResponseDTO getMajorScripts(@PathVariable("themeId") Long themeId) { MajorScriptsResponseDTO majorScripts = scriptService.getMajorScripts(themeId); return majorScripts;