Skip to content

Commit

Permalink
feature: 멤버 도메인 구현 (#18)
Browse files Browse the repository at this point in the history
* feature: 멤버 도메인 구현

* refactor: getter 추가

* feature: 마일리지 도메인 추가

* style: spotless apply

* feature: 마일리지 레포지토리 추가
  • Loading branch information
Sangwook02 authored Jul 27, 2024
1 parent 93038da commit 3cea371
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.goldbalance.dive.domain.member.api;

public class MemberController {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.goldbalance.dive.domain.member.domain;

import jakarta.persistence.Column;
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;

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

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

@Column(unique = true)
private String nickname;

@Enumerated(EnumType.STRING)
private Tier tier;

private long totalMileage;

private long monthlyMileage;

@Builder(access = AccessLevel.PRIVATE)
private Member(String nickname, Tier tier, long totalMileage, long monthlyMileage) {
this.nickname = nickname;
this.tier = tier;
this.totalMileage = totalMileage;
this.monthlyMileage = monthlyMileage;
}

public static Member create(String nickname) {
return Member.builder()
.nickname(nickname)
.tier(Tier.BRONZE)
.totalMileage(0)
.monthlyMileage(0)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.goldbalance.dive.domain.member.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Mileage {

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

private long amount;

@Enumerated(EnumType.STRING)
private MileageType type;

private LocalDateTime createdAt;

@Builder(access = AccessLevel.PRIVATE)
private Mileage(Member member, long amount, MileageType type) {
this.member = member;
this.amount = amount;
this.type = type;
this.createdAt = LocalDateTime.now();
}

public static Mileage create(Member member, long amount, MileageType type) {
return Mileage.builder().member(member).amount(amount).type(type).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.goldbalance.dive.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MileageType {
ATTENDANCE("출석"),
READ_ARTICLE("글 읽기"),
QUIZ_CORRECT("퀴즈 정답");

private final String mileageTypeName;
}
16 changes: 16 additions & 0 deletions src/main/java/com/goldbalance/dive/domain/member/domain/Tier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.goldbalance.dive.domain.member.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Tier {
BRONZE("브론즈"),
SILVER("실버"),
GOLD("골드"),
DIAMOND("다이아"),
MASTER("마스터");

private final String tierName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.goldbalance.dive.domain.member.repository;

import com.goldbalance.dive.domain.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

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

import com.goldbalance.dive.domain.member.domain.Mileage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MileageRepository extends JpaRepository<Mileage, Long> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.goldbalance.dive.domain.member.service;

public class MemberService {}

0 comments on commit 3cea371

Please sign in to comment.