Skip to content

Commit

Permalink
Feat : 게스트 회원 관련 api개발
Browse files Browse the repository at this point in the history
  • Loading branch information
MatchaKim committed Mar 22, 2024
1 parent f9b947a commit 1f9e464
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import site.balpyo.ai.entity.AIGenerateLogEntity;
import site.balpyo.ai.entity.GPTInfoEntity;

import java.util.Optional;

@Repository
public interface AIGenerateLogRepository extends JpaRepository<AIGenerateLogEntity, Long> {
Optional<AIGenerateLogEntity> findByGptInfoEntity(GPTInfoEntity gptInfoEntity);
}
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);
}
}
1 change: 1 addition & 0 deletions src/main/java/site/balpyo/script/dto/ScriptRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class ScriptRequest {
private String script;
private String gptId;
private String uid;
private String title;
private Integer secTime;
}
7 changes: 7 additions & 0 deletions src/main/java/site/balpyo/script/entity/ScriptEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public class ScriptEntity {
@GeneratedValue
private Long script_id;

@Lob
private String script;

private String title;

private Integer secTime;

@CreationTimestamp
private LocalDateTime createdAt;

Expand Down
51 changes: 51 additions & 0 deletions src/main/java/site/balpyo/script/service/ScriptService.java
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);
}
}

0 comments on commit 1f9e464

Please sign in to comment.