diff --git a/src/main/java/site/balpyo/ai/entity/AIGenerateLogEntity.java b/src/main/java/site/balpyo/ai/entity/AIGenerateLogEntity.java index 9678f90..01aca5c 100644 --- a/src/main/java/site/balpyo/ai/entity/AIGenerateLogEntity.java +++ b/src/main/java/site/balpyo/ai/entity/AIGenerateLogEntity.java @@ -7,7 +7,6 @@ import org.hibernate.annotations.CreationTimestamp; import site.balpyo.ai.dto.AIGenerateRequest; import site.balpyo.script.entity.ScriptEntity; -import site.balpyo.user.entity.GuestEntity; import javax.persistence.*; import java.time.LocalDateTime; diff --git a/src/main/java/site/balpyo/common/util/GuestUtils.java b/src/main/java/site/balpyo/common/util/GuestUtils.java new file mode 100644 index 0000000..38afd36 --- /dev/null +++ b/src/main/java/site/balpyo/common/util/GuestUtils.java @@ -0,0 +1,19 @@ +package site.balpyo.common.util; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import site.balpyo.guest.entity.GuestEntity; +import site.balpyo.guest.repository.GuestRepository; + +import java.util.Optional; + +@Component +@RequiredArgsConstructor +public class GuestUtils { + + public static boolean verifyUID(String uid, GuestRepository guestRepository){ + Optional guestEntity = guestRepository.findById(uid); + return guestEntity.isPresent(); + } +} diff --git a/src/main/java/site/balpyo/guest/controller/GuestController.java b/src/main/java/site/balpyo/guest/controller/GuestController.java new file mode 100644 index 0000000..ca2973a --- /dev/null +++ b/src/main/java/site/balpyo/guest/controller/GuestController.java @@ -0,0 +1,26 @@ +package site.balpyo.guest.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import site.balpyo.common.dto.CommonResponse; +import site.balpyo.guest.service.GuestService; + +@RestController +@CrossOrigin +@RequiredArgsConstructor +@RequestMapping("/guest") +public class GuestController { + + private final GuestService guestService; + @PostMapping("/uid") + public ResponseEntity generateUniqueIdentifier(){ + return guestService.generateUID(); + } + + @GetMapping("/uid") + public ResponseEntity verifyUID(@RequestParam String uid){ + return guestService.verifyUID(uid); + } + +} diff --git a/src/main/java/site/balpyo/guest/dto/UIDResponse.java b/src/main/java/site/balpyo/guest/dto/UIDResponse.java new file mode 100644 index 0000000..c9f1cce --- /dev/null +++ b/src/main/java/site/balpyo/guest/dto/UIDResponse.java @@ -0,0 +1,13 @@ +package site.balpyo.guest.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class UIDResponse { + + private String uid; + + +} diff --git a/src/main/java/site/balpyo/guest/dto/VerifyResponse.java b/src/main/java/site/balpyo/guest/dto/VerifyResponse.java new file mode 100644 index 0000000..4275cf6 --- /dev/null +++ b/src/main/java/site/balpyo/guest/dto/VerifyResponse.java @@ -0,0 +1,11 @@ +package site.balpyo.guest.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class VerifyResponse { + boolean isVerified; + String yourUID; +} diff --git a/src/main/java/site/balpyo/user/entity/GuestEntity.java b/src/main/java/site/balpyo/guest/entity/GuestEntity.java similarity index 83% rename from src/main/java/site/balpyo/user/entity/GuestEntity.java rename to src/main/java/site/balpyo/guest/entity/GuestEntity.java index 420a62c..80d4064 100644 --- a/src/main/java/site/balpyo/user/entity/GuestEntity.java +++ b/src/main/java/site/balpyo/guest/entity/GuestEntity.java @@ -1,15 +1,13 @@ -package site.balpyo.user.entity; +package site.balpyo.guest.entity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; -import site.balpyo.ai.entity.GPTInfoEntity; import site.balpyo.script.entity.ScriptEntity; import javax.persistence.*; -import java.rmi.server.UID; import java.time.LocalDateTime; import java.util.List; @@ -22,7 +20,6 @@ public class GuestEntity { @Id - @GeneratedValue private String uid; @CreationTimestamp diff --git a/src/main/java/site/balpyo/guest/repository/GuestRepository.java b/src/main/java/site/balpyo/guest/repository/GuestRepository.java new file mode 100644 index 0000000..b80aaaa --- /dev/null +++ b/src/main/java/site/balpyo/guest/repository/GuestRepository.java @@ -0,0 +1,7 @@ +package site.balpyo.guest.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import site.balpyo.guest.entity.GuestEntity; + +public interface GuestRepository extends JpaRepository { +} diff --git a/src/main/java/site/balpyo/guest/service/GuestService.java b/src/main/java/site/balpyo/guest/service/GuestService.java new file mode 100644 index 0000000..ade5dcd --- /dev/null +++ b/src/main/java/site/balpyo/guest/service/GuestService.java @@ -0,0 +1,37 @@ +package site.balpyo.guest.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import site.balpyo.common.dto.CommonResponse; +import site.balpyo.common.util.GuestUtils; +import site.balpyo.guest.dto.UIDResponse; +import site.balpyo.guest.dto.VerifyResponse; +import site.balpyo.guest.entity.GuestEntity; +import site.balpyo.guest.repository.GuestRepository; + +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class GuestService { + + private final GuestRepository guestRepository; + public ResponseEntity generateUID(){ + UUID uuid = UUID.randomUUID(); + String uuidString = uuid.toString(); + + GuestEntity guestEntity = GuestEntity.builder() + .uid(uuidString) + .build(); + guestRepository.save(guestEntity); + + return CommonResponse.success(new UIDResponse(uuidString)); + } + + public ResponseEntity verifyUID(String uid) { + boolean isVerified = GuestUtils.verifyUID(uid,guestRepository); + + return CommonResponse.success(new VerifyResponse(isVerified,uid)); + } +} diff --git a/src/main/java/site/balpyo/script/dto/ScriptRequest.java b/src/main/java/site/balpyo/script/dto/ScriptRequest.java new file mode 100644 index 0000000..138c9d9 --- /dev/null +++ b/src/main/java/site/balpyo/script/dto/ScriptRequest.java @@ -0,0 +1,14 @@ +package site.balpyo.script.dto; + + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ScriptRequest { + private String script; + private String gptId; + private String title; + private Integer secTime; +} diff --git a/src/main/java/site/balpyo/script/entity/ScriptEntity.java b/src/main/java/site/balpyo/script/entity/ScriptEntity.java index ef88b5a..779dc72 100644 --- a/src/main/java/site/balpyo/script/entity/ScriptEntity.java +++ b/src/main/java/site/balpyo/script/entity/ScriptEntity.java @@ -6,11 +6,9 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; import site.balpyo.ai.entity.AIGenerateLogEntity; -import site.balpyo.ai.entity.GPTInfoEntity; -import site.balpyo.user.entity.GuestEntity; +import site.balpyo.guest.entity.GuestEntity; import javax.persistence.*; -import java.rmi.server.UID; import java.time.LocalDateTime; @Data @@ -32,7 +30,7 @@ public class ScriptEntity { private AIGenerateLogEntity aiGenerateLogEntity; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "guest_id") + @JoinColumn(name = "uid") private GuestEntity guestEntity; diff --git a/src/main/java/site/balpyo/script/repository/ScriptRepository.java b/src/main/java/site/balpyo/script/repository/ScriptRepository.java index 0a7217d..b0e3aac 100644 --- a/src/main/java/site/balpyo/script/repository/ScriptRepository.java +++ b/src/main/java/site/balpyo/script/repository/ScriptRepository.java @@ -2,7 +2,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import site.balpyo.script.entity.ScriptEntity; -import site.balpyo.user.entity.GuestEntity; public interface ScriptRepository extends JpaRepository { } diff --git a/src/main/java/site/balpyo/user/repository/GuestRepository.java b/src/main/java/site/balpyo/user/repository/GuestRepository.java deleted file mode 100644 index a9e03ca..0000000 --- a/src/main/java/site/balpyo/user/repository/GuestRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package site.balpyo.user.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import site.balpyo.ai.entity.AIGenerateLogEntity; -import site.balpyo.user.entity.GuestEntity; - -import java.rmi.server.UID; - -public interface GuestRepository extends JpaRepository { -}