Skip to content

Commit

Permalink
feat : users 공통 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
jw427 committed Aug 22, 2024
1 parent d16ae82 commit fd30ca4
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/java/wanted/media/user/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -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;
}
37 changes: 37 additions & 0 deletions src/main/java/wanted/media/user/domain/Code.java
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 5 additions & 0 deletions src/main/java/wanted/media/user/domain/Grade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package wanted.media.user.domain;

public enum Grade {
NORMAL_USER, PREMIUM_USER;
}
28 changes: 28 additions & 0 deletions src/main/java/wanted/media/user/domain/Token.java
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 20 additions & 1 deletion src/main/java/wanted/media/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,7 +16,8 @@
@AllArgsConstructor
@Builder
@Entity
@Table(name="users")
@Getter
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
Expand All @@ -24,4 +27,20 @@ public class User {
@OneToMany(mappedBy = "user")
@Builder.Default
List<Content> 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;
}
11 changes: 11 additions & 0 deletions src/main/java/wanted/media/user/repository/UserRepository.java
Original file line number Diff line number Diff line change
@@ -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<User, UUID> {
}
12 changes: 12 additions & 0 deletions src/main/java/wanted/media/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit fd30ca4

Please sign in to comment.