From 3cea3714d25731e6da2d00c9d2d3fce9b61d4ce0 Mon Sep 17 00:00:00 2001 From: Cho Sangwook <82208159+Sangwook02@users.noreply.github.com> Date: Sat, 27 Jul 2024 23:56:55 +0900 Subject: [PATCH] =?UTF-8?q?feature:=20=EB=A9=A4=EB=B2=84=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B5=AC=ED=98=84=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feature: 멤버 도메인 구현 * refactor: getter 추가 * feature: 마일리지 도메인 추가 * style: spotless apply * feature: 마일리지 레포지토리 추가 --- .../domain/member/api/MemberController.java | 3 ++ .../dive/domain/member/domain/Member.java | 51 +++++++++++++++++++ .../dive/domain/member/domain/Mileage.java | 51 +++++++++++++++++++ .../domain/member/domain/MileageType.java | 14 +++++ .../dive/domain/member/domain/Tier.java | 16 ++++++ .../member/repository/MemberRepository.java | 6 +++ .../member/repository/MileageRepository.java | 6 +++ .../domain/member/service/MemberService.java | 3 ++ 8 files changed, 150 insertions(+) create mode 100644 src/main/java/com/goldbalance/dive/domain/member/api/MemberController.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/domain/Member.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/domain/Mileage.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/domain/MileageType.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/domain/Tier.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/repository/MemberRepository.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/repository/MileageRepository.java create mode 100644 src/main/java/com/goldbalance/dive/domain/member/service/MemberService.java diff --git a/src/main/java/com/goldbalance/dive/domain/member/api/MemberController.java b/src/main/java/com/goldbalance/dive/domain/member/api/MemberController.java new file mode 100644 index 0000000..ebe0410 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/api/MemberController.java @@ -0,0 +1,3 @@ +package com.goldbalance.dive.domain.member.api; + +public class MemberController {} diff --git a/src/main/java/com/goldbalance/dive/domain/member/domain/Member.java b/src/main/java/com/goldbalance/dive/domain/member/domain/Member.java new file mode 100644 index 0000000..19b17bd --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/domain/Member.java @@ -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(); + } +} diff --git a/src/main/java/com/goldbalance/dive/domain/member/domain/Mileage.java b/src/main/java/com/goldbalance/dive/domain/member/domain/Mileage.java new file mode 100644 index 0000000..8e45030 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/domain/Mileage.java @@ -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(); + } +} diff --git a/src/main/java/com/goldbalance/dive/domain/member/domain/MileageType.java b/src/main/java/com/goldbalance/dive/domain/member/domain/MileageType.java new file mode 100644 index 0000000..dbf92ee --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/domain/MileageType.java @@ -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; +} diff --git a/src/main/java/com/goldbalance/dive/domain/member/domain/Tier.java b/src/main/java/com/goldbalance/dive/domain/member/domain/Tier.java new file mode 100644 index 0000000..e52f027 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/domain/Tier.java @@ -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; +} diff --git a/src/main/java/com/goldbalance/dive/domain/member/repository/MemberRepository.java b/src/main/java/com/goldbalance/dive/domain/member/repository/MemberRepository.java new file mode 100644 index 0000000..f5bbc16 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/repository/MemberRepository.java @@ -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 {} diff --git a/src/main/java/com/goldbalance/dive/domain/member/repository/MileageRepository.java b/src/main/java/com/goldbalance/dive/domain/member/repository/MileageRepository.java new file mode 100644 index 0000000..d197631 --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/repository/MileageRepository.java @@ -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 {} diff --git a/src/main/java/com/goldbalance/dive/domain/member/service/MemberService.java b/src/main/java/com/goldbalance/dive/domain/member/service/MemberService.java new file mode 100644 index 0000000..47a677b --- /dev/null +++ b/src/main/java/com/goldbalance/dive/domain/member/service/MemberService.java @@ -0,0 +1,3 @@ +package com.goldbalance.dive.domain.member.service; + +public class MemberService {}