Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-299] GetMemberPurchases EP 마이그레이션 #113

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@
import com.tiketeer.Tiketeer.auth.SecurityContextHelper;
import com.tiketeer.Tiketeer.domain.member.controller.dto.ChargePointRequestDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.ChargePointResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchasesResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberAllPurchasesResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberPurchaseResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.GetMemberTicketingSalesResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.MemberRegisterRequestDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.MemberRegisterResponseDto;
import com.tiketeer.Tiketeer.domain.member.controller.dto.ResetPasswordRequestDto;
import com.tiketeer.Tiketeer.domain.member.usecase.ChargeMemberPointUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.DeleteMemberUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberPurchasesUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberAllPurchasesUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberPurchaseUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberTicketingSalesUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.GetMemberUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.MemberRegisterUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.ResetPasswordUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.SendPasswordChangeEmailUseCase;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.DeleteMemberCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberTicketingSalesCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.MemberRegisterCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.SendPwdChangeEmailCommandDto;
Expand All @@ -49,7 +52,8 @@ public class MemberController {
private final ChargeMemberPointUseCase chargeMemberPointUseCase;
private final GetMemberTicketingSalesUseCase getMemberTicketingSalesUseCase;
private final GetMemberUseCase getMemberUseCase;
private final GetMemberPurchasesUseCase getMemberPurchasesUseCase;
private final GetMemberAllPurchasesUseCase getMemberAllPurchasesUseCase;
private final GetMemberPurchaseUseCase getMemberPurchasesUseCase;
private final ResetPasswordUseCase resetPasswordUseCase;
private final SendPasswordChangeEmailUseCase sendPasswordChangeEmailUseCase;
private final DeleteMemberUseCase deleteMemberUseCase;
Expand All @@ -59,7 +63,8 @@ public class MemberController {
public MemberController(MemberRegisterUseCase memberRegisterUseCase,
ChargeMemberPointUseCase chargeMemberPointUseCase, ResetPasswordUseCase resetPasswordUseCase,
GetMemberTicketingSalesUseCase getMemberTicketingSalesUseCase,
GetMemberUseCase getMemberUseCase, GetMemberPurchasesUseCase getMemberPurchasesUseCase,
GetMemberUseCase getMemberUseCase, GetMemberAllPurchasesUseCase getMemberAllPurchasesUseCase,
GetMemberPurchaseUseCase getMemberPurchasesUseCase,
SendPasswordChangeEmailUseCase sendPasswordChangeEmailUseCase,
DeleteMemberUseCase deleteMemberUseCase,
SecurityContextHelper securityContextHelper) {
Expand All @@ -68,6 +73,7 @@ public MemberController(MemberRegisterUseCase memberRegisterUseCase,
this.getMemberTicketingSalesUseCase = getMemberTicketingSalesUseCase;
this.getMemberUseCase = getMemberUseCase;
this.resetPasswordUseCase = resetPasswordUseCase;
this.getMemberAllPurchasesUseCase = getMemberAllPurchasesUseCase;
this.getMemberPurchasesUseCase = getMemberPurchasesUseCase;
this.sendPasswordChangeEmailUseCase = sendPasswordChangeEmailUseCase;
this.deleteMemberUseCase = deleteMemberUseCase;
Expand Down Expand Up @@ -105,13 +111,23 @@ public ResponseEntity<ApiResponse<ChargePointResponseDto>> chargePoint(@PathVari
}

@GetMapping("/{memberId}/purchases")
public ResponseEntity<ApiResponse<List<GetMemberPurchasesResponseDto>>> getMemberPurchases(
public ResponseEntity<ApiResponse<List<GetMemberAllPurchasesResponseDto>>> getMemberAllPurchases(
@PathVariable UUID memberId) {
var email = securityContextHelper.getEmailInToken();
var results = getMemberPurchasesUseCase.getMemberPurchases(
GetMemberPurchasesCommandDto.builder().memberEmail(email).build());
var results = getMemberAllPurchasesUseCase.getMemberPurchases(
GetMemberAllPurchasesCommandDto.builder().memberEmail(email).build());
var responseBody = ApiResponse.wrap(
results.stream().map(GetMemberPurchasesResponseDto::convertFromDto).toList());
results.stream().map(GetMemberAllPurchasesResponseDto::convertFromDto).toList());
return ResponseEntity.status(HttpStatus.OK).body(responseBody);
}

@GetMapping("/{memberId}/purchases/{purchaseId}")
public ResponseEntity<ApiResponse<GetMemberPurchaseResponseDto>> getMemberPurchase(
@PathVariable UUID memberId, @PathVariable UUID purchaseId) {
var email = securityContextHelper.getEmailInToken();
var result = getMemberPurchasesUseCase.getMemberPurchases(
GetMemberPurchaseCommandDto.builder().memberEmail(email).purchaseId(purchaseId).build());
var responseBody = ApiResponse.wrap(GetMemberPurchaseResponseDto.convertFromDto(result));
return ResponseEntity.status(HttpStatus.OK).body(responseBody);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.tiketeer.Tiketeer.domain.member.controller.dto;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesResultDto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public final class GetMemberAllPurchasesResponseDto {
private final UUID purchaseId;
private final UUID ticketingId;
private final String title;
private final LocalDateTime eventTime;
private final LocalDateTime createdAt;
private final String category;
private final String thumbnailPath;
private final List<GetMemberAllPurchasesResultDto.PurchaseItem> purchaseItems;

@Builder
public GetMemberAllPurchasesResponseDto(UUID purchaseId, UUID ticketingId, String title,
LocalDateTime eventTime, LocalDateTime createdAt, String category, String thumbnailPath,
List<GetMemberAllPurchasesResultDto.PurchaseItem> purchaseItems) {
this.purchaseId = purchaseId;
this.ticketingId = ticketingId;
this.title = title;
this.eventTime = eventTime;
this.createdAt = createdAt;
this.category = category;
this.thumbnailPath = thumbnailPath;
this.purchaseItems = purchaseItems;
}

public static GetMemberAllPurchasesResponseDto convertFromDto(GetMemberAllPurchasesResultDto dto) {
return GetMemberAllPurchasesResponseDto.builder()
.purchaseId(dto.getPurchaseId())
.ticketingId(dto.getTicketingId())
.title(dto.getTitle())
.eventTime(dto.getEventTime())
.createdAt(dto.getCreatedAt())
.category(dto.getCategory())
.thumbnailPath(dto.getThumbnailPath())
.purchaseItems(dto.getPurchaseItems())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.tiketeer.Tiketeer.domain.member.controller.dto;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseResultDto;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public final class GetMemberPurchaseResponseDto {
private final UUID purchaseId;
private final UUID ticketingId;
private final String title;
private final String location;
private final LocalDateTime eventTime;
private final LocalDateTime createdAt;
private final String category;
private final int runningMinute;
private final List<GetMemberPurchaseResultDto.PurchaseItem> purchaseItems;

@Builder
public GetMemberPurchaseResponseDto(UUID purchaseId, UUID ticketingId, String title, String location,
LocalDateTime eventTime, LocalDateTime createdAt, String category,
int runningMinute,
List<GetMemberPurchaseResultDto.PurchaseItem> purchaseItems) {
this.purchaseId = purchaseId;
this.ticketingId = ticketingId;
this.title = title;
this.location = location;
this.eventTime = eventTime;
this.createdAt = createdAt;
this.category = category;
this.runningMinute = runningMinute;
this.purchaseItems = purchaseItems;
}

public static GetMemberPurchaseResponseDto convertFromDto(GetMemberPurchaseResultDto dto) {
return GetMemberPurchaseResponseDto.builder()
.purchaseId(dto.getPurchaseId())
.ticketingId(dto.getTicketingId())
.title(dto.getTitle())
.location(dto.getLocation())
.eventTime(dto.getEventTime())
.createdAt(dto.getCreatedAt())
.category(dto.getCategory())
.runningMinute(dto.getRunningMinutes())
.purchaseItems(dto.getPurchaseItems())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@

import com.tiketeer.Tiketeer.domain.member.exception.MemberNotFoundException;
import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchasesResultDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberAllPurchasesResultDto;
import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository;

@Service
@Transactional(readOnly = true)
public class GetMemberPurchasesUseCase {
public class GetMemberAllPurchasesUseCase {
private final MemberRepository memberRepository;
private final PurchaseRepository purchaseRepository;

@Autowired
public GetMemberPurchasesUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) {
public GetMemberAllPurchasesUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) {
this.memberRepository = memberRepository;
this.purchaseRepository = purchaseRepository;
}

public List<GetMemberPurchasesResultDto> getMemberPurchases(GetMemberPurchasesCommandDto command) {
public List<GetMemberAllPurchasesResultDto> getMemberPurchases(GetMemberAllPurchasesCommandDto command) {
var member = memberRepository.findByEmail(command.getMemberEmail()).orElseThrow(MemberNotFoundException::new);
return purchaseRepository.findWithTicketingByMember(member);
var results = purchaseRepository.findWithTicketingByMember(member);
return results.stream().map(GetMemberAllPurchasesResultDto::new).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.tiketeer.Tiketeer.domain.member.usecase;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tiketeer.Tiketeer.domain.member.exception.MemberNotFoundException;
import com.tiketeer.Tiketeer.domain.member.repository.MemberRepository;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseCommandDto;
import com.tiketeer.Tiketeer.domain.member.usecase.dto.GetMemberPurchaseResultDto;
import com.tiketeer.Tiketeer.domain.purchase.exception.PurchaseNotFoundException;
import com.tiketeer.Tiketeer.domain.purchase.repository.PurchaseRepository;

@Service
@Transactional(readOnly = true)
public class GetMemberPurchaseUseCase {
private final MemberRepository memberRepository;
private final PurchaseRepository purchaseRepository;

@Autowired
public GetMemberPurchaseUseCase(MemberRepository memberRepository, PurchaseRepository purchaseRepository) {
this.memberRepository = memberRepository;
this.purchaseRepository = purchaseRepository;
}

public GetMemberPurchaseResultDto getMemberPurchases(GetMemberPurchaseCommandDto command) {
var member = memberRepository.findByEmail(command.getMemberEmail()).orElseThrow(MemberNotFoundException::new);
var results = purchaseRepository.findWithTicketingByMember(member);
if (results.isEmpty()) {
throw new PurchaseNotFoundException();
}
return new GetMemberPurchaseResultDto(results.getFirst());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

@Getter
@ToString
public class GetMemberPurchasesCommandDto {
public class GetMemberAllPurchasesCommandDto {
private final String memberEmail;

@Builder
public GetMemberPurchasesCommandDto(String memberEmail) {
public GetMemberAllPurchasesCommandDto(String memberEmail) {
this.memberEmail = memberEmail;
}
}
Loading
Loading