From 2f15dcff3fd956047ee850dde536ab446a4224dd Mon Sep 17 00:00:00 2001 From: PgmJun Date: Mon, 5 Feb 2024 16:25:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Point=EB=A5=BC=20Ticket=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20#39?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/dto/MemberMyPageResponse.java | 6 ++--- .../member/service/MemberCommandService.java | 14 +++++----- .../member/service/MemberQueryService.java | 10 +++---- .../member/service/PointServiceUtils.java | 8 +++--- .../member/point/{Point.java => Ticket.java} | 24 ++++++++++------- .../domain/member/point/TicketType.java | 10 +++++++ .../point/repository/PointRepository.java | 7 ----- .../repository/PointRepositoryCustom.java | 8 ------ .../point/repository/TicketRepository.java | 7 +++++ .../repository/TicketRepositoryCustom.java | 8 ++++++ ...oryImpl.java => TicketRepositoryImpl.java} | 13 ++++----- .../domain/member/setting/Setting.java | 2 +- src/main/resources/sql/schema.sql | 27 ++++++++++--------- 13 files changed, 80 insertions(+), 64 deletions(-) rename src/main/java/com/nice/petudio/domain/member/point/{Point.java => Ticket.java} (62%) create mode 100644 src/main/java/com/nice/petudio/domain/member/point/TicketType.java delete mode 100644 src/main/java/com/nice/petudio/domain/member/point/repository/PointRepository.java delete mode 100644 src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryCustom.java create mode 100644 src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepository.java create mode 100644 src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryCustom.java rename src/main/java/com/nice/petudio/domain/member/point/repository/{PointRepositoryImpl.java => TicketRepositoryImpl.java} (50%) diff --git a/src/main/java/com/nice/petudio/api/controller/member/dto/MemberMyPageResponse.java b/src/main/java/com/nice/petudio/api/controller/member/dto/MemberMyPageResponse.java index 0e89da7..9772fa8 100644 --- a/src/main/java/com/nice/petudio/api/controller/member/dto/MemberMyPageResponse.java +++ b/src/main/java/com/nice/petudio/api/controller/member/dto/MemberMyPageResponse.java @@ -4,14 +4,14 @@ import lombok.Builder; @Builder -public record MemberMyPageResponse(SocialType socialType, String email, boolean notificationStatus, int pointAmount) { - public static MemberMyPageResponse of(SocialType socialType, String email, boolean notificationStatus, int pointAmount) { +public record MemberMyPageResponse(SocialType socialType, String email, boolean notificationStatus, int ticketAmount) { + public static MemberMyPageResponse of(SocialType socialType, String email, boolean notificationStatus, int ticketAmount) { return MemberMyPageResponse .builder() .socialType(socialType) .email(email) .notificationStatus(notificationStatus) - .pointAmount(pointAmount) + .ticketAmount(ticketAmount) .build(); } } diff --git a/src/main/java/com/nice/petudio/api/controller/member/service/MemberCommandService.java b/src/main/java/com/nice/petudio/api/controller/member/service/MemberCommandService.java index dc61930..5c8f367 100644 --- a/src/main/java/com/nice/petudio/api/controller/member/service/MemberCommandService.java +++ b/src/main/java/com/nice/petudio/api/controller/member/service/MemberCommandService.java @@ -7,8 +7,8 @@ import com.nice.petudio.domain.album.Album; import com.nice.petudio.domain.album.repository.AlbumRepository; import com.nice.petudio.domain.member.Member; -import com.nice.petudio.domain.member.point.Point; -import com.nice.petudio.domain.member.point.repository.PointRepository; +import com.nice.petudio.domain.member.point.Ticket; +import com.nice.petudio.domain.member.point.repository.TicketRepository; import com.nice.petudio.domain.member.repository.MemberRepository; import com.nice.petudio.domain.member.setting.Setting; import com.nice.petudio.domain.member.setting.repository.SettingRepository; @@ -23,7 +23,7 @@ @RequiredArgsConstructor public class MemberCommandService { private final MemberRepository memberRepository; - private final PointRepository pointRepository; + private final TicketRepository ticketRepository; private final SettingRepository settingRepository; private final PetRepository petRepository; private final AlbumRepository albumRepository; @@ -32,8 +32,8 @@ public Long registerMember(CreateMemberRequest request) { MemberServiceUtils.validateNotExistsMember(memberRepository, request.getSocialId(), request.getSocialType()); Member member = memberRepository.save( Member.newInstance(request.getSocialId(), request.getSocialType(), request.getFcmToken(), request.getEmail())); - pointRepository.save(Point.fromMemberId(member.getId())); - settingRepository.save(Setting.fromMemberId(member.getId())); + ticketRepository.save(Ticket.newInstance(member.getId())); + settingRepository.save(Setting.newInstance(member.getId())); return member.getId(); } @@ -54,10 +54,10 @@ public void deleteMember(final Long memberId) { private void deleteMemberBasicInfo(Long memberId) { Member member = MemberServiceUtils.findMemberById(memberRepository, memberId); Setting setting = SettingServiceUtils.findSettingByMemberId(settingRepository, memberId); - Point point = PointServiceUtils.findPointByMemberId(pointRepository, memberId); + Ticket ticket = PointServiceUtils.findPointByMemberId(ticketRepository, memberId); memberRepository.delete(member); settingRepository.delete(setting); - pointRepository.delete(point); + ticketRepository.delete(ticket); } // AI 프로필이 없는 애완동물 데이터 삭제 diff --git a/src/main/java/com/nice/petudio/api/controller/member/service/MemberQueryService.java b/src/main/java/com/nice/petudio/api/controller/member/service/MemberQueryService.java index 41a89c5..e6b0b5a 100644 --- a/src/main/java/com/nice/petudio/api/controller/member/service/MemberQueryService.java +++ b/src/main/java/com/nice/petudio/api/controller/member/service/MemberQueryService.java @@ -2,8 +2,8 @@ import com.nice.petudio.api.controller.member.dto.MemberMyPageResponse; import com.nice.petudio.domain.member.Member; -import com.nice.petudio.domain.member.point.Point; -import com.nice.petudio.domain.member.point.repository.PointRepository; +import com.nice.petudio.domain.member.point.Ticket; +import com.nice.petudio.domain.member.point.repository.TicketRepository; import com.nice.petudio.domain.member.repository.MemberRepository; import com.nice.petudio.domain.member.setting.Setting; import com.nice.petudio.domain.member.setting.repository.SettingRepository; @@ -16,15 +16,15 @@ @RequiredArgsConstructor public class MemberQueryService { private final MemberRepository memberRepository; - private final PointRepository pointRepository; + private final TicketRepository ticketRepository; private final SettingRepository settingRepository; public MemberMyPageResponse getMemberMypageInfo(final Long memberId) { Member member = MemberServiceUtils.findMemberById(memberRepository, memberId); - Point point = PointServiceUtils.findPointByMemberId(pointRepository, memberId); + Ticket ticket = PointServiceUtils.findPointByMemberId(ticketRepository, memberId); Setting setting = SettingServiceUtils.findSettingByMemberId(settingRepository, memberId); return MemberMyPageResponse.of(member.getSocialType(), member.getEmail(), setting.getNotificationStatus(), - point.getAmount()); + ticket.getAmount()); } } diff --git a/src/main/java/com/nice/petudio/api/controller/member/service/PointServiceUtils.java b/src/main/java/com/nice/petudio/api/controller/member/service/PointServiceUtils.java index 4143840..4fcb455 100644 --- a/src/main/java/com/nice/petudio/api/controller/member/service/PointServiceUtils.java +++ b/src/main/java/com/nice/petudio/api/controller/member/service/PointServiceUtils.java @@ -1,14 +1,14 @@ package com.nice.petudio.api.controller.member.service; -import com.nice.petudio.domain.member.point.Point; -import com.nice.petudio.domain.member.point.repository.PointRepository; +import com.nice.petudio.domain.member.point.Ticket; +import com.nice.petudio.domain.member.point.repository.TicketRepository; import com.nice.petudio.common.exception.error.ErrorCode; import com.nice.petudio.common.exception.model.NotFoundException; public class PointServiceUtils { - public static Point findPointByMemberId(PointRepository pointRepository, final Long memberId) { - return pointRepository.findByMemberId(memberId) + public static Ticket findPointByMemberId(TicketRepository ticketRepository, final Long memberId) { + return ticketRepository.findByMemberId(memberId) .orElseThrow(() -> new NotFoundException( ErrorCode.NOT_FOUND_MEMBER_INFO_EXCEPTION, String.format("memberId(%d)의 Point 정보를 찾을 수 없습니다.", memberId))); diff --git a/src/main/java/com/nice/petudio/domain/member/point/Point.java b/src/main/java/com/nice/petudio/domain/member/point/Ticket.java similarity index 62% rename from src/main/java/com/nice/petudio/domain/member/point/Point.java rename to src/main/java/com/nice/petudio/domain/member/point/Ticket.java index d8f8d0f..b50745b 100644 --- a/src/main/java/com/nice/petudio/domain/member/point/Point.java +++ b/src/main/java/com/nice/petudio/domain/member/point/Ticket.java @@ -3,6 +3,8 @@ import com.nice.petudio.domain.base.BaseEntity; 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; @@ -14,30 +16,32 @@ import lombok.NoArgsConstructor; @Entity -@Table(name = "points") +@Table(name = "tickets") @Builder @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PROTECTED) -public class Point extends BaseEntity { +public class Ticket extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "point_id") + @Column(name = "ticket_id") private Long id; @Column(name = "member_id", nullable = false) private Long memberId; - @Column(name = "point_amount", nullable = false) - private int amount; - + @Enumerated(EnumType.STRING) + @Column(name = "ticket_type", length = 30, nullable = false) + private TicketType type; - private static final int INIT_POINT_AMOUNT = 0; + @Column(name = "ticket_amount", nullable = false) + private int amount; - public static Point fromMemberId(Long memberId) { - return Point.builder() + public static Ticket newInstance(Long memberId) { + return Ticket.builder() .memberId(memberId) - .amount(INIT_POINT_AMOUNT) + .type(TicketType.DEFAULT) + .amount(0) .build(); } } diff --git a/src/main/java/com/nice/petudio/domain/member/point/TicketType.java b/src/main/java/com/nice/petudio/domain/member/point/TicketType.java new file mode 100644 index 0000000..0c4bc53 --- /dev/null +++ b/src/main/java/com/nice/petudio/domain/member/point/TicketType.java @@ -0,0 +1,10 @@ +package com.nice.petudio.domain.member.point; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum TicketType { + DEFAULT(8_800); + + private final int price; +} diff --git a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepository.java b/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepository.java deleted file mode 100644 index 3b33d7d..0000000 --- a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nice.petudio.domain.member.point.repository; - -import com.nice.petudio.domain.member.point.Point; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PointRepository extends PointRepositoryCustom, JpaRepository { -} diff --git a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryCustom.java b/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryCustom.java deleted file mode 100644 index c2afd27..0000000 --- a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryCustom.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.nice.petudio.domain.member.point.repository; - -import com.nice.petudio.domain.member.point.Point; -import java.util.Optional; - -public interface PointRepositoryCustom { - Optional findByMemberId(Long memberId); -} diff --git a/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepository.java b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepository.java new file mode 100644 index 0000000..ff38164 --- /dev/null +++ b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepository.java @@ -0,0 +1,7 @@ +package com.nice.petudio.domain.member.point.repository; + +import com.nice.petudio.domain.member.point.Ticket; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TicketRepository extends TicketRepositoryCustom, JpaRepository { +} diff --git a/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryCustom.java b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryCustom.java new file mode 100644 index 0000000..d0ae9ab --- /dev/null +++ b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryCustom.java @@ -0,0 +1,8 @@ +package com.nice.petudio.domain.member.point.repository; + +import com.nice.petudio.domain.member.point.Ticket; +import java.util.Optional; + +public interface TicketRepositoryCustom { + Optional findByMemberId(Long memberId); +} diff --git a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryImpl.java b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryImpl.java similarity index 50% rename from src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryImpl.java rename to src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryImpl.java index 7a4c909..e68d1dd 100644 --- a/src/main/java/com/nice/petudio/domain/member/point/repository/PointRepositoryImpl.java +++ b/src/main/java/com/nice/petudio/domain/member/point/repository/TicketRepositoryImpl.java @@ -1,21 +1,22 @@ package com.nice.petudio.domain.member.point.repository; -import static com.nice.petudio.domain.member.point.QPoint.point; -import com.nice.petudio.domain.member.point.Point; +import static com.nice.petudio.domain.member.point.QTicket.ticket; + +import com.nice.petudio.domain.member.point.Ticket; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.Optional; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor -public class PointRepositoryImpl implements PointRepositoryCustom { +public class TicketRepositoryImpl implements TicketRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public Optional findByMemberId(Long memberId) { + public Optional findByMemberId(Long memberId) { return Optional.ofNullable(queryFactory - .selectFrom(point) - .where(point.memberId.eq(memberId)) + .selectFrom(ticket) + .where(ticket.memberId.eq(memberId)) .fetchOne()); } } diff --git a/src/main/java/com/nice/petudio/domain/member/setting/Setting.java b/src/main/java/com/nice/petudio/domain/member/setting/Setting.java index f57e2c5..9e24914 100644 --- a/src/main/java/com/nice/petudio/domain/member/setting/Setting.java +++ b/src/main/java/com/nice/petudio/domain/member/setting/Setting.java @@ -32,7 +32,7 @@ public class Setting extends BaseEntity { private Boolean notificationStatus; - public static Setting fromMemberId(Long memberId) { + public static Setting newInstance(Long memberId) { return Setting.builder() .memberId(memberId) .notificationStatus(false) diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index 9087f43..fbc09ff 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -1,6 +1,6 @@ DROP TABLE IF EXISTS `members`; DROP TABLE IF EXISTS `settings`; -DROP TABLE IF EXISTS `points`; +DROP TABLE IF EXISTS `tickets`; DROP TABLE IF EXISTS `pets`; DROP TABLE IF EXISTS `concepts`; DROP TABLE IF EXISTS `albums`; @@ -28,13 +28,14 @@ CREATE TABLE `settings` `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); -CREATE TABLE `points` +CREATE TABLE `tickets` ( - `point_id` bigint AUTO_INCREMENT PRIMARY KEY, - `member_id` bigint NOT NULL, - `point_amount` int NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + `ticket_id` bigint AUTO_INCREMENT PRIMARY KEY NOT NULL, + `member_id` bigint NOT NULL, + `ticket_type` varchar(30) NOT NULL, + `ticket_amount` int NOT NULL, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `modified_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE `concepts` @@ -58,13 +59,13 @@ CREATE TABLE `concepts` CREATE TABLE `pets` ( `pet_id` bigint AUTO_INCREMENT PRIMARY KEY, - `member_id` bigint NOT NULL, - `pet_name` varchar(30) NOT NULL, - `pet_fur_color` varchar(30) NOT NULL, + `member_id` bigint NOT NULL, + `pet_name` varchar(30) NOT NULL, + `pet_fur_color` varchar(30) NOT NULL, `pet_image_s3_directory_path` varchar(100) NOT NULL, - `pet_photos` json NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + `pet_photos` json NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE `albums`