Skip to content

Commit

Permalink
Merge pull request #7 from T1F5/feature/#6
Browse files Browse the repository at this point in the history
feat: 회원 엔티티 구현(1차)
  • Loading branch information
char-yb authored Apr 5, 2024
2 parents cf40a25 + d813239 commit 0b8fa95
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 0 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.unit.daybook.domain.common.model;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {

@Column(updatable = false)
@CreatedDate
private LocalDateTime createdAt;

@Column @LastModifiedDate
private LocalDateTime updatedAt;
}

Empty file.
74 changes: 74 additions & 0 deletions src/main/java/com/unit/daybook/domain/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.unit.daybook.domain.member.domain;

import java.time.LocalDateTime;

import com.unit.daybook.domain.common.model.BaseTimeEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;

private String nickname;

@Embedded
private OauthInfo oauthInfo;

@Enumerated(EnumType.STRING)
private MemberStatus status;

@Enumerated(EnumType.STRING)
private MemberRole role;

private LocalDateTime lastLoginAt;


@Builder(access = AccessLevel.PRIVATE)
private Member(
String nickname,
OauthInfo oauthInfo,
MemberStatus status,
MemberRole role,
LocalDateTime lastLoginAt) {
this.nickname = nickname;
this.oauthInfo = oauthInfo;
this.status = status;
this.role = role;
this.lastLoginAt = lastLoginAt;
}

public static Member createNormalMember(OauthInfo oauthInfo, String nickname) {
return Member.builder()
.nickname(nickname)
.oauthInfo(oauthInfo)
.status(MemberStatus.NORMAL)
.role(MemberRole.USER)
.build();
}

public void updateLastLoginAt() {
this.lastLoginAt = LocalDateTime.now();
}

public void updateNickname() {
this.nickname = nickname;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.unit.daybook.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberRole {
USER("ROLE_USER"),
ADMIN("ROLE_ADMIN");

private final String value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.unit.daybook.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MemberStatus {
NORMAL("NORMAL"),
DELETED("DELETED"),
FORBIDDEN("FORBIDDEN");

private final String value;
}
33 changes: 33 additions & 0 deletions src/main/java/com/unit/daybook/domain/member/domain/OauthInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.unit.daybook.domain.member.domain;

import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OauthInfo {

private String oauthId;
private String oauthProvider;
private String oauthEmail;

@Builder(access = AccessLevel.PRIVATE)
private OauthInfo(String oauthId, String oauthProvider, String oauthEmail) {
this.oauthId = oauthId;
this.oauthProvider = oauthProvider;
this.oauthEmail = oauthEmail;
}

public static OauthInfo createOauthInfo(
String oauthId, String oauthProvider, String oauthEmail) {
return OauthInfo.builder()
.oauthId(oauthId)
.oauthProvider(oauthProvider)
.oauthEmail(oauthEmail)
.build();
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.unit.daybook.domain.member.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.unit.daybook.domain.member.domain.Member;

public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.unit.daybook.domain.member.repository;

public interface MemberRepositoryCustom {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.unit.daybook.domain.member.repository;

import org.springframework.stereotype.Repository;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class MemberRepositoryImpl implements MemberRepositoryCustom {
}

0 comments on commit 0b8fa95

Please sign in to comment.