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

Feature: 티켓팅 서비스를 위해 기본적인 구현을 한다. #31

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,34 @@
package com.thirdparty.ticketing.domain.ticket;

import java.util.UUID;

import jakarta.persistence.*;

import com.thirdparty.ticketing.domain.BaseEntity;
import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.seat.Seat;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@AllArgsConstructor
@Table(name = "member")
seminchoi marked this conversation as resolved.
Show resolved Hide resolved
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Ticket extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private UUID ticketId;
seminchoi marked this conversation as resolved.
Show resolved Hide resolved

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seat_id")
private Seat seat;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.thirdparty.ticketing.domain.ticket.controller;

import jakarta.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.thirdparty.ticketing.domain.ItemResult;
import com.thirdparty.ticketing.domain.ticket.dto.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.ticket.dto.TicketElement;
import com.thirdparty.ticketing.domain.ticket.dto.TicketPaymentRequest;
import com.thirdparty.ticketing.domain.ticket.service.TicketService;
import com.thirdparty.ticketing.global.security.LoginMember;

import lombok.RequiredArgsConstructor;

@RestController("/api")
@RequiredArgsConstructor
public class TicketController {
private final TicketService ticketService;

@GetMapping("/members/tickets")
public ResponseEntity<ItemResult<TicketElement>> selectMyTickets(@LoginMember String email) {
return ResponseEntity.ok().body(ticketService.selectMyTicket(email));
}

@PostMapping("/seats/select")
public ResponseEntity<Void> selectSeat(
@RequestBody @Valid SeatSelectionRequest seatSelectionRequest) {
ticketService.selectSeat(seatSelectionRequest);
return ResponseEntity.ok().build();
}

@PostMapping("/tickets")
public ResponseEntity<Void> payTicket(
@RequestBody @Valid TicketPaymentRequest ticketPaymentRequest) {
ticketService.reservationTicket(ticketPaymentRequest);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.thirdparty.ticketing.domain.ticket.dto;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

import lombok.Data;

@Data
public class SeatSelectionRequest {
@NotNull(message = "좌석 ID를 요청하지 않았습니다.")
@Min(value = 1, message = "좌석 ID는 1 이상이어야 합니다.")
private Long seatId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.thirdparty.ticketing.domain.ticket.dto;

import java.util.UUID;

import com.thirdparty.ticketing.domain.ticket.Ticket;

import lombok.Data;

@Data
public class TicketElement {
private final UUID id;

public static TicketElement of(Ticket ticket) {
return new TicketElement(ticket.getTicketId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.thirdparty.ticketing.domain.ticket.dto;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

import lombok.Data;

@Data
public class TicketPaymentRequest {
@NotNull(message = "좌석 ID를 요청하지 않았습니다.")
@Min(value = 1, message = "좌석 ID는 1 이상이어야 합니다.")
private Long seatId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.thirdparty.ticketing.domain.ticket.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.ticket.Ticket;

public interface TicketRepository extends JpaRepository<Ticket, Integer> {
List<Ticket> findAllByMember(Member member);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.thirdparty.ticketing.domain.ticket.service;

import com.thirdparty.ticketing.domain.member.repository.MemberRepository;
import com.thirdparty.ticketing.domain.seat.repository.SeatRepository;
import com.thirdparty.ticketing.domain.ticket.dto.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.ticket.dto.TicketPaymentRequest;
import com.thirdparty.ticketing.domain.ticket.repository.TicketRepository;

public class CacheTicketService extends TicketService {
public CacheTicketService(
MemberRepository memberRepository,
TicketRepository ticketRepository,
SeatRepository seatRepository) {
super(memberRepository, ticketRepository, seatRepository);
}

@Override
public void selectSeat(SeatSelectionRequest seatSelectionRequest) {}

@Override
public void reservationTicket(TicketPaymentRequest ticketPaymentRequest) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.thirdparty.ticketing.domain.ticket.service;

import org.springframework.stereotype.Service;

import com.thirdparty.ticketing.domain.member.repository.MemberRepository;
import com.thirdparty.ticketing.domain.seat.repository.SeatRepository;
import com.thirdparty.ticketing.domain.ticket.dto.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.ticket.dto.TicketPaymentRequest;
import com.thirdparty.ticketing.domain.ticket.repository.TicketRepository;

@Service
public class PersistenceTicketService extends TicketService {
public PersistenceTicketService(
MemberRepository memberRepository,
TicketRepository ticketRepository,
SeatRepository seatRepository) {
super(memberRepository, ticketRepository, seatRepository);
}

@Override
public void selectSeat(SeatSelectionRequest seatSelectionRequest) {}

@Override
public void reservationTicket(TicketPaymentRequest ticketPaymentRequest) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.thirdparty.ticketing.domain.ticket.service;

import java.util.List;

import com.thirdparty.ticketing.domain.ItemResult;
import com.thirdparty.ticketing.domain.common.TicketingException;
import com.thirdparty.ticketing.domain.member.Member;
import com.thirdparty.ticketing.domain.member.repository.MemberRepository;
import com.thirdparty.ticketing.domain.seat.repository.SeatRepository;
import com.thirdparty.ticketing.domain.ticket.dto.SeatSelectionRequest;
import com.thirdparty.ticketing.domain.ticket.dto.TicketElement;
import com.thirdparty.ticketing.domain.ticket.dto.TicketPaymentRequest;
import com.thirdparty.ticketing.domain.ticket.repository.TicketRepository;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public abstract class TicketService {
private final MemberRepository memberRepository;
private final TicketRepository ticketRepository;
private final SeatRepository seatRepository;

public ItemResult<TicketElement> selectMyTicket(String memberEmail) {
Member member =
memberRepository
.findByEmail(memberEmail)
.orElseThrow(() -> new TicketingException("Member not found"));

List<TicketElement> ticketElementList =
ticketRepository.findAllByMember(member).stream().map(TicketElement::of).toList();

seminchoi marked this conversation as resolved.
Show resolved Hide resolved
return ItemResult.of(ticketElementList);
}

public abstract void selectSeat(SeatSelectionRequest seatSelectionRequest);

public abstract void reservationTicket(TicketPaymentRequest ticketPaymentRequest);
}
Loading