Skip to content

Commit

Permalink
Merge pull request #7 from 2024-pre-onboarding-backend-F/feat/user
Browse files Browse the repository at this point in the history
[feat] users 공통 코드 작성
  • Loading branch information
jw427 authored Aug 23, 2024
2 parents c4182f9 + 8108606 commit 20ad8a6
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
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;
}
34 changes: 34 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,34 @@
package wanted.media.user.domain;

import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;

import java.time.LocalDateTime;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Entity
@Table(name = "codes")
public class Code {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long codeId;

@OneToOne
@JoinColumn(name = "user_id")
private User user;

@Size(max = 10)
@Column(nullable = false)
private String authCode;

@CreatedDate
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;
}
26 changes: 26 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,26 @@
package wanted.media.user.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Entity
@Table(name = "tokens")
public class Token {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long tokenId;

@Column(nullable = false)
private String refreshToken;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
}
18 changes: 18 additions & 0 deletions 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 java.util.UUID;
Expand All @@ -11,11 +13,27 @@
@AllArgsConstructor
@Builder
@Entity
@Getter
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "user_id", nullable = false)
private UUID userId;

@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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wanted.media.user.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import wanted.media.user.domain.User;

import java.util.UUID;

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 20ad8a6

Please sign in to comment.