Skip to content

Commit

Permalink
Revert "create-user-not-compelet"
Browse files Browse the repository at this point in the history
This reverts commit 78875b2.
  • Loading branch information
junglesub committed Sep 23, 2024
1 parent 3452260 commit 1780701
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 188 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sourceSets {
}
}

// processResources { dependsOn "copyReactBuildFiles" }
processResources { dependsOn "copyReactBuildFiles" }

task installReact(type: Exec) {
workingDir "$frontendDir"
Expand Down
75 changes: 27 additions & 48 deletions src/main/java/com/thc/realspr/controller/TbuserController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.thc.realspr.controller;

import com.thc.realspr.domain.Tbuser;
import com.thc.realspr.dto.GoogleLoginRequest;
import com.thc.realspr.dto.GoogleLoginResponse;
import com.thc.realspr.exception.NoAuthorizationException;
import com.thc.realspr.service.GoogleAuthService;
import com.thc.realspr.service.TbuserService;
import com.thc.realspr.util.TokenFactory;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/api/tbuser")
Expand All @@ -19,72 +22,48 @@ public class TbuserController {

private final GoogleAuthService googleAuthService;


public TbuserController(TbuserService tbuserService, GoogleAuthService googleAuthService) {
this.tbuserService = tbuserService;
this.googleAuthService = googleAuthService;
}


// CREATE: POST 요청으로 새로운 사용자 생성
@PostMapping("")
public ResponseEntity<Tbuser> create(@RequestBody Map<String, Object> param) {
public Map<String, Object> create(@RequestBody Map<String, Object> param){
System.out.println(param);
// Tbuser response = tbuserService.create(param);
return ResponseEntity.ok(response);
return tbuserService.create(param);
}
@PutMapping("")
public Map<String, Object> update(@RequestBody Map<String, Object> param){
System.out.println(param);
return tbuserService.update(param);
}

// @PutMapping("")
// public Map<String, Object> update(@RequestBody Map<String, Object> param){
// System.out.println(param);
// return tbuserService.update(param);
// }
@GetMapping("/get/{id}")
public ResponseEntity<Tbuser> detail(@PathVariable("id") String id) {
public Map<String, Object> detail(@PathVariable("id") String id){
System.out.println(id);
Tbuser response = tbuserService.get(id);
return ResponseEntity.ok(response);
return tbuserService.get(id);
}


// Google 로그인 처리
// @PostMapping("/login/google")
// public ResponseEntity<GoogleLoginResponse> loginWithGoogle(@RequestBody GoogleLoginRequest request) {
// String email = googleAuthService.verifyGoogleToken(request.getCredential());
// String name = googleAuthService.verifyGoogleToken(request.getCredential());
// LocalDateTime now = LocalDateTime.now();
// String uuid = UUID.randomUUID().toString().replace("-", "");
// Tbuser tbuser = Tbuser.of(uuid, name, now, now);
//
// System.out.println("동작중입니다.");
// System.out.println("이메일: " + email);
// System.out.println("이름: " + name);
// System.out.println("UUID: " + uuid);
//
//
// System.out.println("동작중입니다. ");
//
// if (email == null || !email.endsWith("@handong.ac.kr")) {
// throw new NoAuthorizationException("Unauthorized user");
// }
//
//
// String refreshToken = TokenFactory.issueRefreshToken(email); // 리프레시 토큰 발급
//
// System.out.println(refreshToken);
// return ResponseEntity.ok(new GoogleLoginResponse(refreshToken));
//
// }

@PostMapping("/login/google")
public ResponseEntity<GoogleLoginResponse> loginWithGoogle(@RequestBody GoogleLoginRequest request) {
// 서비스 계층에서 유저 로그인 처리
Tbuser tbuser = tbuserService.loginWithGoogle(request.getCredential());
String email = googleAuthService.verifyGoogleToken(request.getCredential());

System.out.println("동작중입니다. ");

System.out.println(email);

// 리프레시 토큰 발급
String refreshToken = TokenFactory.issueRefreshToken(tbuser.getId());
if (email == null || !email.endsWith("@handong.ac.kr")) {
throw new NoAuthorizationException("Unauthorized user");
}

// 응답 리턴

String refreshToken = TokenFactory.issueRefreshToken(email); // 리프레시 토큰 발급

System.out.println(refreshToken);
return ResponseEntity.ok(new GoogleLoginResponse(refreshToken));

}

// @ResponseBody
Expand Down
75 changes: 29 additions & 46 deletions src/main/java/com/thc/realspr/domain/Tbuser.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,57 @@
package com.thc.realspr.domain;

import com.thc.realspr.dto.TbuserDto;
import com.thc.realspr.config.Role;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.antlr.v4.runtime.misc.NotNull;

import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@Entity
public class Tbuser {
/*
* - email
- uuid
- 이름
- last login time
- modified_at
- created_at*/
@Id private String id; // 이메일
@Setter @Column(nullable = false) private String uuid; // 사용자아이디
@Id private String id;
@Setter @Column(nullable = false) private String deleted; // 삭제여부

@Setter @Column(nullable = false) private String username; // 사용자아이디
@Setter @Column(nullable = false) private String password; // 비번
@Setter @Column(nullable = false) private String name;
@Setter @Column(nullable = false) private LocalDateTime last_login_time;
@Setter @Column(nullable = false) private LocalDateTime modified_at;
@Setter @Column(nullable = false) private LocalDateTime created_at; // 프로필 사진
@Setter @Column(nullable = false) private String nick;
@Setter @Column(nullable = false) private String phone;
@Setter @Column(nullable = false) private String mpic; // 프로필 사진
@Setter @Column(nullable = false, length=2000000) @Lob private String content; // 본문


@Enumerated(EnumType.STRING)
@NotNull
private Role role;


protected Tbuser(){}
private Tbuser(String id, String uuid, String name, LocalDateTime last_login_time, LocalDateTime modified_at, LocalDateTime created_at) {
this.id = id;
this.uuid = uuid;
this.name = name;
this.last_login_time = last_login_time;
this.modified_at = modified_at;
this.created_at = created_at;
}

public Tbuser(String uuid, String name, LocalDateTime last_login_time, LocalDateTime created_at) {
this.uuid = uuid;
private Tbuser(String username, String password, String name, String nick, String phone, String mpic, String content, Role role) {
this.username = username;
this.password = password;
this.name = name;
this.last_login_time = last_login_time;
this.created_at = created_at;
}

public Tbuser(String id) {
this.id = id;
this.nick = nick;
this.phone = phone;
this.mpic = mpic;
this.content = content;
this.role = role;
}



// TODO: role 추가 해야 함 .
public static Tbuser of(String id, String uuid, String name, LocalDateTime last_login_time, LocalDateTime created_at){
return new Tbuser(id, uuid, name, last_login_time, null, created_at);
public static Tbuser of(String username, String password){
return new Tbuser(username, password, "", "", "", "", "", null);
}

@PrePersist
public void onPrePersist() {
this.uuid = UUID.randomUUID().toString().replace("-", "");
this.id = UUID.randomUUID().toString().replace("-", "");
this.deleted = "N";
}



// public String getRoleKey(){
// return this.role.getKey();
// }
public String getRoleKey(){
return this.role.getKey();
}



Expand Down
124 changes: 79 additions & 45 deletions src/main/java/com/thc/realspr/dto/TbuserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

public class TbuserDto {

@Builder
Expand All @@ -25,59 +23,95 @@ public static class AccessReqDto{
@NotEmpty
private String refreshToken;
}

@Builder
@Schema
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class CreateReqDto{
// @Schema(description = "username", example="")
// @NotNull
// @NotEmpty
// @Size(max=400)
// private String username;
// @Schema(description = "password", example="")
// @NotNull
// @NotEmpty
// @Size(max=100)
// private String password;
//
// public Tbuser toEntity(){
// return Tbuser.of(username, password);
// }

@Schema(description = "사용자 이메일", example = "")
@NotNull(message = "email cannot be null")
@NotEmpty(message = "email cannot be empty")
@Size(max = 36, message = "email must be less than 36 characters")
private String id;


@Schema(description = "사용자 아이디(UUID)", example = "")
@NotNull(message = "UUID cannot be null")
@NotEmpty(message = "UUID cannot be empty")
@Size(max = 36, message = "UUID must be less than 36 characters")
private String uuid;
public static class ConfirmReqDto{
@Schema(description = "username", example="")
@NotNull
@NotEmpty
@Size(max=400)
private String username;
@Schema(description = "number", example="")
@NotNull
@NotEmpty
private String number;
}
@Builder
@Schema
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class UidReqDto{
@Schema(description = "username", example="")
@NotNull
@NotEmpty
@Size(max=400)
private String username;
}

@Schema(description = "유저 이름", example = "")
@NotNull(message = "Name cannot be null")
@NotEmpty(message = "Name cannot be empty")
@Size(max = 100, message = "Name must be less than 100 characters")
private String name;
@Builder
@Schema
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class LoginReqDto{
@Schema(description = "username", example="")
@NotNull
@NotEmpty
@Size(max=400)
private String username;
@Schema(description = "password", example="")
@NotNull
@NotEmpty
@Size(max=100)
private String password;
}

@Schema(description = "마지막 로그인 시간", example = "")
@NotNull(message = "Last login time cannot be null")
private LocalDateTime lastLoginTime;
@Builder
@Schema
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class SignupReqDto{
@Schema(description = "username", example="")
@NotNull
@NotEmpty
@Size(max=400)
private String username;
@Schema(description = "password", example="")
@NotNull
@NotEmpty
@Size(max=100)
private String password;
}

@Schema(description = "생성 시간", example = "")
@NotNull(message = "Created at time cannot be null")
private LocalDateTime createdAt;
@Builder
@Schema
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class CreateReqDto{
@Schema(description = "username", example="")
@NotNull
@NotEmpty
@Size(max=400)
private String username;
@Schema(description = "password", example="")
@NotNull
@NotEmpty
@Size(max=100)
private String password;

// Tbuser 엔티티로 변환하는 메서드
public Tbuser toEntity() {
return Tbuser.of(id ,uuid, name, lastLoginTime, createdAt);
public Tbuser toEntity(){
return Tbuser.of(username, password);
}
}
@Builder
Expand Down
Loading

0 comments on commit 1780701

Please sign in to comment.