-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/site/balpyo/script/controller/EveryScriptController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package site.balpyo.script.controller; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
import site.balpyo.script.dto.ScriptRequest; | ||
import site.balpyo.script.service.ScriptService; | ||
|
||
@RestController | ||
@CrossOrigin | ||
@RequiredArgsConstructor | ||
@RequestMapping("/every") | ||
public class EveryScriptController { | ||
|
||
private final ScriptService scriptService; | ||
|
||
@PostMapping("/script") | ||
public void saveScript(@RequestBody ScriptRequest scriptRequest){ | ||
scriptService.saveScript(scriptRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/site/balpyo/script/service/ScriptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package site.balpyo.script.service; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import site.balpyo.ai.entity.AIGenerateLogEntity; | ||
import site.balpyo.ai.entity.GPTInfoEntity; | ||
import site.balpyo.ai.repository.AIGenerateLogRepository; | ||
import site.balpyo.ai.repository.GPTInfoRepository; | ||
import site.balpyo.common.dto.CommonResponse; | ||
import site.balpyo.guest.entity.GuestEntity; | ||
import site.balpyo.guest.repository.GuestRepository; | ||
import site.balpyo.script.dto.ScriptRequest; | ||
import site.balpyo.script.entity.ScriptEntity; | ||
import site.balpyo.script.repository.ScriptRepository; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ScriptService { | ||
|
||
private final ScriptRepository scriptRepository; | ||
|
||
private final GuestRepository guestRepository; | ||
private final AIGenerateLogRepository aiGenerateLogRepository; | ||
private final GPTInfoRepository gptInfoRepository; | ||
|
||
|
||
public ResponseEntity<CommonResponse> saveScript(ScriptRequest scriptRequest) { | ||
|
||
|
||
Optional<GuestEntity> guestEntity = guestRepository.findById(scriptRequest.getUid()); | ||
Optional<GPTInfoEntity> gptInfoEntity = gptInfoRepository.findById(scriptRequest.getGptId()); | ||
Optional<AIGenerateLogEntity> aiGenerateLogEntity = aiGenerateLogRepository.findByGptInfoEntity(gptInfoEntity.get()); | ||
|
||
|
||
ScriptEntity scriptEntity = ScriptEntity.builder() | ||
.title(scriptRequest.getTitle()) | ||
.script(scriptRequest.getScript()) | ||
.secTime(scriptRequest.getSecTime()) | ||
.guestEntity(guestEntity.get()) | ||
.aiGenerateLogEntity(aiGenerateLogEntity.get()) | ||
.build(); | ||
|
||
scriptRepository.save(scriptEntity); | ||
|
||
return CommonResponse.success(scriptEntity); | ||
} | ||
} |