Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] users 공통 코드 작성 #7

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB 테이블을 추가하셨다면 노션에 ERD도 변경 해주시면 좋을 것 같아요 ~

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

노션에 추가해놓겠습니다!

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;
}
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;
}
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;
}