Skip to content

Commit

Permalink
Feat: member 엔티티 추가 (#12)
Browse files Browse the repository at this point in the history
* Feat: member 엔티티 추가

* Feat: 생성, 변경 일자 auditing class 추가

* Fix: annotation formatting을 여러줄 형식으로 수정
  • Loading branch information
Jaewon-pro authored Jul 22, 2024
1 parent 5562fb6 commit 57ba668
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 1 deletion.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ spotless {
trimTrailingWhitespace()
importOrder("", "java|javax", "\\#").wildcardsLast()
removeUnusedImports()
formatAnnotations()
}

format("misc") {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/dnd/runus/domain/common/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dnd.runus.domain.common;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.Instant;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {
@CreatedDate
private Instant createdAt;

@LastModifiedDate
private Instant updatedAt;
}
44 changes: 44 additions & 0 deletions src/main/java/com/dnd/runus/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.dnd.runus.domain.member.entity;

import com.dnd.runus.domain.common.BaseTimeEntity;
import com.dnd.runus.global.constant.MemberRole;
import com.dnd.runus.global.constant.SocialType;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static jakarta.persistence.EnumType.STRING;
import static lombok.AccessLevel.PROTECTED;

@Getter
@Entity
@NoArgsConstructor(access = PROTECTED)
public class Member extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@Enumerated(STRING)
private MemberRole role;

@NotNull
private String oauthId;

@NotNull
@Enumerated(STRING)
private SocialType socialType;

@NotNull
private String oauthEmail;

@Builder
private Member(MemberRole role, String oauthId, SocialType socialType, String oauthEmail) {
this.role = role;
this.oauthId = oauthId;
this.socialType = socialType;
this.oauthEmail = oauthEmail;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dnd.runus.domain.member.repository;

import com.dnd.runus.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Long> {}
8 changes: 8 additions & 0 deletions src/main/java/com/dnd/runus/global/config/JpaConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.dnd.runus.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@Configuration
public class JpaConfig {}
15 changes: 15 additions & 0 deletions src/main/java/com/dnd/runus/global/constant/MemberRole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dnd.runus.global.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static lombok.AccessLevel.PRIVATE;

@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum MemberRole {
USER("ROLE_USER"),
ADMIN("ROLE_ADMIN"),
;
private final String value;
}
14 changes: 14 additions & 0 deletions src/main/java/com/dnd/runus/global/constant/SocialType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dnd.runus.global.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static lombok.AccessLevel.PRIVATE;

@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum SocialType {
APPLE("apple"),
;
private final String value;
}

0 comments on commit 57ba668

Please sign in to comment.