From fd30ca4c9a8b02aacd20ee759e27aa723a9fcf18 Mon Sep 17 00:00:00 2001 From: LeeJiWon Date: Thu, 22 Aug 2024 22:00:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20users=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media/user/controller/UserController.java | 14 +++++++ .../java/wanted/media/user/domain/Code.java | 37 +++++++++++++++++++ .../java/wanted/media/user/domain/Grade.java | 5 +++ .../java/wanted/media/user/domain/Token.java | 28 ++++++++++++++ .../java/wanted/media/user/domain/User.java | 21 ++++++++++- .../media/user/repository/UserRepository.java | 11 ++++++ .../media/user/service/UserService.java | 12 ++++++ 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/main/java/wanted/media/user/controller/UserController.java create mode 100644 src/main/java/wanted/media/user/domain/Code.java create mode 100644 src/main/java/wanted/media/user/domain/Grade.java create mode 100644 src/main/java/wanted/media/user/domain/Token.java create mode 100644 src/main/java/wanted/media/user/repository/UserRepository.java create mode 100644 src/main/java/wanted/media/user/service/UserService.java diff --git a/src/main/java/wanted/media/user/controller/UserController.java b/src/main/java/wanted/media/user/controller/UserController.java new file mode 100644 index 0000000..867ccff --- /dev/null +++ b/src/main/java/wanted/media/user/controller/UserController.java @@ -0,0 +1,14 @@ +package wanted.media.user.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import wanted.media.user.service.UserService; + +@RestController +@RequestMapping("/user") +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; +} diff --git a/src/main/java/wanted/media/user/domain/Code.java b/src/main/java/wanted/media/user/domain/Code.java new file mode 100644 index 0000000..7f33643 --- /dev/null +++ b/src/main/java/wanted/media/user/domain/Code.java @@ -0,0 +1,37 @@ +package wanted.media.user.domain; + +import jakarta.persistence.*; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; + +import java.time.LocalDateTime; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +@Entity +@Table(name = "codes") +public class Code { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "code_id", nullable = false) + private Long codeId; + + @OneToOne + @JoinColumn(name = "user_id") + private User user; + + @Size(max = 10) + @Column(name = "auth_code", nullable = false) + private String authCode; + + @CreatedDate + @Column(name = "created_time") + private LocalDateTime createdTime; +} diff --git a/src/main/java/wanted/media/user/domain/Grade.java b/src/main/java/wanted/media/user/domain/Grade.java new file mode 100644 index 0000000..f52dd75 --- /dev/null +++ b/src/main/java/wanted/media/user/domain/Grade.java @@ -0,0 +1,5 @@ +package wanted.media.user.domain; + +public enum Grade { + NORMAL_USER, PREMIUM_USER; +} diff --git a/src/main/java/wanted/media/user/domain/Token.java b/src/main/java/wanted/media/user/domain/Token.java new file mode 100644 index 0000000..58c14ce --- /dev/null +++ b/src/main/java/wanted/media/user/domain/Token.java @@ -0,0 +1,28 @@ +package wanted.media.user.domain; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +@Entity +@Table(name = "tokens") +public class Token { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "token_id", nullable = false) + private Long tokenId; + + @Column(name = "refresh_token", nullable = false) + private String refreshToken; + + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private User user; +} diff --git a/src/main/java/wanted/media/user/domain/User.java b/src/main/java/wanted/media/user/domain/User.java index 0c4cca0..6da7d1a 100644 --- a/src/main/java/wanted/media/user/domain/User.java +++ b/src/main/java/wanted/media/user/domain/User.java @@ -1,8 +1,10 @@ package wanted.media.user.domain; import jakarta.persistence.*; +import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import wanted.media.content.domain.Content; @@ -14,7 +16,8 @@ @AllArgsConstructor @Builder @Entity -@Table(name="users") +@Getter +@Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.UUID) @@ -24,4 +27,20 @@ public class User { @OneToMany(mappedBy = "user") @Builder.Default List interviews = new ArrayList<>(); + + @Column(unique = true, nullable = false) + @Size(max = 50) + private String account; + + @Size(max = 200) + @Column(nullable = false) + private String email; + + @Size(max = 200) + @Column(nullable = false) + private String password; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private Grade grade; } diff --git a/src/main/java/wanted/media/user/repository/UserRepository.java b/src/main/java/wanted/media/user/repository/UserRepository.java new file mode 100644 index 0000000..49fe077 --- /dev/null +++ b/src/main/java/wanted/media/user/repository/UserRepository.java @@ -0,0 +1,11 @@ +package wanted.media.user.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import wanted.media.user.domain.User; + +import java.util.UUID; + +@Repository +public interface UserRepository extends JpaRepository { +} diff --git a/src/main/java/wanted/media/user/service/UserService.java b/src/main/java/wanted/media/user/service/UserService.java new file mode 100644 index 0000000..e642526 --- /dev/null +++ b/src/main/java/wanted/media/user/service/UserService.java @@ -0,0 +1,12 @@ +package wanted.media.user.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import wanted.media.user.repository.UserRepository; + +@Service +@RequiredArgsConstructor +public class UserService { + + private final UserRepository userRepository; +} From 6a9705ee17b11e239f0f7130345dacc4e2e7b392 Mon Sep 17 00:00:00 2001 From: LeeJiWon Date: Thu, 22 Aug 2024 22:23:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20spring=20security,=20jwt=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 42 ++++++++++--------- .../media/user/config/SecurityConfig.java | 7 ++++ 2 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/main/java/wanted/media/user/config/SecurityConfig.java diff --git a/build.gradle b/build.gradle index dd80e82..cd13b6d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,40 +1,42 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.2.8' - id 'io.spring.dependency-management' version '1.1.6' + id 'java' + id 'org.springframework.boot' version '3.2.8' + id 'io.spring.dependency-management' version '1.1.6' } group = 'wanted' version = '0.0.1-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.boot:spring-boot-starter-web' - compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' - runtimeOnly 'com.mysql:mysql-connector-j' - annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'io.jsonwebtoken:jjwt:0.9.1' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.h2database:h2' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } diff --git a/src/main/java/wanted/media/user/config/SecurityConfig.java b/src/main/java/wanted/media/user/config/SecurityConfig.java new file mode 100644 index 0000000..0d84f89 --- /dev/null +++ b/src/main/java/wanted/media/user/config/SecurityConfig.java @@ -0,0 +1,7 @@ +package wanted.media.user.config; + +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@EnableWebSecurity +public class SecurityConfig { +}