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/#20] USER_ACTIVITY_HISTORIES, USERS, USER_REGISTER_INFOS 엔티티 구현 #21

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions infra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation ("org.springframework.cloud:spring-cloud-starter-openfeign:${property("springOpenFeignVersion")}")
implementation("org.springframework.boot:spring-boot-starter-validation")

//db
runtimeOnly("com.h2database:h2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sopt.makers.authentication.infra.jpa.common;

import java.time.*;

import jakarta.persistence.*;

import org.springframework.data.annotation.*;
import org.springframework.data.jpa.domain.support.*;

import lombok.*;

@Getter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public abstract class BaseTimeEntity {
@CreatedDate
@Column(updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package sopt.makers.authentication.infra.jpa.user.entity;

import sopt.makers.authentication.user.*;

import jakarta.persistence.*;
import jakarta.validation.constraints.*;

import lombok.*;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "USER_ACTIVITY_HISTORIES")
public class UserActivityHistoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@NotNull
private UserEntity user;

@Min(1)
private int generation;

@Enumerated(EnumType.STRING)
private Team team;

@NotNull
@Enumerated(EnumType.STRING)
private Part part;

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

public UserActivityHistoryEntity(final UserEntity user, final Activity activity) {
this.user = user;
this.generation = activity.generation();
this.team = activity.team();
this.part = activity.part();
this.role = activity.role();
}

public Activity toDomain() {
return new Activity(generation, team, part);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package sopt.makers.authentication.infra.jpa.user.entity;

import sopt.makers.authentication.infra.jpa.common.*;
import sopt.makers.authentication.user.*;

import java.time.*;

import jakarta.persistence.*;
import jakarta.validation.constraints.*;

import lombok.*;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "USERS")
public class UserEntity extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull String name;
@NotNull String phone;
@NotNull String email;
@NotNull LocalDate birthday;
@NotNull String authPlatformId;

@NotNull
@Enumerated(EnumType.STRING)
AuthPlatform authPlatformType;

@NotNull Boolean isActive;

public UserEntity(final User user, boolean isActive) {
Profile profile = user.getProfile();
SocialAccount socialAccount = user.getSocialAccount();

this.name = profile.name();
this.phone = profile.phone();
this.email = profile.email();
this.birthday = profile.birthday();
this.authPlatformId = socialAccount.authPlatformId();
this.authPlatformType = socialAccount.authPlatformType();
this.isActive = isActive;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sopt.makers.authentication.infra.jpa.user.entity;

import sopt.makers.authentication.user.*;

import java.time.*;

import jakarta.persistence.*;
import jakarta.validation.constraints.*;

import lombok.*;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "USER_REGISTER_INFOS")
public class UserRegisterInfoEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull private String name;
@NotNull private String phone;
@NotNull private LocalDate birthday;

@Min(1)
private int generation;

@NotNull
@Enumerated(EnumType.STRING)
private Part part;
}