Skip to content

Commit

Permalink
Feat : uid 생성,검증 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
MatchaKim committed Mar 21, 2024
1 parent 941e2dc commit f9b947a
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/site/balpyo/common/util/GuestUtils.java
Original file line number Diff line number Diff line change
@@ -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> guestEntity = guestRepository.findById(uid);
return guestEntity.isPresent();
}
}
26 changes: 26 additions & 0 deletions src/main/java/site/balpyo/guest/controller/GuestController.java
Original file line number Diff line number Diff line change
@@ -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<CommonResponse> generateUniqueIdentifier(){
return guestService.generateUID();
}

@GetMapping("/uid")
public ResponseEntity<CommonResponse> verifyUID(@RequestParam String uid){
return guestService.verifyUID(uid);
}

}
13 changes: 13 additions & 0 deletions src/main/java/site/balpyo/guest/dto/UIDResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package site.balpyo.guest.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class UIDResponse {

private String uid;


}
11 changes: 11 additions & 0 deletions src/main/java/site/balpyo/guest/dto/VerifyResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package site.balpyo.guest.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@AllArgsConstructor
@Data
public class VerifyResponse {
boolean isVerified;
String yourUID;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -22,7 +20,6 @@
public class GuestEntity {

@Id
@GeneratedValue
private String uid;

@CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GuestEntity, String> {
}
37 changes: 37 additions & 0 deletions src/main/java/site/balpyo/guest/service/GuestService.java
Original file line number Diff line number Diff line change
@@ -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<CommonResponse> 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<CommonResponse> verifyUID(String uid) {
boolean isVerified = GuestUtils.verifyUID(uid,guestRepository);

return CommonResponse.success(new VerifyResponse(isVerified,uid));
}
}
14 changes: 14 additions & 0 deletions src/main/java/site/balpyo/script/dto/ScriptRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 2 additions & 4 deletions src/main/java/site/balpyo/script/entity/ScriptEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +30,7 @@ public class ScriptEntity {
private AIGenerateLogEntity aiGenerateLogEntity;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "guest_id")
@JoinColumn(name = "uid")
private GuestEntity guestEntity;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptEntity, Long> {
}
10 changes: 0 additions & 10 deletions src/main/java/site/balpyo/user/repository/GuestRepository.java

This file was deleted.

0 comments on commit f9b947a

Please sign in to comment.