Skip to content

Commit

Permalink
feat: Point를 Ticket으로 변경 #39
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Feb 5, 2024
1 parent 928b5ec commit 8cf694b
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}
Expand All @@ -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 프로필이 없는 애완동물 데이터 삭제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/nice/petudio/domain/member/point/TicketType.java
Original file line number Diff line number Diff line change
@@ -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;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Ticket, Long> {
}
Original file line number Diff line number Diff line change
@@ -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<Ticket> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -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<Point> findByMemberId(Long memberId) {
public Optional<Ticket> findByMemberId(Long memberId) {
return Optional.ofNullable(queryFactory
.selectFrom(point)
.where(point.memberId.eq(memberId))
.selectFrom(ticket)
.where(ticket.memberId.eq(memberId))
.fetchOne());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 14 additions & 13 deletions src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down Expand Up @@ -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`
Expand All @@ -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`
Expand Down

0 comments on commit 8cf694b

Please sign in to comment.