From b403351662ed91ca571cbc774a6e672f64c3272d Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 20 Dec 2023 16:33:16 +0900 Subject: [PATCH 001/603] =?UTF-8?q?feat=20:=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/member/domain/Gender.java | 6 ++ .../catchtable/member/domain/Member.java | 59 +++++++++++++++++++ .../member/repository/MemberRepository.java | 8 +++ .../domain/NotificationMember.java | 43 ++++++++++++++ .../domain/NotificationOwner.java | 41 +++++++++++++ .../NotificationMemberRepository.java | 8 +++ .../NotificationOwnerRepository.java | 8 +++ .../prgrms/catchtable/owner/domain/Owner.java | 58 ++++++++++++++++++ .../owner/repository/OwnerRepository.java | 8 +++ .../reservation/domain/Reservation.java | 58 ++++++++++++++++++ .../reservation/domain/ReservationStatus.java | 14 +++++ .../reservation/domain/ReservationTime.java | 46 +++++++++++++++ .../catchtable/shop/domain/Address.java | 27 +++++++++ .../catchtable/shop/domain/Category.java | 16 +++++ .../prgrms/catchtable/shop/domain/Menu.java | 50 ++++++++++++++++ .../prgrms/catchtable/shop/domain/Shop.java | 52 ++++++++++++++++ .../shop/repository/ShopRepository.java | 8 +++ .../catchtable/waiting/domain/Waiting.java | 55 +++++++++++++++++ .../waiting/repository/WaitingRepository.java | 8 +++ 19 files changed, 573 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/member/domain/Gender.java create mode 100644 src/main/java/com/prgrms/catchtable/member/domain/Member.java create mode 100644 src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java create mode 100644 src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java create mode 100644 src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java create mode 100644 src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java create mode 100644 src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java create mode 100644 src/main/java/com/prgrms/catchtable/owner/domain/Owner.java create mode 100644 src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java create mode 100644 src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java create mode 100644 src/main/java/com/prgrms/catchtable/reservation/domain/ReservationStatus.java create mode 100644 src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/domain/Address.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/domain/Category.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/domain/Menu.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/domain/Shop.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java new file mode 100644 index 00000000..7339bcfe --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java @@ -0,0 +1,6 @@ +package com.prgrms.catchtable.member.domain; + +public enum Gender { + MALE, + FEMALE +} diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java new file mode 100644 index 00000000..2cee07b2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -0,0 +1,59 @@ +package com.prgrms.catchtable.member.domain; + +import static jakarta.persistence.CascadeType.REMOVE; +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.notification.domain.NotificationMember; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import java.time.LocalDate; +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Member { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "member_id") + private Long id; + + @Column(name = "member_name") + private String name; + + @Column(name = "phone_number") + private String phoneNumber; + + @Column(name = "gender") + @Enumerated(STRING) + private Gender gender; + + @Column(name = "date_birth") + private LocalDate dateBirth; + + @Column(name = "notification_activated") + private boolean notification_activated; + + @OneToMany(mappedBy = "member", cascade = REMOVE, orphanRemoval = true) + private List notificationMemberList; + + @Builder + public Member(String name, String phoneNumber, Gender gender, LocalDate dateBirth, + boolean notification_activated) { + this.name = name; + this.phoneNumber = phoneNumber; + this.gender = gender; + this.dateBirth = dateBirth; + this.notification_activated = notification_activated; + } +} diff --git a/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java b/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java new file mode 100644 index 00000000..2d55246a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.member.repository; + +import com.prgrms.catchtable.member.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + +} diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java new file mode 100644 index 00000000..4356549b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java @@ -0,0 +1,43 @@ +package com.prgrms.catchtable.notification.domain; + +import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.member.domain.Member; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class NotificationMember { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "notification_member_id") + private Long id; + + @Column(name = "message") + private String message; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "member_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) + private Member member; + + @Builder + public NotificationMember(String message, Member member) { + this.message = message; + this.member = member; + member.getNotificationMemberList().add(this); + } +} diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java new file mode 100644 index 00000000..c81b9250 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java @@ -0,0 +1,41 @@ +package com.prgrms.catchtable.notification.domain; + +import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.owner.domain.Owner; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class NotificationOwner { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "notification_owner_id") + private Long id; + + @Column(name = "message") + private String message; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "owner_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) + private Owner owner; + + @Builder + public NotificationOwner(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java new file mode 100644 index 00000000..e9c5b5a7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.notification.repository; + +import com.prgrms.catchtable.notification.domain.NotificationMember; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationMemberRepository extends JpaRepository { + +} diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java new file mode 100644 index 00000000..bca2921d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.notification.repository; + +import com.prgrms.catchtable.notification.domain.NotificationOwner; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationOwnerRepository extends JpaRepository { + +} diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java new file mode 100644 index 00000000..d8464116 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -0,0 +1,58 @@ +package com.prgrms.catchtable.owner.domain; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.Column; +import jakarta.persistence.ConstraintMode; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import java.time.LocalDate; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Owner { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "owner_id") + private Long id; + + @Column(name = "owner_name") + private String name; + + @Column(name = "phone_number") + private String phoneNumber; + + @Column(name = "gender") + @Enumerated(STRING) + private Gender gender; + + @Column(name = "date_birth") + private LocalDate dateBirth; + + @OneToOne(fetch = LAZY) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Shop shop; + + @Builder + public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth) { + this.name = name; + this.phoneNumber = phoneNumber; + this.gender = gender; + this.dateBirth = dateBirth; + } +} diff --git a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java new file mode 100644 index 00000000..3dbeb442 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.owner.repository; + +import com.prgrms.catchtable.owner.domain.Owner; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OwnerRepository extends JpaRepository { + +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java new file mode 100644 index 00000000..143251d7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -0,0 +1,58 @@ +package com.prgrms.catchtable.reservation.domain; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.Column; +import jakarta.persistence.ConstraintMode; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Reservation { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "reservation_id") + private Long id; + + @Enumerated(STRING) + @Column(name = "status") + private ReservationStatus status; + + @Column(name = "people_count") + private int peopleCount; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "member_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Member member; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Shop shop; + + @OneToOne(fetch = LAZY) + @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private ReservationTime time; + + @Builder + public Reservation(ReservationStatus status, int peopleCount) { + this.status = status; + this.peopleCount = peopleCount; + } +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationStatus.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationStatus.java new file mode 100644 index 00000000..d3b87ebc --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationStatus.java @@ -0,0 +1,14 @@ +package com.prgrms.catchtable.reservation.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ReservationStatus { + COMPLETED("예약 완료"), + CANCELLED("예약 취소"), + NO_SHOW("노쇼"); + + private final String description; +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java new file mode 100644 index 00000000..60ee4924 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -0,0 +1,46 @@ +package com.prgrms.catchtable.reservation.domain; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.Column; +import jakarta.persistence.ConstraintMode; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class ReservationTime { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "reservation_time_id") + private Long id; + + @Column(name = "time") + private LocalDateTime time; + + @Column(name = "is_occupied") + private boolean isOccupied; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Shop shop; + + @Builder + public ReservationTime(LocalDateTime time) { + this.time = time; + this.isOccupied = false; + } +} diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Address.java b/src/main/java/com/prgrms/catchtable/shop/domain/Address.java new file mode 100644 index 00000000..33ae8ad2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Address.java @@ -0,0 +1,27 @@ +package com.prgrms.catchtable.shop.domain; + +import static lombok.AccessLevel.PROTECTED; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Embeddable +public class Address { + + @Column(name = "city") + private String city; + + @Column(name = "district") + private String district; + + @Builder + public Address(String city, String district) { + this.city = city; + this.district = district; + } +} diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java new file mode 100644 index 00000000..7cfb6af8 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.shop.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Category { + KOREAN_FOOD("한식"), + JAPANESE_FOOD("일식"), + CHINESE_FOOD("중식"), + WESTERN_FOOD("양식"); + + private final String description; + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java b/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java new file mode 100644 index 00000000..549e78da --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java @@ -0,0 +1,50 @@ +package com.prgrms.catchtable.shop.domain; + +import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Menu { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "menu_id") + private Long id; + + @Column(name = "menu_name") + private String name; + + @Column(name = "price") + private int price; + + @Lob + @Column(name = "description") + private String description; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) + private Shop shop; + + @Builder + public Menu(String name, int price, String description) { + this.name = name; + this.price = price; + this.description = description; + } +} diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java new file mode 100644 index 00000000..508fdad1 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -0,0 +1,52 @@ +package com.prgrms.catchtable.shop.domain; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import jakarta.persistence.Column; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import java.math.BigDecimal; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Shop { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "shop_id") + private Long id; + + @Column(name = "shop_name") + private String name; + + @Column(name = "rating") + private BigDecimal rating; + + @Column(name = "category") + @Enumerated(STRING) + private Category category; + + @Embedded + private Address address; + + @Column(name = "capacity") + private int capacity; + + @Builder + public Shop(String name, BigDecimal rating, Category category, Address address, int capacity) { + this.name = name; + this.rating = rating; + this.category = category; + this.address = address; + this.capacity = capacity; + } +} diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java new file mode 100644 index 00000000..2dc4ae92 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.shop.repository; + +import com.prgrms.catchtable.shop.domain.Shop; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ShopRepository extends JpaRepository { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java new file mode 100644 index 00000000..d843f94e --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -0,0 +1,55 @@ +package com.prgrms.catchtable.waiting.domain; + +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.Column; +import jakarta.persistence.ConstraintMode; +import jakarta.persistence.Entity; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class Waiting { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "waiting_id") + private Long id; + + @Column(name = "rank") + private int rank; + + @Column(name = "people_count") + private int peopleCount; + + @Column(name = "delay_remaining_count") + private int delayRemainingCount; + + @OneToOne(fetch = LAZY) + @JoinColumn(name = "member_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Member member; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private Shop shop; + + @Builder + public Waiting(int rank, int peopleCount) { + this.rank = rank; + this.peopleCount = peopleCount; + this.delayRemainingCount = 2; + } +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java new file mode 100644 index 00000000..ae7026b2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.waiting.repository; + +import com.prgrms.catchtable.waiting.domain.Waiting; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface WaitingRepository extends JpaRepository { + +} From b6c7eeb54858d5ad709f9d957a6ad7fd646132e8 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 21 Dec 2023 01:10:25 +0900 Subject: [PATCH 002/603] =?UTF-8?q?chore=20:=20test=20container=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index b0ddb896..2df0a2d1 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,12 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' testImplementation 'org.springframework.security:spring-security-test' + + //test contrainer + testImplementation "org.testcontainers:testcontainers:1.19.2" + testImplementation "org.testcontainers:junit-jupiter:1.19.2" + testImplementation "org.testcontainers:mysql:1.19.2" + testImplementation 'org.testcontainers:jdbc:1.18.3' } tasks.named('test') { From a593a7c63131d172b934f6b45aa71f0dc739ce44 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 21 Dec 2023 14:16:24 +0900 Subject: [PATCH 003/603] =?UTF-8?q?refactor=20:=20=EB=8B=A8=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/member/domain/Member.java | 7 ------- .../catchtable/notification/domain/NotificationMember.java | 1 - 2 files changed, 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java index 2cee07b2..3ed80203 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Member.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -1,19 +1,15 @@ package com.prgrms.catchtable.member.domain; -import static jakarta.persistence.CascadeType.REMOVE; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; -import com.prgrms.catchtable.notification.domain.NotificationMember; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; import java.time.LocalDate; -import java.util.List; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -44,9 +40,6 @@ public class Member { @Column(name = "notification_activated") private boolean notification_activated; - @OneToMany(mappedBy = "member", cascade = REMOVE, orphanRemoval = true) - private List notificationMemberList; - @Builder public Member(String name, String phoneNumber, Gender gender, LocalDate dateBirth, boolean notification_activated) { diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java index 4356549b..1fd674b9 100644 --- a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java @@ -38,6 +38,5 @@ public class NotificationMember { public NotificationMember(String message, Member member) { this.message = message; this.member = member; - member.getNotificationMemberList().add(this); } } From 5a49b40f317dfbf654443caeb5564ee36e03c639 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 21 Dec 2023 14:18:46 +0900 Subject: [PATCH 004/603] =?UTF-8?q?feat=20:=20Auditing=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/CatchtableApplication.java | 2 ++ .../prgrms/catchtable/common/BaseEntity.java | 22 +++++++++++++++++++ .../catchtable/member/domain/Member.java | 3 ++- .../domain/NotificationMember.java | 3 ++- .../domain/NotificationOwner.java | 3 ++- .../prgrms/catchtable/owner/domain/Owner.java | 3 ++- .../reservation/domain/Reservation.java | 3 ++- .../prgrms/catchtable/shop/domain/Shop.java | 3 ++- .../catchtable/waiting/domain/Waiting.java | 3 ++- 9 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/common/BaseEntity.java diff --git a/src/main/java/com/prgrms/catchtable/CatchtableApplication.java b/src/main/java/com/prgrms/catchtable/CatchtableApplication.java index 5b23e6e6..67f21667 100644 --- a/src/main/java/com/prgrms/catchtable/CatchtableApplication.java +++ b/src/main/java/com/prgrms/catchtable/CatchtableApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class CatchtableApplication { diff --git a/src/main/java/com/prgrms/catchtable/common/BaseEntity.java b/src/main/java/com/prgrms/catchtable/common/BaseEntity.java new file mode 100644 index 00000000..d785926a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/BaseEntity.java @@ -0,0 +1,22 @@ +package com.prgrms.catchtable.common; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import java.time.LocalDateTime; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + + @CreatedDate + private LocalDateTime createDate; + + @LastModifiedDate + private LocalDateTime updateDate; + +} diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java index 3ed80203..54043c59 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Member.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -4,6 +4,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; @@ -17,7 +18,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Member { +public class Member extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java index 1fd674b9..2537d9f4 100644 --- a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationMember.java @@ -5,6 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -20,7 +21,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class NotificationMember { +public class NotificationMember extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java index c81b9250..4f4c3935 100644 --- a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java @@ -5,6 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.owner.domain.Owner; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -20,7 +21,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class NotificationOwner { +public class NotificationOwner extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index d8464116..f6d09f8f 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -5,6 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; @@ -24,7 +25,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Owner { +public class Owner extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index 143251d7..f4e47763 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -5,6 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; @@ -24,7 +25,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Reservation { +public class Reservation extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index 508fdad1..e6802531 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -4,6 +4,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -18,7 +19,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Shop { +public class Shop extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index d843f94e..f95abe92 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -4,6 +4,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; @@ -22,7 +23,7 @@ @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Waiting { +public class Waiting extends BaseEntity { @Id @GeneratedValue(strategy = IDENTITY) From cc81ad2544e56934bb533b04deb223856c2cff5e Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 21 Dec 2023 14:39:05 +0900 Subject: [PATCH 005/603] =?UTF-8?q?chore:=20spring=20restdoc=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b0ddb896..c5cb79cd 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ configurations { compileOnly { extendsFrom annotationProcessor } + asciidoctorExt } repositories { @@ -36,16 +37,40 @@ dependencies { runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' testImplementation 'org.springframework.security:spring-security-test' + + // RestDocs + asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' + testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + } tasks.named('test') { - outputs.dir snippetsDir useJUnitPlatform() } -tasks.named('asciidoctor') { +ext { // 전역 변수 + snippetsDir = file('build/generated-snippets') +} + +test { + outputs.dir snippetsDir +} + +asciidoctor { inputs.dir snippetsDir + configurations 'asciidoctorExt' + + sources {//특정 파일만 html로 생성 + include("**/index.adoc") + } + baseDirFollowsSourceFile() //다른 adoc 파일을 include할 때 경로를 baseDir로 맞춤 dependsOn test } + +bootJar { + dependsOn asciidoctor + from("${asciidoctor.outputDir}") { + into 'static/docs' + } +} \ No newline at end of file From 680a93b1a6c3b3fb95e47718e61c5c27c45d9d19 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 21 Dec 2023 14:46:35 +0900 Subject: [PATCH 006/603] =?UTF-8?q?feat:=20restdoc=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CatchtableApplicationTests.java | 13 --------- .../catchtable/common/RestDocsSupport.java | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) delete mode 100644 src/test/java/com/prgrms/catchtable/CatchtableApplicationTests.java create mode 100644 src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java diff --git a/src/test/java/com/prgrms/catchtable/CatchtableApplicationTests.java b/src/test/java/com/prgrms/catchtable/CatchtableApplicationTests.java deleted file mode 100644 index 778811f1..00000000 --- a/src/test/java/com/prgrms/catchtable/CatchtableApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.prgrms.catchtable; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class CatchtableApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java new file mode 100644 index 00000000..5435c9af --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java @@ -0,0 +1,28 @@ +package com.prgrms.catchtable.common; + +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +@ExtendWith(RestDocumentationExtension.class) +public abstract class RestDocsSupport { + + protected MockMvc mockMvc; + protected ObjectMapper objectMapper = new ObjectMapper(); + + + @BeforeEach + void setUp(RestDocumentationContextProvider provider) { + this.mockMvc = MockMvcBuilders.standaloneSetup(initController()) + .apply(documentationConfiguration(provider)) + .build(); + } + + protected abstract Object initController(); +} From 4ca4fc2f917d11e869cccc73b3366d2e41ebb8da Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 21 Dec 2023 15:49:54 +0900 Subject: [PATCH 007/603] =?UTF-8?q?fix=20:=20SQL=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=96=B4=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20=EC=9B=A8=EC=9D=B4=ED=8C=85=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=20=ED=95=84=EB=93=9C=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20rank=20->=20waiting=5Fnumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index f95abe92..0207eaaa 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -30,8 +30,8 @@ public class Waiting extends BaseEntity { @Column(name = "waiting_id") private Long id; - @Column(name = "rank") - private int rank; + @Column(name = "waiting_number") + private int waitingNumber; @Column(name = "people_count") private int peopleCount; @@ -48,8 +48,8 @@ public class Waiting extends BaseEntity { private Shop shop; @Builder - public Waiting(int rank, int peopleCount) { - this.rank = rank; + public Waiting(int waitingNumber, int peopleCount) { + this.waitingNumber = waitingNumber; this.peopleCount = peopleCount; this.delayRemainingCount = 2; } From 2a98a595d95a6a940c01d7c993da057a211c0901 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 21 Dec 2023 16:07:10 +0900 Subject: [PATCH 008/603] =?UTF-8?q?rename=20:=20RestDocs=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=20=ED=99=98=EA=B2=BD=20=ED=8C=8C=EC=9D=BC=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/{ => restdocs}/RestDocsSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/prgrms/catchtable/common/{ => restdocs}/RestDocsSupport.java (95%) diff --git a/src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java similarity index 95% rename from src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java rename to src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index 5435c9af..381b6db1 100644 --- a/src/test/java/com/prgrms/catchtable/common/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.common; +package com.prgrms.catchtable.common.restdocs; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; From c9737074f865f594e2506d32d79e607ed9f1ca7d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 21 Dec 2023 16:34:39 +0900 Subject: [PATCH 009/603] =?UTF-8?q?fix=20:=20CommonException=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/exception/CommonException.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/CommonException.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/CommonException.java b/src/main/java/com/prgrms/catchtable/common/exception/CommonException.java new file mode 100644 index 00000000..9004b306 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/CommonException.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.common.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class CommonException extends RuntimeException { + + private final ErrorCode errorCode; +} From 93e9770f9e13f9c19ababf280433e4f7ca337a42 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 21 Dec 2023 16:35:30 +0900 Subject: [PATCH 010/603] =?UTF-8?q?fix=20:=20ErrorCode=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20-=20http=20=EC=83=81=ED=83=9C=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20-=20=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/exception/ErrorCode.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java new file mode 100644 index 00000000..eb2e6d67 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -0,0 +1,14 @@ +package com.prgrms.catchtable.common.exception; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum ErrorCode { + NOT_EXIST_MEMBER(HttpStatus.BAD_REQUEST, "존재하지 않는 아이디입니다."); + + private final HttpStatus httpStatus; + private final String message; +} From cbbc4c7c1ecef7ab054f69e11f8e9328d86fd130 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 21 Dec 2023 16:35:57 +0900 Subject: [PATCH 011/603] =?UTF-8?q?fix=20:=20ExceptionHandler=20=ED=85=9C?= =?UTF-8?q?=ED=94=8C=EB=A6=BF=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/exception/ExceptionHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java new file mode 100644 index 00000000..e80e90fa --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.common.exception; + +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class ExceptionHandler { + +} From b1683c9680601784bb61785c6863930f370d1c8d Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Dec 2023 19:10:10 +0900 Subject: [PATCH 012/603] =?UTF-8?q?chore=20:=20ci.yml=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..12cc005a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: CI Backend + +on: + push: + branches: [ "main", "dev" ] + pull_request: + branches: [ "main", "dev" ] + +permissions: + contents: read + checks: write + pull-requests: write + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + # 자바 버전 설정 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + # 빌드 시 캐시 적용 + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + # gradle 권한 부여 + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + shell: bash + + # 빌드 + - name: Build with Gradle + run: ./gradlew build + + # 테스트 결과 PR 코멘트에 등록 + - name: Register the test results as PR comments + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: '**/build/test-results/test/TEST-*.xml' + + # 테스트 실패시 코드 라인에 대한 체크 추가 + - name: If test fail, add check comment on failed code line + uses: mikepenz/action-junit-report@v3 + if: always() + with: + report_paths: '**/build/test-results/test/TEST-*.html' \ No newline at end of file From b5865453a25700da234267e5bc4c551eeb0b4542 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:08:53 +0900 Subject: [PATCH 013/603] =?UTF-8?q?feat=20:=20ReservationRepository=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java new file mode 100644 index 00000000..e4e2642a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.reservation.repository; + +import com.prgrms.catchtable.reservation.domain.Reservation; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReservationRepository extends JpaRepository { + +} From f3c8fc4ca3449ae051bb10332df55f1cd678cee7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:09:50 +0900 Subject: [PATCH 014/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=84=A0=EC=A0=90?= =?UTF-8?q?=EA=B6=8C=20=EC=97=AC=EB=B6=80=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/ReservationTime.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 60ee4924..f579f848 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -34,6 +34,9 @@ public class ReservationTime { @Column(name = "is_occupied") private boolean isOccupied; + @Column(name = "is_pre_occupied") + private boolean isPreOccupied; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; From b40b4195c0a40e6856bb9c730978d1da5f74e001 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:12:03 +0900 Subject: [PATCH 015/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20api=20=EA=B4=80=EB=A0=A8=20dto?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/CreateResercationRequest.java | 7 +++++++ .../dto/response/CreateReservationResponse.java | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java new file mode 100644 index 00000000..2d759d2b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.request; + +import java.time.LocalDateTime; + +public record CreateResercationRequest(LocalDateTime date, int peopleCount) { + +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java new file mode 100644 index 00000000..f5da7f55 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import java.time.LocalDateTime; + +public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, int peopleCount) { + +} From c56bce6dacafb47bcbf25fc2feef4624a178bd56 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 03:05:32 +0900 Subject: [PATCH 016/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20api=20=ED=8B=80=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java new file mode 100644 index 00000000..e6b125ab --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -0,0 +1,25 @@ +package com.prgrms.catchtable.reservation.controller; + +import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/reservations") +@RequiredArgsConstructor +public class ReservationController { + + private final ReservationService reservationService; + + @GetMapping("/{shopId}") + public CreateReservationResponse createReservationResponse( + @PathVariable("shopId") Long shopId, + CreateResercationRequest request) { + return null; + } +} From 67325fdc078f96eacb269b97e52f3e7e66b4e659 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 03:05:46 +0900 Subject: [PATCH 017/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20Service=20=ED=8B=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java new file mode 100644 index 00000000..a99fe869 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -0,0 +1,37 @@ +package com.prgrms.catchtable.reservation.service; + +import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.time.LocalDateTime; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ReservationService { + + private final ReservationRepository reservationRepository; + private final ShopRepository shopRepository; + @Transactional + public CreateReservationResponse createReservation(Long shopId, CreateResercationRequest request) { + LocalDateTime requestedReservationTime = request.date(); + int requestedPeopleCount = request.peopleCount(); + + Shop shop = shopRepository.findById(shopId).orElseThrow(); + /** + * 해당 shop의 예약하려는 날짜와 시간이 비어있는 지 확인하는 로직 + * reservationTime = select rt from Shop s join ReservationTime rt where rt.time = :time; + * reservationTime.isOccupied == true? -> 이미 예약되어있다는 예외 발생 + * reservationTime.isPreOccupied == true? -> 타인이 예약중이라는 예외 발생 + * 선점권 스케줄러 실행 + */ + + // 퍼사드를 따로 빼서 이 프로세스가 끝나면 비동기 이벤트가 수행되게 해보자 + // 퍼사드에서 이 서비스 실행 로직 , 그리고 이벤트 발행 + return new CreateReservationResponse(shop.getName(), "member", requestedReservationTime, requestedPeopleCount); + } +} From 569a77e306d04eaae625f215a8624f51c84f8bd1 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 03:12:04 +0900 Subject: [PATCH 018/603] =?UTF-8?q?feat=20:=20=EC=BB=A4=EC=8A=A4=ED=85=80?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20=EA=B8=B0=EC=A1=B4=EC=97=90=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=9C=20=EA=B3=B5=ED=86=B5=20=EC=98=88=EC=99=B8(Co?= =?UTF-8?q?mmonException)=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20?= =?UTF-8?q?=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/custom/BadRequestCustomException.java | 11 +++++++++++ .../exception/custom/NotFoundCustomException.java | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/custom/BadRequestCustomException.java create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/custom/NotFoundCustomException.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/custom/BadRequestCustomException.java b/src/main/java/com/prgrms/catchtable/common/exception/custom/BadRequestCustomException.java new file mode 100644 index 00000000..e173a35c --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/custom/BadRequestCustomException.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.common.exception.custom; + +import com.prgrms.catchtable.common.exception.CommonException; +import com.prgrms.catchtable.common.exception.ErrorCode; + +public class BadRequestCustomException extends CommonException { + + public BadRequestCustomException(ErrorCode errorCode) { + super(errorCode); + } +} diff --git a/src/main/java/com/prgrms/catchtable/common/exception/custom/NotFoundCustomException.java b/src/main/java/com/prgrms/catchtable/common/exception/custom/NotFoundCustomException.java new file mode 100644 index 00000000..645f0d5e --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/custom/NotFoundCustomException.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.common.exception.custom; + +import com.prgrms.catchtable.common.exception.CommonException; +import com.prgrms.catchtable.common.exception.ErrorCode; + +public class NotFoundCustomException extends CommonException { + + public NotFoundCustomException(ErrorCode errorCode) { + super(errorCode); + } +} From 7a12e9411753bd969dc4bf09a5373630bd25705d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 25 Dec 2023 15:20:55 +0900 Subject: [PATCH 019/603] =?UTF-8?q?feat=20:=20ErrorCode=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=BD=94=EB=93=9C=20=ED=95=84=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index eb2e6d67..876f8b79 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -2,13 +2,11 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum ErrorCode { - NOT_EXIST_MEMBER(HttpStatus.BAD_REQUEST, "존재하지 않는 아이디입니다."); + NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."); - private final HttpStatus httpStatus; private final String message; } From c34397d7da851e541a987f9ac4a21bf06c8e1b4f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:20:40 +0900 Subject: [PATCH 020/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=9A=94=EC=B2=AD=20dto=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ateResercationRequest.java => CreateReservationRequest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/prgrms/catchtable/reservation/dto/request/{CreateResercationRequest.java => CreateReservationRequest.java} (62%) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java similarity index 62% rename from src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java rename to src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 2d759d2b..2de0a9cb 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -2,6 +2,6 @@ import java.time.LocalDateTime; -public record CreateResercationRequest(LocalDateTime date, int peopleCount) { +public record CreateReservationRequest(LocalDateTime date, int peopleCount) { } From bbf3e0e368940c09a25675810f420e384e971e2e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:21:28 +0900 Subject: [PATCH 021/603] =?UTF-8?q?feat=20:=20Reservation=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/Reservation.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index f4e47763..ed02024b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -56,4 +56,12 @@ public Reservation(ReservationStatus status, int peopleCount) { this.status = status; this.peopleCount = peopleCount; } + + public void insertReservvationTime(ReservationTime reservationTime){ + this.time = reservationTime; + } + + public void insertShop(Shop shop) { + this.shop = shop; + } } From edb3ab913519a7a1e8038a03b93fc7cd739c6772 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:22:45 +0900 Subject: [PATCH 022/603] =?UTF-8?q?feat=20:=20ReservaitonTime=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=97=AC=EB=B6=80,=20=EC=84=A0=EC=A0=90=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/ReservationTime.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index f579f848..98022d4d 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -46,4 +46,12 @@ public ReservationTime(LocalDateTime time) { this.time = time; this.isOccupied = false; } + + public void reverseOccupied(){ + this.isOccupied = !this.isOccupied; + } + + public void reversePreOccupied(){ + this.isPreOccupied = !this.isPreOccupied; + } } From e4141009907ec9b1153dd2322b0d09954bbf3678 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:25:06 +0900 Subject: [PATCH 023/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B6=8C=20=EC=B7=A8=EB=93=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=201=EC=B0=A8=20=EA=B5=AC=ED=98=84=20-=20=EC=B6=94?= =?UTF-8?q?=ED=9B=84=EC=97=90=20Oauth=EB=A5=BC=20=ED=86=B5=ED=95=B4=20memb?= =?UTF-8?q?er=20=ED=95=84=ED=84=B0=EB=A7=81=20-=20=ED=98=84=EC=9E=AC?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EC=A0=9C=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=84=20=EC=A7=81=EC=A0=91=20=EC=83=9D=EC=84=B1,?= =?UTF-8?q?=20=EC=B6=94=ED=9B=84=EC=97=90=20shop=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=A1=B0=ED=9A=8C=ED=95=B4?= =?UTF-8?q?=EC=95=BC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index a99fe869..23338922 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,7 +1,11 @@ package com.prgrms.catchtable.reservation.service; -import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; -import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; + +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -16,22 +20,35 @@ public class ReservationService { private final ReservationRepository reservationRepository; private final ShopRepository shopRepository; + @Transactional - public CreateReservationResponse createReservation(Long shopId, CreateResercationRequest request) { + public ValidateReservationResponse validateReservationIsPossible(Long shopId, + CreateReservationRequest request) { LocalDateTime requestedReservationTime = request.date(); int requestedPeopleCount = request.peopleCount(); Shop shop = shopRepository.findById(shopId).orElseThrow(); - /** - * 해당 shop의 예약하려는 날짜와 시간이 비어있는 지 확인하는 로직 - * reservationTime = select rt from Shop s join ReservationTime rt where rt.time = :time; - * reservationTime.isOccupied == true? -> 이미 예약되어있다는 예외 발생 - * reservationTime.isPreOccupied == true? -> 타인이 예약중이라는 예외 발생 - * 선점권 스케줄러 실행 - */ - - // 퍼사드를 따로 빼서 이 프로세스가 끝나면 비동기 이벤트가 수행되게 해보자 - // 퍼사드에서 이 서비스 실행 로직 , 그리고 이벤트 발행 - return new CreateReservationResponse(shop.getName(), "member", requestedReservationTime, requestedPeopleCount); + //예제 데이터 + ReservationTime reservationTime = ReservationTime.builder() + .time(request.date()) + .build(); + Reservation reservation = Reservation.builder() + .status(COMPLETED) + .peopleCount(request.peopleCount()) + .build(); + + if (reservationTime.isPreOccupied()) { + throw new RuntimeException("타인에게 선점권이 있음"); + } + if (reservationTime.isOccupied()) { + throw new RuntimeException("이미 예약된 시간임"); + } + + reservation.insertReservvationTime(reservationTime); + reservation.insertShop(shop); + + Reservation savedReservation = reservationRepository.save(reservation); + + return new ValidateReservationResponse(savedReservation.getShop().getName(), savedReservation.getTime()); } } From daa8856cb475bdfa26b59df104c1cf87fd64b5b5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:26:49 +0900 Subject: [PATCH 024/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=ED=95=98=EB=8A=94=20=EB=B9=84=EB=8F=99?= =?UTF-8?q?=EA=B8=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationAsync.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java new file mode 100644 index 00000000..a6551170 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -0,0 +1,29 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@RequiredArgsConstructor +public class ReservationAsync { + + @Async + @Transactional(propagation = REQUIRES_NEW) + public void setPreOcuppied(ReservationTime reservationTime) { + reservationTime.reversePreOccupied(); + + try { + Thread.sleep(5_000); + } catch (InterruptedException exception) { + exception.printStackTrace(); + } + + reservationTime.reversePreOccupied(); + } + +} From 6a8474dea21ae0615029f9e4f9bee8e0758b38d6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:27:52 +0900 Subject: [PATCH 025/603] =?UTF-8?q?feat=20:=20Test=20data=EC=9A=A9=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84(=EC=98=88?= =?UTF-8?q?=EC=95=BD,=20=EB=A7=A4=EC=9E=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reservation/ReservationData.java | 28 +++++++++++++++++++ .../catchtable/common/data/shop/ShopData.java | 20 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java create mode 100644 src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java new file mode 100644 index 00000000..f56faa8f --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -0,0 +1,28 @@ +package com.prgrms.catchtable.common.data.reservation; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; + +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import java.time.LocalDateTime; + +public class ReservationData { + public static Reservation getReservation(){ + return Reservation.builder() + .status(COMPLETED) + .peopleCount(4) + .build(); + } + public static ReservationTime getReservationTime(){ + return ReservationTime.builder() + .time(LocalDateTime.of(2023, 12, 31, 19, 30)) + .build(); + } + + public static CreateReservationRequest getCreateReservationRequest(){ + return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); + } + +} diff --git a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java new file mode 100644 index 00000000..a7a33ad3 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java @@ -0,0 +1,20 @@ +package com.prgrms.catchtable.common.data.shop; + +import static com.prgrms.catchtable.shop.domain.Category.*; + +import com.prgrms.catchtable.shop.domain.Address; +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import java.math.BigDecimal; + +public class ShopData { + public static Shop getShop(){ + return Shop.builder() + .name("shopA") + .rating(BigDecimal.valueOf(5L)) + .category(JAPANESE_FOOD) + .address(Address.builder().build()) + .capacity(30) + .build(); + } +} From 125769f2e493d0305787872f4cb483ad9f0bb15f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:28:29 +0900 Subject: [PATCH 026/603] =?UTF-8?q?feat=20:=20ReservationService=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EC=84=A0=EC=A0=90=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java new file mode 100644 index 00000000..6ec9ca3d --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -0,0 +1,57 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; + +@ExtendWith(MockitoExtension.class) +class ReservationServiceTest { + + @Mock + private ReservationRepository reservationRepository; + @Mock + private ShopRepository shopRepository; + @InjectMocks + private ReservationService reservationService; + + @Test + @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") + void validateReservation() { + Reservation reservation = ReservationData.getReservation(); + CreateReservationRequest createReservationRequest = ReservationData.getCreateReservationRequest(); + Shop shop = ShopData.getShop(); + + reservation.insertShop(shop); + reservation.insertReservvationTime(ReservationData.getReservationTime()); + + ReflectionTestUtils.setField(shop, "id", 1L); + + when(shopRepository.findById(any(Long.class))).thenReturn(Optional.of(shop)); + when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + + ValidateReservationResponse response = reservationService.validateReservationIsPossible( + shop.getId(), createReservationRequest); + assertAll( + () -> assertThat(response.reservationTime().getTime()).isEqualTo(createReservationRequest.date()), + () -> assertThat(response.shopName()).isEqualTo(shop.getName()) + ); + } +} \ No newline at end of file From bccd4f5c11ee66033711adccf9d7b6d422a2e64a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:28:43 +0900 Subject: [PATCH 027/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=ED=95=98=EB=8A=94=20=EB=B9=84=EB=8F=99?= =?UTF-8?q?=EA=B8=B0=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java new file mode 100644 index 00000000..c2d1b7c4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -0,0 +1,42 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ReservationAsyncTest { + + @Mock + private ReservationRepository reservationRepository; + @InjectMocks + private ReservationAsync reservationAsync; + + @Test + @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") + void preOccupiedAsync(){ + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationAsync.setPreOcuppied(reservationTime); + + assertThat(reservationTime.isPreOccupied()).isTrue(); + + try { + Thread.sleep(6_000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + assertThat(reservationTime.isPreOccupied()).isFalse(); + } +} \ No newline at end of file From 78e0c338dcf78ac75f8d24302b012f0ed90846b5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:30:22 +0900 Subject: [PATCH 028/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=ED=8D=BC=EC=82=AC=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=B0=9B=EB=8A=94=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?dto=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ValidateReservationResponse.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java new file mode 100644 index 00000000..ee0e91d1 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; + +public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { + +} From ac5d2a7478764d26e2172bbceb7f74df558118a2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:30:33 +0900 Subject: [PATCH 029/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=ED=8D=BC=EC=82=AC=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/facade/ReservationFacade.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java new file mode 100644 index 00000000..84cc2490 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -0,0 +1,33 @@ +package com.prgrms.catchtable.facade; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationAsync; +import com.prgrms.catchtable.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReservationFacade { + + private final ReservationService reservationService; + private final ReservationAsync reservationAsync; + + public CreateReservationResponse createReservation(Long shopId, + CreateReservationRequest request) { + ValidateReservationResponse validateReservationResponse = reservationService.validateReservationIsPossible( + shopId, + request); + + String shopName = validateReservationResponse.shopName(); + ReservationTime reservationTime = validateReservationResponse.reservationTime(); + + reservationAsync.setPreOcuppied(reservationTime); + + return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), request.peopleCount()); + } + +} From 651291789d51b454cfd6ab20263c1eab76c81679 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:31:44 +0900 Subject: [PATCH 030/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20api?= =?UTF-8?q?=20=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20dto=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index e6b125ab..3cff7823 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.controller; -import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ public class ReservationController { @GetMapping("/{shopId}") public CreateReservationResponse createReservationResponse( @PathVariable("shopId") Long shopId, - CreateResercationRequest request) { + CreateReservationRequest request) { return null; } } From b4c47f945468ab0d986ad007682901e8b492de13 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:33:25 +0900 Subject: [PATCH 031/603] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/facade/ReservationFacade.java | 3 ++- .../prgrms/catchtable/reservation/domain/Reservation.java | 2 +- .../catchtable/reservation/domain/ReservationTime.java | 4 ++-- .../reservation/dto/response/CreateReservationResponse.java | 3 ++- .../catchtable/reservation/service/ReservationService.java | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index 84cc2490..8cf1f723 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -27,7 +27,8 @@ public CreateReservationResponse createReservation(Long shopId, reservationAsync.setPreOcuppied(reservationTime); - return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), request.peopleCount()); + return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), + request.peopleCount()); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index ed02024b..ddb26f2f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -57,7 +57,7 @@ public Reservation(ReservationStatus status, int peopleCount) { this.peopleCount = peopleCount; } - public void insertReservvationTime(ReservationTime reservationTime){ + public void insertReservvationTime(ReservationTime reservationTime) { this.time = reservationTime; } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 98022d4d..d11f2f8a 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -47,11 +47,11 @@ public ReservationTime(LocalDateTime time) { this.isOccupied = false; } - public void reverseOccupied(){ + public void reverseOccupied() { this.isOccupied = !this.isOccupied; } - public void reversePreOccupied(){ + public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index f5da7f55..1730ec96 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; -public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, int peopleCount) { +public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, + int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 23338922..75f8668b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -49,6 +49,7 @@ public ValidateReservationResponse validateReservationIsPossible(Long shopId, Reservation savedReservation = reservationRepository.save(reservation); - return new ValidateReservationResponse(savedReservation.getShop().getName(), savedReservation.getTime()); + return new ValidateReservationResponse(savedReservation.getShop().getName(), + savedReservation.getTime()); } } From 321bacd5d1150e90aef79215b72e225cdbe0f9df Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:59:46 +0900 Subject: [PATCH 032/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=97=AC?= =?UTF-8?q?=EB=B6=80,=20=EC=84=A0=EC=A0=90=EC=97=AC=EB=B6=80=20=EA=B0=92?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/ReservationTimeTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java new file mode 100644 index 00000000..abade0a4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -0,0 +1,28 @@ +package com.prgrms.catchtable.reservation.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ReservationTimeTest { + + @Test + @DisplayName("예약 선점 여부 변경에 성공한다") + void reversePreOccupied() { + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationTime.reversePreOccupied(); + + assertThat(reservationTime.isPreOccupied()).isTrue(); + } + + @Test + @DisplayName("예약 여부 변경에 성공한다.") + void reverseOccupied() { + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationTime.reverseOccupied(); + + assertThat(reservationTime.isOccupied()).isTrue(); + } +} \ No newline at end of file From 826fb02ea1376f533e7bc51df5f3bcb3376212cd Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 02:00:33 +0900 Subject: [PATCH 033/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20=EB=B9=84=EB=8F=99=EA=B8=B0=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20SpringbootTest=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java index c2d1b7c4..c0f09353 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -1,33 +1,28 @@ package com.prgrms.catchtable.reservation.service; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import com.prgrms.catchtable.common.data.reservation.ReservationData; import com.prgrms.catchtable.reservation.domain.ReservationTime; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ReservationAsyncTest { - @Mock - private ReservationRepository reservationRepository; - @InjectMocks + @Autowired private ReservationAsync reservationAsync; @Test @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") - void preOccupiedAsync(){ + void preOccupiedAsync() { ReservationTime reservationTime = ReservationData.getReservationTime(); reservationAsync.setPreOcuppied(reservationTime); + reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -36,7 +31,7 @@ void preOccupiedAsync(){ } catch (InterruptedException e) { throw new RuntimeException(e); } - + reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isFalse(); } } \ No newline at end of file From d454045f0867cac153eeb47836fe5d09a343ba99 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 02:02:23 +0900 Subject: [PATCH 034/603] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/data/reservation/ReservationData.java | 9 +++++---- .../com/prgrms/catchtable/common/data/shop/ShopData.java | 6 +++--- .../reservation/service/ReservationAsyncTest.java | 2 -- .../reservation/service/ReservationServiceTest.java | 3 ++- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index f56faa8f..624f3f10 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -2,26 +2,27 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import java.time.LocalDateTime; public class ReservationData { - public static Reservation getReservation(){ + + public static Reservation getReservation() { return Reservation.builder() .status(COMPLETED) .peopleCount(4) .build(); } - public static ReservationTime getReservationTime(){ + + public static ReservationTime getReservationTime() { return ReservationTime.builder() .time(LocalDateTime.of(2023, 12, 31, 19, 30)) .build(); } - public static CreateReservationRequest getCreateReservationRequest(){ + public static CreateReservationRequest getCreateReservationRequest() { return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); } diff --git a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java index a7a33ad3..4b71a7d1 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java @@ -1,14 +1,14 @@ package com.prgrms.catchtable.common.data.shop; -import static com.prgrms.catchtable.shop.domain.Category.*; +import static com.prgrms.catchtable.shop.domain.Category.JAPANESE_FOOD; import com.prgrms.catchtable.shop.domain.Address; -import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; import java.math.BigDecimal; public class ShopData { - public static Shop getShop(){ + + public static Shop getShop() { return Shop.builder() .name("shopA") .rating(BigDecimal.valueOf(5L)) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java index c0f09353..4734c7df 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -6,8 +6,6 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 6ec9ca3d..a3a64724 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -50,7 +50,8 @@ void validateReservation() { ValidateReservationResponse response = reservationService.validateReservationIsPossible( shop.getId(), createReservationRequest); assertAll( - () -> assertThat(response.reservationTime().getTime()).isEqualTo(createReservationRequest.date()), + () -> assertThat(response.reservationTime().getTime()).isEqualTo( + createReservationRequest.date()), () -> assertThat(response.shopName()).isEqualTo(shop.getName()) ); } From 25e4eeee7d7b19e8a23c80e5a1f078f816d61d14 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 11:23:59 +0900 Subject: [PATCH 035/603] =?UTF-8?q?chore:=20OAuth2.0=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 57f64ad1..92614a8e 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,9 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + //OAuth2.0 Client + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + } tasks.named('test') { From 8797651098bea591ae6bac0cab6599472e3d8948 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 26 Dec 2023 14:33:43 +0900 Subject: [PATCH 036/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/domain/Waiting.java | 25 +++++++++++++++---- .../waiting/domain/WaitingStatus.java | 14 +++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 0207eaaa..4f894bdf 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,15 +1,19 @@ package com.prgrms.catchtable.waiting.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_CANCELED_WAITING; +import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; +import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; -import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; @@ -33,24 +37,35 @@ public class Waiting extends BaseEntity { @Column(name = "waiting_number") private int waitingNumber; + @Column(name = "waiting_order") + private int waitingOrder; + @Column(name = "people_count") private int peopleCount; + @Column(name = "status") + @Enumerated(STRING) + private WaitingStatus status; + @Column(name = "delay_remaining_count") private int delayRemainingCount; @OneToOne(fetch = LAZY) - @JoinColumn(name = "member_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @JoinColumn(name = "member_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) private Member member; @ManyToOne(fetch = LAZY) - @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) private Shop shop; @Builder - public Waiting(int waitingNumber, int peopleCount) { + public Waiting(int waitingNumber, int waitingOrder, int peopleCount, Member member, Shop shop) { this.waitingNumber = waitingNumber; + this.waitingOrder = waitingOrder; this.peopleCount = peopleCount; - this.delayRemainingCount = 2; + this.member = member; + this.shop = shop; + status = WaitingStatus.PROGRESS; + delayRemainingCount = 2; } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java new file mode 100644 index 00000000..a711f5a9 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java @@ -0,0 +1,14 @@ +package com.prgrms.catchtable.waiting.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +@Getter +@RequiredArgsConstructor +public enum WaitingStatus { + PROGRESS("웨이팅 진행 중"), + COMPLETED("웨이팅 입장"), + CANCELED("웨이팅 취소"), + NO_SHOW("노쇼"); + + private final String description; +} From 0c38f506639001a041b636ae58edf52d650b97d8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 26 Dec 2023 14:35:11 +0900 Subject: [PATCH 037/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20DTO=20?= =?UTF-8?q?=EB=B0=8F=20Mapper=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/dto/CreateWaitingRequest.java | 10 ++++++ .../waiting/dto/CreateWaitingResponse.java | 13 ++++++++ .../catchtable/waiting/dto/WaitingMapper.java | 33 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java new file mode 100644 index 00000000..959d125c --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java @@ -0,0 +1,10 @@ +package com.prgrms.catchtable.waiting.dto; + +import jakarta.validation.constraints.Positive; +import lombok.Builder; + +@Builder +public record CreateWaitingRequest( + @Positive(message = "인원은 1명 이상이어야 합니다.") + int peopleCount +){} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java new file mode 100644 index 00000000..64775645 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java @@ -0,0 +1,13 @@ +package com.prgrms.catchtable.waiting.dto; + +import lombok.Builder; + +@Builder +public record CreateWaitingResponse( + Long createdWaitingId, + Long shopId, + String shopName, + int peopleCount, + int waitingNumber, + int waitingOrder +){} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java new file mode 100644 index 00000000..df40a002 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -0,0 +1,33 @@ +package com.prgrms.catchtable.waiting.dto; + +import static lombok.AccessLevel.PRIVATE; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.waiting.domain.Waiting; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public class WaitingMapper { + // dto -> entity + public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, int waitingOrder, Member member, Shop shop){ + return Waiting.builder() + .waitingNumber(waitingNumber) + .waitingOrder(waitingOrder) + .peopleCount(request.peopleCount()) + .member(member) + .shop(shop).build(); + } + + // entity -> dto + public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting){ + return CreateWaitingResponse.builder() + .createdWaitingId(waiting.getId()) + .shopId(waiting.getShop().getId()) + .shopName(waiting.getShop().getName()) + .peopleCount(waiting.getPeopleCount()) + .waitingNumber(waiting.getWaitingNumber()) + .waitingOrder(waiting.getWaitingOrder()) + .build(); + } +} From 8281ed2c6cca092bac3a4f3182bb0c67084ecc8e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 20:30:48 +0900 Subject: [PATCH 038/603] =?UTF-8?q?feat=20:=20Member=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20email=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20&?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EC=97=AC=EB=B6=80=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=EA=B0=92=20true=EB=A1=9C=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/member/domain/Member.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java index 54043c59..5d076350 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Member.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -28,6 +28,9 @@ public class Member extends BaseEntity { @Column(name = "member_name") private String name; + @Column(name = "email") + private String email; + @Column(name = "phone_number") private String phoneNumber; @@ -42,12 +45,12 @@ public class Member extends BaseEntity { private boolean notification_activated; @Builder - public Member(String name, String phoneNumber, Gender gender, LocalDate dateBirth, - boolean notification_activated) { + public Member(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { this.name = name; + this.email = email; this.phoneNumber = phoneNumber; this.gender = gender; this.dateBirth = dateBirth; - this.notification_activated = notification_activated; + this.notification_activated = true; } } From 81722d6a09bdb7591d38baa02e986b34027e4ed5 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 20:33:42 +0900 Subject: [PATCH 039/603] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/dto/OAuthAttribute.java | 65 +++++++++++++++++++ .../service/CustomOAuth2SuccessHandler.java | 38 +++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java create mode 100644 src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java diff --git a/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java b/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java new file mode 100644 index 00000000..8c0d689c --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java @@ -0,0 +1,65 @@ +package com.prgrms.catchtable.security.dto; + +import java.util.Map; +import lombok.Builder; +import lombok.Getter; +import org.springframework.security.oauth2.core.user.OAuth2User; + +@Getter +public class OAuthAttribute { + + String name; + + String email; + + String phoneNumber; + + String birthYear; + + String birthDay; + + String gender; + + @Builder + public OAuthAttribute(String name, String email, String phoneNumber, String birthYear, + String birthDay, String gender) { + this.name = name; + this.email = email; + this.phoneNumber = phoneNumber; + this.birthYear = birthYear; + this.birthDay = birthDay; + this.gender = gender; + } + + public static OAuthAttribute of(OAuth2User oAuth2User, String provider) { + + OAuthAttribute oAuthAttribute; + + if (provider.equals("kakao")) { + Map userAttributes = oAuth2User.getAttributes(); + Map kakaoAccount = (Map) userAttributes.get( + "kakao_account"); + Map profile = (Map) kakaoAccount.get("profile"); + + String nickName = (String) profile.get("nickname"); + String email = (String) kakaoAccount.get("email"); + String phoneNumber = (String) kakaoAccount.get("phone_number"); + String birthYear = (String) kakaoAccount.get("birthyear"); + String birthDay = (String) kakaoAccount.get("birthday"); + String gender = (String) kakaoAccount.get("gender"); + + oAuthAttribute = OAuthAttribute.builder() + .name(nickName) + .email(email) + .phoneNumber(phoneNumber) + .birthYear(birthYear) + .birthDay(birthDay) + .gender(gender) + .build(); + } else { + oAuthAttribute = null; + } + + return oAuthAttribute; + } +} diff --git a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java new file mode 100644 index 00000000..7ea9b399 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java @@ -0,0 +1,38 @@ +package com.prgrms.catchtable.security.service; + +import com.prgrms.catchtable.member.service.MemberService; +import com.prgrms.catchtable.security.dto.OAuthAttribute; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class CustomOAuth2SuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { + + private final MemberService memberService; + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, + Authentication authentication) throws IOException { + + if (authentication instanceof OAuth2AuthenticationToken) { + OAuth2User oauth2User = ((OAuth2AuthenticationToken) authentication).getPrincipal(); + String provider = ((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId(); + + OAuthAttribute oAuthAttribute = OAuthAttribute.of(oauth2User, provider); + + //JWT 토큰 함께 발급 + memberService.oauthLogin(oAuthAttribute); + + //JWT 토큰을 Json으로 전달 + + } + } +} From ab72dac365b29c2829764aa47f61c1dee61417a4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 20:36:49 +0900 Subject: [PATCH 040/603] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=ED=9B=84=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/member/dto/MemberMapper.java | 27 ++++++++++++++++ .../member/repository/MemberRepository.java | 3 ++ .../member/service/MemberService.java | 31 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/member/dto/MemberMapper.java create mode 100644 src/main/java/com/prgrms/catchtable/member/service/MemberService.java diff --git a/src/main/java/com/prgrms/catchtable/member/dto/MemberMapper.java b/src/main/java/com/prgrms/catchtable/member/dto/MemberMapper.java new file mode 100644 index 00000000..9ac1f9c0 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/dto/MemberMapper.java @@ -0,0 +1,27 @@ +package com.prgrms.catchtable.member.dto; + +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.security.dto.OAuthAttribute; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class MemberMapper { + + public static Member changeOAuth(OAuthAttribute attributes) { + + String birthString = attributes.getBirthYear() + attributes.getBirthDay(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + LocalDate birthDay = LocalDate.parse(birthString, dateTimeFormatter); + System.out.println(birthDay); + + return Member.builder() + .name(attributes.getName()) + .email(attributes.getEmail()) + .phoneNumber(attributes.getPhoneNumber()) + .gender(attributes.getGender().equals("male") ? Gender.MALE : Gender.FEMALE) + .dateBirth(birthDay) + .build(); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java b/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java index 2d55246a..ba205c5b 100644 --- a/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/member/repository/MemberRepository.java @@ -1,8 +1,11 @@ package com.prgrms.catchtable.member.repository; import com.prgrms.catchtable.member.domain.Member; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { + Optional findMemberByEmail(String email); + } diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java new file mode 100644 index 00000000..2803023c --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -0,0 +1,31 @@ +package com.prgrms.catchtable.member.service; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.dto.MemberMapper; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.security.dto.OAuthAttribute; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberService { + + private final MemberRepository memberRepository; + + @Transactional + public void oauthLogin(OAuthAttribute attributes) { + String email = attributes.getEmail(); + Optional optionalMember = memberRepository.findMemberByEmail(email); + + if (optionalMember.isEmpty()) { + Member entity = MemberMapper.changeOAuth(attributes); + memberRepository.save(entity); + } + + //JWT 토큰 생성 & 반환 + } + +} From 55a743ceb12917582d3a3a6293637840093da5d1 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 20:37:29 +0900 Subject: [PATCH 041/603] =?UTF-8?q?feat=20:=20OAuth2.0=20=EC=BB=A4?= =?UTF-8?q?=EC=8A=A4=ED=85=80=20=EB=A1=9C=EC=A7=81=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/config/SecurityConfig.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java new file mode 100644 index 00000000..6de948cf --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -0,0 +1,37 @@ +package com.prgrms.catchtable.security.config; + +import com.prgrms.catchtable.security.service.CustomOAuth2SuccessHandler; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@EnableWebSecurity +public class SecurityConfig { + + private final CustomOAuth2SuccessHandler successHandler; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + + http + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy( + SessionCreationPolicy.STATELESS)) + .formLogin(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(authorization -> authorization + .requestMatchers(new AntPathRequestMatcher("/**")).permitAll() + ) + .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); + + return http.build(); + } + +} From 099c46066db770ad5cd3ed9648c2ca2672371ca0 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 20:52:37 +0900 Subject: [PATCH 042/603] =?UTF-8?q?chore=20:=20JWT=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 92614a8e..86b3657b 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,11 @@ dependencies { //OAuth2.0 Client implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + //JWT + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + } tasks.named('test') { From ca90a5f520f04ceb2625f2bfd4cfffad981f7bd1 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 22:56:02 +0900 Subject: [PATCH 043/603] =?UTF-8?q?feat=20:=20JWT=20properties=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/jwt/config/JwtConfig.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/jwt/config/JwtConfig.java diff --git a/src/main/java/com/prgrms/catchtable/jwt/config/JwtConfig.java b/src/main/java/com/prgrms/catchtable/jwt/config/JwtConfig.java new file mode 100644 index 00000000..1f51fefc --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/config/JwtConfig.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.jwt.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@Data +@ConfigurationProperties(prefix = "jwt") +public class JwtConfig { + + private String clientSecret; + private int expiryMinute; + private int expiryMinuteRefresh; + +} From 708f60230988f1ddeb301f08a7eedf1b719654d2 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 22:56:49 +0900 Subject: [PATCH 044/603] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20JWT=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EB=B0=9C=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/provider/JwtTokenProvider.java | 54 +++++++++++++++++++ .../prgrms/catchtable/jwt/token/Token.java | 15 ++++++ .../member/service/MemberService.java | 9 ++-- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java create mode 100644 src/main/java/com/prgrms/catchtable/jwt/token/Token.java diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java new file mode 100644 index 00000000..3bfb4819 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -0,0 +1,54 @@ +package com.prgrms.catchtable.jwt.provider; + + +import com.prgrms.catchtable.jwt.config.JwtConfig; +import com.prgrms.catchtable.jwt.token.Token; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import java.util.Date; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class JwtTokenProvider { + + private final JwtConfig jwtConfig; + + public Token createToken(String email) { + + Claims claims = Jwts.claims().setSubject(email); + Date now = new Date(); + + String accessToken = createAccessToken(claims, now); + String refreshToken = createRefreshToken(claims, now); + + return new Token(accessToken, refreshToken, email); + + } + + private String createAccessToken(Claims claims, Date now) { + long expiryMinute = jwtConfig.getExpiryMinute() * 1000L * 60; + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + expiryMinute)) + .signWith(SignatureAlgorithm.HS256, jwtConfig.getClientSecret()) + .compact(); + } + + private String createRefreshToken(Claims claims, Date now) { + + long expiryMinuteRefresh = jwtConfig.getExpiryMinuteRefresh() * 1000L * 60; + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(new Date(now.getTime() + expiryMinuteRefresh)) + .signWith(SignatureAlgorithm.HS256, jwtConfig.getClientSecret()) + .compact(); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/jwt/token/Token.java b/src/main/java/com/prgrms/catchtable/jwt/token/Token.java new file mode 100644 index 00000000..f2fe8093 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/token/Token.java @@ -0,0 +1,15 @@ +package com.prgrms.catchtable.jwt.token; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class Token { + + private String accessToken; + + private String refreshToken; + + private String email; +} diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 2803023c..c123c4ad 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.member.service; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.dto.MemberMapper; import com.prgrms.catchtable.member.repository.MemberRepository; @@ -15,8 +17,10 @@ public class MemberService { private final MemberRepository memberRepository; + private final JwtTokenProvider jwtTokenProvider; + @Transactional - public void oauthLogin(OAuthAttribute attributes) { + public Token oauthLogin(OAuthAttribute attributes) { String email = attributes.getEmail(); Optional optionalMember = memberRepository.findMemberByEmail(email); @@ -25,7 +29,6 @@ public void oauthLogin(OAuthAttribute attributes) { memberRepository.save(entity); } - //JWT 토큰 생성 & 반환 + return jwtTokenProvider.createToken(email); } - } From c72c0810dbb11ed98cab995fb852e4d70ff2c424 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 23:03:30 +0900 Subject: [PATCH 045/603] =?UTF-8?q?feat=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C=20=ED=9B=84=20=EB=B0=9C=EA=B8=89=EB=90=9C?= =?UTF-8?q?=20JWT=20=ED=86=A0=ED=81=B0=EC=9D=84=20JSON=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CustomOAuth2SuccessHandler.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java index 7ea9b399..94830052 100644 --- a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java +++ b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java @@ -1,5 +1,8 @@ package com.prgrms.catchtable.security.service; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.service.MemberService; import com.prgrms.catchtable.security.dto.OAuthAttribute; import jakarta.servlet.http.HttpServletRequest; @@ -28,11 +31,22 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo OAuthAttribute oAuthAttribute = OAuthAttribute.of(oauth2User, provider); - //JWT 토큰 함께 발급 - memberService.oauthLogin(oAuthAttribute); - - //JWT 토큰을 Json으로 전달 + Token token = memberService.oauthLogin(oAuthAttribute); + sendTokenJson(response, tokenToJson(token)); } } + + public String tokenToJson(Token token) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.writeValueAsString(token); + } + + private void sendTokenJson(HttpServletResponse response, String tokenJson) throws IOException { + response.setContentType("application/json;charset=UTF-8"); + response.setContentLength(tokenJson.getBytes().length); + response.getWriter().write(tokenJson); + } + + } From 6843ab09a6c5bb1c418b2e064896d10add114343 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 23:47:02 +0900 Subject: [PATCH 046/603] =?UTF-8?q?feat=20:=20RefreshToken=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9D=84=20=EC=9C=84=ED=95=9C=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/domain/RefreshToken.java | 35 +++++++++++++++++++ .../repository/RefreshTokenRepository.java | 7 ++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java create mode 100644 src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java diff --git a/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java new file mode 100644 index 00000000..b6ef9087 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java @@ -0,0 +1,35 @@ +package com.prgrms.catchtable.jwt.domain; + +import static lombok.AccessLevel.PROTECTED; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = PROTECTED) +@Entity +public class RefreshToken { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "token") + private String token; + + @Column(name = "email") + private String email; + + @Builder + public RefreshToken(String token, String email) { + this.token = token; + this.email = email; + } + +} diff --git a/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java new file mode 100644 index 00000000..1c7c1e6d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.jwt.repository; + +import com.prgrms.catchtable.jwt.domain.RefreshToken; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RefreshTokenRepository extends JpaRepository { +} From c7d91a4a12403cd5fb3dca990750d51a52d1a1ba Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 26 Dec 2023 23:48:05 +0900 Subject: [PATCH 047/603] =?UTF-8?q?feat=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=8B=9C,=20RefreshToken=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=97=90=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/RefreshTokenRepository.java | 4 +++ .../jwt/service/RefreshTokenService.java | 32 +++++++++++++++++++ .../member/service/MemberService.java | 11 ++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java diff --git a/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java index 1c7c1e6d..5caaed13 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java +++ b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java @@ -4,4 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface RefreshTokenRepository extends JpaRepository { + + boolean existsRefreshTokenByEmail(String email); + + void deleteRefreshTokenByEmail(String email); } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java new file mode 100644 index 00000000..7683ba73 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -0,0 +1,32 @@ +package com.prgrms.catchtable.jwt.service; + +import com.prgrms.catchtable.jwt.domain.RefreshToken; +import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; +import com.prgrms.catchtable.jwt.token.Token; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class RefreshTokenService { + + private final RefreshTokenRepository refreshTokenRepository; + + @Transactional + public void saveRefreshToken(Token totalToken){ + String email = totalToken.getEmail(); + + if(refreshTokenRepository.existsRefreshTokenByEmail(email)){ + refreshTokenRepository.deleteRefreshTokenByEmail(email); + } + + RefreshToken newRefreshToken = RefreshToken.builder() + .token(totalToken.getRefreshToken()) + .email(email) + .build(); + + refreshTokenRepository.save(newRefreshToken); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index c123c4ad..7ce7aed7 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.member.service; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.dto.MemberMapper; @@ -19,6 +20,8 @@ public class MemberService { private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenService refreshTokenService; + @Transactional public Token oauthLogin(OAuthAttribute attributes) { String email = attributes.getEmail(); @@ -29,6 +32,12 @@ public Token oauthLogin(OAuthAttribute attributes) { memberRepository.save(entity); } - return jwtTokenProvider.createToken(email); + return createTotalToken(email); + } + + private Token createTotalToken(String email){ + Token totalToken = jwtTokenProvider.createToken(email); + refreshTokenService.saveRefreshToken(totalToken); + return totalToken; } } From 459dac8c12bc8b890a32b8faae1764084a8ceb9b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 27 Dec 2023 00:31:59 +0900 Subject: [PATCH 048/603] =?UTF-8?q?feat=20:=20=EC=9D=B8=EA=B0=80=EB=A5=BC?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20Member=20Role=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/Role.java | 14 ++++++ .../catchtable/member/domain/Member.java | 48 ++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/common/Role.java diff --git a/src/main/java/com/prgrms/catchtable/common/Role.java b/src/main/java/com/prgrms/catchtable/common/Role.java new file mode 100644 index 00000000..b8b13051 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/Role.java @@ -0,0 +1,14 @@ +package com.prgrms.catchtable.common; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Role { + + MEMBER("ROLE_MEMBER"), + OWNER("ROLE_OWNER"); + + private final String role; +} diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java index 5d076350..a11c9209 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Member.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -5,20 +5,26 @@ import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; +import com.prgrms.catchtable.common.Role; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import java.time.LocalDate; +import java.util.Collection; +import java.util.Collections; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Member extends BaseEntity { +public class Member extends BaseEntity implements UserDetails { @Id @GeneratedValue(strategy = IDENTITY) @@ -38,6 +44,10 @@ public class Member extends BaseEntity { @Enumerated(STRING) private Gender gender; + @Column(name = "role") + @Enumerated(STRING) + private Role role; + @Column(name = "date_birth") private LocalDate dateBirth; @@ -52,5 +62,41 @@ public Member(String name, String email, String phoneNumber, Gender gender, Loca this.gender = gender; this.dateBirth = dateBirth; this.notification_activated = true; + this.role = Role.MEMBER; + } + + @Override + public Collection getAuthorities() { + return Collections.singletonList(new SimpleGrantedAuthority(role.getRole())); + } + + @Override + public String getPassword() { + return null; + } + + @Override + public String getUsername() { + return email; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; } } From efc32e139d8e88f0709f96690b192181901f0023 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 27 Dec 2023 01:11:04 +0900 Subject: [PATCH 049/603] =?UTF-8?q?feat=20:=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=8B=9C,=20JWT=20=ED=86=A0=ED=81=B0=EC=9D=84=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=ED=95=84=ED=84=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/filter/JwtAuthenticationFilter.java | 63 +++++++++++++++++++ .../jwt/provider/JwtTokenProvider.java | 37 ++++++++++- .../repository/RefreshTokenRepository.java | 3 + .../jwt/service/JwtUserDetailsService.java | 21 +++++++ .../jwt/service/RefreshTokenService.java | 6 ++ 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java create mode 100644 src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java new file mode 100644 index 00000000..52762b7a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -0,0 +1,63 @@ +package com.prgrms.catchtable.jwt.filter; + +import com.prgrms.catchtable.jwt.domain.RefreshToken; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; +import com.prgrms.catchtable.jwt.token.Token; +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class JwtAuthenticationFilter extends GenericFilter { + + private final JwtTokenProvider jwtTokenProvider; + + private final RefreshTokenService refreshTokenService; + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + + String accessToken = ((HttpServletRequest) request).getHeader("AccessToken"); + String refreshToken = ((HttpServletRequest) request).getHeader("RefreshToken"); + + if(accessToken!=null){ + //AccessToken 유효 + if(jwtTokenProvider.validateToken(accessToken)){ + setAuthentication(accessToken); + } + //RefreshToken 유효 + else{ + if(jwtTokenProvider.validateToken(refreshToken)){ + RefreshToken refreshTokenEntity = refreshTokenService.getRefreshTokenByToken( + refreshToken); + String email = refreshTokenEntity.getEmail(); + Token newToken = jwtTokenProvider.createToken(email); + + ((HttpServletResponse) response).setHeader("AccessToken", newToken.getAccessToken()); + setAuthentication(newToken.getAccessToken()); + } + else{ + throw new UsernameNotFoundException("Please Login again"); + } + } + } + } + + private void setAuthentication(String accessToken) { + Authentication authentication = jwtTokenProvider.getAuthentication(accessToken); + SecurityContextHolder.getContext().setAuthentication(authentication); + } +} diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 3bfb4819..9d72a47c 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -2,12 +2,17 @@ import com.prgrms.catchtable.jwt.config.JwtConfig; +import com.prgrms.catchtable.jwt.service.JwtUserDetailsService; import com.prgrms.catchtable.jwt.token.Token; import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import java.util.Date; import lombok.RequiredArgsConstructor; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; @Component @@ -16,6 +21,8 @@ public class JwtTokenProvider { private final JwtConfig jwtConfig; + private final JwtUserDetailsService jwtUserDetailsService; + public Token createToken(String email) { Claims claims = Jwts.claims().setSubject(email); @@ -25,7 +32,6 @@ public Token createToken(String email) { String refreshToken = createRefreshToken(claims, now); return new Token(accessToken, refreshToken, email); - } private String createAccessToken(Claims claims, Date now) { @@ -51,4 +57,33 @@ private String createRefreshToken(Claims claims, Date now) { .compact(); } + public boolean validateToken(String token) { + try{ + Claims claims = Jwts.parserBuilder() + .setSigningKey(jwtConfig.getClientSecret()) + .build() + .parseClaimsJws(token) + .getBody(); + + return claims.getExpiration().after(new Date()); + } catch(JwtException je){ + return false; + } + } + + public Authentication getAuthentication(String token){ + String email = getEmail(token); + UserDetails userDetails = jwtUserDetailsService.loadUserByUsername(email); + return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); + } + + private String getEmail(String token){ + Claims claims = Jwts.parserBuilder() + .setSigningKey(jwtConfig.getClientSecret()) + .build() + .parseClaimsJws(token) + .getBody(); + + return claims.getSubject(); + } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java index 5caaed13..688fca16 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java +++ b/src/main/java/com/prgrms/catchtable/jwt/repository/RefreshTokenRepository.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.jwt.repository; import com.prgrms.catchtable.jwt.domain.RefreshToken; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface RefreshTokenRepository extends JpaRepository { @@ -8,4 +9,6 @@ public interface RefreshTokenRepository extends JpaRepository findRefreshTokenByToken(String token); } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java new file mode 100644 index 00000000..a259842b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java @@ -0,0 +1,21 @@ +package com.prgrms.catchtable.jwt.service; + +import com.prgrms.catchtable.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class JwtUserDetailsService implements UserDetailsService { + + private final MemberRepository memberRepository; + + @Override + public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { + return memberRepository.findMemberByEmail(email) + .orElseThrow(() -> new UsernameNotFoundException("Not Found Member")); + } +} diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index 7683ba73..3c072f9d 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; import com.prgrms.catchtable.jwt.token.Token; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,4 +30,9 @@ public void saveRefreshToken(Token totalToken){ refreshTokenRepository.save(newRefreshToken); } + @Transactional(readOnly = true) + public RefreshToken getRefreshTokenByToken(String refreshToken){ + return refreshTokenRepository.findRefreshTokenByToken(refreshToken) + .orElseThrow(() -> new UsernameNotFoundException("Not Found RefreshToken")); + } } From a97bccc0d14fa8752e0a2b5ddd2503fe67831e67 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 27 Dec 2023 11:28:42 +0900 Subject: [PATCH 050/603] =?UTF-8?q?feat=20:=20JwtAuthenticationFilter=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/security/config/SecurityConfig.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 6de948cf..f6a991de 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.security.config; +import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; import com.prgrms.catchtable.security.service.CustomOAuth2SuccessHandler; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; @@ -7,6 +8,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.stereotype.Component; @@ -18,6 +20,8 @@ public class SecurityConfig { private final CustomOAuth2SuccessHandler successHandler; + private final JwtAuthenticationFilter jwtAuthenticationFilter; + @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -31,6 +35,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); + http.addFilterBefore(jwtAuthenticationFilter, OAuth2AuthorizationRequestRedirectFilter.class); + return http.build(); } From 63b6a888d0884a94d8337d2f866b2d70b45bf3c4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 27 Dec 2023 11:28:51 +0900 Subject: [PATCH 051/603] =?UTF-8?q?fix=20:=20=EB=88=84=EB=9D=BD=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index 52762b7a..3ccbf8ed 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -54,6 +54,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } } } + chain.doFilter(request, response); } private void setAuthentication(String accessToken) { From d2e967fa706f65be359bd50f5685f39edddd60f4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 27 Dec 2023 14:36:20 +0900 Subject: [PATCH 052/603] =?UTF-8?q?style=20:=20=EC=9D=B8=EB=8D=B4=ED=8A=B8?= =?UTF-8?q?=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/filter/JwtAuthenticationFilter.java | 14 +++++++------- .../catchtable/jwt/provider/JwtTokenProvider.java | 11 ++++++----- .../jwt/service/RefreshTokenService.java | 6 +++--- .../prgrms/catchtable/member/domain/Member.java | 3 ++- .../catchtable/member/service/MemberService.java | 2 +- .../catchtable/security/config/SecurityConfig.java | 3 ++- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index 3ccbf8ed..f7651cb6 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -33,23 +33,23 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha String accessToken = ((HttpServletRequest) request).getHeader("AccessToken"); String refreshToken = ((HttpServletRequest) request).getHeader("RefreshToken"); - if(accessToken!=null){ + if (accessToken != null) { //AccessToken 유효 - if(jwtTokenProvider.validateToken(accessToken)){ + if (jwtTokenProvider.validateToken(accessToken)) { setAuthentication(accessToken); } //RefreshToken 유효 - else{ - if(jwtTokenProvider.validateToken(refreshToken)){ + else { + if (jwtTokenProvider.validateToken(refreshToken)) { RefreshToken refreshTokenEntity = refreshTokenService.getRefreshTokenByToken( refreshToken); String email = refreshTokenEntity.getEmail(); Token newToken = jwtTokenProvider.createToken(email); - ((HttpServletResponse) response).setHeader("AccessToken", newToken.getAccessToken()); + ((HttpServletResponse) response).setHeader("AccessToken", + newToken.getAccessToken()); setAuthentication(newToken.getAccessToken()); - } - else{ + } else { throw new UsernameNotFoundException("Please Login again"); } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 9d72a47c..9bc8f529 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -58,7 +58,7 @@ private String createRefreshToken(Claims claims, Date now) { } public boolean validateToken(String token) { - try{ + try { Claims claims = Jwts.parserBuilder() .setSigningKey(jwtConfig.getClientSecret()) .build() @@ -66,18 +66,19 @@ public boolean validateToken(String token) { .getBody(); return claims.getExpiration().after(new Date()); - } catch(JwtException je){ + } catch (JwtException je) { return false; } } - public Authentication getAuthentication(String token){ + public Authentication getAuthentication(String token) { String email = getEmail(token); UserDetails userDetails = jwtUserDetailsService.loadUserByUsername(email); - return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); + return new UsernamePasswordAuthenticationToken(userDetails, "", + userDetails.getAuthorities()); } - private String getEmail(String token){ + private String getEmail(String token) { Claims claims = Jwts.parserBuilder() .setSigningKey(jwtConfig.getClientSecret()) .build() diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index 3c072f9d..be10c362 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -15,10 +15,10 @@ public class RefreshTokenService { private final RefreshTokenRepository refreshTokenRepository; @Transactional - public void saveRefreshToken(Token totalToken){ + public void saveRefreshToken(Token totalToken) { String email = totalToken.getEmail(); - if(refreshTokenRepository.existsRefreshTokenByEmail(email)){ + if (refreshTokenRepository.existsRefreshTokenByEmail(email)) { refreshTokenRepository.deleteRefreshTokenByEmail(email); } @@ -31,7 +31,7 @@ public void saveRefreshToken(Token totalToken){ } @Transactional(readOnly = true) - public RefreshToken getRefreshTokenByToken(String refreshToken){ + public RefreshToken getRefreshTokenByToken(String refreshToken) { return refreshTokenRepository.findRefreshTokenByToken(refreshToken) .orElseThrow(() -> new UsernameNotFoundException("Not Found RefreshToken")); } diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Member.java b/src/main/java/com/prgrms/catchtable/member/domain/Member.java index a11c9209..08a72ec0 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Member.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Member.java @@ -55,7 +55,8 @@ public class Member extends BaseEntity implements UserDetails { private boolean notification_activated; @Builder - public Member(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Member(String name, String email, String phoneNumber, Gender gender, + LocalDate dateBirth) { this.name = name; this.email = email; this.phoneNumber = phoneNumber; diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 7ce7aed7..82d85412 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -35,7 +35,7 @@ public Token oauthLogin(OAuthAttribute attributes) { return createTotalToken(email); } - private Token createTotalToken(String email){ + private Token createTotalToken(String email) { Token totalToken = jwtTokenProvider.createToken(email); refreshTokenService.saveRefreshToken(totalToken); return totalToken; diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index f6a991de..8b9edb01 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -35,7 +35,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); - http.addFilterBefore(jwtAuthenticationFilter, OAuth2AuthorizationRequestRedirectFilter.class); + http.addFilterBefore(jwtAuthenticationFilter, + OAuth2AuthorizationRequestRedirectFilter.class); return http.build(); } From 6308661fa775bde1c12b327cee8d01c97707d9a5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:42:28 +0900 Subject: [PATCH 053/603] =?UTF-8?q?chore=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 57f64ad1..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,8 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' } tasks.named('test') { From 8cd163ba871e8a513e2089256fc516f09dfcc676 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:44:51 +0900 Subject: [PATCH 054/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20=EC=9A=94=EC=B2=AD=20dto=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20=EA=B8=B0=EC=A1=B4=20:=20=EC=8B=9C=EA=B0=84,=20?= =?UTF-8?q?=EC=9D=B8=EC=9B=90=20-=20=EB=B3=80=EA=B2=BD=20:=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=8B=9C=EA=B0=84=20=EC=95=84=EC=9D=B4=EB=94=94,=20?= =?UTF-8?q?=EC=9D=B8=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/CreateReservationRequest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 2de0a9cb..41c3b6a0 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,7 +1,5 @@ package com.prgrms.catchtable.reservation.dto.request; -import java.time.LocalDateTime; - -public record CreateReservationRequest(LocalDateTime date, int peopleCount) { +public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { } From cf1de2d74faf1282cec5d79314a55ceb36f776fb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:48:22 +0900 Subject: [PATCH 055/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EC=97=90=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 876f8b79..45db60e4 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -6,7 +6,11 @@ @Getter @RequiredArgsConstructor public enum ErrorCode { - NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."); + NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."), + IS_PRE_OCCUPIED("이미 타인에게 선점권이 있는 예약시간입니다."), + IS_OCCUPIED("이미 예약된 시간입니다."), + NOT_EXIST_SHOP("존재하지 않는 매장입니다."), + NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); private final String message; } From f831d84b15442b91d5022b19303d5b53cc24e932 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:48:45 +0900 Subject: [PATCH 056/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20-=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84=20=EC=98=81=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=A0=84=EC=9D=B4=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/Reservation.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index ddb26f2f..e9e08d5b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -8,6 +8,7 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -47,18 +48,15 @@ public class Reservation extends BaseEntity { @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - @OneToOne(fetch = LAZY) + @OneToOne(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private ReservationTime time; + private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount) { + public Reservation(ReservationStatus status, int peopleCount, ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; - } - - public void insertReservvationTime(ReservationTime reservationTime) { - this.time = reservationTime; + this.reservationTime = reservationTime; } public void insertShop(Shop shop) { From f20aa75c1f3063f320dcab5a28fee0a1f79a51b1 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:49:09 +0900 Subject: [PATCH 057/603] =?UTF-8?q?remove=20:=20ReservationAsync=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java deleted file mode 100644 index 4734c7df..00000000 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.prgrms.catchtable.reservation.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.prgrms.catchtable.common.data.reservation.ReservationData; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ReservationAsyncTest { - - @Autowired - private ReservationAsync reservationAsync; - - @Test - @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") - void preOccupiedAsync() { - ReservationTime reservationTime = ReservationData.getReservationTime(); - reservationAsync.setPreOcuppied(reservationTime); - reservationTime.reversePreOccupied(); - - assertThat(reservationTime.isPreOccupied()).isTrue(); - - try { - Thread.sleep(6_000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - reservationTime.reversePreOccupied(); - assertThat(reservationTime.isPreOccupied()).isFalse(); - } -} \ No newline at end of file From 87bf03a7d5fca0b1a74ddbe2c0b92059d8d7edb0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:50:16 +0900 Subject: [PATCH 058/603] =?UTF-8?q?remove=20:=20ReservationAsync=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B6=8C=20=ED=9A=8D=EB=93=9D=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A4=84=EB=9F=AC=EB=A5=BC=20=ED=86=B5=ED=95=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationAsync.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index a6551170..2d495747 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -1,29 +1,26 @@ package com.prgrms.catchtable.reservation.service; -import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; - import com.prgrms.catchtable.reservation.domain.ReservationTime; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Async; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor +@Slf4j public class ReservationAsync { - @Async - @Transactional(propagation = REQUIRES_NEW) + @Transactional public void setPreOcuppied(ReservationTime reservationTime) { reservationTime.reversePreOccupied(); - try { - Thread.sleep(5_000); - } catch (InterruptedException exception) { - exception.printStackTrace(); - } + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + scheduler.schedule(reservationTime::reversePreOccupied, 10, TimeUnit.SECONDS); - reservationTime.reversePreOccupied(); + scheduler.shutdown(); } - } From f05aea7c7696f925edaa766aec75810eadb5f7d9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:56:17 +0900 Subject: [PATCH 059/603] =?UTF-8?q?remove=20:=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20api=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=9A=94=EC=B2=AD=20dto=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 3cff7823..8f344697 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,11 +1,11 @@ package com.prgrms.catchtable.reservation.controller; +import com.prgrms.catchtable.facade.ReservationFacade; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,12 +14,11 @@ @RequiredArgsConstructor public class ReservationController { - private final ReservationService reservationService; + private final ReservationFacade reservationFacade; - @GetMapping("/{shopId}") - public CreateReservationResponse createReservationResponse( - @PathVariable("shopId") Long shopId, + @PostMapping + public ResponseEntity createReservationResponse( CreateReservationRequest request) { - return null; + return ResponseEntity.ok(reservationFacade.preOccupyReservation(request)); } } From c0ff8f59c01f0091725c11dbe719d5f99db4ae61 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:58:48 +0900 Subject: [PATCH 060/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=97=AD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 75f8668b..d3e25e90 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,15 +1,15 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static com.prgrms.catchtable.common.exception.ErrorCode.IS_PRE_OCCUPIED; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; -import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.repository.ShopRepository; -import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,38 +18,17 @@ @RequiredArgsConstructor public class ReservationService { - private final ReservationRepository reservationRepository; - private final ShopRepository shopRepository; + private final ReservationTimeRepository reservationTimeRepository; @Transactional - public ValidateReservationResponse validateReservationIsPossible(Long shopId, - CreateReservationRequest request) { - LocalDateTime requestedReservationTime = request.date(); - int requestedPeopleCount = request.peopleCount(); - - Shop shop = shopRepository.findById(shopId).orElseThrow(); - //예제 데이터 - ReservationTime reservationTime = ReservationTime.builder() - .time(request.date()) - .build(); - Reservation reservation = Reservation.builder() - .status(COMPLETED) - .peopleCount(request.peopleCount()) - .build(); + public ReservationTime validateReservationAndSave(CreateReservationRequest request) { + ReservationTime reservationTime = reservationTimeRepository.findById(request.reservationTimeId()) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { - throw new RuntimeException("타인에게 선점권이 있음"); - } - if (reservationTime.isOccupied()) { - throw new RuntimeException("이미 예약된 시간임"); + throw new BadRequestCustomException(IS_PRE_OCCUPIED); } - reservation.insertReservvationTime(reservationTime); - reservation.insertShop(shop); - - Reservation savedReservation = reservationRepository.save(reservation); - - return new ValidateReservationResponse(savedReservation.getShop().getName(), - savedReservation.getTime()); + return reservationTime; } } From 3e1f6c507257fc0af3462feaaa42e2538abd5b42 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:12 +0900 Subject: [PATCH 061/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=ED=8D=BC=EC=82=AC=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacade.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index 8cf1f723..a3e26046 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -3,7 +3,6 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -16,14 +15,12 @@ public class ReservationFacade { private final ReservationService reservationService; private final ReservationAsync reservationAsync; - public CreateReservationResponse createReservation(Long shopId, + public CreateReservationResponse preOccupyReservation ( CreateReservationRequest request) { - ValidateReservationResponse validateReservationResponse = reservationService.validateReservationIsPossible( - shopId, + ReservationTime reservationTime = reservationService.validateReservationAndSave( request); - String shopName = validateReservationResponse.shopName(); - ReservationTime reservationTime = validateReservationResponse.reservationTime(); + String shopName = reservationTime.getShop().getName(); reservationAsync.setPreOcuppied(reservationTime); From 762e4f4f1cf2b5ae81f71fdabdfd26d2dfc1b477 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:40 +0900 Subject: [PATCH 062/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20-=20=EB=A7=A4=EC=9E=A5=20=EC=97=B0=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=ED=8E=B8=EC=9D=98=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/ReservationTime.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index d11f2f8a..319703f0 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -54,4 +54,8 @@ public void reverseOccupied() { public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } + + public void insertShop(Shop shop){ + this.shop = shop; + } } From 84a86fc4c7c40942081c52c197b8219a1724b9c3 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:55 +0900 Subject: [PATCH 063/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationTimeRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java new file mode 100644 index 00000000..63ae522a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.reservation.repository; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReservationTimeRepository extends JpaRepository { + +} From 51fb95f9c119cbea263455fc39b2a9f17930399a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:01:36 +0900 Subject: [PATCH 064/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EC=98=88=EC=95=BD=EA=B4=80=EB=A0=A8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reservation/ReservationData.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 624f3f10..8026898b 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -2,6 +2,7 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -13,17 +14,29 @@ public static Reservation getReservation() { return Reservation.builder() .status(COMPLETED) .peopleCount(4) + .reservationTime(getReservationTimeNotPreOccupied()) .build(); } - public static ReservationTime getReservationTime() { - return ReservationTime.builder() - .time(LocalDateTime.of(2023, 12, 31, 19, 30)) + public static ReservationTime getReservationTimeNotPreOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 12, 31, 19, 30)) .build(); + reservationTime.insertShop(ShopData.getShop()); + return reservationTime; + } + + public static ReservationTime getReservationTimePreOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 12, 31, 19, 30)) + .build(); + reservationTime.insertShop(ShopData.getShop()); + reservationTime.reversePreOccupied(); + return reservationTime; } public static CreateReservationRequest getCreateReservationRequest() { - return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); + return new CreateReservationRequest(1L, 4); } } From bc306d46bf3b5931ea41607b60fb680fc4b1dd1d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:02:48 +0900 Subject: [PATCH 065/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=97=AD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/ReservationTimeTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java index abade0a4..d8ff901d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -11,7 +11,7 @@ class ReservationTimeTest { @Test @DisplayName("예약 선점 여부 변경에 성공한다") void reversePreOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTime(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -20,7 +20,7 @@ void reversePreOccupied() { @Test @DisplayName("예약 여부 변경에 성공한다.") void reverseOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTime(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); reservationTime.reverseOccupied(); assertThat(reservationTime.isOccupied()).isTrue(); From 8b0c940407472b9ca95c4461be120be084d4dc69 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:03:32 +0900 Subject: [PATCH 066/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index a3a64724..80d65ee7 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -2,17 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import static org.mockito.ArgumentMatchers.any; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.data.reservation.ReservationData; -import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -26,33 +23,47 @@ class ReservationServiceTest { @Mock - private ReservationRepository reservationRepository; - @Mock - private ShopRepository shopRepository; + private ReservationTimeRepository reservationTimeRepository; @InjectMocks private ReservationService reservationService; @Test @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { - Reservation reservation = ReservationData.getReservation(); - CreateReservationRequest createReservationRequest = ReservationData.getCreateReservationRequest(); - Shop shop = ShopData.getShop(); - - reservation.insertShop(shop); - reservation.insertReservvationTime(ReservationData.getReservationTime()); + //given + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReflectionTestUtils.setField(reservationTime, "id", 1L); - ReflectionTestUtils.setField(shop, "id", 1L); + when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); - when(shopRepository.findById(any(Long.class))).thenReturn(Optional.of(shop)); - when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + //when + ReservationTime savedReservationTime = reservationService.validateReservationAndSave( + request); - ValidateReservationResponse response = reservationService.validateReservationIsPossible( - shop.getId(), createReservationRequest); + //then assertAll( - () -> assertThat(response.reservationTime().getTime()).isEqualTo( - createReservationRequest.date()), - () -> assertThat(response.shopName()).isEqualTo(shop.getName()) + () -> assertThat(savedReservationTime.getTime()).isEqualTo(reservationTime.getTime()), + () -> assertThat(savedReservationTime.getShop()).isEqualTo(reservationTime.getShop()) ); + + + } + + @Test + @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") + void alreadyPreOccupied() { + //given + ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReflectionTestUtils.setField(reservationTime, "id", 1L); + + when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + + //when + assertThrows(BadRequestCustomException.class, + () -> reservationService.validateReservationAndSave(request)); + + } } \ No newline at end of file From 07b850d12cc3491507e3dab283f5036e6d31a400 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:03:40 +0900 Subject: [PATCH 067/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20=ED=8D=BC=EC=82=AC=EB=93=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/ReservationFacadeTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java new file mode 100644 index 00000000..ea27b6cc --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -0,0 +1,49 @@ +package com.prgrms.catchtable.facade; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationAsync; +import com.prgrms.catchtable.reservation.service.ReservationService; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class ReservationFacadeTest { + + @Mock + private ReservationAsync reservationAsync; + @Mock + private ReservationService reservationService; + @InjectMocks + private ReservationFacade reservationFacade; + + @Test + @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") + void preOccupyReservation(){ + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + + when(reservationService.validateReservationAndSave(any(CreateReservationRequest.class))).thenReturn(reservationTime); + + CreateReservationResponse response = reservationFacade.preOccupyReservation( + request); + + assertAll( + () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()), + () -> assertThat(reservationTime.isPreOccupied()).isTrue() + ); + } +} \ No newline at end of file From 9dca08806b9a32ee47946bf2cc9445612481bb9f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:07:01 +0900 Subject: [PATCH 068/603] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/facade/ReservationFacade.java | 2 +- .../catchtable/reservation/domain/ReservationTime.java | 2 +- .../reservation/service/ReservationService.java | 5 ++--- .../catchtable/facade/ReservationFacadeTest.java | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index a3e26046..bb5ded8a 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -15,7 +15,7 @@ public class ReservationFacade { private final ReservationService reservationService; private final ReservationAsync reservationAsync; - public CreateReservationResponse preOccupyReservation ( + public CreateReservationResponse preOccupyReservation( CreateReservationRequest request) { ReservationTime reservationTime = reservationService.validateReservationAndSave( request); diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 319703f0..8b4f6e43 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -55,7 +55,7 @@ public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } - public void insertShop(Shop shop){ + public void insertShop(Shop shop) { this.shop = shop; } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index d3e25e90..fe22621f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -7,9 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; -import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +20,8 @@ public class ReservationService { @Transactional public ReservationTime validateReservationAndSave(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findById(request.reservationTimeId()) + ReservationTime reservationTime = reservationTimeRepository.findById( + request.reservationTimeId()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index ea27b6cc..759985f4 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.facade; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -11,7 +11,6 @@ import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; import com.prgrms.catchtable.reservation.service.ReservationService; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,11 +30,12 @@ class ReservationFacadeTest { @Test @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") - void preOccupyReservation(){ + void preOccupyReservation() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); CreateReservationRequest request = ReservationData.getCreateReservationRequest(); - when(reservationService.validateReservationAndSave(any(CreateReservationRequest.class))).thenReturn(reservationTime); + when(reservationService.validateReservationAndSave( + any(CreateReservationRequest.class))).thenReturn(reservationTime); CreateReservationResponse response = reservationFacade.preOccupyReservation( request); From 5c0d43a8dc8c58fcb17f0ea855b62a17d0230d32 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:08:21 +0900 Subject: [PATCH 069/603] =?UTF-8?q?fix=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=ED=8D=BC=EC=82=AC=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacadeTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 759985f4..5323b921 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -42,8 +42,7 @@ void preOccupyReservation() { assertAll( () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), - () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()), - () -> assertThat(reservationTime.isPreOccupied()).isTrue() + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()) ); } } \ No newline at end of file From 4346874e617ef3ad226515235a1ed0ba8df670e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:00:29 +0900 Subject: [PATCH 070/603] =?UTF-8?q?feat=20:=20CI=EC=9A=A9=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=20test=20application.yaml=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application.yaml | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/resources/application.yaml diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml new file mode 100644 index 00000000..6981bc62 --- /dev/null +++ b/src/test/resources/application.yaml @@ -0,0 +1,44 @@ +spring: + datasource: + url: jdbc:tc:mysql:8:/// + driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 10 + security: + oauth2: + client: + registration: + kakao: + client-name: kakao + client-id: e3a7bd1f8c24fe6a0c9d56789213abef + client-secret: QWu9hBgFzT1nRc3mXxNvLpK4aD7Jg0Vf + redirect-uri: "http://localhost:8080/login/oauth2/code/{registrationId}" + authorization-grant-type: authorization_code + client-authentication-method: client_secret_post + scope: + - account_email + - profile_nickname + - gender + - birthday + - phone_number + - birthyear + provider: + kakao: + authorization-uri: https://kauth.kakao.com/oauth/authorize + token-uri: https://kauth.kakao.com/oauth/token + user-info-uri: https://kapi.kakao.com/v2/user/me + user-name-attribute: id + +jwt: + client-secret: S0gKf9bwPzT7eAJN3RyWvQlKcY4uGh1jIxDp5VrC8EoH2dL6sMkXaF7ZtL9W6dR1 + expiry-minute: 5 #5분 + expiry-minute-refresh: 30 #30분 +logging.level: + org.hibernate.SQL: debug + org.hibernate.orm.jdbc.bind: trace + From ab7d66b1f70c73132dfcb151116caea10f4fbbce Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:28:37 +0900 Subject: [PATCH 071/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20-?= =?UTF-8?q?=20=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84=20=EC=97=B0=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=98=81=EC=86=8D=EC=84=B1=20=EC=A0=84?= =?UTF-8?q?=EC=9D=B4=20=EC=86=8D=EC=84=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index e9e08d5b..c22ed292 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -47,8 +47,8 @@ public class Reservation extends BaseEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - - @OneToOne(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + + @OneToOne(fetch = LAZY) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private ReservationTime reservationTime; From 5e7e42d4113b9d30a573e8f8ac058cace18be11b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:30:43 +0900 Subject: [PATCH 072/603] =?UTF-8?q?refactor=20:=20dto=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 3 +-- .../reservation/dto/request/CreateReservationRequest.java | 3 ++- .../reservation/dto/response/CreateReservationResponse.java | 4 +++- .../reservation/dto/response/ValidateReservationResponse.java | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index c22ed292..c8bf0a7e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -8,7 +8,6 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -47,7 +46,7 @@ public class Reservation extends BaseEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - + @OneToOne(fetch = LAZY) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private ReservationTime reservationTime; diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 41c3b6a0..099fa86e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.reservation.dto.request; -public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { +public record CreateReservationRequest(Long reservationTimeId, + int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index 1730ec96..7457a599 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -2,7 +2,9 @@ import java.time.LocalDateTime; -public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, +public record CreateReservationResponse(String shopName, + String memberName, + LocalDateTime date, int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java index ee0e91d1..435c8ad8 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -2,6 +2,7 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; -public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { +public record ValidateReservationResponse(String shopName, + ReservationTime reservationTime) { } From b43c4fa546c28e4b79962af11e03c4b333a910b2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:46:41 +0900 Subject: [PATCH 073/603] =?UTF-8?q?refactor=20:=20dto=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B9=8C=EB=8D=94=ED=8C=A8=ED=84=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacade.java | 8 ++++++-- .../reservation/dto/request/CreateReservationRequest.java | 3 +++ .../dto/response/CreateReservationResponse.java | 2 ++ .../dto/response/ValidateReservationResponse.java | 2 ++ .../common/data/reservation/ReservationData.java | 5 ++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index bb5ded8a..a00172a5 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -24,8 +24,12 @@ public CreateReservationResponse preOccupyReservation( reservationAsync.setPreOcuppied(reservationTime); - return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), - request.peopleCount()); + return CreateReservationResponse.builder() + .shopName(shopName) + .memberName("memberA") + .date(reservationTime.getTime()) + .peopleCount(request.peopleCount()) + .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 099fa86e..94ec2b44 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,5 +1,8 @@ package com.prgrms.catchtable.reservation.dto.request; +import lombok.Builder; + +@Builder public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index 7457a599..fb871d6f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.reservation.dto.response; import java.time.LocalDateTime; +import lombok.Builder; +@Builder public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java index 435c8ad8..f40f07ef 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.reservation.dto.response; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import lombok.Builder; +@Builder public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 8026898b..f47d9941 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -36,7 +36,10 @@ public static ReservationTime getReservationTimePreOccupied() { } public static CreateReservationRequest getCreateReservationRequest() { - return new CreateReservationRequest(1L, 4); + return CreateReservationRequest.builder() + .reservationTimeId(1L) + .peopleCount(4) + .build(); } } From d64bdc78140e24dffc362ddd24fd2db1fb3275a9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:48:26 +0900 Subject: [PATCH 074/603] =?UTF-8?q?remove=20:=20ValidateReservationRespons?= =?UTF-8?q?e=20dto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ValidateReservationResponse.java | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java deleted file mode 100644 index f40f07ef..00000000 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.prgrms.catchtable.reservation.dto.response; - -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import lombok.Builder; - -@Builder -public record ValidateReservationResponse(String shopName, - ReservationTime reservationTime) { - -} From 03fba25fc6c7f22be05c91edf95966c8949a360c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:57:55 +0900 Subject: [PATCH 075/603] =?UTF-8?q?fix=20:=20indent=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml index 6981bc62..e8f2e025 100644 --- a/src/test/resources/application.yaml +++ b/src/test/resources/application.yaml @@ -17,16 +17,16 @@ spring: client-name: kakao client-id: e3a7bd1f8c24fe6a0c9d56789213abef client-secret: QWu9hBgFzT1nRc3mXxNvLpK4aD7Jg0Vf - redirect-uri: "http://localhost:8080/login/oauth2/code/{registrationId}" - authorization-grant-type: authorization_code - client-authentication-method: client_secret_post - scope: - - account_email - - profile_nickname - - gender - - birthday - - phone_number - - birthyear + redirect-uri: "http://localhost:8080/login/oauth2/code/{registrationId}" + authorization-grant-type: authorization_code + client-authentication-method: client_secret_post + scope: + - account_email + - profile_nickname + - gender + - birthday + - phone_number + - birthyear provider: kakao: authorization-uri: https://kauth.kakao.com/oauth/authorize From 585a0a89e519d2951462775f4314000841341f4b Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 00:26:44 +0900 Subject: [PATCH 076/603] =?UTF-8?q?feat=20:=20Shop=20=EC=98=81=EC=97=85=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/domain/Shop.java | 21 +++++++++- .../catchtable/shop/domain/ShopTest.java | 42 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index e6802531..e89ad27a 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -1,10 +1,12 @@ package com.prgrms.catchtable.shop.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.SHOP_NOT_RUNNING; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -12,6 +14,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import java.math.BigDecimal; +import java.time.LocalTime; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -42,12 +45,28 @@ public class Shop extends BaseEntity { @Column(name = "capacity") private int capacity; + @Column(name = "opening_time") + private LocalTime openingTime; + + @Column(name = "closing_time") + private LocalTime closingTime; + + + @Builder - public Shop(String name, BigDecimal rating, Category category, Address address, int capacity) { + public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, LocalTime openingTime, LocalTime closingTime) { this.name = name; this.rating = rating; this.category = category; this.address = address; this.capacity = capacity; + this.openingTime = openingTime; + this.closingTime = closingTime; + } + + public void validateIfShopOpened(LocalTime localTime) { + if (localTime.isBefore(openingTime)|| localTime.isAfter(closingTime)){ + throw new BadRequestCustomException(SHOP_NOT_RUNNING); + } } } diff --git a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java new file mode 100644 index 00000000..2c1a4624 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java @@ -0,0 +1,42 @@ +package com.prgrms.catchtable.shop.domain; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import java.time.LocalTime; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ShopTest { + @DisplayName("가게 영업 시간이 아닐 때는 예외를 발생시킨다.") + @Test + void validate_shop_not_running_time() { + //given + LocalTime beforeOpeningTime = LocalTime.of(10, 59); + LocalTime afterClosingTime = LocalTime.of(21, 1); + Shop shop = ShopFixture.shop(); + //when, then + assertThrows( + BadRequestCustomException.class, + () -> shop.validateIfShopOpened(beforeOpeningTime)); + assertThrows( + BadRequestCustomException.class, + () -> shop.validateIfShopOpened(afterClosingTime)); + } + + @DisplayName("가게 영업 시간 내에서는 예외를 발생시키지 않는다.") + @Test + void validate_shop_running_time(){ + //given + LocalTime openingTime = LocalTime.of(11, 0); + LocalTime closingTime = LocalTime.of(21,0); + Shop shop = ShopFixture.shop(); + //when, then + assertDoesNotThrow( + ()->shop.validateIfShopOpened(openingTime)); + assertDoesNotThrow( + ()->shop.validateIfShopOpened(closingTime)); + } +} \ No newline at end of file From 10fd5efb65bf6ba73312eece83022ebeae9201f1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 00:28:26 +0900 Subject: [PATCH 077/603] =?UTF-8?q?refactor=20:=20BaseEntity=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/common/BaseEntity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/BaseEntity.java b/src/main/java/com/prgrms/catchtable/common/BaseEntity.java index d785926a..1af93fdf 100644 --- a/src/main/java/com/prgrms/catchtable/common/BaseEntity.java +++ b/src/main/java/com/prgrms/catchtable/common/BaseEntity.java @@ -14,9 +14,9 @@ public abstract class BaseEntity { @CreatedDate - private LocalDateTime createDate; + private LocalDateTime createdAt; @LastModifiedDate - private LocalDateTime updateDate; + private LocalDateTime updatedAt; } From 17a180d20673881a72440aa0f2170c94c5ab71cd Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 03:04:13 +0900 Subject: [PATCH 078/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20reposit?= =?UTF-8?q?ory=20=ED=95=A8=EC=88=98=20=EC=84=A0=EC=96=B8=20=EB=B0=8F=20tes?= =?UTF-8?q?t=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 11 +- .../catchtable/member/MemberFixture.java | 18 +++ .../repository/WaitingRepositoryTest.java | 113 ++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/prgrms/catchtable/member/MemberFixture.java create mode 100644 src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index ae7026b2..0a68d11c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -1,8 +1,17 @@ package com.prgrms.catchtable.waiting.repository; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import java.time.LocalDate; +import java.time.LocalDateTime; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface WaitingRepository extends JpaRepository { - + boolean existsByMember(Member member); + Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, LocalDateTime start, LocalDateTime end); + Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java new file mode 100644 index 00000000..9543a633 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -0,0 +1,18 @@ +package com.prgrms.catchtable.member; + +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import java.time.LocalDate; + +public class MemberFixture { + public static Member member(String name) { + return Member.builder() + .name(name) + .phoneNumber("010-1111-1111") + .gender(Gender.FEMALE) + .dateBirth(LocalDate.parse("2008-12-18")) + .notification_activated(true) + .build(); + } +} diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java new file mode 100644 index 00000000..a3aa8759 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -0,0 +1,113 @@ +package com.prgrms.catchtable.waiting.repository; + +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; +import static org.assertj.core.api.Assertions.assertThat; + +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.util.ReflectionTestUtils; + + +@SpringBootTest +class WaitingRepositoryTest { + + @Autowired + private WaitingRepository waitingRepository; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private ShopRepository shopRepository; + private Shop shop; + private Waiting waiting1; + private Waiting waiting2; + private Waiting waiting3; + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); + + @BeforeEach + void setUp(){ + Member member1 = MemberFixture.member("test1"); + Member member2 = MemberFixture.member("test2"); + Member member3 = MemberFixture.member("test3"); + + memberRepository.save(member1); + memberRepository.save(member2); + memberRepository.save(member3); + + shop = ShopFixture.shop(); + shopRepository.save(shop); + + waiting1 = Waiting.builder() + .member(member1) + .shop(shop) + .waitingNumber(1) + .waitingOrder(1) + .peopleCount(2) + .build(); + + waiting2 = Waiting.builder() + .member(member2) + .shop(shop) + .waitingNumber(2) + .waitingOrder(2) + .peopleCount(2) + .build(); + + waiting3 = Waiting.builder() + .member(member3) + .shop(shop) + .waitingNumber(3) + .waitingOrder(3) + .peopleCount(2) + .build(); + waitingRepository.save(waiting1); + waitingRepository.save(waiting2); + waitingRepository.save(waiting3); + } + + @DisplayName("특정 가게의 당일 대기 인원을 조회할 수 있다.") + @Test + void countByShopAndStatusAndCreatedAtBetween() { + //given + ReflectionTestUtils.setField(waiting1, "createdAt", LocalDateTime.now().minusDays(1)); + waitingRepository.save(waiting1); //어제자 대기 생성 + ReflectionTestUtils.setField(waiting2, "status", WaitingStatus.COMPLETED); + waitingRepository.save(waiting2); //입장상태 대기 생성 + + //when + Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop,PROGRESS,START_DATE_TIME, END_DATE_TIME); + //then + assertThat(count).isEqualTo(1L); + } + + @DisplayName("특정 가게의 당일 대기 인원을 조회할 수 있다.") + @Test + void countByShopAndCreatedAtBetween() { + //given + ReflectionTestUtils.setField(waiting1, "createdAt", LocalDateTime.now().minusDays(1)); + waitingRepository.save(waiting1); + ReflectionTestUtils.setField(waiting2, "status", WaitingStatus.COMPLETED); + waitingRepository.save(waiting2); + + //when + Long count = waitingRepository.countByShopAndCreatedAtBetween(shop,START_DATE_TIME, END_DATE_TIME); + //then + assertThat(count).isEqualTo(2L); + } +} \ No newline at end of file From bb6ee06de62334a82f6b7848d89285be06af4370 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 03:15:57 +0900 Subject: [PATCH 079/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 8 ++- .../waiting/facade/WaitingFacade.java | 31 ++++++++++ .../waiting/service/WaitingService.java | 59 +++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 876f8b79..ac7071d5 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -2,11 +2,17 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum ErrorCode { - NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."); + NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."), + NOT_EXIST_SHOP("존재하지 않는 가게 아이디입니다."), + ALREADY_CANCELED_WAITING("이미 웨이팅을 취소하였습니다."), + EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), + SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), + INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); private final String message; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java b/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java new file mode 100644 index 00000000..6d4ed580 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java @@ -0,0 +1,31 @@ +package com.prgrms.catchtable.waiting.facade; + +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; + +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class WaitingFacade { + private final MemberRepository memberRepository; + private final ShopRepository shopRepository; + + public Member getMemberEntity(Long memberId){ + return memberRepository.findById(memberId).orElseThrow( + ()-> new NotFoundCustomException(NOT_EXIST_MEMBER) + ); + } + + public Shop getShopEntity(Long shopId){ + return shopRepository.findById(shopId).orElseThrow( + () -> new NotFoundCustomException(NOT_EXIST_SHOP) + ); + } +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java new file mode 100644 index 00000000..8cc74a1b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -0,0 +1,59 @@ +package com.prgrms.catchtable.waiting.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.dto.WaitingMapper; +import com.prgrms.catchtable.waiting.facade.WaitingFacade; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class WaitingService { + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); + private final WaitingRepository waitingRepository; + private final WaitingFacade waitingFacade; + public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { + // 연관 엔티티 조회 + Member member = waitingFacade.getMemberEntity(1L); //member, shop 아이디 임시 1L + Shop shop = waitingFacade.getShopEntity(shopId); + + // shop 영업 중인지 검증 + shop.validateIfShopOpened(LocalTime.now()); + + // 기존 waiting이 있는지 검증 + validateIfMemberWaitingExists(member); + + // 대기 번호 생성 + int waitingNumber = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, + PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue()+1; + + // 대기 순서 생성 + int waitingOrder = (waitingRepository.countByShopAndCreatedAtBetween(shop, + START_DATE_TIME, END_DATE_TIME)).intValue()+1; + + // waiting 저장 + Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, shop); + Waiting savedWaiting = waitingRepository.save(waiting); + + return WaitingMapper.toCreateWaitingResponse(savedWaiting); + } + + private void validateIfMemberWaitingExists(Member member) { + if (waitingRepository.existsByMember(member)){ + throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); + } + } +} From 73aad85cf76bb46ad8b57842662b22af4c225784 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 03:17:05 +0900 Subject: [PATCH 080/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java new file mode 100644 index 00000000..4e75aff0 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -0,0 +1,27 @@ +package com.prgrms.catchtable.waiting.controller; + +import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.service.WaitingService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RequestMapping("/waitings") +@RestController +public class WaitingController { + + private final WaitingService waitingService; + + @PostMapping("/{shopId}") + public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, + @RequestBody CreateWaitingRequest request) { + CreateWaitingResponse response = waitingService.createWaiting(shopId, request); + return ResponseEntity.ok(response); + } +} From 51c0f2eed56fe2f828e7b44b262dc39e0771d87e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:51:09 +0900 Subject: [PATCH 081/603] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EB=AF=B8=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/service/ReservationAsync.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index 2d495747..c9a1e897 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -5,13 +5,11 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor -@Slf4j public class ReservationAsync { @Transactional From 44e3c40bc2c6cbe0bdea1a9c5c2d39c065576fae Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:52:48 +0900 Subject: [PATCH 082/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD-?= =?UTF-8?q?=EB=A7=A4=EC=9E=A5=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20?= =?UTF-8?q?=EB=A7=A4=ED=95=91=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B4=88=EA=B8=B0=ED=99=94=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/Reservation.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index c8bf0a7e..f7e9f076 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -52,13 +52,11 @@ public class Reservation extends BaseEntity { private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount, ReservationTime reservationTime) { + public Reservation(ReservationStatus status, int peopleCount, Shop shop, ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; + this.shop = shop; this.reservationTime = reservationTime; } - public void insertShop(Shop shop) { - this.shop = shop; - } } From 8eaf6ec958f8f7d9af84d204a0da7a1b36d2b97e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:53:26 +0900 Subject: [PATCH 083/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index f7e9f076..db66a48b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -52,7 +52,8 @@ public class Reservation extends BaseEntity { private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount, Shop shop, ReservationTime reservationTime) { + public Reservation(ReservationStatus status, int peopleCount, Shop shop, + ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; this.shop = shop; From 2898a36d19a0976534b8fb58bc6c3a44d004bf07 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:59:17 +0900 Subject: [PATCH 084/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=84=A0=EC=A0=90=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 45db60e4..02c9e311 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -7,8 +7,8 @@ @RequiredArgsConstructor public enum ErrorCode { NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."), - IS_PRE_OCCUPIED("이미 타인에게 선점권이 있는 예약시간입니다."), - IS_OCCUPIED("이미 예약된 시간입니다."), + ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), + ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); From bd8a90fbeb28fce7962cb4b5ec3c35be7853ea67 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 14:05:13 +0900 Subject: [PATCH 085/603] =?UTF-8?q?fix=20:=20Errorcode=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=8D=98=EC=A7=80=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/service/ReservationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index fe22621f..343a1293 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.IS_PRE_OCCUPIED; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -25,7 +25,7 @@ public ReservationTime validateReservationAndSave(CreateReservationRequest reque .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { - throw new BadRequestCustomException(IS_PRE_OCCUPIED); + throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } return reservationTime; From a913f6b241060b6cd0ec7880748d07682987c02d Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 15:17:16 +0900 Subject: [PATCH 086/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/fixture/ShopFixture.java | 21 +++++++ .../waiting/service/WaitingServiceTest.java | 62 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java create mode 100644 src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java new file mode 100644 index 00000000..5c4cca00 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -0,0 +1,21 @@ +package com.prgrms.catchtable.shop.fixture; + +import com.prgrms.catchtable.shop.domain.Address; +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import java.math.BigDecimal; +import java.time.LocalTime; + +public class ShopFixture { + public static Shop shop(){ + return Shop.builder() + .name("testShop") + .rating(BigDecimal.valueOf(3.5)) + .category(Category.WESTERN_FOOD) + .address(new Address("서울시", "중구")) + .capacity(30) + .openingTime(LocalTime.of(11,0)) + .closingTime(LocalTime.of(21,0)) + .build(); + } +} diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java new file mode 100644 index 00000000..8b0a8691 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -0,0 +1,62 @@ +package com.prgrms.catchtable.waiting.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.BDDMockito.given; + +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.facade.WaitingFacade; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WaitingServiceTest { + + @Mock + private WaitingRepository waitingRepository; + @Mock + private WaitingFacade waitingFacade; + @InjectMocks + private WaitingService waitingService; + + @Test + void createWaiting() { + //given + CreateWaitingRequest request = CreateWaitingRequest.builder() + .peopleCount(2) + .build(); + Shop shop = ShopFixture.shop(); + Member member = MemberFixture.member("member1"); + Waiting waiting = Waiting.builder() + .member(member) + .shop(shop) + .waitingNumber(1) + .waitingOrder(1) + .peopleCount(2) + .build(); + given(waitingFacade.getShopEntity(1L)).willReturn(shop); + given(waitingFacade.getMemberEntity(1L)).willReturn(member); + given(waitingRepository.existsByMember(member)).willReturn(false); + given(waitingRepository.save(Mockito.any(Waiting.class))).willReturn(waiting); + + //when + CreateWaitingResponse response = waitingService.createWaiting(1L, request); + //then + assertAll( + () -> assertThat(response.peopleCount()).isEqualTo(2), + () -> assertThat(response.waitingOrder()).isEqualTo(1L), + () -> assertThat(response.waitingNumber()).isEqualTo(1L) + ); + } +} \ No newline at end of file From 503cb2370ded1143448f59e461b855c448670aeb Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 17:00:24 +0900 Subject: [PATCH 087/603] =?UTF-8?q?feat=20:=20restDocs=EC=9A=A9=20controll?= =?UTF-8?q?er=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/album/waiting.adoc | 11 +++ src/docs/asciidoc/index.adoc | 15 ++++ .../waiting/service/WaitingService.java | 2 +- .../controller/WaitingControllerDocsTest.java | 79 +++++++++++++++++++ .../waiting/service/WaitingServiceTest.java | 4 +- 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 src/docs/asciidoc/api/album/waiting.adoc create mode 100644 src/docs/asciidoc/index.adoc create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java diff --git a/src/docs/asciidoc/api/album/waiting.adoc b/src/docs/asciidoc/api/album/waiting.adoc new file mode 100644 index 00000000..106a583d --- /dev/null +++ b/src/docs/asciidoc/api/album/waiting.adoc @@ -0,0 +1,11 @@ +[[waiting-create]] +=== 웨이팅 등록 + +==== HTTP Request +include::{snippets}/waiting-create/http-request.adoc[] +include::{snippets}/waiting-create/request-fields.adoc[] + + +==== HTTP Response +include::{snippets}/waiting-create/http-response.adoc[] +include::{snippets}/waiting-create/response-fields.adoc[] \ No newline at end of file diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc new file mode 100644 index 00000000..160506fc --- /dev/null +++ b/src/docs/asciidoc/index.adoc @@ -0,0 +1,15 @@ +ifndef::snippets[] +:snippets: ../../build/generated-snippets +endif::[] += Catch Table REST API 문서 +:doctype: book +:icons: font +:source-highlighter: highlightjs +:toc: left +:toclevels: 2 +:sectlinks: + +[[CatchTable-API]] +== Waiting API + +include::api/album/waiting.adoc[] \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 8cc74a1b..470fdb11 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -27,7 +27,7 @@ public class WaitingService { private final WaitingFacade waitingFacade; public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { // 연관 엔티티 조회 - Member member = waitingFacade.getMemberEntity(1L); //member, shop 아이디 임시 1L + Member member = waitingFacade.getMemberEntity(1L); Shop shop = waitingFacade.getShopEntity(shopId); // shop 영업 중인지 검증 diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java new file mode 100644 index 00000000..0200bcb8 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -0,0 +1,79 @@ +package com.prgrms.catchtable.waiting.controller; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.restdocs.RestDocsSupport; +import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.service.WaitingService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.restdocs.payload.JsonFieldType; + +class WaitingControllerDocsTest extends RestDocsSupport { + + private final WaitingService waitingService = mock(WaitingService.class); + + @Override + protected Object initController() { + return new WaitingController(waitingService); + } + + @DisplayName("웨이팅 생성 API") + @Test + void createWaiting() throws Exception { + CreateWaitingRequest request = CreateWaitingRequest + .builder() + .peopleCount(2).build(); + CreateWaitingResponse response = CreateWaitingResponse.builder() + .createdWaitingId(201L) + .shopId(1L) + .shopName("shop1") + .waitingNumber(324) + .waitingOrder(20) + .peopleCount(2) + .build(); + + given(waitingService.createWaiting(1L, request)).willReturn(response); + + mockMvc.perform(post("/waitings/{shopId}", 1) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andExpect(status().isOk()) + .andDo(document("waiting-create", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestFields( + fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + .description("인원수") + ), + responseFields( + fieldWithPath("createdWaitingId").type(JsonFieldType.NUMBER) + .description("생성된 웨이팅 아이디"), + fieldWithPath("shopId").type(JsonFieldType.NUMBER) + .description("상점 아이디"), + fieldWithPath("shopName").type(JsonFieldType.STRING) + .description("상점 이름"), + fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + .description("인원 수"), + fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("waitingOrder").type(JsonFieldType.NUMBER) + .description("웨이팅 순서") + ) + )); + + + } +} \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 8b0a8691..071184b1 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -55,8 +55,8 @@ void createWaiting() { //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), - () -> assertThat(response.waitingOrder()).isEqualTo(1L), - () -> assertThat(response.waitingNumber()).isEqualTo(1L) + () -> assertThat(response.waitingOrder()).isEqualTo(1), + () -> assertThat(response.waitingNumber()).isEqualTo(1) ); } } \ No newline at end of file From b7fd6645a90d583cd04e3e08a9a5bd4be09126db Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 17:25:40 +0900 Subject: [PATCH 088/603] =?UTF-8?q?fix=20:=20enum=20=EB=B3=91=ED=95=A9=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 3 ++- .../java/com/prgrms/catchtable/waiting/domain/Waiting.java | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index a774590f..785be28e 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -12,11 +12,12 @@ public enum ErrorCode { ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), - NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); + NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), ALREADY_CANCELED_WAITING("이미 웨이팅을 취소하였습니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); + private final String message; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 4f894bdf..e12443bb 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.waiting.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_CANCELED_WAITING; import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; @@ -8,7 +7,6 @@ import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; From 08da02b37002b3c5658f6549ee5cdd7c99066c6c Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 28 Dec 2023 17:50:20 +0900 Subject: [PATCH 089/603] =?UTF-8?q?fix=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/WaitingServiceTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 071184b1..b092ce70 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -2,22 +2,23 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; -import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; import com.prgrms.catchtable.waiting.facade.WaitingFacade; import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import java.time.LocalTime; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -36,8 +37,8 @@ void createWaiting() { CreateWaitingRequest request = CreateWaitingRequest.builder() .peopleCount(2) .build(); - Shop shop = ShopFixture.shop(); - Member member = MemberFixture.member("member1"); + Shop shop = mock(Shop.class); + Member member = mock(Member.class); Waiting waiting = Waiting.builder() .member(member) .shop(shop) @@ -45,10 +46,11 @@ void createWaiting() { .waitingOrder(1) .peopleCount(2) .build(); + doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); given(waitingFacade.getShopEntity(1L)).willReturn(shop); given(waitingFacade.getMemberEntity(1L)).willReturn(member); given(waitingRepository.existsByMember(member)).willReturn(false); - given(waitingRepository.save(Mockito.any(Waiting.class))).willReturn(waiting); + given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); //when CreateWaitingResponse response = waitingService.createWaiting(1L, request); From 35c02b954a0edb900ed3572bc4cadf8f8429297e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:04:07 +0900 Subject: [PATCH 090/603] =?UTF-8?q?chore=20:=20=EC=8B=9C=ED=81=90=EB=A6=AC?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=98=EC=A1=B4=EC=84=B1=20disabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 361994f5..06fac189 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' - implementation 'org.springframework.boot:spring-boot-starter-security' +// implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' From 3790be15f0f1e8ab2b762b35a6262f8d0a871597 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:05:21 +0900 Subject: [PATCH 091/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=84=A0?= =?UTF-8?q?=EC=A0=90=20=EC=9D=91=EB=8B=B5=20dto=EC=9D=98=20date=20?= =?UTF-8?q?=ED=98=95=EC=8B=9D=20=ED=8F=AC=EB=A7=B7=ED=99=94=20(=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EA=B0=92=EC=97=90=EC=84=9C=20=EC=B4=88=EB=8A=94=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8,=20=EB=82=A0=EC=A7=9C,=20=EC=8B=9C=EA=B0=84,?= =?UTF-8?q?=20=EB=B6=84=EA=B9=8C=EC=A7=80=EB=A7=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/response/CreateReservationResponse.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index fb871d6f..3751910f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -1,11 +1,14 @@ package com.prgrms.catchtable.reservation.dto.response; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; import java.time.LocalDateTime; import lombok.Builder; @Builder public record CreateReservationResponse(String shopName, String memberName, + @JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") LocalDateTime date, int peopleCount) { From 7da888578c06e4f6cc92bec5444c62d34e590093 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:07:58 +0900 Subject: [PATCH 092/603] =?UTF-8?q?refactor=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20=EC=98=88=EC=95=BD=EC=84=A0=EC=A0=90=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EA=B3=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20:=20=EC=95=84=EC=9D=B4=EB=94=94=EB=A5=BC?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=A7=8C=EB=93=A4=20=EB=95=8C?= =?UTF-8?q?=20=EC=A7=81=EC=A0=91=20=EC=A7=80=EC=A0=95=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20-=20=EB=B3=80=EA=B2=BD=20:=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EB=90=A0=20=EB=95=8C=20=EC=95=84=EC=9D=B4=EB=94=94?= =?UTF-8?q?=EB=A5=BC=20=EB=8F=99=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/data/reservation/ReservationData.java | 4 ++-- .../prgrms/catchtable/facade/ReservationFacadeTest.java | 3 ++- .../reservation/service/ReservationServiceTest.java | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index f47d9941..5d4e51b7 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -35,9 +35,9 @@ public static ReservationTime getReservationTimePreOccupied() { return reservationTime; } - public static CreateReservationRequest getCreateReservationRequest() { + public static CreateReservationRequest getCreateReservationRequest(Long reservationTimeId) { return CreateReservationRequest.builder() - .reservationTimeId(1L) + .reservationTimeId(reservationTimeId) .peopleCount(4) .build(); } diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 5323b921..56a0ae73 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -32,7 +32,8 @@ class ReservationFacadeTest { @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") void preOccupyReservation() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest( + reservationTime.getId()); when(reservationService.validateReservationAndSave( any(CreateReservationRequest.class))).thenReturn(reservationTime); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 80d65ee7..d647e40e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -31,9 +31,10 @@ class ReservationServiceTest { @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { //given - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); + CreateReservationRequest request = ReservationData.getCreateReservationRequest( + reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -55,8 +56,10 @@ void validateReservation() { void alreadyPreOccupied() { //given ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); ReflectionTestUtils.setField(reservationTime, "id", 1L); + CreateReservationRequest request = ReservationData.getCreateReservationRequest( + reservationTime.getId()); + when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); From 553f5e5c42951251b1287811a3dce08d16eb1f5b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:09:02 +0900 Subject: [PATCH 093/603] =?UTF-8?q?refactor=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=EB=8C=80=EA=B8=B0=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?2=EC=B4=88=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/service/ReservationAsync.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index c9a1e897..e8a82518 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -17,7 +17,7 @@ public void setPreOcuppied(ReservationTime reservationTime) { reservationTime.reversePreOccupied(); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - scheduler.schedule(reservationTime::reversePreOccupied, 10, TimeUnit.SECONDS); + scheduler.schedule(reservationTime::reversePreOccupied, 2, TimeUnit.SECONDS); scheduler.shutdown(); } From cb88c99e12bcf19a37706786c77054beb2a5c6b9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:09:24 +0900 Subject: [PATCH 094/603] =?UTF-8?q?feat=20:=20RequestBody=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 8f344697..00fb3a34 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -18,7 +19,7 @@ public class ReservationController { @PostMapping public ResponseEntity createReservationResponse( - CreateReservationRequest request) { + @RequestBody CreateReservationRequest request) { return ResponseEntity.ok(reservationFacade.preOccupyReservation(request)); } } From b7662b10a7ecc76d3c2c6091be13d2a93513cce6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:09:47 +0900 Subject: [PATCH 095/603] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20Base=20class=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/BaseIntegrationTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java new file mode 100644 index 00000000..1496b3ac --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -0,0 +1,24 @@ +package com.prgrms.catchtable.common.base; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +@AutoConfigureMockMvc +public class BaseIntegrationTest { + @Autowired + public MockMvc mvc; + + public static String asJsonString(final Object obj) { + try { + return new ObjectMapper().writeValueAsString(obj); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} From 597344a63de0106d2933ba2ad88fed118b58ea70 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:10:23 +0900 Subject: [PATCH 096/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20api=20=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java new file mode 100644 index 00000000..2b3e6240 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -0,0 +1,63 @@ +package com.prgrms.catchtable.reservation.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; + + +class ReservationControllerTest extends BaseIntegrationTest { + + @Autowired + private ReservationTimeRepository reservationTimeRepository; + + @Test + @Transactional + @DisplayName("예약 선점 api 호출에 성공한다.") + void preOccupyReservation() throws Exception { + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + CreateReservationRequest request = ReservationData.getCreateReservationRequest( + savedReservationTime.getId()); + + mvc.perform(post("/reservations") + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) + .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) + .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); + } + + @Test + @Transactional + @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") + void test() throws Exception{ + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + CreateReservationRequest request = ReservationData.getCreateReservationRequest( + savedReservationTime.getId()); + + mvc.perform(post("/reservations") + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(request))); + + Assertions.assertThat(reservationTime.isPreOccupied()).isTrue(); + Thread.sleep(3_000); //현재 스케줄러는 2초로 설정되어있어 3초간 대기 후 검증 + Assertions.assertThat(reservationTime.isPreOccupied()).isFalse(); + } + + +} \ No newline at end of file From 58c2a08f2f1fd42af184e4502bae25b9efc02116 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:28:09 +0900 Subject: [PATCH 097/603] =?UTF-8?q?refactor=20:=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 2b3e6240..acd3f99d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -44,7 +44,7 @@ void preOccupyReservation() throws Exception { @Test @Transactional @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") - void test() throws Exception{ + void schedulerTest() throws Exception{ ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); CreateReservationRequest request = ReservationData.getCreateReservationRequest( From ca5d4ff3acdba33533ac1b10b9ebc35498e5012f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 29 Dec 2023 01:29:12 +0900 Subject: [PATCH 098/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/base/BaseIntegrationTest.java | 1 + .../reservation/controller/ReservationControllerTest.java | 3 +-- .../catchtable/reservation/service/ReservationServiceTest.java | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 1496b3ac..926f6069 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -11,6 +11,7 @@ @Transactional @AutoConfigureMockMvc public class BaseIntegrationTest { + @Autowired public MockMvc mvc; diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index acd3f99d..a2a76594 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -10,7 +10,6 @@ import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -44,7 +43,7 @@ void preOccupyReservation() throws Exception { @Test @Transactional @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") - void schedulerTest() throws Exception{ + void schedulerTest() throws Exception { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); CreateReservationRequest request = ReservationData.getCreateReservationRequest( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index d647e40e..3b8dc980 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -60,7 +60,6 @@ void alreadyPreOccupied() { CreateReservationRequest request = ReservationData.getCreateReservationRequest( reservationTime.getId()); - when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); //when From df3de2d83297541a29065fc33f176c6fd40843a8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 29 Dec 2023 18:23:26 +0900 Subject: [PATCH 099/603] =?UTF-8?q?feat=20:=20ErrorResponse=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorResponse.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java new file mode 100644 index 00000000..2c5a93f5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.common.exception; + +public class ErrorResponse { + private final String code; + private final String message; + + public ErrorResponse(ErrorCode errorCode){ + this.code = errorCode.name(); + this.message = errorCode.getMessage(); + } + + public ErrorResponse(String message){ + this.code = "BAD_REQUEST"; + this.message = message; + } +} From 4a3650c2d1adcc8f4609a6eb0dd36752a3937bbf Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 29 Dec 2023 18:24:38 +0900 Subject: [PATCH 100/603] =?UTF-8?q?feat=20:=20=EC=A0=84=EC=97=AD=EC=98=88?= =?UTF-8?q?=EC=99=B8=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 3 +- .../exception/GlobalExceptionHandler.java | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 02c9e311..8df1bae2 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -10,7 +10,8 @@ public enum ErrorCode { ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), - NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); + NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), + INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); private final String message; } diff --git a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..f23045d6 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,45 @@ +package com.prgrms.catchtable.common.exception; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionHandler { + @ExceptionHandler + protected ResponseEntity handleMethodArgumentNotValid(final MethodArgumentNotValidException ex) { + StringBuilder sb = new StringBuilder(); + for (FieldError e : ex.getBindingResult().getFieldErrors()) { + sb.append(e.getDefaultMessage()); + sb.append(", "); + } + return ResponseEntity + .badRequest() + .body(new ErrorResponse(sb.toString())); + } + + @ExceptionHandler(NotFoundCustomException.class) + protected ResponseEntity handleNotFoundException(final NotFoundCustomException ex) { + return ResponseEntity + .badRequest() + .body(new ErrorResponse(ex.getErrorCode())); + } + + @ExceptionHandler(BadRequestCustomException.class) + protected ResponseEntity handleBadRequestException(final BadRequestCustomException ex){ + return ResponseEntity + .badRequest() + .body(new ErrorResponse(ex.getErrorCode())); + } + + @ExceptionHandler(Exception.class) + protected ResponseEntity handleServerException(final Exception ex) { + return ResponseEntity + .internalServerError() + .body(new ErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR)); + } +} From 7df18a6dd54e1b6809fab1cdf5ee0f4de2bb3500 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 31 Dec 2023 17:40:12 +0900 Subject: [PATCH 101/603] =?UTF-8?q?refactor=20:=20waitingFacade=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ExceptionHandler.java | 8 ----- .../waiting/facade/WaitingFacade.java | 31 ------------------- .../waiting/service/WaitingService.java | 25 ++++++++++++--- .../waiting/service/WaitingServiceTest.java | 12 ++++--- 4 files changed, 29 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java delete mode 100644 src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java deleted file mode 100644 index e80e90fa..00000000 --- a/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.prgrms.catchtable.common.exception; - -import org.springframework.web.bind.annotation.RestControllerAdvice; - -@RestControllerAdvice -public class ExceptionHandler { - -} diff --git a/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java b/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java deleted file mode 100644 index 6d4ed580..00000000 --- a/src/main/java/com/prgrms/catchtable/waiting/facade/WaitingFacade.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.prgrms.catchtable.waiting.facade; - -import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; -import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; - -import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; -import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.member.repository.MemberRepository; -import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.repository.ShopRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@RequiredArgsConstructor -@Component -public class WaitingFacade { - private final MemberRepository memberRepository; - private final ShopRepository shopRepository; - - public Member getMemberEntity(Long memberId){ - return memberRepository.findById(memberId).orElseThrow( - ()-> new NotFoundCustomException(NOT_EXIST_MEMBER) - ); - } - - public Shop getShopEntity(Long shopId){ - return shopRepository.findById(shopId).orElseThrow( - () -> new NotFoundCustomException(NOT_EXIST_SHOP) - ); - } -} diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 470fdb11..ccc39e64 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -1,16 +1,20 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; import com.prgrms.catchtable.waiting.dto.WaitingMapper; -import com.prgrms.catchtable.waiting.facade.WaitingFacade; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.time.LocalDate; import java.time.LocalDateTime; @@ -24,11 +28,12 @@ public class WaitingService { private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); private final WaitingRepository waitingRepository; - private final WaitingFacade waitingFacade; + private final MemberRepository memberRepository; + private final ShopRepository shopRepository; public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { // 연관 엔티티 조회 - Member member = waitingFacade.getMemberEntity(1L); - Shop shop = waitingFacade.getShopEntity(shopId); + Member member = getMemberEntity(1L); + Shop shop = getShopEntity(shopId); // shop 영업 중인지 검증 shop.validateIfShopOpened(LocalTime.now()); @@ -56,4 +61,16 @@ private void validateIfMemberWaitingExists(Member member) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); } } + + public Member getMemberEntity(Long memberId){ + return memberRepository.findById(memberId).orElseThrow( + ()-> new NotFoundCustomException(NOT_EXIST_MEMBER) + ); + } + + public Shop getShopEntity(Long shopId){ + return shopRepository.findById(shopId).orElseThrow( + () -> new NotFoundCustomException(NOT_EXIST_SHOP) + ); + } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index b092ce70..e22924cf 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -8,13 +8,15 @@ import static org.mockito.Mockito.mock; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; -import com.prgrms.catchtable.waiting.facade.WaitingFacade; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.time.LocalTime; +import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -27,7 +29,9 @@ class WaitingServiceTest { @Mock private WaitingRepository waitingRepository; @Mock - private WaitingFacade waitingFacade; + private ShopRepository shopRepository; + @Mock + private MemberRepository memberRepository; @InjectMocks private WaitingService waitingService; @@ -47,8 +51,8 @@ void createWaiting() { .peopleCount(2) .build(); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); - given(waitingFacade.getShopEntity(1L)).willReturn(shop); - given(waitingFacade.getMemberEntity(1L)).willReturn(member); + given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.existsByMember(member)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); From 07d188ec8f91df22a8daea550f51c2e31e81d71b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 20:25:24 +0900 Subject: [PATCH 102/603] =?UTF-8?q?feat=20:=20static=20import=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=B0=8F=20=EC=95=BD=EC=96=B4=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index a2a76594..c60eac1f 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.reservation.controller; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -9,12 +11,9 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.transaction.annotation.Transactional; class ReservationControllerTest extends BaseIntegrationTest { @@ -23,7 +22,6 @@ class ReservationControllerTest extends BaseIntegrationTest { private ReservationTimeRepository reservationTimeRepository; @Test - @Transactional @DisplayName("예약 선점 api 호출에 성공한다.") void preOccupyReservation() throws Exception { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); @@ -31,8 +29,8 @@ void preOccupyReservation() throws Exception { CreateReservationRequest request = ReservationData.getCreateReservationRequest( savedReservationTime.getId()); - mvc.perform(post("/reservations") - .contentType(MediaType.APPLICATION_JSON) + mockMvc.perform(post("/reservations") + .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) @@ -41,7 +39,6 @@ void preOccupyReservation() throws Exception { } @Test - @Transactional @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") void schedulerTest() throws Exception { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); @@ -49,13 +46,13 @@ void schedulerTest() throws Exception { CreateReservationRequest request = ReservationData.getCreateReservationRequest( savedReservationTime.getId()); - mvc.perform(post("/reservations") - .contentType(MediaType.APPLICATION_JSON) + mockMvc.perform(post("/reservations") + .contentType(APPLICATION_JSON) .content(asJsonString(request))); - Assertions.assertThat(reservationTime.isPreOccupied()).isTrue(); + assertThat(reservationTime.isPreOccupied()).isTrue(); Thread.sleep(3_000); //현재 스케줄러는 2초로 설정되어있어 3초간 대기 후 검증 - Assertions.assertThat(reservationTime.isPreOccupied()).isFalse(); + assertThat(reservationTime.isPreOccupied()).isFalse(); } From 94d9b78150188d8eb3963b7e4ebb413d56b92d8e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 20:25:59 +0900 Subject: [PATCH 103/603] =?UTF-8?q?feat=20:=20ObjectMapper=20=EC=8B=B1?= =?UTF-8?q?=EA=B8=80=ED=86=A4=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/base/BaseIntegrationTest.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 926f6069..50ffcd4b 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -13,13 +13,10 @@ public class BaseIntegrationTest { @Autowired - public MockMvc mvc; + public MockMvc mockMvc; + public static ObjectMapper objectMapper = new ObjectMapper(); - public static String asJsonString(final Object obj) { - try { - return new ObjectMapper().writeValueAsString(obj); - } catch (Exception e) { - throw new RuntimeException(e); - } + public static String asJsonString(final Object object) throws Exception{ + return objectMapper.writeValueAsString(object); } } From 3b6466d74ac5b1c7077bb9c7c5036a39fcf7920f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 20:34:20 +0900 Subject: [PATCH 104/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/base/BaseIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 50ffcd4b..8142bc65 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -16,7 +16,7 @@ public class BaseIntegrationTest { public MockMvc mockMvc; public static ObjectMapper objectMapper = new ObjectMapper(); - public static String asJsonString(final Object object) throws Exception{ + public static String asJsonString(final Object object) throws Exception { return objectMapper.writeValueAsString(object); } } From 672724667d40b3bb58fd07d9b853bc5a5dd143e1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 31 Dec 2023 21:27:32 +0900 Subject: [PATCH 105/603] =?UTF-8?q?feat=20:=20=EA=B8=B0=ED=83=80=20excepti?= =?UTF-8?q?on=20=ED=95=B8=EB=93=A4=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 3 +-- .../common/exception/ExceptionHandler.java | 8 ------- .../exception/GlobalExceptionHandler.java | 21 +++++++------------ 3 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 8df1bae2..02c9e311 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -10,8 +10,7 @@ public enum ErrorCode { ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), - NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), - INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); + NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); private final String message; } diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java deleted file mode 100644 index e80e90fa..00000000 --- a/src/main/java/com/prgrms/catchtable/common/exception/ExceptionHandler.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.prgrms.catchtable.common.exception; - -import org.springframework.web.bind.annotation.RestControllerAdvice; - -@RestControllerAdvice -public class ExceptionHandler { - -} diff --git a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java index f23045d6..cfa9cf8c 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java @@ -11,10 +11,10 @@ @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler - protected ResponseEntity handleMethodArgumentNotValid(final MethodArgumentNotValidException ex) { + protected ResponseEntity handleMethodArgumentNotValidException(final MethodArgumentNotValidException exception) { StringBuilder sb = new StringBuilder(); - for (FieldError e : ex.getBindingResult().getFieldErrors()) { - sb.append(e.getDefaultMessage()); + for (FieldError fieldError : exception.getBindingResult().getFieldErrors()) { + sb.append(fieldError.getDefaultMessage()); sb.append(", "); } return ResponseEntity @@ -23,23 +23,16 @@ protected ResponseEntity handleMethodArgumentNotValid(final Metho } @ExceptionHandler(NotFoundCustomException.class) - protected ResponseEntity handleNotFoundException(final NotFoundCustomException ex) { + protected ResponseEntity handleNotFoundException(final NotFoundCustomException exception) { return ResponseEntity .badRequest() - .body(new ErrorResponse(ex.getErrorCode())); + .body(new ErrorResponse(exception.getErrorCode())); } @ExceptionHandler(BadRequestCustomException.class) - protected ResponseEntity handleBadRequestException(final BadRequestCustomException ex){ + protected ResponseEntity handleBadRequestException(final BadRequestCustomException exception){ return ResponseEntity .badRequest() - .body(new ErrorResponse(ex.getErrorCode())); - } - - @ExceptionHandler(Exception.class) - protected ResponseEntity handleServerException(final Exception ex) { - return ResponseEntity - .internalServerError() - .body(new ErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR)); + .body(new ErrorResponse(exception.getErrorCode())); } } From c9aea80f997302b0197209332f45af555e80bd2c Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 31 Dec 2023 21:52:22 +0900 Subject: [PATCH 106/603] =?UTF-8?q?feat=20:=20@Getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorResponse.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java index 2c5a93f5..0e1b7cf1 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java @@ -1,5 +1,8 @@ package com.prgrms.catchtable.common.exception; +import lombok.Getter; + +@Getter public class ErrorResponse { private final String code; private final String message; @@ -13,4 +16,5 @@ public ErrorResponse(String message){ this.code = "BAD_REQUEST"; this.message = message; } + } From 3d5c645a1f1afd2ae7d14ca4b25ae2aa74f0375c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:46:07 +0900 Subject: [PATCH 107/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C=20shop=20=EC=A0=95=EB=B3=B4=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=ED=8E=98=EC=B9=98=20=EC=A1=B0=EC=9D=B8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationTimeRepository.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 63ae522a..3517ec35 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -1,8 +1,12 @@ package com.prgrms.catchtable.reservation.repository; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface ReservationTimeRepository extends JpaRepository { - + @Query("select rt from ReservationTime rt join fetch rt.shop s where rt.id = :id") + Optional findByIdWithShop(@Param("id") Long id); } From 2a6980648535427a7f995778b2cf707bd0a3bbe8 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:46:53 +0900 Subject: [PATCH 108/603] =?UTF-8?q?feat=20:=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=9D=B4=20=EB=B9=84=EC=97=88=EB=8A=94=EC=A7=80=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=ED=9B=84=20=EC=98=88=EC=95=BD=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 343a1293..86c58a60 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,12 +1,16 @@ package com.prgrms.catchtable.reservation.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,6 +21,7 @@ public class ReservationService { private final ReservationTimeRepository reservationTimeRepository; + private final ReservationRepository reservationRepository; @Transactional public ReservationTime validateReservationAndSave(CreateReservationRequest request) { @@ -30,4 +35,24 @@ public ReservationTime validateReservationAndSave(CreateReservationRequest reque return reservationTime; } + + @Transactional + public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest request){ + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( + request.reservationTimeId()). + orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); + + if(reservationTime.isOccupied()){ + throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); + } + + Reservation reservation = Reservation.builder() + .status(COMPLETED) + .peopleCount(request.peopleCount()) + .shop(reservationTime.getShop()) + .reservationTime(reservationTime) + .build(); + Reservation savedReservation = reservationRepository.save(reservation); + return savedReservation; + } } From b75fa62436911466aa303db859ffbc70ea8c7a31 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:47:06 +0900 Subject: [PATCH 109/603] =?UTF-8?q?feat=20:=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D=20=ED=8D=BC=EC=82=AC?= =?UTF-8?q?=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacade.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index a00172a5..5a9fb62b 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.facade; +import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; @@ -32,4 +34,9 @@ public CreateReservationResponse preOccupyReservation( .build(); } + public CreateReservationResponse registerReservation(CreateReservationRequest request) { + Reservation reservation = reservationService.validateReservationAndSaveIsEmpty(request); + return ReservationMapper.toCreateReservationResponse(reservation); + } + } From 13abc794f9288faca266498e80eab149fd775008 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:47:18 +0900 Subject: [PATCH 110/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EC=98=88=EC=95=BD=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/data/reservation/ReservationData.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index f47d9941..31a33393 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -6,7 +6,9 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDateTime; +import org.springframework.test.util.ReflectionTestUtils; public class ReservationData { @@ -30,7 +32,9 @@ public static ReservationTime getReservationTimePreOccupied() { ReservationTime reservationTime = ReservationTime.builder() .time(LocalDateTime.of(2024, 12, 31, 19, 30)) .build(); - reservationTime.insertShop(ShopData.getShop()); + Shop shop = ShopData.getShop(); + ReflectionTestUtils.setField(shop, "id", 1L); + reservationTime.insertShop(shop); reservationTime.reversePreOccupied(); return reservationTime; } From d0e7cad958e1790d7b0e6805ec42f3ecd2b0ab03 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:47:29 +0900 Subject: [PATCH 111/603] =?UTF-8?q?feat=20:=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 80d65ee7..4dac8680 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -1,14 +1,19 @@ package com.prgrms.catchtable.reservation.service; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.data.reservation.ReservationData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -21,7 +26,8 @@ @ExtendWith(MockitoExtension.class) class ReservationServiceTest { - + @Mock + ReservationRepository reservationRepository; @Mock private ReservationTimeRepository reservationTimeRepository; @InjectMocks @@ -66,4 +72,42 @@ void alreadyPreOccupied() { } + + @Test + @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") + void registerReservation(){ + ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + Reservation reservation = Reservation.builder() + .status(COMPLETED) + .peopleCount(request.peopleCount()) + .shop(reservationTime.getShop()) + .reservationTime(reservationTime) + .build(); + + when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( + Optional.of(reservationTime)); + when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + Reservation findReservation = reservationService.validateReservationAndSaveIsEmpty(request); + + assertAll( + () -> assertThat(findReservation.getReservationTime().getTime()).isEqualTo(reservationTime.getTime()), + () -> assertThat(findReservation.getPeopleCount()).isEqualTo(request.peopleCount()), + () -> assertThat(findReservation.getStatus()).isEqualTo(COMPLETED) + ); + } + @Test + @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") + void registerReservationAlreadyOccupied() { + ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + + reservationTime.reverseOccupied(); + when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( + Optional.of(reservationTime)); + + assertThrows(BadRequestCustomException.class, + () -> reservationService.validateReservationAndSaveIsEmpty(request)); + } + } \ No newline at end of file From cba23db9484fae6f4453e343e46f9e591f057a76 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 31 Dec 2023 23:48:26 +0900 Subject: [PATCH 112/603] =?UTF-8?q?feat=20:=20BaseIntegrationTest=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/base/BaseIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 8142bc65..387ddb6f 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -10,7 +10,7 @@ @SpringBootTest @Transactional @AutoConfigureMockMvc -public class BaseIntegrationTest { +public abstract class BaseIntegrationTest { @Autowired public MockMvc mockMvc; From 8163b3fcce855ae6581d4fd95939377cf3f2efa5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 00:15:01 +0900 Subject: [PATCH 113/603] =?UTF-8?q?chore=20:=20=EC=8B=9C=ED=81=90=EB=A6=AC?= =?UTF-8?q?=ED=8B=B0=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 06fac189..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' -// implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' From 04c40137c1eda1527aa8d420ce2a14fe5d64f396 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 00:18:29 +0900 Subject: [PATCH 114/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20=EC=98=88=EC=95=BD=EC=B0=A8?= =?UTF-8?q?=EC=A7=80=EC=97=AC=EB=B6=80=20=EB=B3=80=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/service/ReservationService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 86c58a60..4854fe2d 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -46,6 +46,8 @@ public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest re throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } + reservationTime.reverseOccupied(); + Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) From 3dad33ba7f6774f883577a55a3214b160ce23c23 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 00:19:26 +0900 Subject: [PATCH 115/603] =?UTF-8?q?chore=20:=20oauth=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A8=B8=EC=A7=80=20=EC=A0=84=EC=9D=B4=EB=9D=BC=20?= =?UTF-8?q?=EC=8B=9C=ED=81=90=EB=A6=AC=ED=8B=B0=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EB=8B=A4=EC=8B=9C=20=EC=A3=BC=EC=84=9D=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 361994f5..06fac189 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' - implementation 'org.springframework.boot:spring-boot-starter-security' +// implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' From a88ace9d272ce5a2387578be4ae8c660dfd1bcda Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 15:34:00 +0900 Subject: [PATCH 116/603] feat : mapper static import --- .../java/com/prgrms/catchtable/facade/ReservationFacade.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index 5a9fb62b..b0c1c527 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -1,8 +1,9 @@ package com.prgrms.catchtable.facade; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; + import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; -import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; @@ -36,7 +37,7 @@ public CreateReservationResponse preOccupyReservation( public CreateReservationResponse registerReservation(CreateReservationRequest request) { Reservation reservation = reservationService.validateReservationAndSaveIsEmpty(request); - return ReservationMapper.toCreateReservationResponse(reservation); + return toCreateReservationResponse(reservation); } } From 71ca5b8ea0da99a942a9c3c8b2b8b7487ff65467 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 15:34:59 +0900 Subject: [PATCH 117/603] =?UTF-8?q?feat=20:=20=EB=A6=AC=ED=84=B4=EA=B0=92?= =?UTF-8?q?=20=EC=9D=B8=EB=9D=BC=EC=9D=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/service/ReservationService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 4854fe2d..7150dbf4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -54,7 +54,6 @@ public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest re .shop(reservationTime.getShop()) .reservationTime(reservationTime) .build(); - Reservation savedReservation = reservationRepository.save(reservation); - return savedReservation; + return reservationRepository.save(reservation); } } From 84595826a04102e2a1001e3235bd5d99c6f39a85 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 15:39:08 +0900 Subject: [PATCH 118/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 - .../common/exception/ErrorResponse.java | 5 ++-- .../exception/GlobalExceptionHandler.java | 10 +++++--- .../repository/ReservationTimeRepository.java | 1 + .../service/ReservationService.java | 10 ++++---- .../prgrms/catchtable/shop/domain/Shop.java | 6 ++--- .../waiting/domain/WaitingStatus.java | 1 + .../waiting/dto/CreateWaitingRequest.java | 4 +++- .../waiting/dto/CreateWaitingResponse.java | 4 +++- .../catchtable/waiting/dto/WaitingMapper.java | 6 +++-- .../waiting/repository/WaitingRepository.java | 9 ++++---- .../waiting/service/WaitingService.java | 23 +++++++++++-------- .../catchtable/member/MemberFixture.java | 2 +- .../service/ReservationServiceTest.java | 10 ++++---- .../catchtable/shop/domain/ShopTest.java | 9 ++++---- .../catchtable/shop/fixture/ShopFixture.java | 7 +++--- .../repository/WaitingRepositoryTest.java | 14 +++++++---- 17 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 785be28e..a262cd2f 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java index 0e1b7cf1..b0d3ba0b 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java @@ -4,15 +4,16 @@ @Getter public class ErrorResponse { + private final String code; private final String message; - public ErrorResponse(ErrorCode errorCode){ + public ErrorResponse(ErrorCode errorCode) { this.code = errorCode.name(); this.message = errorCode.getMessage(); } - public ErrorResponse(String message){ + public ErrorResponse(String message) { this.code = "BAD_REQUEST"; this.message = message; } diff --git a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java index cfa9cf8c..a84c3f71 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java @@ -10,8 +10,10 @@ @RestControllerAdvice public class GlobalExceptionHandler { + @ExceptionHandler - protected ResponseEntity handleMethodArgumentNotValidException(final MethodArgumentNotValidException exception) { + protected ResponseEntity handleMethodArgumentNotValidException( + final MethodArgumentNotValidException exception) { StringBuilder sb = new StringBuilder(); for (FieldError fieldError : exception.getBindingResult().getFieldErrors()) { sb.append(fieldError.getDefaultMessage()); @@ -23,14 +25,16 @@ protected ResponseEntity handleMethodArgumentNotValidException(fi } @ExceptionHandler(NotFoundCustomException.class) - protected ResponseEntity handleNotFoundException(final NotFoundCustomException exception) { + protected ResponseEntity handleNotFoundException( + final NotFoundCustomException exception) { return ResponseEntity .badRequest() .body(new ErrorResponse(exception.getErrorCode())); } @ExceptionHandler(BadRequestCustomException.class) - protected ResponseEntity handleBadRequestException(final BadRequestCustomException exception){ + protected ResponseEntity handleBadRequestException( + final BadRequestCustomException exception) { return ResponseEntity .badRequest() .body(new ErrorResponse(exception.getErrorCode())); diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 3517ec35..1b37a04c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.repository.query.Param; public interface ReservationTimeRepository extends JpaRepository { + @Query("select rt from ReservationTime rt join fetch rt.shop s where rt.id = :id") Optional findByIdWithShop(@Param("id") Long id); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 7150dbf4..fd567aaf 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -35,14 +35,14 @@ public ReservationTime validateReservationAndSave(CreateReservationRequest reque return reservationTime; } - + @Transactional - public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest request){ + public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( - request.reservationTimeId()). + request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); - - if(reservationTime.isOccupied()){ + + if (reservationTime.isOccupied()) { throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index e89ad27a..36e74ef6 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -52,9 +52,9 @@ public class Shop extends BaseEntity { private LocalTime closingTime; - @Builder - public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, LocalTime openingTime, LocalTime closingTime) { + public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, + LocalTime openingTime, LocalTime closingTime) { this.name = name; this.rating = rating; this.category = category; @@ -65,7 +65,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, } public void validateIfShopOpened(LocalTime localTime) { - if (localTime.isBefore(openingTime)|| localTime.isAfter(closingTime)){ + if (localTime.isBefore(openingTime) || localTime.isAfter(closingTime)) { throw new BadRequestCustomException(SHOP_NOT_RUNNING); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java index a711f5a9..07ee07a1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + @Getter @RequiredArgsConstructor public enum WaitingStatus { diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java index 959d125c..4b9f9205 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java @@ -7,4 +7,6 @@ public record CreateWaitingRequest( @Positive(message = "인원은 1명 이상이어야 합니다.") int peopleCount -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java index 64775645..66f30561 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java @@ -10,4 +10,6 @@ public record CreateWaitingResponse( int peopleCount, int waitingNumber, int waitingOrder -){} \ No newline at end of file +) { + +} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index df40a002..db8912fd 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -9,8 +9,10 @@ @NoArgsConstructor(access = PRIVATE) public class WaitingMapper { + // dto -> entity - public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, int waitingOrder, Member member, Shop shop){ + public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, + int waitingOrder, Member member, Shop shop) { return Waiting.builder() .waitingNumber(waitingNumber) .waitingOrder(waitingOrder) @@ -20,7 +22,7 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting){ + public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting) { return CreateWaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 0a68d11c..9a074017 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -4,14 +4,15 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDate; import java.time.LocalDateTime; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; public interface WaitingRepository extends JpaRepository { + boolean existsByMember(Member member); - Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, LocalDateTime start, LocalDateTime end); + + Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, + LocalDateTime start, LocalDateTime end); + Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index ccc39e64..647796e8 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -25,11 +25,15 @@ @RequiredArgsConstructor @Service public class WaitingService { - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); + + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); private final WaitingRepository waitingRepository; private final MemberRepository memberRepository; private final ShopRepository shopRepository; + public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { // 연관 엔티티 조회 Member member = getMemberEntity(1L); @@ -43,32 +47,33 @@ public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest req // 대기 번호 생성 int waitingNumber = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, - PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue()+1; + PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // 대기 순서 생성 int waitingOrder = (waitingRepository.countByShopAndCreatedAtBetween(shop, - START_DATE_TIME, END_DATE_TIME)).intValue()+1; + START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // waiting 저장 - Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, shop); + Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, + shop); Waiting savedWaiting = waitingRepository.save(waiting); return WaitingMapper.toCreateWaitingResponse(savedWaiting); } private void validateIfMemberWaitingExists(Member member) { - if (waitingRepository.existsByMember(member)){ + if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); } } - public Member getMemberEntity(Long memberId){ + public Member getMemberEntity(Long memberId) { return memberRepository.findById(memberId).orElseThrow( - ()-> new NotFoundCustomException(NOT_EXIST_MEMBER) + () -> new NotFoundCustomException(NOT_EXIST_MEMBER) ); } - public Shop getShopEntity(Long shopId){ + public Shop getShopEntity(Long shopId) { return shopRepository.findById(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) ); diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index 9543a633..fdba13fc 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -2,10 +2,10 @@ import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDate; public class MemberFixture { + public static Member member(String name) { return Member.builder() .name(name) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 4dac8680..871eb809 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -10,7 +10,6 @@ import com.prgrms.catchtable.common.data.reservation.ReservationData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; -import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.repository.ReservationRepository; @@ -26,6 +25,7 @@ @ExtendWith(MockitoExtension.class) class ReservationServiceTest { + @Mock ReservationRepository reservationRepository; @Mock @@ -75,7 +75,7 @@ void alreadyPreOccupied() { @Test @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") - void registerReservation(){ + void registerReservation() { ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationData.getCreateReservationRequest(); Reservation reservation = Reservation.builder() @@ -91,11 +91,13 @@ void registerReservation(){ Reservation findReservation = reservationService.validateReservationAndSaveIsEmpty(request); assertAll( - () -> assertThat(findReservation.getReservationTime().getTime()).isEqualTo(reservationTime.getTime()), + () -> assertThat(findReservation.getReservationTime().getTime()).isEqualTo( + reservationTime.getTime()), () -> assertThat(findReservation.getPeopleCount()).isEqualTo(request.peopleCount()), () -> assertThat(findReservation.getStatus()).isEqualTo(COMPLETED) ); } + @Test @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") void registerReservationAlreadyOccupied() { diff --git a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java index 2c1a4624..ec7a8e74 100644 --- a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; class ShopTest { + @DisplayName("가게 영업 시간이 아닐 때는 예외를 발생시킨다.") @Test void validate_shop_not_running_time() { @@ -28,15 +29,15 @@ void validate_shop_not_running_time() { @DisplayName("가게 영업 시간 내에서는 예외를 발생시키지 않는다.") @Test - void validate_shop_running_time(){ + void validate_shop_running_time() { //given LocalTime openingTime = LocalTime.of(11, 0); - LocalTime closingTime = LocalTime.of(21,0); + LocalTime closingTime = LocalTime.of(21, 0); Shop shop = ShopFixture.shop(); //when, then assertDoesNotThrow( - ()->shop.validateIfShopOpened(openingTime)); + () -> shop.validateIfShopOpened(openingTime)); assertDoesNotThrow( - ()->shop.validateIfShopOpened(closingTime)); + () -> shop.validateIfShopOpened(closingTime)); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 5c4cca00..8b19cc62 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -7,15 +7,16 @@ import java.time.LocalTime; public class ShopFixture { - public static Shop shop(){ + + public static Shop shop() { return Shop.builder() .name("testShop") .rating(BigDecimal.valueOf(3.5)) .category(Category.WESTERN_FOOD) .address(new Address("서울시", "중구")) .capacity(30) - .openingTime(LocalTime.of(11,0)) - .closingTime(LocalTime.of(21,0)) + .openingTime(LocalTime.of(11, 0)) + .closingTime(LocalTime.of(21, 0)) .build(); } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index a3aa8759..a082be1b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -37,11 +37,13 @@ class WaitingRepositoryTest { private Waiting waiting1; private Waiting waiting2; private Waiting waiting3; - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); @BeforeEach - void setUp(){ + void setUp() { Member member1 = MemberFixture.member("test1"); Member member2 = MemberFixture.member("test2"); Member member3 = MemberFixture.member("test3"); @@ -91,7 +93,8 @@ void countByShopAndStatusAndCreatedAtBetween() { waitingRepository.save(waiting2); //입장상태 대기 생성 //when - Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop,PROGRESS,START_DATE_TIME, END_DATE_TIME); + Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, PROGRESS, + START_DATE_TIME, END_DATE_TIME); //then assertThat(count).isEqualTo(1L); } @@ -106,7 +109,8 @@ void countByShopAndCreatedAtBetween() { waitingRepository.save(waiting2); //when - Long count = waitingRepository.countByShopAndCreatedAtBetween(shop,START_DATE_TIME, END_DATE_TIME); + Long count = waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, + END_DATE_TIME); //then assertThat(count).isEqualTo(2L); } From 991b6cbf1d4283c3ca0b9872d2343d6f5d705ae6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 16:11:50 +0900 Subject: [PATCH 119/603] =?UTF-8?q?feat=20:=20mapper=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/mapper/ReservationMapper.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java new file mode 100644 index 00000000..f58be265 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -0,0 +1,21 @@ +package com.prgrms.catchtable.reservation.dto.mapper; + +import static lombok.AccessLevel.PRIVATE; + +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public class ReservationMapper { + + public static CreateReservationResponse toCreateReservationResponse(Reservation reservation) { + return CreateReservationResponse.builder() + .shopName(reservation.getShop().getName()) + .memberName("memberA") + .date(reservation.getReservationTime().getTime()) + .peopleCount(reservation.getPeopleCount()) + .build(); + } + +} From ebf5beefdabd185deeb7ad8062b8a5123f327a87 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 1 Jan 2024 16:12:09 +0900 Subject: [PATCH 120/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationTimeRepositoryTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java new file mode 100644 index 00000000..56a42d07 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -0,0 +1,53 @@ +package com.prgrms.catchtable.reservation.repository; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.common.exception.ErrorCode; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +class ReservationTimeRepositoryTest { + + @Autowired + private ReservationTimeRepository reservationTimeRepository; + @Autowired + private ShopRepository shopRepository; + + @Test + @DisplayName("예약시간과 그 시간의 매장까지 한번의 쿼리로 조회할 수 있다.") + void findReservationTimeWithShop() { + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + reservationTime.insertShop(savedShop); + ReservationTime savedTime = reservationTimeRepository.save(reservationTime); + + ReservationTime findReservationTime = reservationTimeRepository.findByIdWithShop( + savedTime.getId()) + .orElseThrow(() -> new NotFoundCustomException(ErrorCode.NOT_EXIST_TIME)); + + assertAll( + () -> assertThat(findReservationTime.getShop().getName()).isEqualTo(shop.getName()), + () -> assertThat(findReservationTime.getShop().getCapacity()).isEqualTo( + shop.getCapacity()), + () -> assertThat(findReservationTime.getShop().getCategory()).isEqualTo( + shop.getCategory()), + () -> assertThat(findReservationTime.getShop().getRating()).isEqualTo(shop.getRating()) + ); + + + } +} \ No newline at end of file From 86ea0178a7adb7410a71142d4b65d9cf23a16741 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:01:52 +0900 Subject: [PATCH 121/603] =?UTF-8?q?refactor=20:=20=EB=88=84=EB=9D=BD=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EC=A0=9C=EC=96=B4=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/dto/OAuthAttribute.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java b/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java index 8c0d689c..87dc486e 100644 --- a/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java +++ b/src/main/java/com/prgrms/catchtable/security/dto/OAuthAttribute.java @@ -8,17 +8,17 @@ @Getter public class OAuthAttribute { - String name; + private final String name; - String email; + private final String email; - String phoneNumber; + private final String phoneNumber; - String birthYear; + private final String birthYear; - String birthDay; + private final String birthDay; - String gender; + private final String gender; @Builder public OAuthAttribute(String name, String email, String phoneNumber, String birthYear, From e177ee51ba1db480bcbe8c2a02d92e68c4ab1bc7 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:09:51 +0900 Subject: [PATCH 122/603] chore : conflict resolve --- build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 86b3657b..73a589d7 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,9 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + //OAuth2.0 Client implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' @@ -56,7 +59,6 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' - } tasks.named('test') { From 8db399fbb3ab11db25244c3916ad79e82e58e546 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:12:00 +0900 Subject: [PATCH 123/603] chore : conflict resolve --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 73a589d7..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -51,14 +51,6 @@ dependencies { testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' - - //OAuth2.0 Client - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - - //JWT - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' } tasks.named('test') { From 4b3136b0deea46182d8ac0e50d438ec608561324 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:13:18 +0900 Subject: [PATCH 124/603] chore : conflict resolve --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 361994f5..73a589d7 100644 --- a/build.gradle +++ b/build.gradle @@ -51,6 +51,14 @@ dependencies { testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' + + //OAuth2.0 Client + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + + //JWT + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' } tasks.named('test') { From c00daa5cd6c7de3206f659efd81b5a43582c2eaf Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:21:11 +0900 Subject: [PATCH 125/603] chore : conflict resolve --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 73a589d7..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -51,14 +51,6 @@ dependencies { testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' - - //OAuth2.0 Client - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - - //JWT - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' } tasks.named('test') { From 0495100161770774dee74db7c96117da283d8274 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:31:44 +0900 Subject: [PATCH 126/603] chore : conflict resolve --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 361994f5..63572141 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,14 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + //OAuth2.0 Client + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + + //JWT + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' } From f7799fe552a640438b136a9ab3a0550afe4bef68 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:34:47 +0900 Subject: [PATCH 127/603] chore : conflict resolve --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 63572141..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -49,14 +49,6 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' - //OAuth2.0 Client - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' - - //JWT - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' - testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' } From f919a91a240a91fd2f90d46e65ec1b2dcabb8d83 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 18:46:15 +0900 Subject: [PATCH 128/603] chore : conflict resolve --- build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build.gradle b/build.gradle index 361994f5..e099399f 100644 --- a/build.gradle +++ b/build.gradle @@ -51,6 +51,15 @@ dependencies { testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' + + //OAuth2.0 Client + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + + //JWT + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + } tasks.named('test') { From 3914f462ed1c1d537424bba0268b8ca21284fed8 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 1 Jan 2024 19:00:17 +0900 Subject: [PATCH 129/603] =?UTF-8?q?fix=20:=20notification=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B4=88=EA=B8=B0=ED=99=94=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/prgrms/catchtable/member/MemberFixture.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index 9543a633..e89ca019 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -12,7 +12,6 @@ public static Member member(String name) { .phoneNumber("010-1111-1111") .gender(Gender.FEMALE) .dateBirth(LocalDate.parse("2008-12-18")) - .notification_activated(true) .build(); } } From 4b4f164479b8085f465cefaf490b25328789d6f7 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 10:38:31 +0900 Subject: [PATCH 130/603] =?UTF-8?q?refactor=20:=20=EC=83=81=ED=99=A9?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=98=88=EC=99=B8=20=EB=B6=84?= =?UTF-8?q?=EB=A5=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 2 ++ .../catchtable/jwt/filter/JwtAuthenticationFilter.java | 6 +++++- .../catchtable/jwt/service/JwtUserDetailsService.java | 6 +++++- .../prgrms/catchtable/jwt/service/RefreshTokenService.java | 6 +++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 785be28e..40d2a634 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -8,6 +8,8 @@ @RequiredArgsConstructor public enum ErrorCode { NOT_EXIST_MEMBER("존재하지 않는 회원입니다."), + NOT_FOUND_REFRESH_TOKEN("알 수 없는 RefreshToken입니다."), + TOKEN_EXPIRES("토큰이 만료되었습니다. 다시 로그인 해 주세요."), ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index f7651cb6..f5898d2c 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -1,5 +1,9 @@ package com.prgrms.catchtable.jwt.filter; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.ErrorCode; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; @@ -50,7 +54,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha newToken.getAccessToken()); setAuthentication(newToken.getAccessToken()); } else { - throw new UsernameNotFoundException("Please Login again"); + throw new BadRequestCustomException(TOKEN_EXPIRES); } } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java index a259842b..7e6f3f5d 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java @@ -1,5 +1,9 @@ package com.prgrms.catchtable.jwt.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.ErrorCode; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; @@ -16,6 +20,6 @@ public class JwtUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { return memberRepository.findMemberByEmail(email) - .orElseThrow(() -> new UsernameNotFoundException("Not Found Member")); + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_MEMBER)); } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index be10c362..ed7530a9 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -1,5 +1,9 @@ package com.prgrms.catchtable.jwt.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.ErrorCode; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; import com.prgrms.catchtable.jwt.token.Token; @@ -33,6 +37,6 @@ public void saveRefreshToken(Token totalToken) { @Transactional(readOnly = true) public RefreshToken getRefreshTokenByToken(String refreshToken) { return refreshTokenRepository.findRefreshTokenByToken(refreshToken) - .orElseThrow(() -> new UsernameNotFoundException("Not Found RefreshToken")); + .orElseThrow(() -> new NotFoundCustomException(NOT_FOUND_REFRESH_TOKEN)); } } From 59f7b36c04f114050fa5e95ee9864014bee075fb Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 11:18:29 +0900 Subject: [PATCH 131/603] =?UTF-8?q?feat=20:=20security=20=EB=82=B4=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/config/SecurityConfig.java | 6 ++- .../filter/ExceptionHandlerFilter.java | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 8b9edb01..cf4e07af 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.security.config; import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; +import com.prgrms.catchtable.security.filter.ExceptionHandlerFilter; import com.prgrms.catchtable.security.service.CustomOAuth2SuccessHandler; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; @@ -19,7 +20,7 @@ public class SecurityConfig { private final CustomOAuth2SuccessHandler successHandler; - + private final ExceptionHandlerFilter exceptionHandlerFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter; @Bean @@ -35,6 +36,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); + http.addFilterBefore(exceptionHandlerFilter, + OAuth2AuthorizationRequestRedirectFilter.class); + http.addFilterBefore(jwtAuthenticationFilter, OAuth2AuthorizationRequestRedirectFilter.class); diff --git a/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java b/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java new file mode 100644 index 00000000..6dbe0f02 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java @@ -0,0 +1,47 @@ +package com.prgrms.catchtable.security.filter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.prgrms.catchtable.common.exception.ErrorResponse; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import org.springframework.stereotype.Component; + +@Component +public class ExceptionHandlerFilter extends GenericFilter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + + HttpServletResponse httpServletResponse = (HttpServletResponse) response; + + try { + chain.doFilter(request, response); + } catch (BadRequestCustomException be) { + httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); + sendJson(httpServletResponse, toJson(new ErrorResponse(be.getErrorCode()))); + } catch (NotFoundCustomException ne) { + httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); + sendJson(httpServletResponse, toJson(new ErrorResponse(ne.getErrorCode()))); + } + } + + private String toJson(ErrorResponse response) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(response); + } + + private void sendJson(HttpServletResponse response, String resultJson) throws IOException { + response.setContentType("application/json;charset=UTF-8"); + response.setContentLength(resultJson.getBytes().length); + response.getWriter().write(resultJson); + } +} From e1767676d582b6346adcc77a8bb72800e2b97de3 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 11:19:08 +0900 Subject: [PATCH 132/603] =?UTF-8?q?fix=20:=20OAuth=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EC=8B=9C,=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/service/CustomOAuth2SuccessHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java index 94830052..9af11675 100644 --- a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java +++ b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java @@ -43,6 +43,7 @@ public String tokenToJson(Token token) throws JsonProcessingException { } private void sendTokenJson(HttpServletResponse response, String tokenJson) throws IOException { + response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json;charset=UTF-8"); response.setContentLength(tokenJson.getBytes().length); response.getWriter().write(tokenJson); From d93402862e433b837f005ad80a6bc0acda32df3a Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 11:23:30 +0900 Subject: [PATCH 133/603] =?UTF-8?q?style=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 - .../common/exception/ErrorResponse.java | 5 ++-- .../exception/GlobalExceptionHandler.java | 10 +++++--- .../jwt/filter/JwtAuthenticationFilter.java | 4 +--- .../jwt/service/JwtUserDetailsService.java | 3 +-- .../jwt/service/RefreshTokenService.java | 4 +--- .../prgrms/catchtable/shop/domain/Shop.java | 6 ++--- .../waiting/domain/WaitingStatus.java | 1 + .../waiting/dto/CreateWaitingRequest.java | 4 +++- .../waiting/dto/CreateWaitingResponse.java | 4 +++- .../catchtable/waiting/dto/WaitingMapper.java | 6 +++-- .../waiting/repository/WaitingRepository.java | 9 ++++---- .../waiting/service/WaitingService.java | 23 +++++++++++-------- .../common/base/BaseIntegrationTest.java | 2 +- .../catchtable/member/MemberFixture.java | 2 +- .../catchtable/shop/domain/ShopTest.java | 9 ++++---- .../catchtable/shop/fixture/ShopFixture.java | 7 +++--- .../repository/WaitingRepositoryTest.java | 16 +++++++------ 18 files changed, 66 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 40d2a634..b04f5260 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java index 0e1b7cf1..b0d3ba0b 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorResponse.java @@ -4,15 +4,16 @@ @Getter public class ErrorResponse { + private final String code; private final String message; - public ErrorResponse(ErrorCode errorCode){ + public ErrorResponse(ErrorCode errorCode) { this.code = errorCode.name(); this.message = errorCode.getMessage(); } - public ErrorResponse(String message){ + public ErrorResponse(String message) { this.code = "BAD_REQUEST"; this.message = message; } diff --git a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java index cfa9cf8c..a84c3f71 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/GlobalExceptionHandler.java @@ -10,8 +10,10 @@ @RestControllerAdvice public class GlobalExceptionHandler { + @ExceptionHandler - protected ResponseEntity handleMethodArgumentNotValidException(final MethodArgumentNotValidException exception) { + protected ResponseEntity handleMethodArgumentNotValidException( + final MethodArgumentNotValidException exception) { StringBuilder sb = new StringBuilder(); for (FieldError fieldError : exception.getBindingResult().getFieldErrors()) { sb.append(fieldError.getDefaultMessage()); @@ -23,14 +25,16 @@ protected ResponseEntity handleMethodArgumentNotValidException(fi } @ExceptionHandler(NotFoundCustomException.class) - protected ResponseEntity handleNotFoundException(final NotFoundCustomException exception) { + protected ResponseEntity handleNotFoundException( + final NotFoundCustomException exception) { return ResponseEntity .badRequest() .body(new ErrorResponse(exception.getErrorCode())); } @ExceptionHandler(BadRequestCustomException.class) - protected ResponseEntity handleBadRequestException(final BadRequestCustomException exception){ + protected ResponseEntity handleBadRequestException( + final BadRequestCustomException exception) { return ResponseEntity .badRequest() .body(new ErrorResponse(exception.getErrorCode())); diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index f5898d2c..316a18c8 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -1,8 +1,7 @@ package com.prgrms.catchtable.jwt.filter; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.TOKEN_EXPIRES; -import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; @@ -19,7 +18,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; @Component diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java index 7e6f3f5d..e445d69e 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java @@ -1,8 +1,7 @@ package com.prgrms.catchtable.jwt.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; -import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index ed7530a9..4d993587 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -1,14 +1,12 @@ package com.prgrms.catchtable.jwt.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_FOUND_REFRESH_TOKEN; -import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; import com.prgrms.catchtable.jwt.token.Token; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index e89ad27a..36e74ef6 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -52,9 +52,9 @@ public class Shop extends BaseEntity { private LocalTime closingTime; - @Builder - public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, LocalTime openingTime, LocalTime closingTime) { + public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, + LocalTime openingTime, LocalTime closingTime) { this.name = name; this.rating = rating; this.category = category; @@ -65,7 +65,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, } public void validateIfShopOpened(LocalTime localTime) { - if (localTime.isBefore(openingTime)|| localTime.isAfter(closingTime)){ + if (localTime.isBefore(openingTime) || localTime.isAfter(closingTime)) { throw new BadRequestCustomException(SHOP_NOT_RUNNING); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java index a711f5a9..07ee07a1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + @Getter @RequiredArgsConstructor public enum WaitingStatus { diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java index 959d125c..4b9f9205 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java @@ -7,4 +7,6 @@ public record CreateWaitingRequest( @Positive(message = "인원은 1명 이상이어야 합니다.") int peopleCount -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java index 64775645..66f30561 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java @@ -10,4 +10,6 @@ public record CreateWaitingResponse( int peopleCount, int waitingNumber, int waitingOrder -){} \ No newline at end of file +) { + +} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index df40a002..db8912fd 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -9,8 +9,10 @@ @NoArgsConstructor(access = PRIVATE) public class WaitingMapper { + // dto -> entity - public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, int waitingOrder, Member member, Shop shop){ + public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, + int waitingOrder, Member member, Shop shop) { return Waiting.builder() .waitingNumber(waitingNumber) .waitingOrder(waitingOrder) @@ -20,7 +22,7 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting){ + public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting) { return CreateWaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 0a68d11c..9a074017 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -4,14 +4,15 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDate; import java.time.LocalDateTime; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; public interface WaitingRepository extends JpaRepository { + boolean existsByMember(Member member); - Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, LocalDateTime start, LocalDateTime end); + + Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, + LocalDateTime start, LocalDateTime end); + Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index ccc39e64..647796e8 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -25,11 +25,15 @@ @RequiredArgsConstructor @Service public class WaitingService { - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); + + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); private final WaitingRepository waitingRepository; private final MemberRepository memberRepository; private final ShopRepository shopRepository; + public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { // 연관 엔티티 조회 Member member = getMemberEntity(1L); @@ -43,32 +47,33 @@ public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest req // 대기 번호 생성 int waitingNumber = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, - PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue()+1; + PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // 대기 순서 생성 int waitingOrder = (waitingRepository.countByShopAndCreatedAtBetween(shop, - START_DATE_TIME, END_DATE_TIME)).intValue()+1; + START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // waiting 저장 - Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, shop); + Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, + shop); Waiting savedWaiting = waitingRepository.save(waiting); return WaitingMapper.toCreateWaitingResponse(savedWaiting); } private void validateIfMemberWaitingExists(Member member) { - if (waitingRepository.existsByMember(member)){ + if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); } } - public Member getMemberEntity(Long memberId){ + public Member getMemberEntity(Long memberId) { return memberRepository.findById(memberId).orElseThrow( - ()-> new NotFoundCustomException(NOT_EXIST_MEMBER) + () -> new NotFoundCustomException(NOT_EXIST_MEMBER) ); } - public Shop getShopEntity(Long shopId){ + public Shop getShopEntity(Long shopId) { return shopRepository.findById(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) ); diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 387ddb6f..c85cc279 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -12,9 +12,9 @@ @AutoConfigureMockMvc public abstract class BaseIntegrationTest { + public static ObjectMapper objectMapper = new ObjectMapper(); @Autowired public MockMvc mockMvc; - public static ObjectMapper objectMapper = new ObjectMapper(); public static String asJsonString(final Object object) throws Exception { return objectMapper.writeValueAsString(object); diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index e89ca019..32b44a6c 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -2,10 +2,10 @@ import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDate; public class MemberFixture { + public static Member member(String name) { return Member.builder() .name(name) diff --git a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java index 2c1a4624..ec7a8e74 100644 --- a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; class ShopTest { + @DisplayName("가게 영업 시간이 아닐 때는 예외를 발생시킨다.") @Test void validate_shop_not_running_time() { @@ -28,15 +29,15 @@ void validate_shop_not_running_time() { @DisplayName("가게 영업 시간 내에서는 예외를 발생시키지 않는다.") @Test - void validate_shop_running_time(){ + void validate_shop_running_time() { //given LocalTime openingTime = LocalTime.of(11, 0); - LocalTime closingTime = LocalTime.of(21,0); + LocalTime closingTime = LocalTime.of(21, 0); Shop shop = ShopFixture.shop(); //when, then assertDoesNotThrow( - ()->shop.validateIfShopOpened(openingTime)); + () -> shop.validateIfShopOpened(openingTime)); assertDoesNotThrow( - ()->shop.validateIfShopOpened(closingTime)); + () -> shop.validateIfShopOpened(closingTime)); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 5c4cca00..8b19cc62 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -7,15 +7,16 @@ import java.time.LocalTime; public class ShopFixture { - public static Shop shop(){ + + public static Shop shop() { return Shop.builder() .name("testShop") .rating(BigDecimal.valueOf(3.5)) .category(Category.WESTERN_FOOD) .address(new Address("서울시", "중구")) .capacity(30) - .openingTime(LocalTime.of(11,0)) - .closingTime(LocalTime.of(21,0)) + .openingTime(LocalTime.of(11, 0)) + .closingTime(LocalTime.of(21, 0)) .build(); } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index a3aa8759..011d92b8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -25,23 +25,23 @@ @SpringBootTest class WaitingRepositoryTest { + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); @Autowired private WaitingRepository waitingRepository; - @Autowired private MemberRepository memberRepository; - @Autowired private ShopRepository shopRepository; private Shop shop; private Waiting waiting1; private Waiting waiting2; private Waiting waiting3; - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0,0,0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23,59,59)); @BeforeEach - void setUp(){ + void setUp() { Member member1 = MemberFixture.member("test1"); Member member2 = MemberFixture.member("test2"); Member member3 = MemberFixture.member("test3"); @@ -91,7 +91,8 @@ void countByShopAndStatusAndCreatedAtBetween() { waitingRepository.save(waiting2); //입장상태 대기 생성 //when - Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop,PROGRESS,START_DATE_TIME, END_DATE_TIME); + Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, PROGRESS, + START_DATE_TIME, END_DATE_TIME); //then assertThat(count).isEqualTo(1L); } @@ -106,7 +107,8 @@ void countByShopAndCreatedAtBetween() { waitingRepository.save(waiting2); //when - Long count = waitingRepository.countByShopAndCreatedAtBetween(shop,START_DATE_TIME, END_DATE_TIME); + Long count = waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, + END_DATE_TIME); //then assertThat(count).isEqualTo(2L); } From 63ae5bb052e85069d43b4fab177c31f36552635e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 13:23:56 +0900 Subject: [PATCH 134/603] fix : conflict resolve --- .../waiting/repository/WaitingRepositoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 011d92b8..0afddfc3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -25,10 +25,6 @@ @SpringBootTest class WaitingRepositoryTest { - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(0, 0, 0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(23, 59, 59)); @Autowired private WaitingRepository waitingRepository; @Autowired @@ -39,6 +35,10 @@ class WaitingRepositoryTest { private Waiting waiting1; private Waiting waiting2; private Waiting waiting3; + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); @BeforeEach void setUp() { From 85d9c77f3c0d75409e116cb0c5fc6eb5c722edc2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 13:52:26 +0900 Subject: [PATCH 135/603] =?UTF-8?q?feat=20:=20Id=20=EC=9D=B8=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EC=95=88=20=EB=B0=9B=EB=8A=94=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20dto=20=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/data/reservation/ReservationData.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 5cb18087..862ccfe6 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -39,11 +39,17 @@ public static ReservationTime getReservationTimePreOccupied() { return reservationTime; } - public static CreateReservationRequest getCreateReservationRequest(Long reservationTimeId) { + public static CreateReservationRequest getCreateReservationRequestWithId(Long reservationTimeId) { return CreateReservationRequest.builder() .reservationTimeId(reservationTimeId) .peopleCount(4) .build(); } + public static CreateReservationRequest getCreateReservationRequest() { + return CreateReservationRequest.builder() + .reservationTimeId(1L) + .peopleCount(4) + .build(); + } } From 331d697c45b4f57cccd10fad360abbcc0b20e7b5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 13:53:16 +0900 Subject: [PATCH 136/603] =?UTF-8?q?feat=20:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacadeTest.java | 2 +- .../reservation/controller/ReservationControllerTest.java | 4 ++-- .../reservation/service/ReservationServiceTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 56a0ae73..29876a05 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -32,7 +32,7 @@ class ReservationFacadeTest { @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") void preOccupyReservation() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest( + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationService.validateReservationAndSave( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index c60eac1f..d7cd7035 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -26,7 +26,7 @@ class ReservationControllerTest extends BaseIntegrationTest { void preOccupyReservation() throws Exception { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequest( + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations") @@ -43,7 +43,7 @@ void preOccupyReservation() throws Exception { void schedulerTest() throws Exception { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequest( + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations") diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index ff0eb1a6..02900aa2 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -39,7 +39,7 @@ void validateReservation() { //given ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequest( + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -63,7 +63,7 @@ void alreadyPreOccupied() { //given ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequest( + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); From 5f21fd953d2e5f91d03f648accdeaa03fd490674 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 13:53:40 +0900 Subject: [PATCH 137/603] =?UTF-8?q?feat=20:=20ReservationData=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/data/reservation/ReservationData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 862ccfe6..17750d2c 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -39,12 +39,14 @@ public static ReservationTime getReservationTimePreOccupied() { return reservationTime; } - public static CreateReservationRequest getCreateReservationRequestWithId(Long reservationTimeId) { + public static CreateReservationRequest getCreateReservationRequestWithId( + Long reservationTimeId) { return CreateReservationRequest.builder() .reservationTimeId(reservationTimeId) .peopleCount(4) .build(); } + public static CreateReservationRequest getCreateReservationRequest() { return CreateReservationRequest.builder() .reservationTimeId(1L) From fcd3c0996d369fdf9d1e5da27e1dd19e9d489dc9 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 16:00:57 +0900 Subject: [PATCH 138/603] =?UTF-8?q?refactor=20:=20ObjectMapper=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20final=EB=A1=9C=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/filter/ExceptionHandlerFilter.java | 3 ++- .../security/service/CustomOAuth2SuccessHandler.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java b/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java index 6dbe0f02..7279a08e 100644 --- a/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java +++ b/src/main/java/com/prgrms/catchtable/security/filter/ExceptionHandlerFilter.java @@ -17,6 +17,8 @@ @Component public class ExceptionHandlerFilter extends GenericFilter { + private final ObjectMapper mapper = new ObjectMapper(); + @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { @@ -35,7 +37,6 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } private String toJson(ErrorResponse response) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(response); } diff --git a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java index 9af11675..2603a238 100644 --- a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java +++ b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java @@ -19,6 +19,7 @@ @RequiredArgsConstructor public class CustomOAuth2SuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { + private final ObjectMapper objectMapper = new ObjectMapper(); private final MemberService memberService; @Override @@ -38,7 +39,6 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo } public String tokenToJson(Token token) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.writeValueAsString(token); } From a23b0bee3d43904658dbcab3e702d808724de62d Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 16:01:26 +0900 Subject: [PATCH 139/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index b04f5260..f61d25a9 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -7,7 +7,7 @@ @RequiredArgsConstructor public enum ErrorCode { NOT_EXIST_MEMBER("존재하지 않는 회원입니다."), - NOT_FOUND_REFRESH_TOKEN("알 수 없는 RefreshToken입니다."), + NOT_FOUND_REFRESH_TOKEN("유효하지 않은 RefreshToken입니다."), TOKEN_EXPIRES("토큰이 만료되었습니다. 다시 로그인 해 주세요."), ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), From 5ed28d1feee9c78a7f82963046c79cd914324ad6 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 2 Jan 2024 16:48:30 +0900 Subject: [PATCH 140/603] =?UTF-8?q?style=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=20=EA=B3=B5=EA=B0=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/service/CustomOAuth2SuccessHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java index 2603a238..fa0f6ae3 100644 --- a/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java +++ b/src/main/java/com/prgrms/catchtable/security/service/CustomOAuth2SuccessHandler.java @@ -48,6 +48,4 @@ private void sendTokenJson(HttpServletResponse response, String tokenJson) throw response.setContentLength(tokenJson.getBytes().length); response.getWriter().write(tokenJson); } - - } From 16b34ad16d035387816667cca201198996cf1fc3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:53:29 +0900 Subject: [PATCH 141/603] =?UTF-8?q?feat=20:=20waitingOrder=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EB=8C=80=EA=B8=B0?= =?UTF-8?q?=20=EC=9E=94=EC=97=AC=20=ED=9A=9F=EC=88=98=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/domain/Waiting.java | 27 ++++++++++++------- .../catchtable/waiting/dto/WaitingMapper.java | 9 +++---- .../waiting/service/WaitingService.java | 13 +++++---- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index e12443bb..84e537e0 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,5 +1,10 @@ package com.prgrms.catchtable.waiting.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.NO_SHOW; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; @@ -7,6 +12,7 @@ import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; @@ -35,9 +41,6 @@ public class Waiting extends BaseEntity { @Column(name = "waiting_number") private int waitingNumber; - @Column(name = "waiting_order") - private int waitingOrder; - @Column(name = "people_count") private int peopleCount; @@ -45,8 +48,8 @@ public class Waiting extends BaseEntity { @Enumerated(STRING) private WaitingStatus status; - @Column(name = "delay_remaining_count") - private int delayRemainingCount; + @Column(name = "postpone_remaining_count") + private int postponeRemainingCount; @OneToOne(fetch = LAZY) @JoinColumn(name = "member_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) @@ -57,13 +60,19 @@ public class Waiting extends BaseEntity { private Shop shop; @Builder - public Waiting(int waitingNumber, int waitingOrder, int peopleCount, Member member, Shop shop) { + public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { this.waitingNumber = waitingNumber; - this.waitingOrder = waitingOrder; this.peopleCount = peopleCount; this.member = member; this.shop = shop; - status = WaitingStatus.PROGRESS; - delayRemainingCount = 2; + status = PROGRESS; + postponeRemainingCount = 2; + } + + public void completeWaiting() { + if (status == NO_SHOW || status == CANCELED) { + throw new BadRequestCustomException(CAN_NOT_COMPLETE_WAITING); + } + status = COMPLETED; } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index db8912fd..bf989af6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -11,25 +11,24 @@ public class WaitingMapper { // dto -> entity - public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, - int waitingOrder, Member member, Shop shop) { + public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, Member member, + Shop shop) { return Waiting.builder() .waitingNumber(waitingNumber) - .waitingOrder(waitingOrder) .peopleCount(request.peopleCount()) .member(member) .shop(shop).build(); } // entity -> dto - public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting) { + public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting, int waitingOrder) { return CreateWaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) .peopleCount(waiting.getPeopleCount()) .waitingNumber(waiting.getWaitingNumber()) - .waitingOrder(waiting.getWaitingOrder()) + .waitingOrder(waitingOrder) .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 647796e8..7be73945 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -46,19 +46,18 @@ public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest req validateIfMemberWaitingExists(member); // 대기 번호 생성 - int waitingNumber = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, - PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; + int waitingNumber = (waitingRepository.countByShopAndCreatedAtBetween(shop, + START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // 대기 순서 생성 - int waitingOrder = (waitingRepository.countByShopAndCreatedAtBetween(shop, - START_DATE_TIME, END_DATE_TIME)).intValue() + 1; + int waitingOrder = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, + PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // waiting 저장 - Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, waitingOrder, member, - shop); + Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, member, shop); Waiting savedWaiting = waitingRepository.save(waiting); - return WaitingMapper.toCreateWaitingResponse(savedWaiting); + return WaitingMapper.toCreateWaitingResponse(savedWaiting, waitingOrder); } private void validateIfMemberWaitingExists(Member member) { From d651d55df57751896a689b255a4c3fa7cb5d290c Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:54:33 +0900 Subject: [PATCH 142/603] =?UTF-8?q?feat=20:=20dto=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/WaitingController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index 4e75aff0..ba500d1c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -3,6 +3,7 @@ import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; import com.prgrms.catchtable.waiting.service.WaitingService; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -20,7 +21,7 @@ public class WaitingController { @PostMapping("/{shopId}") public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, - @RequestBody CreateWaitingRequest request) { + @Valid @RequestBody CreateWaitingRequest request) { CreateWaitingResponse response = waitingService.createWaiting(shopId, request); return ResponseEntity.ok(response); } From c3aca5e1381f538de4db22aa38efd39963a18f82 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:55:47 +0900 Subject: [PATCH 143/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=82=B4=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/service/WaitingServiceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index e22924cf..1531773a 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -47,7 +47,6 @@ void createWaiting() { .member(member) .shop(shop) .waitingNumber(1) - .waitingOrder(1) .peopleCount(2) .build(); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); From 07db284bbedc95e9bf2cedd4594c9eb087de1e31 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:56:27 +0900 Subject: [PATCH 144/603] =?UTF-8?q?feat=20:=20waitingFixture=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=9D=B4=EC=97=90=20=EB=94=B0=EB=A5=B8?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=EC=86=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/fixture/WaitingFixture.java | 24 +++++ .../repository/WaitingRepositoryTest.java | 94 +++++++------------ 2 files changed, 60 insertions(+), 58 deletions(-) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java new file mode 100644 index 00000000..b27f5164 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -0,0 +1,24 @@ +package com.prgrms.catchtable.waiting.fixture; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.waiting.domain.Waiting; + +public class WaitingFixture { + + public static Waiting waiting(Member member, Shop shop, int waitingNumber) { + return Waiting.builder() + .member(member) + .shop(shop) + .waitingNumber(waitingNumber) + .peopleCount(2) + .build(); + } + + public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { + Waiting waiting = waiting(member, shop, waitingNumber); + waiting.completeWaiting(); + return waiting; + } + +} \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 0afddfc3..1bbdea2d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -10,10 +10,11 @@ import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -27,14 +28,15 @@ class WaitingRepositoryTest { @Autowired private WaitingRepository waitingRepository; + @Autowired private MemberRepository memberRepository; + @Autowired private ShopRepository shopRepository; private Shop shop; - private Waiting waiting1; - private Waiting waiting2; - private Waiting waiting3; + private Member member1, member2, member3; + private Waiting yesterdayWaiting, completedWaiting, normalWaiting; private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0, 0)); private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), @@ -42,74 +44,50 @@ class WaitingRepositoryTest { @BeforeEach void setUp() { - Member member1 = MemberFixture.member("test1"); - Member member2 = MemberFixture.member("test2"); - Member member3 = MemberFixture.member("test3"); - - memberRepository.save(member1); - memberRepository.save(member2); - memberRepository.save(member3); + member1 = MemberFixture.member("test1"); + member2 = MemberFixture.member("test2"); + member3 = MemberFixture.member("test3"); + memberRepository.saveAll(List.of(member1, member2, member3)); shop = ShopFixture.shop(); shopRepository.save(shop); - - waiting1 = Waiting.builder() - .member(member1) - .shop(shop) - .waitingNumber(1) - .waitingOrder(1) - .peopleCount(2) - .build(); - - waiting2 = Waiting.builder() - .member(member2) - .shop(shop) - .waitingNumber(2) - .waitingOrder(2) - .peopleCount(2) - .build(); - - waiting3 = Waiting.builder() - .member(member3) - .shop(shop) - .waitingNumber(3) - .waitingOrder(3) - .peopleCount(2) - .build(); - waitingRepository.save(waiting1); - waitingRepository.save(waiting2); - waitingRepository.save(waiting3); } - @DisplayName("특정 가게의 당일 대기 인원을 조회할 수 있다.") + @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test - void countByShopAndStatusAndCreatedAtBetween() { - //given - ReflectionTestUtils.setField(waiting1, "createdAt", LocalDateTime.now().minusDays(1)); - waitingRepository.save(waiting1); //어제자 대기 생성 - ReflectionTestUtils.setField(waiting2, "status", WaitingStatus.COMPLETED); - waitingRepository.save(waiting2); //입장상태 대기 생성 + void countByShopAndCreatedAtBetween() { + yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); + completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); + normalWaiting = WaitingFixture.waiting(member3, shop, 3); + waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); + + ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", + LocalDateTime.now().minusDays(1)); + waitingRepository.save(yesterdayWaiting); //when - Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, PROGRESS, - START_DATE_TIME, END_DATE_TIME); + Long count = waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, + END_DATE_TIME); //then - assertThat(count).isEqualTo(1L); + assertThat(count).isEqualTo(2L); //waiting2, waiting3 } - @DisplayName("특정 가게의 당일 대기 인원을 조회할 수 있다.") + @DisplayName("특정 가게의 당일 대기 순서를 조회할 수 있다.") @Test - void countByShopAndCreatedAtBetween() { - //given - ReflectionTestUtils.setField(waiting1, "createdAt", LocalDateTime.now().minusDays(1)); - waitingRepository.save(waiting1); - ReflectionTestUtils.setField(waiting2, "status", WaitingStatus.COMPLETED); - waitingRepository.save(waiting2); + void countByShopAndStatusAndCreatedAtBetween() { + yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); + completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); + normalWaiting = WaitingFixture.waiting(member3, shop, 3); + waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); + + ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", + LocalDateTime.now().minusDays(1)); + waitingRepository.save(yesterdayWaiting); //when - Long count = waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, - END_DATE_TIME); + Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, PROGRESS, + START_DATE_TIME, END_DATE_TIME); //then - assertThat(count).isEqualTo(2L); + assertThat(count).isEqualTo(1L); //waiting3 } } \ No newline at end of file From 18fea513b780b8de46a5d3c7e990da5b3627a63f Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:57:21 +0900 Subject: [PATCH 145/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaitingControllerTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java new file mode 100644 index 00000000..377d4078 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -0,0 +1,85 @@ +package com.prgrms.catchtable.waiting.controller; + +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; + +class WaitingControllerTest extends BaseIntegrationTest { + + @Autowired + private ShopRepository shopRepository; + + @Autowired + MemberRepository memberRepository; + + @Autowired + WaitingRepository waitingRepository; + + private Shop shop; + List waitings; + + @BeforeEach + void setUp() { + shop = ShopFixture.shop(); + shopRepository.save(shop); + + Member member1 = MemberFixture.member("test1@naver.com"); + Member member2 = MemberFixture.member("test2@naver.com"); + Member member3 = MemberFixture.member("test3@naver.com"); + memberRepository.saveAll(List.of(member1, member2, member3)); + + Waiting waiting1 = Waiting.builder() + .member(member2) + .shop(shop) + .waitingNumber(1) + .peopleCount(2) + .build(); + Waiting waiting2 = Waiting.builder() + .member(member3) + .shop(shop) + .waitingNumber(2) + .peopleCount(2) + .build(); + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2)); + waiting2.completeWaiting(); + } + + @DisplayName("웨이팅 생성 API를 호출할 수 있다.") + @Test + void createWaiting() throws Exception { + //given + CreateWaitingRequest request = CreateWaitingRequest + .builder() + .peopleCount(2).build(); + // when, then + mockMvc.perform(post("/waitings/{shopId}", 1) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopId").value(shop.getId())) + .andExpect(jsonPath("$.shopName").value(shop.getName())) + .andExpect(jsonPath("$.waitingOrder").value(2)) + .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) + .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) + .andDo(MockMvcResultHandlers.print()); + + } +} From 6a957ecd5f45a10c3c795eb7ba15cd5014985678 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:57:42 +0900 Subject: [PATCH 146/603] =?UTF-8?q?feat=20:=20MemberFixture=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/member/MemberFixture.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index 32b44a6c..1dff7c4f 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -6,9 +6,10 @@ public class MemberFixture { - public static Member member(String name) { + public static Member member(String email) { return Member.builder() - .name(name) + .name("member") + .email(email) .phoneNumber("010-1111-1111") .gender(Gender.FEMALE) .dateBirth(LocalDate.parse("2008-12-18")) From 077604c8917879290a8e685427ce280cb87d6fc8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 2 Jan 2024 17:58:40 +0900 Subject: [PATCH 147/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/common/exception/ErrorCode.java | 2 +- .../waiting/controller/WaitingControllerTest.java | 9 +++------ .../waiting/repository/WaitingRepositoryTest.java | 10 ++++------ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index f61d25a9..cff7cd26 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -15,7 +15,7 @@ public enum ErrorCode { NOT_EXIST_SHOP("존재하지 않는 매장입니다."), NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), - ALREADY_CANCELED_WAITING("이미 웨이팅을 취소하였습니다."), + CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 377d4078..a13e8176 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -24,17 +24,14 @@ class WaitingControllerTest extends BaseIntegrationTest { - @Autowired - private ShopRepository shopRepository; - @Autowired MemberRepository memberRepository; - @Autowired WaitingRepository waitingRepository; - - private Shop shop; List waitings; + @Autowired + private ShopRepository shopRepository; + private Shop shop; @BeforeEach void setUp() { diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 1bbdea2d..1fa3c6c0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -26,21 +26,19 @@ @SpringBootTest class WaitingRepositoryTest { + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); @Autowired private WaitingRepository waitingRepository; - @Autowired private MemberRepository memberRepository; - @Autowired private ShopRepository shopRepository; private Shop shop; private Member member1, member2, member3; private Waiting yesterdayWaiting, completedWaiting, normalWaiting; - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(0, 0, 0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(23, 59, 59)); @BeforeEach void setUp() { From a06140eef17dd44b27e4ed79fb8480339a9c1c13 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 21:27:32 +0900 Subject: [PATCH 148/603] =?UTF-8?q?feat=20:=20=ED=86=B5=ED=95=A9=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20base=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=ED=8A=B8=EB=9E=9C=EC=9E=AD=EC=85=98=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/base/BaseIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index c85cc279..bd8f2e50 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -8,7 +8,6 @@ import org.springframework.transaction.annotation.Transactional; @SpringBootTest -@Transactional @AutoConfigureMockMvc public abstract class BaseIntegrationTest { From 1ddf3da141456c823ce1b3a41622420e515dd208 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 21:47:47 +0900 Subject: [PATCH 149/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 00fb3a34..295d69ec 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -18,8 +18,13 @@ public class ReservationController { private final ReservationFacade reservationFacade; @PostMapping - public ResponseEntity createReservationResponse( + public ResponseEntity preOccupyReservation( @RequestBody CreateReservationRequest request) { return ResponseEntity.ok(reservationFacade.preOccupyReservation(request)); } + + @PostMapping("/success") + public ResponseEntity registerReservation(@RequestBody CreateReservationRequest request){ + return ResponseEntity.ok(reservationFacade.registerReservation(request)); + } } From d634b3f41c357e7145b4ea9706f7a2de3159dcfc Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 21:48:51 +0900 Subject: [PATCH 150/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20api=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20-=20=EC=9D=91=EB=8B=B5=20=EA=B0=92=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20-=20=EC=98=88=EC=95=BD=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20isOccupied=20=EB=B3=80=EA=B2=BD=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index d7cd7035..34423372 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -8,26 +8,46 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; - +@Transactional class ReservationControllerTest extends BaseIntegrationTest { @Autowired private ReservationTimeRepository reservationTimeRepository; + @Autowired + private ShopRepository shopRepository; + + @BeforeEach + void setUp(){ + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + reservationTime.insertShop(savedShop); + reservationTimeRepository.save(reservationTime); + } + @Test @DisplayName("예약 선점 api 호출에 성공한다.") void preOccupyReservation() throws Exception { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + List all = reservationTimeRepository.findAll(); + ReservationTime reservationTime = all.get(0); + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( - savedReservationTime.getId()); + reservationTime.getId()); mockMvc.perform(post("/reservations") .contentType(APPLICATION_JSON) @@ -41,10 +61,11 @@ void preOccupyReservation() throws Exception { @Test @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") void schedulerTest() throws Exception { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + List all = reservationTimeRepository.findAll(); + ReservationTime reservationTime = all.get(0); + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( - savedReservationTime.getId()); + reservationTime.getId()); mockMvc.perform(post("/reservations") .contentType(APPLICATION_JSON) @@ -55,5 +76,23 @@ void schedulerTest() throws Exception { assertThat(reservationTime.isPreOccupied()).isFalse(); } + @Test + void resigerReservation() throws Exception { + List all = reservationTimeRepository.findAll(); + ReservationTime reservationTime = all.get(0); + + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + reservationTime.getId()); + + mockMvc.perform(post("/reservations/success") + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) + .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) + .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); + + assertThat(reservationTime.isOccupied()).isTrue(); + } } \ No newline at end of file From bdc9b23f9e7787f07b2707c6182eb5e99d1b43b1 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 21:58:32 +0900 Subject: [PATCH 151/603] =?UTF-8?q?feat=20:=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=EB=90=9C=20=EC=98=88=EC=95=BD=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=EB=B0=9C=EC=83=9D=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 34423372..0f5bc245 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.reservation.controller; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -77,6 +78,7 @@ void schedulerTest() throws Exception { } @Test + @DisplayName("예약 등록 api 호출에 성공한다.") void resigerReservation() throws Exception { List all = reservationTimeRepository.findAll(); ReservationTime reservationTime = all.get(0); @@ -95,4 +97,25 @@ void resigerReservation() throws Exception { assertThat(reservationTime.isOccupied()).isTrue(); } + @Test + @DisplayName("이미 예약이 된 시간에 대해 예약 등록 api 호출 시 에러 메세지가 반환된다.") + void registerReservationWithException() throws Exception { + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + reservationTime.reverseOccupied(); + List shops = shopRepository.findAll(); + Shop shop = shops.get(0); + reservationTime.insertShop(shop); + + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId(savedReservationTime.getId()); + mockMvc.perform(post("/reservations/success") + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value(ALREADY_OCCUPIED_RESERVATION_TIME.getMessage())); + + + } + } \ No newline at end of file From 819ab63e9a930e9e329be7d7a6bef2ce80b3adef Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 22:08:22 +0900 Subject: [PATCH 152/603] =?UTF-8?q?feat=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 3 ++- .../catchtable/common/base/BaseIntegrationTest.java | 1 - .../controller/ReservationControllerTest.java | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 295d69ec..cef0f3b5 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -24,7 +24,8 @@ public ResponseEntity preOccupyReservation( } @PostMapping("/success") - public ResponseEntity registerReservation(@RequestBody CreateReservationRequest request){ + public ResponseEntity registerReservation( + @RequestBody CreateReservationRequest request) { return ResponseEntity.ok(reservationFacade.registerReservation(request)); } } diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index bd8f2e50..1d86293a 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -5,7 +5,6 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; @SpringBootTest @AutoConfigureMockMvc diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 0f5bc245..43cb12eb 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -32,7 +32,7 @@ class ReservationControllerTest extends BaseIntegrationTest { private ShopRepository shopRepository; @BeforeEach - void setUp(){ + void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); @@ -87,8 +87,8 @@ void resigerReservation() throws Exception { reservationTime.getId()); mockMvc.perform(post("/reservations/success") - .contentType(APPLICATION_JSON) - .content(asJsonString(request))) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) @@ -108,7 +108,8 @@ void registerReservationWithException() throws Exception { ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId(savedReservationTime.getId()); + CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + savedReservationTime.getId()); mockMvc.perform(post("/reservations/success") .contentType(APPLICATION_JSON) .content(asJsonString(request))) From 4db60e70b426b53a6ec8c97af0532ee4e8c31ff3 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 2 Jan 2024 22:26:40 +0900 Subject: [PATCH 153/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/ReservationFacadeTest.java | 6 +++--- .../controller/ReservationControllerTest.java | 14 +++++++------- .../domain/ReservationTimeTest.java | 6 +++--- .../fixture/ReservationFixture.java} | 4 ++-- .../ReservationTimeRepositoryTest.java | 4 ++-- .../service/ReservationServiceTest.java | 18 +++++++++--------- 6 files changed, 26 insertions(+), 26 deletions(-) rename src/test/java/com/prgrms/catchtable/{common/data/reservation/ReservationData.java => reservation/fixture/ReservationFixture.java} (95%) diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 29876a05..9e42f069 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -5,7 +5,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; @@ -31,8 +31,8 @@ class ReservationFacadeTest { @Test @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") void preOccupyReservation() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationService.validateReservationAndSave( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 43cb12eb..0c16ba51 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -8,7 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -36,7 +36,7 @@ void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); } @@ -47,7 +47,7 @@ void preOccupyReservation() throws Exception { List all = reservationTimeRepository.findAll(); ReservationTime reservationTime = all.get(0); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); mockMvc.perform(post("/reservations") @@ -65,7 +65,7 @@ void schedulerTest() throws Exception { List all = reservationTimeRepository.findAll(); ReservationTime reservationTime = all.get(0); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); mockMvc.perform(post("/reservations") @@ -83,7 +83,7 @@ void resigerReservation() throws Exception { List all = reservationTimeRepository.findAll(); ReservationTime reservationTime = all.get(0); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); mockMvc.perform(post("/reservations/success") @@ -100,7 +100,7 @@ void resigerReservation() throws Exception { @Test @DisplayName("이미 예약이 된 시간에 대해 예약 등록 api 호출 시 에러 메세지가 반환된다.") void registerReservationWithException() throws Exception { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.reverseOccupied(); List shops = shopRepository.findAll(); Shop shop = shops.get(0); @@ -108,7 +108,7 @@ void registerReservationWithException() throws Exception { ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations/success") .contentType(APPLICATION_JSON) diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java index d8ff901d..a79fc8c4 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,7 +11,7 @@ class ReservationTimeTest { @Test @DisplayName("예약 선점 여부 변경에 성공한다") void reversePreOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -20,7 +20,7 @@ void reversePreOccupied() { @Test @DisplayName("예약 여부 변경에 성공한다.") void reverseOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.reverseOccupied(); assertThat(reservationTime.isOccupied()).isTrue(); diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java similarity index 95% rename from src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java rename to src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index 17750d2c..730faf1c 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.common.data.reservation; +package com.prgrms.catchtable.reservation.fixture; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; @@ -10,7 +10,7 @@ import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; -public class ReservationData { +public class ReservationFixture { public static Reservation getReservation() { return Reservation.builder() diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index 56a42d07..95da2910 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -31,7 +31,7 @@ void findReservationTimeWithShop() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); ReservationTime savedTime = reservationTimeRepository.save(reservationTime); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 02900aa2..d7c2bb36 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -7,7 +7,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -37,9 +37,9 @@ class ReservationServiceTest { @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { //given - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -61,9 +61,9 @@ void validateReservation() { @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") void alreadyPreOccupied() { //given - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -78,8 +78,8 @@ void alreadyPreOccupied() { @Test @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") void registerReservation() { - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) @@ -103,8 +103,8 @@ void registerReservation() { @Test @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") void registerReservationAlreadyOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); reservationTime.reverseOccupied(); when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( From 3e727bdbf21d837150db9a00ae6d6e9d16a55d4e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:06:44 +0900 Subject: [PATCH 154/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=9D=91=EB=8B=B5=20dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/GetAllReservationResponse.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java new file mode 100644 index 00000000..b16ec69b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java @@ -0,0 +1,17 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record GetAllReservationResponse(Long reservationId, + @JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") + LocalDateTime date, + String shopName, + int peopleCount, + ReservationStatus status) { + +} From 6e441dbb861d5c23d226236d66ba1698a2cd4f32 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:07:46 +0900 Subject: [PATCH 155/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index e4e2642a..a6a779f8 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -1,8 +1,14 @@ package com.prgrms.catchtable.reservation.repository; import com.prgrms.catchtable.reservation.domain.Reservation; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface ReservationRepository extends JpaRepository { + @Query("select r from Reservation r " + + "join fetch r.reservationTime rt " + + "join fetch rt.shop") + List findAllWithReservationTimeAndShop(); } From 5f7060e284a0bd060bc723e42efea3084ceafd3f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:08:18 +0900 Subject: [PATCH 156/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index fd567aaf..6df87f2f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -9,9 +9,12 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -51,9 +54,16 @@ public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest re Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) - .shop(reservationTime.getShop()) .reservationTime(reservationTime) .build(); return reservationRepository.save(reservation); } + + @Transactional(readOnly = true) + public List getAllReservation(){ + List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + return reservations.stream() + .map(ReservationMapper::toGetAllReservationRepsonse) + .toList(); + } } From 5fe0bcdf9b0706295391c2ee53216cb944cc402e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:08:45 +0900 Subject: [PATCH 157/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=9D=91=EB=8B=B5=20dto=20mapper?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/mapper/ReservationMapper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index f58be265..d6732fbe 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -18,4 +19,14 @@ public static CreateReservationResponse toCreateReservationResponse(Reservation .build(); } + public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation reservation){ + return GetAllReservationResponse.builder() + .reservationId(reservation.getId()) + .date(reservation.getReservationTime().getTime()) + .shopName(reservation.getShop().getName()) + .peopleCount(reservation.getPeopleCount()) + .status(reservation.getStatus()) + .build(); + } + } From aefef17172e67f09c116801ca7b63657f1319a72 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:09:29 +0900 Subject: [PATCH 158/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1=EC=9E=90=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20-=20=EA=B8=B0=EC=A1=B4=20:=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=8B=9C=EA=B0=84,=20=EB=A7=A4=EC=9E=A5=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20-=20=EB=B3=80=EA=B2=BD=20:=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EB=A7=8C=20=EB=B0=9B=EA=B3=A0=20=EB=A7=A4?= =?UTF-8?q?=EC=9E=A5=ED=95=84=EB=93=9C=EB=8A=94=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EC=9D=98=20=EB=A7=A4=EC=9E=A5=EC=9D=84=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index db66a48b..e933348b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -52,12 +52,12 @@ public class Reservation extends BaseEntity { private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount, Shop shop, + public Reservation(ReservationStatus status, int peopleCount, ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; - this.shop = shop; this.reservationTime = reservationTime; + this.shop = reservationTime.getShop(); } } From 3f977eb356279f925e3ecb3f08ff10df10963d58 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:10:48 +0900 Subject: [PATCH 159/603] =?UTF-8?q?feat=20:=20=EC=83=9D=EC=84=B1=EC=9E=90?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=83=9D=EC=84=B1=20=EA=B3=BC=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/data/reservation/ReservationData.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 17750d2c..c5e10886 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -12,11 +12,11 @@ public class ReservationData { - public static Reservation getReservation() { + public static Reservation getReservation(ReservationTime reservationTime) { return Reservation.builder() .status(COMPLETED) .peopleCount(4) - .reservationTime(getReservationTimeNotPreOccupied()) + .reservationTime(reservationTime) .build(); } From d3cac5164e8e4df51aab0852d2652f29290e686a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:11:11 +0900 Subject: [PATCH 160/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20reposit?= =?UTF-8?q?ory=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepositoryTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java new file mode 100644 index 00000000..4e67d0d9 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -0,0 +1,54 @@ +package com.prgrms.catchtable.reservation.repository; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import jakarta.persistence.EntityManager; +import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigurationPackage; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = NONE) +class ReservationRepositoryTest { + @Autowired + private ReservationRepository reservationRepository; + @Autowired + private ShopRepository shopRepository; + @Autowired + private ReservationTimeRepository reservationTimeRepository; + + @Test + @DisplayName("예약 엔티티 조회 시 페치 조인을 통해 예약시간과 매장 엔티티를 한번에 조회한다.") + void findAllWithReservationTimeAndShop(){ + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + reservationTime.insertShop(savedShop); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + + Reservation reservation = ReservationData.getReservation(savedReservationTime); + reservationRepository.save(reservation); + + List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + Reservation findReservation = reservations.get(0); + + assertAll( + () -> assertThat(findReservation.getReservationTime()).isEqualTo(savedReservationTime), + () -> assertThat(findReservation.getShop()).isEqualTo(savedShop) + ); + } + +} \ No newline at end of file From 19d8065fb0642c0cd8577e61fb5340a932eee7f5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:11:48 +0900 Subject: [PATCH 161/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20-=20=EC=A0=95=EC=83=81=20=EC=A1=B0=ED=9A=8C=20-=20?= =?UTF-8?q?=EC=95=84=EB=AC=B4=EA=B2=83=EB=8F=84=20=EC=97=86=EC=9D=84=20?= =?UTF-8?q?=EC=8B=9C=20=EB=B0=98=ED=99=98=20X=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 02900aa2..ac47a84e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -12,8 +12,10 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -83,7 +85,6 @@ void registerReservation() { Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) - .shop(reservationTime.getShop()) .reservationTime(reservationTime) .build(); @@ -114,4 +115,31 @@ void registerReservationAlreadyOccupied() { () -> reservationService.validateReservationAndSaveIsEmpty(request)); } + @Test + @DisplayName("예약 전체 조회를 할 수 있다") + void getAllReservation(){ + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + Reservation reservation = ReservationData.getReservation(reservationTime); + + when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of(reservation)); + List all = reservationService.getAllReservation(); + GetAllReservationResponse findReservation = all.get(0); + + assertAll( + () -> assertThat(findReservation.date()).isEqualTo(reservation.getReservationTime().getTime()), + () -> assertThat(findReservation.peopleCount()).isEqualTo(reservation.getPeopleCount()), + () -> assertThat(findReservation.shopName()).isEqualTo(reservation.getShop().getName()), + () -> assertThat(findReservation.status()).isEqualTo(reservation.getStatus()) + ); + } + + @Test + @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") + void getAllReservationWithNoResult(){ + when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); + + List all = reservationService.getAllReservation(); + assertThat(all.size()).isZero(); + } + } \ No newline at end of file From 937ae7db1050ee034860646a1cc3127710525b1b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 02:12:15 +0900 Subject: [PATCH 162/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/mapper/ReservationMapper.java | 2 +- .../reservation/service/ReservationService.java | 2 +- .../repository/ReservationRepositoryTest.java | 10 ++++------ .../reservation/service/ReservationServiceTest.java | 10 ++++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index d6732fbe..3abb6220 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -19,7 +19,7 @@ public static CreateReservationResponse toCreateReservationResponse(Reservation .build(); } - public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation reservation){ + public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation reservation) { return GetAllReservationResponse.builder() .reservationId(reservation.getId()) .date(reservation.getReservationTime().getTime()) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 6df87f2f..54a0e7bf 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -60,7 +60,7 @@ public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest re } @Transactional(readOnly = true) - public List getAllReservation(){ + public List getAllReservation() { List reservations = reservationRepository.findAllWithReservationTimeAndShop(); return reservations.stream() .map(ReservationMapper::toGetAllReservationRepsonse) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 4e67d0d9..e38736e5 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.reservation.repository; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.common.data.reservation.ReservationData; @@ -10,19 +10,17 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; -import jakarta.persistence.EntityManager; import java.util.List; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @DataJpaTest @AutoConfigureTestDatabase(replace = NONE) class ReservationRepositoryTest { + @Autowired private ReservationRepository reservationRepository; @Autowired @@ -32,7 +30,7 @@ class ReservationRepositoryTest { @Test @DisplayName("예약 엔티티 조회 시 페치 조인을 통해 예약시간과 매장 엔티티를 한번에 조회한다.") - void findAllWithReservationTimeAndShop(){ + void findAllWithReservationTimeAndShop() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index ac47a84e..e377af2d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -117,16 +117,18 @@ void registerReservationAlreadyOccupied() { @Test @DisplayName("예약 전체 조회를 할 수 있다") - void getAllReservation(){ + void getAllReservation() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); Reservation reservation = ReservationData.getReservation(reservationTime); - when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of(reservation)); + when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn( + List.of(reservation)); List all = reservationService.getAllReservation(); GetAllReservationResponse findReservation = all.get(0); assertAll( - () -> assertThat(findReservation.date()).isEqualTo(reservation.getReservationTime().getTime()), + () -> assertThat(findReservation.date()).isEqualTo( + reservation.getReservationTime().getTime()), () -> assertThat(findReservation.peopleCount()).isEqualTo(reservation.getPeopleCount()), () -> assertThat(findReservation.shopName()).isEqualTo(reservation.getShop().getName()), () -> assertThat(findReservation.status()).isEqualTo(reservation.getStatus()) @@ -135,7 +137,7 @@ void getAllReservation(){ @Test @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") - void getAllReservationWithNoResult(){ + void getAllReservationWithNoResult() { when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); List all = reservationService.getAllReservation(); From 3715bcfe9d54a71a0c004d8d796208c70c7dc85b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 3 Jan 2024 03:37:01 +0900 Subject: [PATCH 163/603] =?UTF-8?q?feat=20:=20Test=20Member=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/member/MemberFixture.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index 32b44a6c..e9753dc3 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -14,4 +14,14 @@ public static Member member(String name) { .dateBirth(LocalDate.parse("2008-12-18")) .build(); } + + public static Member userDetailsMember(String email){ + return Member.builder() + .name("예시용") + .email(email) + .phoneNumber("010-1111-1111") + .gender(Gender.FEMALE) + .dateBirth(LocalDate.parse("2008-12-18")) + .build(); + } } From 7a19a975d3b61a569d43e0212d75945e1713b900 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 3 Jan 2024 03:37:23 +0900 Subject: [PATCH 164/603] feat : JwtTokenProvider Test --- .../jwt/provider/JwtTokenProviderTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java diff --git a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java new file mode 100644 index 00000000..d911aa9d --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java @@ -0,0 +1,76 @@ +package com.prgrms.catchtable.jwt.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.jwt.config.JwtConfig; +import com.prgrms.catchtable.jwt.service.JwtUserDetailsService; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class JwtTokenProviderTest { + @Mock + private JwtConfig config; + @Mock + private JwtUserDetailsService jwtUserDetailsService; + @InjectMocks + private JwtTokenProvider jwtTokenProvider; + private final String email = "abc1234@naver.com"; + private final String clientKey = "FLGs0worldbOS8CEdfSPW04mb0dkD9SKFlsob9WK9wW0WkdlskYof5142u3jdmsk"; + + @Test + @DisplayName("유효한 토큰 발급 후 토큰 검증 시, true를 반환한다.") + void validToken() { + //when + when(config.getClientSecret()).thenReturn(clientKey); + when(config.getExpiryMinute()).thenReturn(1); + when(config.getExpiryMinuteRefresh()).thenReturn(1); + Token token = jwtTokenProvider.createToken(email); + + //then + assertThat(jwtTokenProvider.validateToken(token.getAccessToken())).isTrue(); + assertThat(jwtTokenProvider.validateToken(token.getRefreshToken())).isTrue(); + } + + @Test + @DisplayName("유효 기간이 지난 토큰을 검증 시, false를 반환한다.") + void invalidToken() { + //when + when(config.getClientSecret()).thenReturn(clientKey); + when(config.getExpiryMinute()).thenReturn(0); + when(config.getExpiryMinuteRefresh()).thenReturn(0); + Token token = jwtTokenProvider.createToken(email); + + //then + assertThat(jwtTokenProvider.validateToken(token.getAccessToken())).isFalse(); + assertThat(jwtTokenProvider.validateToken(token.getRefreshToken())).isFalse(); + } + + @Test + @DisplayName("토큰을 통해서 Member Entity가 담긴 Authentication 반환") + void getAuthenticationTest() { + //given + Member member = MemberFixture.userDetailsMember(email); + + //when + when(config.getClientSecret()).thenReturn(clientKey); + when(config.getExpiryMinute()).thenReturn(1); + when(config.getExpiryMinuteRefresh()).thenReturn(1); + Token token = jwtTokenProvider.createToken(email); + + when(jwtUserDetailsService.loadUserByUsername(email)) + .thenReturn(member); + + //then + assertThat(jwtTokenProvider.getAuthentication(token.getAccessToken()).getPrincipal()) + .isEqualTo(member); + } +} \ No newline at end of file From e03d5f763fd55be4314a3b1c93c2b9c064ee6879 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 3 Jan 2024 03:39:08 +0900 Subject: [PATCH 165/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=A4=ED=8C=85=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/provider/JwtTokenProviderTest.java | 5 +++-- .../java/com/prgrms/catchtable/member/MemberFixture.java | 2 +- .../waiting/repository/WaitingRepositoryTest.java | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java index d911aa9d..524da87e 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java @@ -17,14 +17,15 @@ @ExtendWith(MockitoExtension.class) class JwtTokenProviderTest { + + private final String email = "abc1234@naver.com"; + private final String clientKey = "FLGs0worldbOS8CEdfSPW04mb0dkD9SKFlsob9WK9wW0WkdlskYof5142u3jdmsk"; @Mock private JwtConfig config; @Mock private JwtUserDetailsService jwtUserDetailsService; @InjectMocks private JwtTokenProvider jwtTokenProvider; - private final String email = "abc1234@naver.com"; - private final String clientKey = "FLGs0worldbOS8CEdfSPW04mb0dkD9SKFlsob9WK9wW0WkdlskYof5142u3jdmsk"; @Test @DisplayName("유효한 토큰 발급 후 토큰 검증 시, true를 반환한다.") diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index e9753dc3..fc056b09 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -15,7 +15,7 @@ public static Member member(String name) { .build(); } - public static Member userDetailsMember(String email){ + public static Member userDetailsMember(String email) { return Member.builder() .name("예시용") .email(email) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 0afddfc3..011d92b8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -25,6 +25,10 @@ @SpringBootTest class WaitingRepositoryTest { + private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(0, 0, 0)); + private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), + LocalTime.of(23, 59, 59)); @Autowired private WaitingRepository waitingRepository; @Autowired @@ -35,10 +39,6 @@ class WaitingRepositoryTest { private Waiting waiting1; private Waiting waiting2; private Waiting waiting3; - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(0, 0, 0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(23, 59, 59)); @BeforeEach void setUp() { From d07630d8f8abdc4908a0e63641d8bd8783206e3d Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 3 Jan 2024 07:18:55 +0900 Subject: [PATCH 166/603] =?UTF-8?q?feat=20:=20ShopFixture=20=EC=98=81?= =?UTF-8?q?=EC=97=85=20=EC=8B=9C=EA=B0=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/shop/domain/ShopTest.java | 8 ++++---- .../com/prgrms/catchtable/shop/fixture/ShopFixture.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java index ec7a8e74..6c552e9e 100644 --- a/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/domain/ShopTest.java @@ -15,8 +15,8 @@ class ShopTest { @Test void validate_shop_not_running_time() { //given - LocalTime beforeOpeningTime = LocalTime.of(10, 59); - LocalTime afterClosingTime = LocalTime.of(21, 1); + LocalTime beforeOpeningTime = LocalTime.of(5, 59); + LocalTime afterClosingTime = LocalTime.of(23, 1); Shop shop = ShopFixture.shop(); //when, then assertThrows( @@ -31,8 +31,8 @@ void validate_shop_not_running_time() { @Test void validate_shop_running_time() { //given - LocalTime openingTime = LocalTime.of(11, 0); - LocalTime closingTime = LocalTime.of(21, 0); + LocalTime openingTime = LocalTime.of(6, 0); + LocalTime closingTime = LocalTime.of(23, 0); Shop shop = ShopFixture.shop(); //when, then assertDoesNotThrow( diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 8b19cc62..6c0802c7 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -15,8 +15,8 @@ public static Shop shop() { .category(Category.WESTERN_FOOD) .address(new Address("서울시", "중구")) .capacity(30) - .openingTime(LocalTime.of(11, 0)) - .closingTime(LocalTime.of(21, 0)) + .openingTime(LocalTime.of(6, 0)) + .closingTime(LocalTime.of(23, 0)) .build(); } } From 35c14cfb9c47bb5f1aba4b0cffec6dccf3f3619a Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 3 Jan 2024 08:21:23 +0900 Subject: [PATCH 167/603] =?UTF-8?q?fix=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingController.java | 5 +++-- .../waiting/service/WaitingService.java | 5 +++-- .../controller/WaitingControllerDocsTest.java | 4 ++-- .../controller/WaitingControllerTest.java | 18 +++++++++++------- .../repository/WaitingRepositoryTest.java | 10 ++++++++++ .../waiting/service/WaitingServiceTest.java | 4 ++-- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index ba500d1c..e3adec2e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -19,10 +19,11 @@ public class WaitingController { private final WaitingService waitingService; - @PostMapping("/{shopId}") + @PostMapping("/{shopId}/{memberId}") public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, + @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - CreateWaitingResponse response = waitingService.createWaiting(shopId, request); + CreateWaitingResponse response = waitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 7be73945..0a7718c7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -34,9 +34,10 @@ public class WaitingService { private final MemberRepository memberRepository; private final ShopRepository shopRepository; - public CreateWaitingResponse createWaiting(Long shopId, CreateWaitingRequest request) { + public CreateWaitingResponse createWaiting(Long shopId, Long memberId, + CreateWaitingRequest request) { // 연관 엔티티 조회 - Member member = getMemberEntity(1L); + Member member = getMemberEntity(memberId); Shop shop = getShopEntity(shopId); // shop 영업 중인지 검증 diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java index 0200bcb8..8fcbab8d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -45,9 +45,9 @@ void createWaiting() throws Exception { .peopleCount(2) .build(); - given(waitingService.createWaiting(1L, request)).willReturn(response); + given(waitingService.createWaiting(1L, 1L, request)).willReturn(response); - mockMvc.perform(post("/waitings/{shopId}", 1) + mockMvc.perform(post("/waitings/{shopId}/{memberId}", 1, 1) .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index a13e8176..26b3a1de 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -32,25 +32,25 @@ class WaitingControllerTest extends BaseIntegrationTest { @Autowired private ShopRepository shopRepository; private Shop shop; + private Member member1, member2, member3; @BeforeEach void setUp() { shop = ShopFixture.shop(); shopRepository.save(shop); - - Member member1 = MemberFixture.member("test1@naver.com"); - Member member2 = MemberFixture.member("test2@naver.com"); - Member member3 = MemberFixture.member("test3@naver.com"); + member1 = MemberFixture.member("test1@naver.com"); + member2 = MemberFixture.member("test2@naver.com"); + member3 = MemberFixture.member("test3@naver.com"); memberRepository.saveAll(List.of(member1, member2, member3)); Waiting waiting1 = Waiting.builder() - .member(member2) + .member(member1) .shop(shop) .waitingNumber(1) .peopleCount(2) .build(); Waiting waiting2 = Waiting.builder() - .member(member3) + .member(member2) .shop(shop) .waitingNumber(2) .peopleCount(2) @@ -59,15 +59,19 @@ void setUp() { waiting2.completeWaiting(); } + @DisplayName("웨이팅 생성 API를 호출할 수 있다.") @Test void createWaiting() throws Exception { + System.out.println("member1.getId( = " + member1.getId()); + System.out.println("member2.getId( = " + member2.getId()); + System.out.println("member3.getId( = " + member3.getId()); //given CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); // when, then - mockMvc.perform(post("/waitings/{shopId}", 1) + mockMvc.perform(post("/waitings/{shopId}/{memberId}", shop.getId(), member3.getId()) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 1fa3c6c0..d352f53c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -15,15 +15,18 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.transaction.annotation.Transactional; @SpringBootTest +@Transactional class WaitingRepositoryTest { private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), @@ -51,6 +54,13 @@ void setUp() { shopRepository.save(shop); } + @AfterEach + void clear() { + memberRepository.deleteAll(); + waitingRepository.deleteAll(); + shopRepository.deleteAll(); + } + @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test void countByShopAndCreatedAtBetween() { diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 1531773a..f9ae2bd4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -51,12 +51,12 @@ void createWaiting() { .build(); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); given(waitingRepository.existsByMember(member)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); //when - CreateWaitingResponse response = waitingService.createWaiting(1L, request); + CreateWaitingResponse response = waitingService.createWaiting(1L, member.getId(), request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), From c5fd464c66790be9bab6c03ce7483c5eb90661b3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 3 Jan 2024 14:34:26 +0900 Subject: [PATCH 168/603] =?UTF-8?q?feat=20:=20ShopFixture24=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/album/waiting.adoc | 3 ++- .../prgrms/catchtable/shop/fixture/ShopFixture.java | 12 ++++++++++++ .../waiting/controller/WaitingControllerTest.java | 5 +---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/docs/asciidoc/api/album/waiting.adoc b/src/docs/asciidoc/api/album/waiting.adoc index 106a583d..7b3afde4 100644 --- a/src/docs/asciidoc/api/album/waiting.adoc +++ b/src/docs/asciidoc/api/album/waiting.adoc @@ -2,10 +2,11 @@ === 웨이팅 등록 ==== HTTP Request + include::{snippets}/waiting-create/http-request.adoc[] include::{snippets}/waiting-create/request-fields.adoc[] - ==== HTTP Response + include::{snippets}/waiting-create/http-response.adoc[] include::{snippets}/waiting-create/response-fields.adoc[] \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 6c0802c7..d31ac8b8 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -19,4 +19,16 @@ public static Shop shop() { .closingTime(LocalTime.of(23, 0)) .build(); } + + public static Shop shopWith24() { + return Shop.builder() + .name("testShop") + .rating(BigDecimal.valueOf(3.5)) + .category(Category.WESTERN_FOOD) + .address(new Address("서울시", "중구")) + .capacity(30) + .openingTime(LocalTime.of(0, 0)) + .closingTime(LocalTime.of(23, 59,59)) + .build(); + } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 26b3a1de..0e933b83 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -36,7 +36,7 @@ class WaitingControllerTest extends BaseIntegrationTest { @BeforeEach void setUp() { - shop = ShopFixture.shop(); + shop = ShopFixture.shopWith24(); shopRepository.save(shop); member1 = MemberFixture.member("test1@naver.com"); member2 = MemberFixture.member("test2@naver.com"); @@ -63,9 +63,6 @@ void setUp() { @DisplayName("웨이팅 생성 API를 호출할 수 있다.") @Test void createWaiting() throws Exception { - System.out.println("member1.getId( = " + member1.getId()); - System.out.println("member2.getId( = " + member2.getId()); - System.out.println("member3.getId( = " + member3.getId()); //given CreateWaitingRequest request = CreateWaitingRequest .builder() From 053d1d94856bf26f714d39e739dc1448fb0f35d1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 3 Jan 2024 14:35:08 +0900 Subject: [PATCH 169/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/shop/fixture/ShopFixture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index d31ac8b8..615e126b 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -28,7 +28,7 @@ public static Shop shopWith24() { .address(new Address("서울시", "중구")) .capacity(30) .openingTime(LocalTime.of(0, 0)) - .closingTime(LocalTime.of(23, 59,59)) + .closingTime(LocalTime.of(23, 59, 59)) .build(); } } From 8e56a2b4e66c9fdca39e27a37992f349d235bd4d Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 3 Jan 2024 14:45:53 +0900 Subject: [PATCH 170/603] =?UTF-8?q?feat=20:=20transactional=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 0e933b83..06d59f7b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -21,14 +21,16 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.transaction.annotation.Transactional; +@Transactional class WaitingControllerTest extends BaseIntegrationTest { @Autowired - MemberRepository memberRepository; + private MemberRepository memberRepository; @Autowired - WaitingRepository waitingRepository; - List waitings; + private WaitingRepository waitingRepository; + private List waitings; @Autowired private ShopRepository shopRepository; private Shop shop; From 4256d04a107d2ae10b0192d647e8025051b7f460 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 15:30:27 +0900 Subject: [PATCH 171/603] =?UTF-8?q?refactor=20:=20ReservationData=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9C=84=EC=B9=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/ReservationFacadeTest.java | 6 ++--- .../controller/ReservationControllerTest.java | 10 ++++----- .../domain/ReservationTimeTest.java | 6 ++--- .../fixture/ReservationFixture.java} | 4 ++-- .../repository/ReservationRepositoryTest.java | 6 ++--- .../ReservationTimeRepositoryTest.java | 4 ++-- .../service/ReservationServiceTest.java | 22 +++++++++---------- 7 files changed, 29 insertions(+), 29 deletions(-) rename src/test/java/com/prgrms/catchtable/{common/data/reservation/ReservationData.java => reservation/fixture/ReservationFixture.java} (95%) diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 29876a05..9e42f069 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -5,7 +5,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; @@ -31,8 +31,8 @@ class ReservationFacadeTest { @Test @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") void preOccupyReservation() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationService.validateReservationAndSave( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index d7cd7035..0589427b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -7,7 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; @@ -24,9 +24,9 @@ class ReservationControllerTest extends BaseIntegrationTest { @Test @DisplayName("예약 선점 api 호출에 성공한다.") void preOccupyReservation() throws Exception { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations") @@ -41,9 +41,9 @@ void preOccupyReservation() throws Exception { @Test @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") void schedulerTest() throws Exception { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations") diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java index d8ff901d..a79fc8c4 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -2,7 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -11,7 +11,7 @@ class ReservationTimeTest { @Test @DisplayName("예약 선점 여부 변경에 성공한다") void reversePreOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -20,7 +20,7 @@ void reversePreOccupied() { @Test @DisplayName("예약 여부 변경에 성공한다.") void reverseOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.reverseOccupied(); assertThat(reservationTime.isOccupied()).isTrue(); diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java similarity index 95% rename from src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java rename to src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index c5e10886..996f85ee 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.common.data.reservation; +package com.prgrms.catchtable.reservation.fixture; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; @@ -10,7 +10,7 @@ import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; -public class ReservationData { +public class ReservationFixture { public static Reservation getReservation(ReservationTime reservationTime) { return Reservation.builder() diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index e38736e5..f6bef1a5 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -31,13 +31,13 @@ class ReservationRepositoryTest { @Test @DisplayName("예약 엔티티 조회 시 페치 조인을 통해 예약시간과 매장 엔티티를 한번에 조회한다.") void findAllWithReservationTimeAndShop() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); reservationTime.insertShop(savedShop); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - Reservation reservation = ReservationData.getReservation(savedReservationTime); + Reservation reservation = ReservationFixture.getReservation(savedReservationTime); reservationRepository.save(reservation); List reservations = reservationRepository.findAllWithReservationTimeAndShop(); diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index 56a42d07..95da2910 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -31,7 +31,7 @@ void findReservationTimeWithShop() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); ReservationTime savedTime = reservationTimeRepository.save(reservationTime); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index e377af2d..2d1a162e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -7,7 +7,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -39,9 +39,9 @@ class ReservationServiceTest { @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { //given - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -63,9 +63,9 @@ void validateReservation() { @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") void alreadyPreOccupied() { //given - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); - CreateReservationRequest request = ReservationData.getCreateReservationRequestWithId( + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); @@ -80,8 +80,8 @@ void alreadyPreOccupied() { @Test @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") void registerReservation() { - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) @@ -104,8 +104,8 @@ void registerReservation() { @Test @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") void registerReservationAlreadyOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); - CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); reservationTime.reverseOccupied(); when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( @@ -118,8 +118,8 @@ void registerReservationAlreadyOccupied() { @Test @DisplayName("예약 전체 조회를 할 수 있다") void getAllReservation() { - ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); - Reservation reservation = ReservationData.getReservation(reservationTime); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Reservation reservation = ReservationFixture.getReservation(reservationTime); when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn( List.of(reservation)); From ba01c74d826b8c6a39a40db3f5738c4b3feb8cb4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 3 Jan 2024 15:34:05 +0900 Subject: [PATCH 172/603] feat : JwtUserDetailsService Test --- .../service/JwtUserDetailsServiceTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java new file mode 100644 index 00000000..96a41226 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java @@ -0,0 +1,45 @@ +package com.prgrms.catchtable.jwt.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class JwtUserDetailsServiceTest { + + @Mock + MemberRepository memberRepository; + @InjectMocks + JwtUserDetailsService jwtUserDetailsService; + String email = "abc1234@gmail.com"; + String invalidEmail = "qwer@7890@naver.com"; + + @Test + @DisplayName("email을 통해 Member entity를 갖고온다") + void loadUserByUsernameTest() { + //given + Member member = MemberFixture.userDetailsMember(email); + + //when + when(memberRepository.findMemberByEmail(email)).thenReturn(Optional.of(member)); + when(memberRepository.findMemberByEmail(invalidEmail)).thenReturn(Optional.empty()); + + //then + assertThat(jwtUserDetailsService.loadUserByUsername(email)).isEqualTo(member); + assertThatThrownBy( + () -> jwtUserDetailsService.loadUserByUsername(invalidEmail)).isInstanceOf( + NotFoundCustomException.class); + + } +} \ No newline at end of file From 4ccc04db02e492547f9cd9c153995a73172859d4 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 15:46:42 +0900 Subject: [PATCH 173/603] =?UTF-8?q?remove=20:=20ReservationFacadeTest=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facade/ReservationFacadeTest.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java deleted file mode 100644 index 9e42f069..00000000 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.prgrms.catchtable.facade; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import com.prgrms.catchtable.reservation.fixture.ReservationFixture; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.service.ReservationAsync; -import com.prgrms.catchtable.reservation.service.ReservationService; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class ReservationFacadeTest { - - @Mock - private ReservationAsync reservationAsync; - @Mock - private ReservationService reservationService; - @InjectMocks - private ReservationFacade reservationFacade; - - @Test - @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") - void preOccupyReservation() { - ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( - reservationTime.getId()); - - when(reservationService.validateReservationAndSave( - any(CreateReservationRequest.class))).thenReturn(reservationTime); - - CreateReservationResponse response = reservationFacade.preOccupyReservation( - request); - - assertAll( - () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), - () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()) - ); - } -} \ No newline at end of file From 346251ea363581b61c0c7cdddaba177acc0c5879 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 15:47:33 +0900 Subject: [PATCH 174/603] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20=EB=A1=9C=EC=A7=81=20=ED=8D=BC=EC=82=AC?= =?UTF-8?q?=EB=93=9C=EC=97=90=EC=84=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/facade/ReservationFacade.java | 17 ----------------- .../service/ReservationService.java | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index b0c1c527..3c9354b9 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -16,24 +16,7 @@ public class ReservationFacade { private final ReservationService reservationService; - private final ReservationAsync reservationAsync; - public CreateReservationResponse preOccupyReservation( - CreateReservationRequest request) { - ReservationTime reservationTime = reservationService.validateReservationAndSave( - request); - - String shopName = reservationTime.getShop().getName(); - - reservationAsync.setPreOcuppied(reservationTime); - - return CreateReservationResponse.builder() - .shopName(shopName) - .memberName("memberA") - .date(reservationTime.getTime()) - .peopleCount(request.peopleCount()) - .build(); - } public CreateReservationResponse registerReservation(CreateReservationRequest request) { Reservation reservation = reservationService.validateReservationAndSaveIsEmpty(request); diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index fd567aaf..f4698213 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -10,8 +10,11 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import com.prgrms.catchtable.shop.domain.Shop; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,12 +22,13 @@ @Service @RequiredArgsConstructor public class ReservationService { - private final ReservationTimeRepository reservationTimeRepository; private final ReservationRepository reservationRepository; + private final ReservationAsync reservationAsync; + private final ReservationLockRepository reservationLockRepository; @Transactional - public ReservationTime validateReservationAndSave(CreateReservationRequest request) { + public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findById( request.reservationTimeId()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); @@ -33,7 +37,15 @@ public ReservationTime validateReservationAndSave(CreateReservationRequest reque throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } - return reservationTime; + reservationAsync.setPreOcuppied(reservationTime); + Shop shop = reservationTime.getShop(); + + return CreateReservationResponse.builder() + .shopName(shop.getName()) + .memberName("memberA") + .date(reservationTime.getTime()) + .peopleCount(request.peopleCount()) + .build(); } @Transactional From 23c0dc676babcfa1dac33847177f48a202e4ff6f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 15:47:58 +0900 Subject: [PATCH 175/603] =?UTF-8?q?refactor=20:=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=EC=97=90=EC=84=9C=20=ED=8D=BC=EC=82=AC?= =?UTF-8?q?=EB=93=9C=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index cef0f3b5..2eb745f3 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -3,6 +3,7 @@ import com.prgrms.catchtable.facade.ReservationFacade; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -15,17 +16,17 @@ @RequiredArgsConstructor public class ReservationController { - private final ReservationFacade reservationFacade; + private final ReservationService reservationService; @PostMapping public ResponseEntity preOccupyReservation( @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(reservationFacade.preOccupyReservation(request)); + return ResponseEntity.ok(reservationService.preOccupyReservation(request)); } @PostMapping("/success") public ResponseEntity registerReservation( @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(reservationFacade.registerReservation(request)); + return ResponseEntity.ok(null); } } From 119b74827562105b25f7afaa222b3513717747bb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 16:19:31 +0900 Subject: [PATCH 176/603] =?UTF-8?q?remove=20:=20ReservationFacade=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/facade/ReservationFacade.java | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java deleted file mode 100644 index 3c9354b9..00000000 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.prgrms.catchtable.facade; - -import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; - -import com.prgrms.catchtable.reservation.domain.Reservation; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.service.ReservationAsync; -import com.prgrms.catchtable.reservation.service.ReservationService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class ReservationFacade { - - private final ReservationService reservationService; - - - public CreateReservationResponse registerReservation(CreateReservationRequest request) { - Reservation reservation = reservationService.validateReservationAndSaveIsEmpty(request); - return toCreateReservationResponse(reservation); - } - -} From bb2c2ed614eae1b8a789e6a50da32057310a51b6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 16:19:53 +0900 Subject: [PATCH 177/603] =?UTF-8?q?refactor=20:=20conflict=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/GetAllReservationResponse.java | 17 ++++++ .../service/ReservationServiceTest.java | 61 +++++++++++++++---- 2 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java new file mode 100644 index 00000000..b16ec69b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/GetAllReservationResponse.java @@ -0,0 +1,17 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record GetAllReservationResponse(Long reservationId, + @JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") + LocalDateTime date, + String shopName, + int peopleCount, + ReservationStatus status) { + +} diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index d7c2bb36..b97fc421 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -5,15 +5,19 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -27,7 +31,9 @@ class ReservationServiceTest { @Mock - ReservationRepository reservationRepository; + private ReservationRepository reservationRepository; + @Mock + private ReservationAsync reservationAsync; @Mock private ReservationTimeRepository reservationTimeRepository; @InjectMocks @@ -43,15 +49,17 @@ void validateReservation() { reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); - + doNothing().when(reservationAsync).setPreOcuppied(reservationTime); //when - ReservationTime savedReservationTime = reservationService.validateReservationAndSave( + CreateReservationResponse response = reservationService.preOccupyReservation( request); + //then assertAll( - () -> assertThat(savedReservationTime.getTime()).isEqualTo(reservationTime.getTime()), - () -> assertThat(savedReservationTime.getShop()).isEqualTo(reservationTime.getShop()) + () -> assertThat(response.shopName()).isEqualTo(reservationTime.getShop().getName()), + () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()) ); @@ -70,7 +78,7 @@ void alreadyPreOccupied() { //when assertThrows(BadRequestCustomException.class, - () -> reservationService.validateReservationAndSave(request)); + () -> reservationService.preOccupyReservation(request)); } @@ -83,20 +91,18 @@ void registerReservation() { Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) - .shop(reservationTime.getShop()) .reservationTime(reservationTime) .build(); when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); - Reservation findReservation = reservationService.validateReservationAndSaveIsEmpty(request); + CreateReservationResponse response = reservationService.registerReservation(request); assertAll( - () -> assertThat(findReservation.getReservationTime().getTime()).isEqualTo( - reservationTime.getTime()), - () -> assertThat(findReservation.getPeopleCount()).isEqualTo(request.peopleCount()), - () -> assertThat(findReservation.getStatus()).isEqualTo(COMPLETED) + () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), + () -> assertThat(response.shopName()).isEqualTo(reservationTime.getShop().getName()), + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()) ); } @@ -111,7 +117,36 @@ void registerReservationAlreadyOccupied() { Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, - () -> reservationService.validateReservationAndSaveIsEmpty(request)); + () -> reservationService.registerReservation(request)); + } + + @Test + @DisplayName("예약 전체 조회를 할 수 있다") + void getAllReservation() { + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + + when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn( + List.of(reservation)); + List all = reservationService.getAllReservation(); + GetAllReservationResponse findReservation = all.get(0); + + assertAll( + () -> assertThat(findReservation.date()).isEqualTo( + reservation.getReservationTime().getTime()), + () -> assertThat(findReservation.peopleCount()).isEqualTo(reservation.getPeopleCount()), + () -> assertThat(findReservation.shopName()).isEqualTo(reservation.getShop().getName()), + () -> assertThat(findReservation.status()).isEqualTo(reservation.getStatus()) + ); + } + + @Test + @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") + void getAllReservationWithNoResult() { + when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); + + List all = reservationService.getAllReservation(); + assertThat(all.size()).isZero(); } } \ No newline at end of file From 6bb08335ac2abdae42ff1d0c8b492e255450b865 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 16:21:13 +0900 Subject: [PATCH 178/603] =?UTF-8?q?refactor=20:=20=ED=8D=BC=EC=82=AC?= =?UTF-8?q?=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=98=88=EC=95=BD=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=EB=B6=80=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index f4698213..1fad5b97 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -4,17 +4,21 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.*; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -49,7 +53,7 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r } @Transactional - public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest request) { + public CreateReservationResponse registerReservation(CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); @@ -63,9 +67,17 @@ public Reservation validateReservationAndSaveIsEmpty(CreateReservationRequest re Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) - .shop(reservationTime.getShop()) .reservationTime(reservationTime) .build(); - return reservationRepository.save(reservation); + Reservation savedReservation = reservationRepository.save(reservation); + return toCreateReservationResponse(savedReservation); + } + + @Transactional(readOnly = true) + public List getAllReservation(){ + List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + return reservations.stream() + .map(ReservationMapper::toGetAllReservationRepsonse) + .toList(); } } From dbd8a8f21790da056e665de0cc98757490e8c04a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 16:21:31 +0900 Subject: [PATCH 179/603] =?UTF-8?q?refactor=20:=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=EC=97=90=EC=84=9C=20=ED=8D=BC=EC=82=AC?= =?UTF-8?q?=EB=93=9C=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20=EC=9D=98=EC=A1=B4=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 2eb745f3..96e3e8a4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.reservation.controller; -import com.prgrms.catchtable.facade.ReservationFacade; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; @@ -27,6 +26,6 @@ public ResponseEntity preOccupyReservation( @PostMapping("/success") public ResponseEntity registerReservation( @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(null); + return ResponseEntity.ok(reservationService.registerReservation(request)); } } From e00bf9fd309bb5542b06344ccbf69a6a48c00ad4 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 3 Jan 2024 16:22:58 +0900 Subject: [PATCH 180/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationLockRepository.java | 24 +++++++++++++++++++ .../service/ReservationService.java | 7 +++--- .../controller/ReservationControllerTest.java | 2 +- .../repository/ReservationRepositoryTest.java | 2 +- .../ReservationTimeRepositoryTest.java | 2 +- .../service/ReservationServiceTest.java | 5 ++-- 6 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/repository/ReservationLockRepository.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationLockRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationLockRepository.java new file mode 100644 index 00000000..102f0576 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationLockRepository.java @@ -0,0 +1,24 @@ +package com.prgrms.catchtable.reservation.repository; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ReservationLockRepository { + + private final RedisTemplate redisTemplate; + + public Boolean lock(Long key) { + return redisTemplate + .opsForValue() + .setIfAbsent(key.toString(), "lock"); + } + + public Boolean unlock(Long key) { + return redisTemplate + .delete(key.toString()); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 1fad5b97..16be9d36 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -4,7 +4,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.*; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -14,7 +14,6 @@ import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; -import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; @@ -26,10 +25,10 @@ @Service @RequiredArgsConstructor public class ReservationService { + private final ReservationTimeRepository reservationTimeRepository; private final ReservationRepository reservationRepository; private final ReservationAsync reservationAsync; - private final ReservationLockRepository reservationLockRepository; @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { @@ -74,7 +73,7 @@ public CreateReservationResponse registerReservation(CreateReservationRequest re } @Transactional(readOnly = true) - public List getAllReservation(){ + public List getAllReservation() { List reservations = reservationRepository.findAllWithReservationTimeAndShop(); return reservations.stream() .map(ReservationMapper::toGetAllReservationRepsonse) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 0c16ba51..8d558c24 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -8,10 +8,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; -import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index f6bef1a5..b855551b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -4,10 +4,10 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; -import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index 95da2910..2bc06f17 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -3,11 +3,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index b97fc421..67086eee 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -8,13 +8,13 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.List; @@ -54,7 +54,6 @@ void validateReservation() { CreateReservationResponse response = reservationService.preOccupyReservation( request); - //then assertAll( () -> assertThat(response.shopName()).isEqualTo(reservationTime.getShop().getName()), From 45113555a528f0578939a80611812a54482a8b93 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 3 Jan 2024 16:23:24 +0900 Subject: [PATCH 181/603] feat : RefreshTokenService Test --- .../jwt/service/RefreshTokenServiceTest.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java new file mode 100644 index 00000000..06e57f20 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java @@ -0,0 +1,104 @@ +package com.prgrms.catchtable.jwt.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.jwt.config.JwtConfig; +import com.prgrms.catchtable.jwt.domain.RefreshToken; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; +import com.prgrms.catchtable.jwt.token.Token; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class RefreshTokenServiceTest { + + @Mock + RefreshTokenRepository refreshTokenRepository; + @InjectMocks + RefreshTokenService refreshTokenService; + + JwtConfig jwtConfig = mock(JwtConfig.class); + JwtUserDetailsService jwtUserDetailsService = mock(JwtUserDetailsService.class); + JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(jwtConfig, jwtUserDetailsService); + + Token token; + String email = "abc1234@gmail.com"; + String clientSecretKey = "FLGs0worldbOS8CEdfSPW04mb0dkD9SKFlsob9WK9wW0WkdlskYof5142u3jdmsk"; + + @BeforeEach + void init() { + when(jwtConfig.getClientSecret()).thenReturn(clientSecretKey); + when(jwtConfig.getExpiryMinute()).thenReturn(1); + when(jwtConfig.getExpiryMinuteRefresh()).thenReturn(1); + token = jwtTokenProvider.createToken(email); + } + + @Test + @DisplayName("새로운 유저의 RefreshToken이라면, DB에 바로 저장한다.") + void saveRefreshTokenTest() { + //when + refreshTokenService.saveRefreshToken(token); + + //then + verify(refreshTokenRepository, times(1)).existsRefreshTokenByEmail(email); + verify(refreshTokenRepository, times(1)).save(any(RefreshToken.class)); + + verify(refreshTokenRepository, never()).deleteRefreshTokenByEmail(email); + } + + @Test + @DisplayName("이미 유효한 RefreshToken을 갖고 있는 유저가 RefreshToken을 새로 발급한다면, DB에서 삭제 후 저장해준다.") + void deleteAndSaveRefreshToken() { + //given + Token newToken = jwtTokenProvider.createToken(email); + + //when + when(refreshTokenRepository.existsRefreshTokenByEmail(email)).thenReturn(true); + refreshTokenService.saveRefreshToken(newToken); + + //then + verify(refreshTokenRepository, times(1)).existsRefreshTokenByEmail(email); + verify(refreshTokenRepository, times(1)).save(any(RefreshToken.class)); + + verify(refreshTokenRepository, times(1)).deleteRefreshTokenByEmail(email); + } + + @Test + @DisplayName("refreshToken을 통해 RefreshToken Entity를 갖고온다.") + void getRefreshTokenTest() { + //given + String invalidEmail = "qwer1234@naver.com"; + Token invalidToken = jwtTokenProvider.createToken(invalidEmail); + + RefreshToken refreshToken = RefreshToken.builder() + .token(token.getRefreshToken()) + .email(token.getEmail()) + .build(); + + //when + when(refreshTokenRepository.findRefreshTokenByToken(token.getRefreshToken())).thenReturn( + Optional.of(refreshToken)); + + //then + assertThat(refreshTokenService.getRefreshTokenByToken(token.getRefreshToken())).isEqualTo( + refreshToken); + assertThatThrownBy(() -> refreshTokenService.getRefreshTokenByToken( + invalidToken.getRefreshToken())).isInstanceOf( + NotFoundCustomException.class); + } +} \ No newline at end of file From f7cdec7f7401ceeeb2d8e15e0f80f2d7472ddf32 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 01:25:20 +0900 Subject: [PATCH 182/603] =?UTF-8?q?fix=20:=20RefreshToken=20null=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jwt/filter/JwtAuthenticationFilter.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index 316a18c8..eb1781c5 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -40,19 +40,24 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha if (jwtTokenProvider.validateToken(accessToken)) { setAuthentication(accessToken); } - //RefreshToken 유효 + //AccessToken 유효 X else { - if (jwtTokenProvider.validateToken(refreshToken)) { - RefreshToken refreshTokenEntity = refreshTokenService.getRefreshTokenByToken( - refreshToken); - String email = refreshTokenEntity.getEmail(); - Token newToken = jwtTokenProvider.createToken(email); + if (refreshToken != null) { + //RefreshToken 유효 + if (jwtTokenProvider.validateToken(refreshToken)) { + RefreshToken refreshTokenEntity = refreshTokenService.getRefreshTokenByToken( + refreshToken); + String email = refreshTokenEntity.getEmail(); + Token newToken = jwtTokenProvider.createToken(email); - ((HttpServletResponse) response).setHeader("AccessToken", - newToken.getAccessToken()); - setAuthentication(newToken.getAccessToken()); - } else { - throw new BadRequestCustomException(TOKEN_EXPIRES); + ((HttpServletResponse) response).setHeader("AccessToken", + newToken.getAccessToken()); + setAuthentication(newToken.getAccessToken()); + } + //RefreshToken 유효 X + else { + throw new BadRequestCustomException(TOKEN_EXPIRES); + } } } } From d55ac4ee16f6aca98849557fbd7dafc6fc86ac81 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 04:27:23 +0900 Subject: [PATCH 183/603] =?UTF-8?q?feat=20:=20=EC=84=A0=EC=A0=90=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=97=90=20=EB=8F=99=EC=8B=9C=EC=84=B1=20?= =?UTF-8?q?=EC=9D=B4=EC=8A=88=20=EC=A0=9C=EC=96=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 16be9d36..5641d147 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -5,6 +5,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; +import static java.lang.Boolean.FALSE; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -14,6 +15,7 @@ import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; @@ -29,19 +31,34 @@ public class ReservationService { private final ReservationTimeRepository reservationTimeRepository; private final ReservationRepository reservationRepository; private final ReservationAsync reservationAsync; + private final ReservationLockRepository reservationLockRepository; @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findById( - request.reservationTimeId()) - .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); + Long reservationTimeId = request.reservationTimeId(); + while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))){ + try { + Thread.sleep(1_500); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + ReservationTime reservationTime = reservationTimeRepository.findById(reservationTimeId) + .orElseThrow(() -> { + reservationLockRepository.unlock(reservationTimeId); + return new NotFoundCustomException(NOT_EXIST_TIME); + } + ); if (reservationTime.isPreOccupied()) { + reservationLockRepository.unlock(reservationTimeId); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } reservationAsync.setPreOcuppied(reservationTime); + Shop shop = reservationTime.getShop(); + reservationLockRepository.unlock(reservationTimeId); return CreateReservationResponse.builder() .shopName(shop.getName()) From 7261f818ec9c0abdeb6d410abf8b3a3d95975238 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 04:31:18 +0900 Subject: [PATCH 184/603] =?UTF-8?q?feat=20:=20service=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=97=90=EC=84=9C=20lock=20mocking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationServiceTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 67086eee..c1658699 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.reservation.service; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static java.lang.Boolean.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -15,6 +16,7 @@ import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.List; @@ -33,6 +35,8 @@ class ReservationServiceTest { @Mock private ReservationRepository reservationRepository; @Mock + private ReservationLockRepository reservationLockRepository; + @Mock private ReservationAsync reservationAsync; @Mock private ReservationTimeRepository reservationTimeRepository; @@ -49,6 +53,8 @@ void validateReservation() { reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationLockRepository.lock(1L)).thenReturn(TRUE); + when(reservationLockRepository.unlock(1L)).thenReturn(TRUE); doNothing().when(reservationAsync).setPreOcuppied(reservationTime); //when CreateReservationResponse response = reservationService.preOccupyReservation( @@ -74,6 +80,7 @@ void alreadyPreOccupied() { reservationTime.getId()); when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationLockRepository.lock(1L)).thenReturn(TRUE); //when assertThrows(BadRequestCustomException.class, @@ -96,6 +103,7 @@ void registerReservation() { when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + CreateReservationResponse response = reservationService.registerReservation(request); assertAll( @@ -145,7 +153,7 @@ void getAllReservationWithNoResult() { when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); List all = reservationService.getAllReservation(); - assertThat(all.size()).isZero(); + assertThat(all).isEmpty(); } } \ No newline at end of file From 629a2ab3d4a89e574de44aafc1b9815931513df8 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 04:32:23 +0900 Subject: [PATCH 185/603] =?UTF-8?q?test=20:=20=EC=84=A0=EC=A0=90=20?= =?UTF-8?q?=EB=8F=99=EC=8B=9C=EC=84=B1=20=EC=9D=B4=EC=8A=88=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationServiceIntegrationTest.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java new file mode 100644 index 00000000..9fb390fb --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java @@ -0,0 +1,75 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ReservationServiceIntegrationTest { + @Autowired + private ReservationService reservationService; + @Autowired + private ReservationTimeRepository reservationTimeRepository; + + @Autowired + private ShopRepository shopRepository; + + @BeforeEach + void setUp() { + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + reservationTime.insertShop(savedShop); + reservationTimeRepository.save(reservationTime); + } + @Test + @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") + void concurrencyTest() throws InterruptedException { + AtomicInteger errorCount = new AtomicInteger(0); + + List all = reservationTimeRepository.findAll(); + ReservationTime reservationTime = all.get(0); + + CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( + reservationTime.getId()); + int threadCount = 10; + ExecutorService executorService = Executors.newFixedThreadPool(32); + CountDownLatch latch = new CountDownLatch(threadCount); + + for (int i = 0; i < threadCount; i++) { + executorService.submit(() -> { + try { + reservationService.preOccupyReservation(request); + } catch (BadRequestCustomException e) { + errorCount.incrementAndGet(); + } finally { + latch.countDown(); + } + }); + } + + latch.await(); + + assertThat(errorCount.get()).isEqualTo(threadCount - 1); + + } + +} From 7b43ac295bf38974f72629628068c75c54769f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Thu, 4 Jan 2024 04:52:53 +0900 Subject: [PATCH 186/603] Update ci.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redis 컨테이너 설정 추가 --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12cc005a..f1abe888 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,12 +17,15 @@ permissions: contents: read checks: write pull-requests: write - jobs: build: runs-on: ubuntu-latest - + services: + redis: + image: redis:latest + ports: + - "6379:6379" steps: - uses: actions/checkout@v3 @@ -65,4 +68,4 @@ jobs: uses: mikepenz/action-junit-report@v3 if: always() with: - report_paths: '**/build/test-results/test/TEST-*.html' \ No newline at end of file + report_paths: '**/build/test-results/test/TEST-*.html' From 64ec9e7d26ae61b0ffc84328d7ef016f44ae2663 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 04:55:19 +0900 Subject: [PATCH 187/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/service/ReservationService.java | 2 +- .../reservation/service/ReservationServiceIntegrationTest.java | 2 ++ .../catchtable/reservation/service/ReservationServiceTest.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 5641d147..02bc9026 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -36,7 +36,7 @@ public class ReservationService { @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); - while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))){ + while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { try { Thread.sleep(1_500); } catch (InterruptedException e) { diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java index 9fb390fb..123bc27c 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java @@ -23,6 +23,7 @@ @SpringBootTest public class ReservationServiceIntegrationTest { + @Autowired private ReservationService reservationService; @Autowired @@ -40,6 +41,7 @@ void setUp() { reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); } + @Test @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") void concurrencyTest() throws InterruptedException { diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index c1658699..05bb271c 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.reservation.service; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import static java.lang.Boolean.*; +import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; From d836debd9e23c4d47fdeee83f845cec108d91a97 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 10:30:22 +0900 Subject: [PATCH 188/603] =?UTF-8?q?feat=20:=20Security=20Test=20API=20=20&?= =?UTF-8?q?=20Controller=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/config/SecurityConfig.java | 1 + .../security/controller/TestController.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/security/controller/TestController.java diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index cf4e07af..e333b13f 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -32,6 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti SessionCreationPolicy.STATELESS)) .formLogin(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorization -> authorization + .requestMatchers(new AntPathRequestMatcher("/testMember/**")).hasRole("MEMBER") .requestMatchers(new AntPathRequestMatcher("/**")).permitAll() ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); diff --git a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java new file mode 100644 index 00000000..6973411d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java @@ -0,0 +1,17 @@ +package com.prgrms.catchtable.security.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +public class TestController { + + @GetMapping("/testMember") + public ResponseEntity testMember(){ + log.info("testMember"); + return ResponseEntity.ok("testMember OK"); + } +} From 28556ac994a60659763bfb513f17941150d51c34 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 10:30:51 +0900 Subject: [PATCH 189/603] feat : JwtAuthenticationTest Test --- .../controller/JwtAuthenticationTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java new file mode 100644 index 00000000..b5892521 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -0,0 +1,86 @@ +package com.prgrms.catchtable.security.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.security.filter.ExceptionHandlerFilter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebAppConfiguration +class JwtAuthenticationTest extends BaseIntegrationTest { + + @Autowired + WebApplicationContext webApplicationContext; + @Autowired + ExceptionHandlerFilter exceptionHandlerFilter; + @Autowired + JwtAuthenticationFilter jwtAuthenticationFilter; + + @Autowired + MemberRepository memberRepository; + @Autowired + RefreshTokenService refreshTokenService; + @Autowired + JwtTokenProvider jwtTokenProvider; + + Member loginMember; + String email = "abc1234@gmail.com"; + Token token; + + @BeforeEach + public void init() { + //Member 객체 저장 + loginMember = MemberFixture.userDetailsMember(email); + memberRepository.save(loginMember); + + //토큰 발급 + token = jwtTokenProvider.createToken(email); + refreshTokenService.saveRefreshToken(token); + + //필터 추가 + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) + .addFilters(exceptionHandlerFilter, jwtAuthenticationFilter) + .build(); + } + + @Test + @DisplayName("Member의 AceessToken이 유효하다면, Member 권한을 갖는다.") + void testMemberAccessToken() throws Exception { + mockMvc.perform(get("/testMember") + .header("AccessToken", token.getAccessToken()) + .header("RefreshToken", token.getRefreshToken())) + .andExpect(status().isOk()); + } + + @Test + @DisplayName("Member의 AccessToken이 유효하지 않고, RefreshToken이 유효하다면, Member 권한을 갖는다.") + void testMemberRefreshToken() throws Exception { + mockMvc.perform(get("/testMember") + .header("AccessToken", token.getAccessToken() + "abc") + .header("RefreshToken", token.getRefreshToken())) + .andExpect(status().isOk()); + } + + @Test + @DisplayName("Member의 AccessToken과 RefreshToken이 모두 유효하지 않다면, 400 Error를 반환한다.") + void testInvalidToken() throws Exception { + mockMvc.perform(get("/testMember") + .header("AccessToken", token.getAccessToken() + "abc") + .header("RefreshToken", token.getRefreshToken() + "abc")) + .andExpect(status().isBadRequest()); + } +} \ No newline at end of file From fe403efa32b5004bbc81d77a6bb64ab5c236acc3 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 10:40:08 +0900 Subject: [PATCH 190/603] =?UTF-8?q?feat=20:=20=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=ED=98=B9=EC=9D=80=20=EC=9D=B8=EA=B0=80=20=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20=EC=9C=A0=EC=A0=80=EA=B0=80=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=20=EC=8B=9C,=204xx=20=EC=97=90=EB=9F=AC=20=EC=A0=84?= =?UTF-8?q?=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/security/config/SecurityConfig.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index e333b13f..b47811c0 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -35,7 +35,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers(new AntPathRequestMatcher("/testMember/**")).hasRole("MEMBER") .requestMatchers(new AntPathRequestMatcher("/**")).permitAll() ) - .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)); + .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)) + .exceptionHandling(exhandle -> exhandle + .authenticationEntryPoint(((request, response, authException) -> + response.sendError(401))) + .accessDeniedHandler((request, response, accessDeniedException) -> + response.sendError(403))); http.addFilterBefore(exceptionHandlerFilter, OAuth2AuthorizationRequestRedirectFilter.class); From 0b2d80981d82ac46f184ba4c96a2abe7e2450267 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 10:50:21 +0900 Subject: [PATCH 191/603] fix : conflict resolve --- .../catchtable/waiting/repository/WaitingRepositoryTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 011d92b8..cb53bcc0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -39,6 +39,8 @@ class WaitingRepositoryTest { private Waiting waiting1; private Waiting waiting2; private Waiting waiting3; + private Member member1, member2, member3; + private Waiting yesterdayWaiting, completedWaiting, normalWaiting; @BeforeEach void setUp() { From 16e8fb6470e75dc52b51b1c4335b65a986285257 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 11:11:59 +0900 Subject: [PATCH 192/603] =?UTF-8?q?refactor=20:=20BaseIntegrationTest=20?= =?UTF-8?q?=EB=AF=B8=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/controller/JwtAuthenticationTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index b5892521..9f26ad4e 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -3,7 +3,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; @@ -16,12 +15,19 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.WebApplicationContext; +@SpringBootTest +@Transactional +@AutoConfigureMockMvc @WebAppConfiguration -class JwtAuthenticationTest extends BaseIntegrationTest { +class JwtAuthenticationTest{ @Autowired WebApplicationContext webApplicationContext; @@ -36,6 +42,7 @@ class JwtAuthenticationTest extends BaseIntegrationTest { RefreshTokenService refreshTokenService; @Autowired JwtTokenProvider jwtTokenProvider; + MockMvc mockMvc; Member loginMember; String email = "abc1234@gmail.com"; From 9ae4bdba1b314a7a5a9199272720f8483cf90b43 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 14:04:18 +0900 Subject: [PATCH 193/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=A3=BC=EC=84=9D=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 02bc9026..83a4fd1b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -36,7 +36,7 @@ public class ReservationService { @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); - while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { + while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { // 락 획득 시도 try { Thread.sleep(1_500); } catch (InterruptedException e) { @@ -48,14 +48,14 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r reservationLockRepository.unlock(reservationTimeId); return new NotFoundCustomException(NOT_EXIST_TIME); } - ); + ); //예약시간 조회 후 없으면 락 해제 + 예외 발생 - if (reservationTime.isPreOccupied()) { + if (reservationTime.isPreOccupied()) { //이미 선점 된 예약시간이면 락 해제 후 예외 발생 reservationLockRepository.unlock(reservationTimeId); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } - reservationAsync.setPreOcuppied(reservationTime); + reservationAsync.setPreOcuppied(reservationTime); //예약 선점 여부 7분동안 true로 바꾸는 스케줄러 실행 Shop shop = reservationTime.getShop(); reservationLockRepository.unlock(reservationTimeId); @@ -70,15 +70,15 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r @Transactional public CreateReservationResponse registerReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( //예약시간과 매장 한번에 가져옴 request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); - if (reservationTime.isOccupied()) { + if (reservationTime.isOccupied()) { //이미 차지된 예약이면 예외 발생 throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } - reservationTime.reverseOccupied(); + reservationTime.reverseOccupied(); //예약 차지된 상태로 변경 Reservation reservation = Reservation.builder() .status(COMPLETED) From 489acf24cee9e4b24a032518769ffe49d3c413bf Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 14:37:37 +0900 Subject: [PATCH 194/603] =?UTF-8?q?fix=20:=20=EB=88=84=EB=9D=BD=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EC=A0=9C=EC=96=B4=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/JwtAuthenticationTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 9f26ad4e..a2e38c82 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -30,23 +30,23 @@ class JwtAuthenticationTest{ @Autowired - WebApplicationContext webApplicationContext; + private WebApplicationContext webApplicationContext; @Autowired - ExceptionHandlerFilter exceptionHandlerFilter; + private ExceptionHandlerFilter exceptionHandlerFilter; @Autowired - JwtAuthenticationFilter jwtAuthenticationFilter; + private JwtAuthenticationFilter jwtAuthenticationFilter; @Autowired - MemberRepository memberRepository; + private MemberRepository memberRepository; @Autowired - RefreshTokenService refreshTokenService; + private RefreshTokenService refreshTokenService; @Autowired - JwtTokenProvider jwtTokenProvider; - MockMvc mockMvc; + private JwtTokenProvider jwtTokenProvider; + private MockMvc mockMvc; - Member loginMember; - String email = "abc1234@gmail.com"; - Token token; + private Member loginMember; + private String email = "abc1234@gmail.com"; + private Token token; @BeforeEach public void init() { From f65e117fbc823f02632a48ee8d8d538390d50135 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 14:50:57 +0900 Subject: [PATCH 195/603] =?UTF-8?q?fix=20:=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=9D=98=20=EC=96=B4=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/security/config/SecurityConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index b47811c0..4871a801 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.security.service.CustomOAuth2SuccessHandler; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; @@ -14,7 +15,7 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.stereotype.Component; -@Component +@Configuration @RequiredArgsConstructor @EnableWebSecurity public class SecurityConfig { From e82706ef68c6d3185f68a911e8f789f238f59137 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 14:52:29 +0900 Subject: [PATCH 196/603] =?UTF-8?q?refactor=20:=20MemberFixture=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/provider/JwtTokenProviderTest.java | 2 +- .../jwt/service/JwtUserDetailsServiceTest.java | 2 +- .../com/prgrms/catchtable/member/MemberFixture.java | 10 ---------- .../security/controller/JwtAuthenticationTest.java | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java index 524da87e..54c2a606 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java @@ -59,7 +59,7 @@ void invalidToken() { @DisplayName("토큰을 통해서 Member Entity가 담긴 Authentication 반환") void getAuthenticationTest() { //given - Member member = MemberFixture.userDetailsMember(email); + Member member = MemberFixture.member(email); //when when(config.getClientSecret()).thenReturn(clientKey); diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java index 96a41226..f3de0c91 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java @@ -29,7 +29,7 @@ class JwtUserDetailsServiceTest { @DisplayName("email을 통해 Member entity를 갖고온다") void loadUserByUsernameTest() { //given - Member member = MemberFixture.userDetailsMember(email); + Member member = MemberFixture.member(email); //when when(memberRepository.findMemberByEmail(email)).thenReturn(Optional.of(member)); diff --git a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java index 45e1dd1f..1dff7c4f 100644 --- a/src/test/java/com/prgrms/catchtable/member/MemberFixture.java +++ b/src/test/java/com/prgrms/catchtable/member/MemberFixture.java @@ -15,14 +15,4 @@ public static Member member(String email) { .dateBirth(LocalDate.parse("2008-12-18")) .build(); } - - public static Member userDetailsMember(String email) { - return Member.builder() - .name("예시용") - .email(email) - .phoneNumber("010-1111-1111") - .gender(Gender.FEMALE) - .dateBirth(LocalDate.parse("2008-12-18")) - .build(); - } } diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index a2e38c82..fa9a37fc 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -51,7 +51,7 @@ class JwtAuthenticationTest{ @BeforeEach public void init() { //Member 객체 저장 - loginMember = MemberFixture.userDetailsMember(email); + loginMember = MemberFixture.member(email); memberRepository.save(loginMember); //토큰 발급 From d2aab0431987bedd7c5341aa7de1ff49c87b055b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 15:56:37 +0900 Subject: [PATCH 197/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EA=B3=BC=20=EB=A7=A4=EC=9E=A5=20=EC=95=84=EC=9D=B4?= =?UTF-8?q?=EB=94=94=EB=A1=9C=20=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=9D=BD=EC=96=B4=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationTimeRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 1b37a04c..18936a26 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.reservation.repository; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -10,4 +12,8 @@ public interface ReservationTimeRepository extends JpaRepository findByIdWithShop(@Param("id") Long id); + + //매장에 해당 예약시간이 있는지 읽어오는 작업 + @Query("select rt from ReservationTime rt where rt.id = :reservationTimeId and rt.shop.id = :shopId") + Optional findByIdAndShoId(@Param("reservationTimeId") Long reservationTimeId, @Param("shopId") Long shopId); } From db67396dceb16d92e464370e2c8e517e42919030 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 15:57:36 +0900 Subject: [PATCH 198/603] =?UTF-8?q?test=20:=20=EA=B5=AC=ED=98=84=ED=95=9C?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=EC=97=90=20=EB=8C=80=ED=95=9C=20repositor?= =?UTF-8?q?y=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationTimeRepositoryTest.java | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index 2bc06f17..d4c4a4bf 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.ErrorCode; @@ -9,35 +10,46 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import java.util.Optional; +import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -@SpringBootTest -@Transactional +@DataJpaTest +@AutoConfigureTestDatabase(replace = NONE) class ReservationTimeRepositoryTest { @Autowired private ReservationTimeRepository reservationTimeRepository; @Autowired private ShopRepository shopRepository; - - @Test - @DisplayName("예약시간과 그 시간의 매장까지 한번의 쿼리로 조회할 수 있다.") - void findReservationTimeWithShop() { + @BeforeEach + void setUp(){ Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); - ReservationTime savedTime = reservationTimeRepository.save(reservationTime); + reservationTimeRepository.save(reservationTime); + } + @Test + @DisplayName("예약시간과 그 시간의 매장까지 한번의 쿼리로 조회할 수 있다.") + void findReservationTimeWithShop() { + ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); ReservationTime findReservationTime = reservationTimeRepository.findByIdWithShop( - savedTime.getId()) + reservationTime.getId()) .orElseThrow(() -> new NotFoundCustomException(ErrorCode.NOT_EXIST_TIME)); + Shop shop = reservationTime.getShop(); assertAll( () -> assertThat(findReservationTime.getShop().getName()).isEqualTo(shop.getName()), @@ -47,7 +59,40 @@ void findReservationTimeWithShop() { shop.getCategory()), () -> assertThat(findReservationTime.getShop().getRating()).isEqualTo(shop.getRating()) ); + } + + @Test + @DisplayName("특정 매장에 특정 예약시간이 존재 하는지 조회할 수 있다") + void findReservationTimeByShop(){ + //given + List all = reservationTimeRepository.findAll(); + ReservationTime reservationTime = all.get(0); + Shop shop = reservationTime.getShop(); + + //when + ReservationTime findReservationTime = reservationTimeRepository.findByIdAndShoId( + reservationTime.getId(), shop.getId()).orElseThrow(); + + //then + assertAll( + () -> assertThat(findReservationTime.getShop()).isEqualTo(shop), + () -> assertThat(findReservationTime.getTime()).isEqualTo(reservationTime.getTime()) + ); + } + + @Test + @DisplayName("조회하려는 예약시간이 해당 매장에 없는 시간이면 null이 반환된다.") + void findReservationTimeNotInShop(){ + //given + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); + //when + Optional findReservationTime = reservationTimeRepository.findByIdAndShoId( + reservationTime.getId(), savedShop.getId()); // 해당 예약시간은 존재하지만 찾으려는 매장의 예약시간이 아니므로 null 리턴 예상 + //then + assertThat(findReservationTime).isEmpty(); } } \ No newline at end of file From 51a7817464e114395012e3a2f2ccef03d0374585 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 15:58:31 +0900 Subject: [PATCH 199/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=EB=A1=9C=20=EC=98=88=EC=95=BD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EA=B3=BC=20=EB=A7=A4=EC=9E=A5=EA=B9=8C=EC=A7=80=20=ED=95=9C?= =?UTF-8?q?=EB=B2=88=EC=97=90=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index a6a779f8..a13288b3 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -2,6 +2,7 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -11,4 +12,9 @@ public interface ReservationRepository extends JpaRepository + "join fetch r.reservationTime rt " + "join fetch rt.shop") List findAllWithReservationTimeAndShop(); + + @Query("select r from Reservation r " + + "join fetch r.reservationTime rt " + + "join fetch rt.shop") + Optional findByIdWithReservationTimeAndShop(Long reservationId); } From f47a3da2880180c079243950b93d966f567ccc99 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 15:58:52 +0900 Subject: [PATCH 200/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9A=94=EC=B2=AD=20dto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/ModifyReservationRequest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java new file mode 100644 index 00000000..dc2f488d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.reservation.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import java.time.LocalDate; +import java.time.LocalDateTime; + +public record ModifyReservationRequest(Long reservationTimeId, + int peopleCount) { + +} From aeaae6d1a201540a407052d2fd731596a4add1f6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 15:59:11 +0900 Subject: [PATCH 201/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9D=91=EB=8B=B5=20dto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ModifyReservationResponse.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/ModifyReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ModifyReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ModifyReservationResponse.java new file mode 100644 index 00000000..a7fa1df3 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ModifyReservationResponse.java @@ -0,0 +1,15 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record ModifyReservationResponse(String shopName, + String memberName, + @JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") + LocalDateTime date, + int peopleCount) { + +} From 415230e2fcbfbde7f808fd7ead58d63e605affc6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 16:02:07 +0900 Subject: [PATCH 202/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20->=20=EC=98=88=EC=95=BD=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=9D=91=EB=8B=B5=20dto=20=EB=B3=80=ED=99=98=20map?= =?UTF-8?q?per=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/mapper/ReservationMapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index 3abb6220..5f793796 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -29,4 +30,13 @@ public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation .build(); } + public static ModifyReservationResponse toModifyReservationResponse (Reservation reservation){ + return ModifyReservationResponse.builder() + .shopName(reservation.getShop().getName()) + .memberName("memberA") + .date(reservation.getReservationTime().getTime()) + .peopleCount(reservation.getPeopleCount()) + .build(); + } + } From d4c3154d97ec0fc1480a15b9cf4b7ca9050aad6c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 16:02:30 +0900 Subject: [PATCH 203/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/Reservation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index e933348b..7530044c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; @@ -60,4 +61,9 @@ public Reservation(ReservationStatus status, int peopleCount, this.shop = reservationTime.getShop(); } + public void modifyReservation(ReservationTime reservationTime, int peopleCount){ + this.reservationTime = reservationTime; + this.peopleCount = peopleCount; + } + } From 6c84b6afed32480acca5399b662bb37cfe764947 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 16:04:16 +0900 Subject: [PATCH 204/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 16be9d36..96677154 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -2,8 +2,11 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; +import static com.prgrms.catchtable.common.exception.ErrorCode.EXCEED_PEOPLE_COUNT; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.*; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -12,8 +15,10 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; @@ -32,13 +37,11 @@ public class ReservationService { @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findById( + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( request.reservationTimeId()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); - if (reservationTime.isPreOccupied()) { - throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); - } + validateIsPreOccupied(reservationTime); reservationAsync.setPreOcuppied(reservationTime); Shop shop = reservationTime.getShop(); @@ -57,9 +60,7 @@ public CreateReservationResponse registerReservation(CreateReservationRequest re request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); - if (reservationTime.isOccupied()) { - throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); - } + validateIsOccupied(reservationTime); reservationTime.reverseOccupied(); @@ -79,4 +80,34 @@ public List getAllReservation() { .map(ReservationMapper::toGetAllReservationRepsonse) .toList(); } + + @Transactional + public ModifyReservationResponse modifyReservation(Long reservavtionId, ModifyReservationRequest request){ + Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop(reservavtionId) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_RESERVATION)); //예약 Id로 예약 조회 + Shop shop = reservation.getShop(); + + ReservationTime reservationTime = reservationTimeRepository.findByIdAndShoId( + request.reservationTimeId(), shop.getId()) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_TIME)); // 예약한 매장의 수정하려는 시간을 조회 + + validateIsPreOccupied(reservationTime); // 예약시간이 선점되었는 지 확인 + + validateIsOccupied(reservationTime); // 예약시간이 이미 차지되었는 지 확인 + + reservation.modifyReservation(reservationTime, request.peopleCount()); // 예약 필드 값 수정하는 엔티티의 메소드 + + return toModifyReservationResponse(reservation); + } + private static void validateIsPreOccupied(ReservationTime reservationTime) { + if (reservationTime.isPreOccupied()) { + throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); + } + } + + private static void validateIsOccupied(ReservationTime reservationTime) { + if(reservationTime.isOccupied()){ + throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); + } + } } From f8c840b5c97905b612d9f5d68dd1d7a6c95bf14d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 16:04:32 +0900 Subject: [PATCH 205/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B4=80=EB=A0=A8=20ErrorCode=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index cff7cd26..39ca065e 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -14,6 +14,8 @@ public enum ErrorCode { ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), + NOT_EXIST_RESERVATION("존재하지 않는 예약입니다"), + EXCEED_PEOPLE_COUNT("예약인원이 해당 시간의 남은 수용가능 인원 수를 초과했습니다."), CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), From 6c87a35fc9e3d8c867fc628916c243dc583a1a61 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 03:56:21 +0900 Subject: [PATCH 206/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=84=A0=EC=A0=90=20=EB=A1=9C=EC=A7=81=EC=97=90=20=EB=8F=99?= =?UTF-8?q?=EC=8B=9C=EC=84=B1=20=EC=9D=B4=EC=8A=88=20=EC=A0=9C=EC=96=B4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 83a4fd1b..615fc401 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -21,11 +21,13 @@ import com.prgrms.catchtable.shop.domain.Shop; import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Slf4j public class ReservationService { private final ReservationTimeRepository reservationTimeRepository; @@ -36,26 +38,29 @@ public class ReservationService { @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); - while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { // 락 획득 시도 + while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))){ try { + log.info("대기"); Thread.sleep(1_500); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } + log.info("이제 획득"); ReservationTime reservationTime = reservationTimeRepository.findById(reservationTimeId) .orElseThrow(() -> { reservationLockRepository.unlock(reservationTimeId); return new NotFoundCustomException(NOT_EXIST_TIME); } - ); //예약시간 조회 후 없으면 락 해제 + 예외 발생 + ); - if (reservationTime.isPreOccupied()) { //이미 선점 된 예약시간이면 락 해제 후 예외 발생 + if (reservationTime.isPreOccupied()) { reservationLockRepository.unlock(reservationTimeId); + log.info("발생~"); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } - reservationAsync.setPreOcuppied(reservationTime); //예약 선점 여부 7분동안 true로 바꾸는 스케줄러 실행 + reservationAsync.setPreOcuppied(reservationTime); Shop shop = reservationTime.getShop(); reservationLockRepository.unlock(reservationTimeId); @@ -70,15 +75,15 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r @Transactional public CreateReservationResponse registerReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( //예약시간과 매장 한번에 가져옴 + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); - if (reservationTime.isOccupied()) { //이미 차지된 예약이면 예외 발생 + if (reservationTime.isOccupied()) { throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } - reservationTime.reverseOccupied(); //예약 차지된 상태로 변경 + reservationTime.reverseOccupied(); Reservation reservation = Reservation.builder() .status(COMPLETED) From 00072b8661b01f8780238e6cf2289c419500363c Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 17:30:56 +0900 Subject: [PATCH 207/603] =?UTF-8?q?refactor=20:=20response=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC=EC=9D=84=20=EC=9C=84=ED=95=9C=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingController.java | 6 +++--- .../catchtable/waiting/dto/WaitingMapper.java | 4 ++-- .../catchtable/waiting/dto/WaitingResponse.java | 15 +++++++++++++++ .../waiting/service/WaitingService.java | 5 +++-- .../controller/WaitingControllerDocsTest.java | 4 ++-- .../waiting/service/WaitingServiceTest.java | 4 ++-- 6 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index e3adec2e..a6f069f6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.waiting.controller; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.service.WaitingService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -20,10 +20,10 @@ public class WaitingController { private final WaitingService waitingService; @PostMapping("/{shopId}/{memberId}") - public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, + public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - CreateWaitingResponse response = waitingService.createWaiting(shopId, memberId, request); + WaitingResponse response = waitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index bf989af6..3c8836ba 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -21,8 +21,8 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static CreateWaitingResponse toCreateWaitingResponse(Waiting waiting, int waitingOrder) { - return CreateWaitingResponse.builder() + public static WaitingResponse toCreateWaitingResponse(Waiting waiting, int waitingOrder) { + return WaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java new file mode 100644 index 00000000..9b69282c --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java @@ -0,0 +1,15 @@ +package com.prgrms.catchtable.waiting.dto; + +import lombok.Builder; + +@Builder +public record WaitingResponse( + Long createdWaitingId, + Long shopId, + String shopName, + int peopleCount, + int waitingNumber, + int waitingOrder +) { + +} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 0a7718c7..bba5d581 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -13,7 +13,7 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.dto.WaitingMapper; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.time.LocalDate; @@ -34,7 +34,7 @@ public class WaitingService { private final MemberRepository memberRepository; private final ShopRepository shopRepository; - public CreateWaitingResponse createWaiting(Long shopId, Long memberId, + public WaitingResponse createWaiting(Long shopId, Long memberId, CreateWaitingRequest request) { // 연관 엔티티 조회 Member member = getMemberEntity(memberId); @@ -61,6 +61,7 @@ public CreateWaitingResponse createWaiting(Long shopId, Long memberId, return WaitingMapper.toCreateWaitingResponse(savedWaiting, waitingOrder); } + private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java index 8fcbab8d..9fb4c6f3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -15,7 +15,7 @@ import com.prgrms.catchtable.common.restdocs.RestDocsSupport; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.service.WaitingService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ void createWaiting() throws Exception { CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); - CreateWaitingResponse response = CreateWaitingResponse.builder() + WaitingResponse response = WaitingResponse.builder() .createdWaitingId(201L) .shopId(1L) .shopName("shop1") diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index f9ae2bd4..c3775373 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -13,7 +13,7 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.CreateWaitingResponse; +import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.time.LocalTime; import java.util.Optional; @@ -56,7 +56,7 @@ void createWaiting() { given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); //when - CreateWaitingResponse response = waitingService.createWaiting(1L, member.getId(), request); + WaitingResponse response = waitingService.createWaiting(1L, member.getId(), request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), From b54bd7839b8caefb7995767294fd16b352c7a5a7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 17:33:04 +0900 Subject: [PATCH 208/603] =?UTF-8?q?feat=20:=20=EB=A1=9C=EC=BB=AC=20queue?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EB=8C=80=EA=B8=B0?= =?UTF-8?q?=EC=97=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/line/WaitingInfo.java | 5 + .../waiting/line/WaitingLineRepository.java | 96 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java new file mode 100644 index 00000000..7d66dc68 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java @@ -0,0 +1,5 @@ +package com.prgrms.catchtable.waiting.line; + +public record WaitingInfo ( + Long waitingId +){} diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java new file mode 100644 index 00000000..8c93a5fd --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java @@ -0,0 +1,96 @@ +package com.prgrms.catchtable.waiting.line; + +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; +import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_ENTRY; +import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.LinkedList; +import java.util.Map; +import java.util.Objects; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +@Slf4j +@Component +public class WaitingLineRepository { + + public final Map> waitingLines = new ConcurrentHashMap<>(); + + public void save(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.computeIfAbsent(shopId, k -> new LinkedList<>()); + waitingLine.add(waitingId); + } + + public void entry(Long shopId, Long waitingId){ + Queue waitingLine = waitingLines.get(shopId); + if (!Objects.equals(waitingLine.peek(), waitingId)){ + throw new BadRequestCustomException(CAN_NOT_ENTRY); + } + waitingLine.remove(); + } + public void cancel(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + validateIfWaitingExists(waitingLine, waitingId); + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + waitingLine.remove(waitingIdInLine); + break; + } + } + } + + public void postpone(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + validateIfWaitingExists(waitingLine, waitingId); + if (findRank(shopId, waitingId)==findRankEnd(shopId)){{ + throw new BadRequestCustomException(ALREADY_END_LINE); + }} + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + waitingLine.remove(waitingIdInLine); + waitingLine.add(waitingIdInLine); + break; + } + } + } + + public int findRank(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + + int index = 0; + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + return index + 1; + } + index++; + } + return -1; + } + + public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { + if (!waitingLine.contains(waitingId)) { + throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); + } + } + + public int findRankEnd(Long shopId) { //postpone에서 사용 + Queue waitingLine = waitingLines.get(shopId); + return waitingLine != null ? waitingLine.size() : 0; + } + + public void clear(){ + waitingLines.clear(); + } + + public void printQueue(Long shopId) { + Queue waitingLine = waitingLines.get(shopId); + if (waitingLine != null) { + log.info("Queue: {}", waitingLine); + } else { + log.warn("Queue is empty or not found for Shop ID: {}", shopId); + } + } +} From 724af91c29a5d25ab0f6525c72fa5753d9e4aa0c Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 17:33:24 +0900 Subject: [PATCH 209/603] =?UTF-8?q?feat=20:=20=EB=A1=9C=EC=BB=AC=20queue?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../line/WaitingLineRepositoryTest.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java new file mode 100644 index 00000000..d9bbdd7a --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java @@ -0,0 +1,115 @@ +package com.prgrms.catchtable.waiting.line; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class WaitingLineRepositoryTest { + + private final WaitingLineRepository waitingLineRepository = new WaitingLineRepository(); + + + @AfterEach() + void clear() { + waitingLineRepository.clear(); + } + + @DisplayName("입장 시 뒤 대기 순서 1씩 앞당겨짐") + @Test + void entry() { + //given + Long shopId = 1L; + + waitingLineRepository.save(shopId, 1L); + waitingLineRepository.save(shopId,2L); + waitingLineRepository.save(shopId,3L); + + //when + waitingLineRepository.entry(1L, 1L); + + //then + assertThat(waitingLineRepository.findRank(1L, 1L)) + .isEqualTo(-1); + assertThat(waitingLineRepository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(waitingLineRepository.findRank(1L, 3L)) + .isEqualTo(2); + } + + @DisplayName("저장 후 대기순서를 가져올 수 있다.") + @Test + void save() { + //given + Long shopId = 1L; + Long waitingId = 1L; + //when + waitingLineRepository.save(shopId, waitingId); + //then + int waitingOrder = waitingLineRepository.findRank(1L, 1L); + assertThat(waitingOrder).isEqualTo(1); + } + + @DisplayName("지연 시 대기 순서가 맨 뒤가 된다. 뒷 순서의 요소들은 한 칸씩 앞으로 이동한다.") + @Test + void postpone() { + //given + Long shopId = 1L; + + waitingLineRepository.save(shopId, 1L); + waitingLineRepository.save(shopId,2L); + waitingLineRepository.save(shopId,3L); + + //when + waitingLineRepository.postpone(1L, 1L); + + //then + assertThat(waitingLineRepository.findRank(1L, 1L)) + .isEqualTo(3); + assertThat(waitingLineRepository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(waitingLineRepository.findRank(1L, 3L)) + .isEqualTo(2); + + } + + @DisplayName("맨 뒤에 있을 시 대기 지연을 할 수 없다.") + @Test + void postpone_fails() { + //given + Long shopId = 1L; + + waitingLineRepository.save(shopId, 1L); + waitingLineRepository.save(shopId,2L); + waitingLineRepository.save(shopId,3L); + + //when, then + assertThrows(BadRequestCustomException.class, + () -> waitingLineRepository.postpone(shopId, 3L)); + } + + @DisplayName("대기 취소를 할 수 있다.") + @Test + void cancel() { + //given + Long shopId = 1L; + + waitingLineRepository.save(shopId, 1L); + waitingLineRepository.save(shopId,2L); + waitingLineRepository.save(shopId,3L); + + //when + waitingLineRepository.cancel(1L, 1L); + //then + assertThat(waitingLineRepository.findRank(1L, 1L)) + .isEqualTo(-1); + assertThat(waitingLineRepository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(waitingLineRepository.findRank(1L, 3L)) + .isEqualTo(2); + } + +} \ No newline at end of file From ed8ada99448de917bea03373000ee3f9ad2785f3 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:35:14 +0900 Subject: [PATCH 210/603] =?UTF-8?q?feat=20:=20Owner=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=9D=84=20=EC=9C=84=ED=95=9C=20email=20&=20Password?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/owner/domain/Owner.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index f6d09f8f..64b7ea81 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -35,6 +35,12 @@ public class Owner extends BaseEntity { @Column(name = "owner_name") private String name; + @Column(name = "email") + private String email; + + @Column(name = "password") + private String password; + @Column(name = "phone_number") private String phoneNumber; @@ -50,8 +56,10 @@ public class Owner extends BaseEntity { private Shop shop; @Builder - public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String password, String phoneNumber, Gender gender, LocalDate dateBirth) { this.name = name; + this.email = email; + this.password = password; this.phoneNumber = phoneNumber; this.gender = gender; this.dateBirth = dateBirth; From 64aeb0f620622f0b5a48065b48d9b8674b73d076 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 17:35:20 +0900 Subject: [PATCH 211/603] =?UTF-8?q?feat=20:=20redis=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/line/config/RedisConfig.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java b/src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java new file mode 100644 index 00000000..b3674380 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java @@ -0,0 +1,22 @@ +package com.prgrms.catchtable.waiting.line.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; + +@Configuration +public class RedisConfig { + + @Value("${spring.data.redis.host}") + private String host; + + @Value("${spring.data.redis.port}") + private int port; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(host, port); + } +} From 28c3c45261c70891992c4353c8076fb1323baa66 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:36:32 +0900 Subject: [PATCH 212/603] =?UTF-8?q?feat=20:=20Owner=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/dto/OwnerMapper.java | 31 +++++++++++++++++++ .../owner/dto/request/JoinOwnerRequest.java | 21 +++++++++++++ .../owner/dto/response/JoinOwnerResponse.java | 16 ++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java create mode 100644 src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/owner/dto/response/JoinOwnerResponse.java diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java new file mode 100644 index 00000000..bca17dd2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java @@ -0,0 +1,31 @@ +package com.prgrms.catchtable.owner.dto; + +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; + +public class OwnerMapper { + + public static Owner toEntity(JoinOwnerRequest joinOwnerRequest, String encodePassword, Gender gender){ + return Owner.builder() + .name(joinOwnerRequest.name()) + .email(joinOwnerRequest.email()) + .password(joinOwnerRequest.password()) + .phoneNumber(joinOwnerRequest.phoneNumber()) + .gender(gender) + .dateBirth(joinOwnerRequest.dateBirth()) + .build(); + } + + public static JoinOwnerResponse from(Owner owner){ + return JoinOwnerResponse.builder() + .name(owner.getName()) + .email(owner.getEmail()) + .phoneNumber(owner.getPhoneNumber()) + .gender(owner.getGender().getType()) + .dateBirth(owner.getDateBirth()) + .build(); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java new file mode 100644 index 00000000..80c67856 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java @@ -0,0 +1,21 @@ +package com.prgrms.catchtable.owner.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Pattern; +import java.time.LocalDate; + +public record JoinOwnerRequest( + + String name, + @Email + String email, + String password, + @Pattern(regexp = "^(01[016789]){1}([0-9]{3,4}){1}([0-9]{4}){1}$") + String phoneNumber, + String gender, + @JsonFormat(pattern = "yyyy-MM-dd") + LocalDate dateBirth +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/response/JoinOwnerResponse.java b/src/main/java/com/prgrms/catchtable/owner/dto/response/JoinOwnerResponse.java new file mode 100644 index 00000000..766c0606 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/dto/response/JoinOwnerResponse.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.owner.dto.response; + +import java.time.LocalDate; +import lombok.Builder; + +@Builder +public record JoinOwnerResponse( + + String name, + String email, + String phoneNumber, + String gender, + LocalDate dateBirth +) { + +} From 2179ae05611130dbfa55d78b594c13792c60b4fa Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:36:50 +0900 Subject: [PATCH 213/603] feat : PasswordEncoder --- .../prgrms/catchtable/security/config/SecurityConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 4871a801..2dc6af45 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -10,6 +10,8 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @@ -24,6 +26,11 @@ public class SecurityConfig { private final ExceptionHandlerFilter exceptionHandlerFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter; + @Bean + public PasswordEncoder passwordEncoder(){ + return new BCryptPasswordEncoder(); + } + @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { From ae90cfb45b70a86a262e76eccde51e5b3d7d66ae Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:41:16 +0900 Subject: [PATCH 214/603] =?UTF-8?q?fix=20:=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=8B=9C=20encoding=EB=90=9C=20Password=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java index bca17dd2..36386be2 100644 --- a/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java +++ b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java @@ -11,7 +11,7 @@ public static Owner toEntity(JoinOwnerRequest joinOwnerRequest, String encodePas return Owner.builder() .name(joinOwnerRequest.name()) .email(joinOwnerRequest.email()) - .password(joinOwnerRequest.password()) + .password(encodePassword) .phoneNumber(joinOwnerRequest.phoneNumber()) .gender(gender) .dateBirth(joinOwnerRequest.dateBirth()) From 76678a99cb970d6742744a09713d6f08002d537b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:48:16 +0900 Subject: [PATCH 215/603] =?UTF-8?q?feat=20:=20=EC=84=B1=EB=B3=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 4 ++- .../catchtable/member/domain/Gender.java | 26 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index cff7cd26..5c7df7f4 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -18,7 +18,9 @@ public enum ErrorCode { CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), - INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); + INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), + + BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); private final String message; } diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java index 7339bcfe..999f8a71 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java @@ -1,6 +1,28 @@ package com.prgrms.catchtable.member.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import java.util.Arrays; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor public enum Gender { - MALE, - FEMALE + MALE("male"), + FEMALE("female"); + + private final String type; + + public static Gender of(String input){ + return Arrays.stream(values()) + .filter(gender -> gender.isEqual(input)) + .findAny() + .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_INPUT_GENDER_TYPE)); + } + + private boolean isEqual(String input){ + return input.equals(this.type); + } } From 15849da642c8e0f666070f8908c02e6601f300ee Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:49:12 +0900 Subject: [PATCH 216/603] =?UTF-8?q?feat=20:=20Owner=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 + .../owner/repository/OwnerRepository.java | 2 + .../owner/service/OwnerService.java | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 5c7df7f4..e0ef1d00 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -20,6 +20,7 @@ public enum ErrorCode { SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), + ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); private final String message; diff --git a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java index 3dbeb442..be512d0f 100644 --- a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java @@ -5,4 +5,6 @@ public interface OwnerRepository extends JpaRepository { + boolean existsOwnerByEmail(String email); + } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java new file mode 100644 index 00000000..cc7518dc --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -0,0 +1,40 @@ +package com.prgrms.catchtable.owner.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.dto.OwnerMapper; +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OwnerService { + + private final OwnerRepository ownerRepository; + private final PasswordEncoder passwordEncoder; + + public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { + + //이미 존재하는 이메일이라면 + if (ownerRepository.existsOwnerByEmail(joinOwnerRequest.email())) { + throw new BadRequestCustomException(ALREADY_EXIST_OWNER); + } + + String encodePassword = passwordEncoder.encode(joinOwnerRequest.password()); + + Gender gender = Gender.of(joinOwnerRequest.gender()); + + Owner joinOwner = ownerRepository.save(OwnerMapper.toEntity(joinOwnerRequest, encodePassword, gender)); + + return OwnerMapper.from(joinOwner); + + } + +} From 5b67aeaa4bfc40619b3a928f0d568206aabbd576 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 17:58:04 +0900 Subject: [PATCH 217/603] =?UTF-8?q?feat=20:=20Owner=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../owner/controller/OwnerController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java new file mode 100644 index 00000000..39dedd68 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -0,0 +1,29 @@ +package com.prgrms.catchtable.owner.controller; + +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; +import com.prgrms.catchtable.owner.service.OwnerService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/owners") +public class OwnerController { + + private final OwnerService ownerService; + + @PostMapping("/join") + public ResponseEntity join(@Valid @RequestBody JoinOwnerRequest joinOwnerRequest){ + JoinOwnerResponse joinOwnerResponse = ownerService.joinOwner(joinOwnerRequest); + + return ResponseEntity.status(HttpStatus.CREATED).body(joinOwnerResponse); + } + +} From 22cfd9bde0e927b656794d3313709517ee42ca98 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 18:18:21 +0900 Subject: [PATCH 218/603] =?UTF-8?q?feat=20:=20UserDetails=20=EC=83=81?= =?UTF-8?q?=EC=86=8D=20&=20role=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/domain/Owner.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index 64b7ea81..7d397eba 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -6,11 +6,13 @@ import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; @@ -18,14 +20,19 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; import java.time.LocalDate; +import java.util.Collection; +import java.util.Collections; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Owner extends BaseEntity { +public class Owner extends BaseEntity implements UserDetails { @Id @GeneratedValue(strategy = IDENTITY) @@ -48,6 +55,10 @@ public class Owner extends BaseEntity { @Enumerated(STRING) private Gender gender; + @Column(name = "role") + @Enumerated(STRING) + private Role role; + @Column(name = "date_birth") private LocalDate dateBirth; @@ -63,5 +74,36 @@ public Owner(String name, String email, String password, String phoneNumber, Gen this.phoneNumber = phoneNumber; this.gender = gender; this.dateBirth = dateBirth; + this.role = Role.OWNER; + } + + @Override + public Collection getAuthorities() { + return Collections.singletonList(new SimpleGrantedAuthority(role.getRole())); + } + + @Override + public String getUsername() { + return email; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; } } From eed4958c83a4ffba43de7997e7206d15de728557 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 18:31:59 +0900 Subject: [PATCH 219/603] =?UTF-8?q?feat=20:=20Owner=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/exception/ErrorCode.java | 1 + .../owner/dto/request/LoginOwnerRequest.java | 13 +++++++++++++ .../owner/repository/OwnerRepository.java | 3 +++ .../catchtable/owner/service/OwnerService.java | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index e0ef1d00..fc11434b 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -21,6 +21,7 @@ public enum ErrorCode { INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), + BAD_REQUEST_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); private final String message; diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java b/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java new file mode 100644 index 00000000..91368d5f --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java @@ -0,0 +1,13 @@ +package com.prgrms.catchtable.owner.dto.request; + +import jakarta.validation.constraints.Email; + +public record LoginOwnerRequest( + + @Email + String email, + String password + +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java index be512d0f..5e783c0e 100644 --- a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java @@ -1,10 +1,13 @@ package com.prgrms.catchtable.owner.repository; import com.prgrms.catchtable.owner.domain.Owner; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface OwnerRepository extends JpaRepository { boolean existsOwnerByEmail(String email); + Optional findOwnerByEmail(String email); + } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index cc7518dc..a425756f 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -3,10 +3,13 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.*; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.OwnerMapper; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; import com.prgrms.catchtable.owner.repository.OwnerRepository; import lombok.RequiredArgsConstructor; @@ -19,6 +22,7 @@ public class OwnerService { private final OwnerRepository ownerRepository; private final PasswordEncoder passwordEncoder; + private final JwtTokenProvider jwtTokenProvider; public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { @@ -37,4 +41,18 @@ public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { } + public Token ownerLogin(LoginOwnerRequest loginRequest){ + + //email 확인 + Owner loginOwner = ownerRepository.findOwnerByEmail(loginRequest.email()) + .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD)); + + //password 확인 + if(passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())){ + throw new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD); + } + + return jwtTokenProvider.createToken(loginOwner.getEmail()); + } + } From 44c78afb00441625d8cf6138e9c10f8469e4949f Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 18:34:19 +0900 Subject: [PATCH 220/603] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/owner/service/OwnerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index a425756f..464ebd7d 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -41,7 +41,7 @@ public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { } - public Token ownerLogin(LoginOwnerRequest loginRequest){ + public Token loginOwner(LoginOwnerRequest loginRequest){ //email 확인 Owner loginOwner = ownerRepository.findOwnerByEmail(loginRequest.email()) From 2fe4fb521ea8defed8ad63af48e0c730e3960258 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Thu, 4 Jan 2024 18:34:31 +0900 Subject: [PATCH 221/603] =?UTF-8?q?feat=20:=20Owner=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/controller/OwnerController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java index 39dedd68..8a047521 100644 --- a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.owner.controller; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; import com.prgrms.catchtable.owner.service.OwnerService; import jakarta.validation.Valid; @@ -26,4 +28,11 @@ public ResponseEntity join(@Valid @RequestBody JoinOwnerReque return ResponseEntity.status(HttpStatus.CREATED).body(joinOwnerResponse); } + @PostMapping("/login") + public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOwnerRequest){ + Token responseToken = ownerService.loginOwner(loginOwnerRequest); + + return ResponseEntity.ok(responseToken); + } + } From 72cf83e4521b3ec65f5926220e9dac0a9bd29fdd Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 19:04:35 +0900 Subject: [PATCH 222/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=9A=94=EC=B2=AD=20dto=20=EB=B9=8C?= =?UTF-8?q?=EB=8D=94=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/ModifyReservationRequest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java index dc2f488d..f9d9d04f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationRequest.java @@ -1,10 +1,8 @@ package com.prgrms.catchtable.reservation.dto.request; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonFormat.Shape; -import java.time.LocalDate; -import java.time.LocalDateTime; +import lombok.Builder; +@Builder public record ModifyReservationRequest(Long reservationTimeId, int peopleCount) { From 4e57cc52cfe9ac307293db94910583fc324fcfb2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 19:04:59 +0900 Subject: [PATCH 223/603] =?UTF-8?q?feat=20:=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20static=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index f185e5f4..900fbee9 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -2,12 +2,11 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; -import static com.prgrms.catchtable.common.exception.ErrorCode.EXCEED_PEOPLE_COUNT; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.*; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toModifyReservationResponse; import static java.lang.Boolean.FALSE; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -114,14 +113,17 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, ModifyRe return toModifyReservationResponse(reservation); } - private static void validateIsPreOccupied(ReservationTime reservationTime) { + + private void validateIsPreOccupied(ReservationTime reservationTime) { if (reservationTime.isPreOccupied()) { + reservationLockRepository.unlock(reservationTime.getId()); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } } - private static void validateIsOccupied(ReservationTime reservationTime) { + private void validateIsOccupied(ReservationTime reservationTime) { if(reservationTime.isOccupied()){ + reservationLockRepository.unlock(reservationTime.getId()); throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } } From 97a831d7cc302451309caa0d2c0eea2ffd922df9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 19:05:10 +0900 Subject: [PATCH 224/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=98=88=EC=A0=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixture/ReservationFixture.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index 236bdc4d..ec0c3d45 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -6,6 +6,7 @@ import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; @@ -55,4 +56,31 @@ public static CreateReservationRequest getCreateReservationRequest() { .build(); } + public static ModifyReservationRequest getModifyReservationRequest(Long reservationTimeId){ + return ModifyReservationRequest.builder() + .reservationTimeId(reservationTimeId) + .peopleCount(2) + .build(); + } + + + public static ReservationTime getAnotherReservationTimeNotPreOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 11, 30, 19, 30)) + .build(); + reservationTime.insertShop(ShopData.getShop()); + return reservationTime; + } + + public static ReservationTime getReservationTimeOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 12, 31, 19, 30)) + .build(); + Shop shop = ShopData.getShop(); + ReflectionTestUtils.setField(shop, "id", 1L); + reservationTime.insertShop(shop); + reservationTime.reverseOccupied(); + return reservationTime; + } + } From 0c94d16dca461ab2b548cd4cde3733b5114527c5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 19:05:38 +0900 Subject: [PATCH 225/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=9D=98=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=A9=94=EC=86=8C=EB=93=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/domain/ReservationTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java new file mode 100644 index 00000000..0d9a71ad --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java @@ -0,0 +1,30 @@ +package com.prgrms.catchtable.reservation.domain; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ReservationTest { + + @Test + @DisplayName("예약 정보 수정에 성공한다.") + void modifyReservationEntity() { + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + + ReservationTime modifyReservationTime = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); + int modifyPeopleCount = 10; + + reservation.modifyReservation(modifyReservationTime, modifyPeopleCount); + + assertAll( + () -> assertThat(reservation.getReservationTime()).isEqualTo(modifyReservationTime), + () -> assertThat(reservation.getPeopleCount()).isEqualTo(modifyPeopleCount) + ); + } + +} \ No newline at end of file From ef8bdd90f4cf9e8deab74dedc7baf8cd3a060330 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 19:05:55 +0900 Subject: [PATCH 226/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=A1=9C=EC=A7=81=20=EB=8B=A8=EC=9C=84?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 05bb271c..508020d4 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -9,16 +9,20 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.reservation.repository.ReservationLockRepository; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import com.prgrms.catchtable.shop.domain.Shop; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -156,4 +160,72 @@ void getAllReservationWithNoResult() { assertThat(all).isEmpty(); } + @Test + @DisplayName("예약 수정을 성공한다.") + void modifyReservation(){ + //given + Shop shop = ShopData.getShop(); + ReflectionTestUtils.setField(shop, "id", 1L); //shop 생성 + + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + reservationTime.insertShop(shop); + ReflectionTestUtils.setField(reservationTime, "id", 1L); // 수정 전 예약시간 객체 -> Id : 1 + + ReservationTime modifyTime = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); + ReflectionTestUtils.setField(modifyTime, "id", 2L); //수정하려는 예약시간 객체 -> Id : 2 + + Reservation reservation = ReservationFixture.getReservation(reservationTime); + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( + 2L); + + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(2L, 1L)).thenReturn(Optional.of(modifyTime)); + + //when + ModifyReservationResponse response = reservationService.modifyReservation( + 1L, request); // 예약 id가 1인 예약 정보 변경 + + //then + assertAll( + () -> assertThat(response.date()).isEqualTo(modifyTime.getTime()), + () -> assertThat(response.peopleCount()).isEqualTo(reservation.getPeopleCount()), + () -> assertThat(reservation.getReservationTime()).isEqualTo(modifyTime) + ); + } + + @Test + @DisplayName("존재하지 않는 예약에 대한 수정을 요청할 경우 예외가 발생한다.") + void modifyReservationNotExist(){ + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.empty()); + + assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L, request)); + } + + @Test + @DisplayName("타인에게 선점된 상태인 예약시간으로 변경하려 하면 예외가 발생한다.") + void modifyReservationPreOccupied(){ + ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); + + assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L ,request)); + } + + @Test + @DisplayName("타인이 이미 예약한 시간으로 변경하려 하면 예외가 발생한다.") + void modifyReservationOccupied(){ + ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); + + assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L ,request)); + } + } \ No newline at end of file From 11af8ba76131a66a786aecaec13b74d0afca1718 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 21:06:20 +0900 Subject: [PATCH 227/603] =?UTF-8?q?feat=20:=20test=EC=9A=A9=20redis=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml index e8f2e025..1beefa13 100644 --- a/src/test/resources/application.yaml +++ b/src/test/resources/application.yaml @@ -33,7 +33,10 @@ spring: token-uri: https://kauth.kakao.com/oauth/token user-info-uri: https://kapi.kakao.com/v2/user/me user-name-attribute: id - + data: + redis: + host: localhost + port: 6379 jwt: client-secret: S0gKf9bwPzT7eAJN3RyWvQlKcY4uGh1jIxDp5VrC8EoH2dL6sMkXaF7ZtL9W6dR1 expiry-minute: 5 #5분 From 23027704b2f8aaaf957bfc8e4c5f476364650368 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 22:16:45 +0900 Subject: [PATCH 228/603] =?UTF-8?q?refactor=20:=20waitingLineRepository=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/line/WaitingInfo.java | 5 ----- .../waiting/line/WaitingLineRepository.java | 18 +++++++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java deleted file mode 100644 index 7d66dc68..00000000 --- a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingInfo.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.prgrms.catchtable.waiting.line; - -public record WaitingInfo ( - Long waitingId -){} diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java index 8c93a5fd..0936d83f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java @@ -45,9 +45,7 @@ public void cancel(Long shopId, Long waitingId) { public void postpone(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); validateIfWaitingExists(waitingLine, waitingId); - if (findRank(shopId, waitingId)==findRankEnd(shopId)){{ - throw new BadRequestCustomException(ALREADY_END_LINE); - }} + validateIfPostponeAvailable(shopId, waitingId); for (Long waitingIdInLine : waitingLine) { if (Objects.equals(waitingIdInLine, waitingId)) { waitingLine.remove(waitingIdInLine); @@ -70,22 +68,28 @@ public int findRank(Long shopId, Long waitingId) { return -1; } + public int findEndRank(Long shopId) { //postpone에서 사용 + Queue waitingLine = waitingLines.get(shopId); + return waitingLine != null ? waitingLine.size() : 0; + } + public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { if (!waitingLine.contains(waitingId)) { throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); } } - public int findRankEnd(Long shopId) { //postpone에서 사용 - Queue waitingLine = waitingLines.get(shopId); - return waitingLine != null ? waitingLine.size() : 0; + private void validateIfPostponeAvailable(Long shopId, Long waitingId) { + if (findRank(shopId, waitingId)== findEndRank(shopId)){{ + throw new BadRequestCustomException(ALREADY_END_LINE); + }} } public void clear(){ waitingLines.clear(); } - public void printQueue(Long shopId) { + public void printWaitingLine(Long shopId) { Queue waitingLine = waitingLines.get(shopId); if (waitingLine != null) { log.info("Queue: {}", waitingLine); From b86b12ee72b14440f74309445cd45e7af9a29665 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 22:17:47 +0900 Subject: [PATCH 229/603] =?UTF-8?q?feat=20:=20redis=20queue=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../line/RedisWaitingLineRepository.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java new file mode 100644 index 00000000..84b1de0d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java @@ -0,0 +1,127 @@ +package com.prgrms.catchtable.waiting.line; + +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; +import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.List; +import java.util.Objects; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.data.redis.core.RedisOperations; +import org.springframework.data.redis.core.SessionCallback; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +@Slf4j +@RequiredArgsConstructor +@Component +public class RedisWaitingLineRepository { + + private final StringRedisTemplate redisTemplate; + + public void save(Long shopId, Long waitingId) { + redisTemplate.execute(new SessionCallback<>() { + @Override + public Object execute(RedisOperations operations) + throws DataAccessException { + try { + operations.multi(); + redisTemplate.opsForList().leftPush("s" + shopId, waitingId.toString()); + return operations.exec(); + } catch (Exception e) { + operations.discard(); + } + return operations.exec(); + } + }); + } + + public void entry(Long shopId, Long waitingId){ + validateIfWaitingExists(shopId, waitingId); + redisTemplate.execute(new SessionCallback<>() { + @Override + public Object execute(RedisOperations operations) + throws DataAccessException { + try { + operations.multi(); + redisTemplate.opsForList().rightPop("s" + shopId); + return operations.exec(); + } catch (Exception e) { + operations.discard(); + } + return operations.exec(); + } + }); + } + + public void cancel(Long shopId, Long waitingId) { + validateIfWaitingExists(shopId, waitingId); + redisTemplate.execute(new SessionCallback<>() { + @Override + public Object execute(RedisOperations operations) + throws DataAccessException { + try { + operations.multi(); + redisTemplate.opsForList().remove("s"+shopId,1,waitingId.toString()); + return operations.exec(); + } catch (Exception e) { + operations.discard(); + } + return operations.exec(); + } + }); + } + + public void postpone(Long shopId, Long waitingId) { + validateIfWaitingExists(shopId, waitingId); + if (Objects.equals(findRank(shopId, waitingId), findEndRank(shopId))) { + throw new BadRequestCustomException(ALREADY_END_LINE); + } + redisTemplate.execute(new SessionCallback<>() { + @Override + public Object execute(RedisOperations operations) + throws DataAccessException { + try { + operations.multi(); + redisTemplate.opsForList().rightPop("s" + shopId); + redisTemplate.opsForList().leftPush("s" + shopId, waitingId.toString()); + return operations.exec(); + } catch (Exception e) { + operations.discard(); + } + return operations.exec(); + } + }); + } + + public Long findRank(Long shopId, Long waitingId) { + Long index = redisTemplate.opsForList().indexOf("s" + shopId, waitingId.toString()); + if (index == null) { + throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); + } + return findEndRank(shopId)-index; + } + + public void validateIfWaitingExists(Long shopId, Long waitingId) { + Long index = redisTemplate.opsForList().indexOf("s" + shopId, waitingId.toString()); + if (index == null) { + throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); + } + } + + public Long findEndRank(Long shopId) { + return redisTemplate.opsForList().size("s" + shopId); + } + + public void printWaitingLine(Long shopId) { + List waitingLine = redisTemplate.opsForList().range("s" + shopId, 0, -1); + if (waitingLine != null) { + log.info("Queue: {}", waitingLine); + } else { + log.warn("Queue is empty or not found for Shop ID: {}", shopId); + } + } +} From 2eed85ba0913d7fc24ad1296dec54bd69a6d244d Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 22:18:15 +0900 Subject: [PATCH 230/603] =?UTF-8?q?feat=20:=20redis=20queue=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../line/RedisWaitingLineRepositoryTest.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java new file mode 100644 index 00000000..077744a4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java @@ -0,0 +1,127 @@ +package com.prgrms.catchtable.waiting.line; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.StringRedisTemplate; + +@SpringBootTest +class RedisWaitingLineRepositoryTest { + + @Autowired + private RedisWaitingLineRepository repository; + + @Autowired + private StringRedisTemplate redisTemplate; + + + @AfterEach + void clear() { + redisTemplate.delete("s1"); + redisTemplate.delete("s2"); + redisTemplate.delete("s3"); + } + + @DisplayName("큐에 웨이팅을 추가한 후 순서를 반환받을 수 있다.") + @Test + void save() { + //given + Long shopId = 1L; + Long waitingId = 1L; + //when + repository.save(shopId, waitingId); + + //then + Long waitingOrder = repository.findRank(1L, 1L); + assertThat(waitingOrder).isEqualTo(1L); + } + + @DisplayName("입장 시 뒤 대기 순서 1씩 앞당겨짐") + @Test + void entry() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + + //when + repository.entry(1L, 1L); + + //then + + assertThrows(NotFoundCustomException.class, + () -> repository.findRank(1L, 1L)); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + } + + @DisplayName("지연 시 대기 순서가 맨 뒤가 된다. 뒷 순서의 요소들은 한 칸씩 앞으로 이동한다.") + @Test + void postpone() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId,2L); + repository.save(shopId,3L); + + //when + repository.postpone(1L, 1L); + + //then + assertThat(repository.findRank(1L, 1L)) + .isEqualTo(3); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + + } + + @DisplayName("맨 뒤에 있을 시 대기 지연을 할 수 없다.") + @Test + void postpone_fails() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId,2L); + repository.save(shopId,3L); + + //when, then + assertThrows(BadRequestCustomException.class, + () -> repository.postpone(shopId, 3L)); + } + + @DisplayName("대기 취소를 할 수 있다.") + @Test + void cancel() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId,2L); + repository.save(shopId,3L); + + //when + repository.cancel(1L, 1L); + //then + assertThrows(NotFoundCustomException.class, + () -> repository.findRank(1L, 1L)); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + } +} \ No newline at end of file From 9003e47dd8915448d30a550d5ccd2fcbe5ddfecd Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 4 Jan 2024 22:24:47 +0900 Subject: [PATCH 231/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/exception/ErrorCode.java | 4 ++++ .../reservation/service/ReservationService.java | 3 ++- .../security/config/SecurityConfig.java | 1 - .../security/controller/TestController.java | 2 +- .../waiting/dto/CreateWaitingResponse.java | 15 --------------- .../waiting/line/RedisWaitingLineRepository.java | 6 +++--- .../waiting/line/WaitingLineRepository.java | 16 ++++++++++------ .../waiting/service/WaitingService.java | 2 +- .../jwt/service/JwtUserDetailsServiceTest.java | 3 ++- .../controller/JwtAuthenticationTest.java | 4 ++-- .../line/RedisWaitingLineRepositoryTest.java | 12 ++++++------ .../waiting/line/WaitingLineRepositoryTest.java | 16 ++++++++-------- 12 files changed, 39 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index cff7cd26..3773494a 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -17,6 +17,10 @@ public enum ErrorCode { CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), + ALREADY_END_LINE("이미 맨뒤라 지연할 수 없습니다."), + + CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), + WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 83a4fd1b..00f3f124 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -70,7 +70,8 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r @Transactional public CreateReservationResponse registerReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( //예약시간과 매장 한번에 가져옴 + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( + //예약시간과 매장 한번에 가져옴 request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 4871a801..a90e7933 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -13,7 +13,6 @@ import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import org.springframework.stereotype.Component; @Configuration @RequiredArgsConstructor diff --git a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java index 6973411d..56f32d9a 100644 --- a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java +++ b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java @@ -10,7 +10,7 @@ public class TestController { @GetMapping("/testMember") - public ResponseEntity testMember(){ + public ResponseEntity testMember() { log.info("testMember"); return ResponseEntity.ok("testMember OK"); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java deleted file mode 100644 index 66f30561..00000000 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.prgrms.catchtable.waiting.dto; - -import lombok.Builder; - -@Builder -public record CreateWaitingResponse( - Long createdWaitingId, - Long shopId, - String shopName, - int peopleCount, - int waitingNumber, - int waitingOrder -) { - -} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java index 84b1de0d..3230ebda 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java @@ -39,7 +39,7 @@ public Object execute(RedisOperations operations) }); } - public void entry(Long shopId, Long waitingId){ + public void entry(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); redisTemplate.execute(new SessionCallback<>() { @Override @@ -65,7 +65,7 @@ public Object execute(RedisOperations operations) throws DataAccessException { try { operations.multi(); - redisTemplate.opsForList().remove("s"+shopId,1,waitingId.toString()); + redisTemplate.opsForList().remove("s" + shopId, 1, waitingId.toString()); return operations.exec(); } catch (Exception e) { operations.discard(); @@ -102,7 +102,7 @@ public Long findRank(Long shopId, Long waitingId) { if (index == null) { throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); } - return findEndRank(shopId)-index; + return findEndRank(shopId) - index; } public void validateIfWaitingExists(Long shopId, Long waitingId) { diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java index 0936d83f..3e74d9ce 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java @@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; + @Slf4j @Component public class WaitingLineRepository { @@ -24,13 +25,14 @@ public void save(Long shopId, Long waitingId) { waitingLine.add(waitingId); } - public void entry(Long shopId, Long waitingId){ + public void entry(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); - if (!Objects.equals(waitingLine.peek(), waitingId)){ + if (!Objects.equals(waitingLine.peek(), waitingId)) { throw new BadRequestCustomException(CAN_NOT_ENTRY); } waitingLine.remove(); } + public void cancel(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); validateIfWaitingExists(waitingLine, waitingId); @@ -80,12 +82,14 @@ public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { } private void validateIfPostponeAvailable(Long shopId, Long waitingId) { - if (findRank(shopId, waitingId)== findEndRank(shopId)){{ - throw new BadRequestCustomException(ALREADY_END_LINE); - }} + if (findRank(shopId, waitingId) == findEndRank(shopId)) { + { + throw new BadRequestCustomException(ALREADY_END_LINE); + } + } } - public void clear(){ + public void clear() { waitingLines.clear(); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index bba5d581..79906f33 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -13,8 +13,8 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.dto.WaitingMapper; +import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.time.LocalDate; import java.time.LocalDateTime; diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java index f3de0c91..b2e47ce9 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.jwt.service; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index fa9a37fc..b1222c44 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.security.controller; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; @@ -27,7 +27,7 @@ @Transactional @AutoConfigureMockMvc @WebAppConfiguration -class JwtAuthenticationTest{ +class JwtAuthenticationTest { @Autowired private WebApplicationContext webApplicationContext; diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java index 077744a4..ba9785d4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java @@ -73,8 +73,8 @@ void postpone() { Long shopId = 1L; repository.save(shopId, 1L); - repository.save(shopId,2L); - repository.save(shopId,3L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); //when repository.postpone(1L, 1L); @@ -96,8 +96,8 @@ void postpone_fails() { Long shopId = 1L; repository.save(shopId, 1L); - repository.save(shopId,2L); - repository.save(shopId,3L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); //when, then assertThrows(BadRequestCustomException.class, @@ -111,8 +111,8 @@ void cancel() { Long shopId = 1L; repository.save(shopId, 1L); - repository.save(shopId,2L); - repository.save(shopId,3L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); //when repository.cancel(1L, 1L); diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java index d9bbdd7a..1d1ce9c9 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java @@ -25,8 +25,8 @@ void entry() { Long shopId = 1L; waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId,2L); - waitingLineRepository.save(shopId,3L); + waitingLineRepository.save(shopId, 2L); + waitingLineRepository.save(shopId, 3L); //when waitingLineRepository.entry(1L, 1L); @@ -60,8 +60,8 @@ void postpone() { Long shopId = 1L; waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId,2L); - waitingLineRepository.save(shopId,3L); + waitingLineRepository.save(shopId, 2L); + waitingLineRepository.save(shopId, 3L); //when waitingLineRepository.postpone(1L, 1L); @@ -83,8 +83,8 @@ void postpone_fails() { Long shopId = 1L; waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId,2L); - waitingLineRepository.save(shopId,3L); + waitingLineRepository.save(shopId, 2L); + waitingLineRepository.save(shopId, 3L); //when, then assertThrows(BadRequestCustomException.class, @@ -98,8 +98,8 @@ void cancel() { Long shopId = 1L; waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId,2L); - waitingLineRepository.save(shopId,3L); + waitingLineRepository.save(shopId, 2L); + waitingLineRepository.save(shopId, 3L); //when waitingLineRepository.cancel(1L, 1L); From 71573cdae86e5be6a49770a370fda6fc2d208f32 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 22:54:17 +0900 Subject: [PATCH 232/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 96e3e8a4..7138a8fc 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,10 +1,15 @@ package com.prgrms.catchtable.reservation.controller; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; +import org.apache.coyote.Response; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -28,4 +33,10 @@ public ResponseEntity registerReservation( @RequestBody CreateReservationRequest request) { return ResponseEntity.ok(reservationService.registerReservation(request)); } + + @PatchMapping("/{reservationId}") + public ResponseEntity modifyReservation(@PathVariable("reservationId") Long reservationTimeId, + @RequestBody ModifyReservationRequest request){ + return ResponseEntity.ok(reservationService.modifyReservation(reservationTimeId, request)); + } } From 31c2df171145a265e629a2e6db2a9d95a93af974 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 4 Jan 2024 22:54:44 +0900 Subject: [PATCH 233/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20api=20=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 8d558c24..0931a22b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -3,19 +3,24 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -30,6 +35,8 @@ class ReservationControllerTest extends BaseIntegrationTest { @Autowired private ShopRepository shopRepository; + @Autowired + private ReservationRepository reservationRepository; @BeforeEach void setUp() { @@ -116,7 +123,29 @@ void registerReservationWithException() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value(ALREADY_OCCUPIED_RESERVATION_TIME.getMessage())); + } + + @Test + @DisplayName("예약 수정 api 호출에 성공한다.") + void modifyReservation() throws Exception { + ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + Reservation savedReservation = reservationRepository.save(reservation); + + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( + reservationTime.getId()); + + ReservationTime modifyReservationTime = reservationTimeRepository.findByIdAndShoId( + request.reservationTimeId(), reservation.getShop().getId()).orElseThrow(); // 수정하려는 예약시간 + + mockMvc.perform(patch("/reservations/{reservaionId}",savedReservation.getId()) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.date").value(modifyReservationTime.getTime().toString())) + .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); + assertThat(savedReservation.getReservationTime()).isEqualTo(modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 } } \ No newline at end of file From 8256924675c36eaf30d5aeda1e3482593bf46210 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:36:12 +0900 Subject: [PATCH 234/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationService.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 900fbee9..1921ec51 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -4,7 +4,9 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCancelReservationResponse; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCreateReservationResponse; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toModifyReservationResponse; import static java.lang.Boolean.FALSE; @@ -16,6 +18,7 @@ import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; @@ -114,6 +117,20 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, ModifyRe return toModifyReservationResponse(reservation); } + @Transactional + public CancelReservationResponse cancelReservation(Long reservationId){ + Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop(reservationId) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_RESERVATION)); + + reservation.changeStatus(CANCELLED); // 해당 예약 상태 취소로 변경 + + ReservationTime reservationTime = reservation.getReservationTime(); // 해당 예약의 예약시간 차지 여부 true로 변경 + + reservationTime.reverseOccupied(); + + return toCancelReservationResponse(reservation); + } + private void validateIsPreOccupied(ReservationTime reservationTime) { if (reservationTime.isPreOccupied()) { reservationLockRepository.unlock(reservationTime.getId()); From 46112c2cf52b57c8d67937cd820179bf7fedcafa Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:36:32 +0900 Subject: [PATCH 235/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EB=B0=94=EA=BE=B8=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index 7530044c..45d7a662 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -66,4 +66,8 @@ public void modifyReservation(ReservationTime reservationTime, int peopleCount){ this.peopleCount = peopleCount; } + public void changeStatus(ReservationStatus status){ + this.status = status; + } + } From 523b905d078fe060b33e1ceb927845a53fee651e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:36:56 +0900 Subject: [PATCH 236/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=EC=9D=91=EB=8B=B5=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CancelReservationResponse.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/CancelReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CancelReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CancelReservationResponse.java new file mode 100644 index 00000000..92fb36c5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CancelReservationResponse.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import lombok.Builder; + +@Builder +public record CancelReservationResponse(ReservationStatus status) { + +} From a2d998dfa8f61f9df5f1709997444680187b0440 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:37:07 +0900 Subject: [PATCH 237/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=EC=9D=91=EB=8B=B5=20dto=20mapper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/mapper/ReservationMapper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index 5f793796..104939f5 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -3,6 +3,7 @@ import static lombok.AccessLevel.PRIVATE; import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; @@ -39,4 +40,10 @@ public static ModifyReservationResponse toModifyReservationResponse (Reservation .build(); } + public static CancelReservationResponse toCancelReservationResponse (Reservation reservation){ + return CancelReservationResponse.builder() + .status(reservation.getStatus()) + .build(); + } + } From 2e2aad93c3c4b2cd6a11d3999527315ea6c745f5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:37:42 +0900 Subject: [PATCH 238/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 7138a8fc..56276f4e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -2,12 +2,14 @@ import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; import org.apache.coyote.Response; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -39,4 +41,9 @@ public ResponseEntity modifyReservation(@PathVariable @RequestBody ModifyReservationRequest request){ return ResponseEntity.ok(reservationService.modifyReservation(reservationTimeId, request)); } + + @DeleteMapping("/{reservationId}") + public ResponseEntity cancelReservation(@PathVariable("reservationId") Long reservationId){ + return ResponseEntity.ok(reservationService.cancelReservation(reservationId)); + } } From f888299ba6437490f4340031a7b910d230ead8af Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:37:56 +0900 Subject: [PATCH 239/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 508020d4..4d5c6a98 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.reservation.service; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; @@ -11,10 +12,12 @@ import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; @@ -228,4 +231,36 @@ void modifyReservationOccupied(){ assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L ,request)); } + @Test + @DisplayName("예약을 취소할 수 있다") + void cancelReservation() { + //given + ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + ReflectionTestUtils.setField(reservation, "id", 1L); + + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); + + //when + CancelReservationResponse response = reservationService.cancelReservation( + reservation.getId()); + + //then + assertAll( + () -> assertThat(reservation.getStatus()).isEqualTo(CANCELLED), + () -> assertThat(reservation.getReservationTime().isOccupied()).isFalse(), + () -> assertThat(response.status()).isEqualTo(CANCELLED) + ); + + } + + @Test + @DisplayName("존재하지 않는 예약에 대한 삭제 요청 시 예외가 발생한다") + void cancelReservationNotExist(){ + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.empty()); + + assertThrows(NotFoundCustomException.class, () -> reservationService.cancelReservation(1L)); + } + } \ No newline at end of file From b0bd44b927c54cd45a8784dca4773ae3a9f59548 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:38:07 +0900 Subject: [PATCH 240/603] =?UTF-8?q?test=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationControllerTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 0931a22b..f4c69a71 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.reservation.controller; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -11,6 +13,7 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; @@ -148,4 +151,17 @@ void modifyReservation() throws Exception { assertThat(savedReservation.getReservationTime()).isEqualTo(modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 } + @Test + @DisplayName("예약 삭제 api 호출에 성공한다") + void cancelReservation() throws Exception { + ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + Reservation savedReservation = reservationRepository.save(reservation); + + mockMvc.perform(delete("/reservations/{reservationId}", savedReservation.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.status").value(CANCELLED.toString())); + } + } \ No newline at end of file From ea278fddd72fbb74484ac3e824539132536b2718 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 00:39:26 +0900 Subject: [PATCH 241/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 6 +-- .../reservation/domain/Reservation.java | 3 +- .../dto/mapper/ReservationMapper.java | 2 +- .../repository/ReservationTimeRepository.java | 5 +-- .../service/ReservationService.java | 16 +++++--- .../security/config/SecurityConfig.java | 1 - .../security/controller/TestController.java | 2 +- .../service/JwtUserDetailsServiceTest.java | 3 +- .../controller/ReservationControllerTest.java | 10 ++--- .../reservation/domain/ReservationTest.java | 5 +-- .../fixture/ReservationFixture.java | 2 +- .../ReservationTimeRepositoryTest.java | 14 +++---- .../service/ReservationServiceTest.java | 38 ++++++++++++------- .../controller/JwtAuthenticationTest.java | 4 +- 14 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 7138a8fc..857a1f01 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -6,7 +6,6 @@ import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; -import org.apache.coyote.Response; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -35,8 +34,9 @@ public ResponseEntity registerReservation( } @PatchMapping("/{reservationId}") - public ResponseEntity modifyReservation(@PathVariable("reservationId") Long reservationTimeId, - @RequestBody ModifyReservationRequest request){ + public ResponseEntity modifyReservation( + @PathVariable("reservationId") Long reservationTimeId, + @RequestBody ModifyReservationRequest request) { return ResponseEntity.ok(reservationService.modifyReservation(reservationTimeId, request)); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index 7530044c..1284a5b6 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -7,7 +7,6 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.shop.domain.Shop; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; @@ -61,7 +60,7 @@ public Reservation(ReservationStatus status, int peopleCount, this.shop = reservationTime.getShop(); } - public void modifyReservation(ReservationTime reservationTime, int peopleCount){ + public void modifyReservation(ReservationTime reservationTime, int peopleCount) { this.reservationTime = reservationTime; this.peopleCount = peopleCount; } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index 5f793796..470cfab3 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -30,7 +30,7 @@ public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation .build(); } - public static ModifyReservationResponse toModifyReservationResponse (Reservation reservation){ + public static ModifyReservationResponse toModifyReservationResponse(Reservation reservation) { return ModifyReservationResponse.builder() .shopName(reservation.getShop().getName()) .memberName("memberA") diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 18936a26..889b1f18 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -1,8 +1,6 @@ package com.prgrms.catchtable.reservation.repository; import com.prgrms.catchtable.reservation.domain.ReservationTime; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -15,5 +13,6 @@ public interface ReservationTimeRepository extends JpaRepository findByIdAndShoId(@Param("reservationTimeId") Long reservationTimeId, @Param("shopId") Long shopId); + Optional findByIdAndShoId(@Param("reservationTimeId") Long reservationTimeId, + @Param("shopId") Long shopId); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 900fbee9..0f4ef76a 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -40,7 +40,7 @@ public class ReservationService { @Transactional public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); - while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))){ + while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { try { Thread.sleep(1_500); } catch (InterruptedException e) { @@ -96,20 +96,24 @@ public List getAllReservation() { } @Transactional - public ModifyReservationResponse modifyReservation(Long reservavtionId, ModifyReservationRequest request){ - Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop(reservavtionId) + public ModifyReservationResponse modifyReservation(Long reservavtionId, + ModifyReservationRequest request) { + Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop( + reservavtionId) .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_RESERVATION)); //예약 Id로 예약 조회 Shop shop = reservation.getShop(); ReservationTime reservationTime = reservationTimeRepository.findByIdAndShoId( request.reservationTimeId(), shop.getId()) - .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_TIME)); // 예약한 매장의 수정하려는 시간을 조회 + .orElseThrow( + () -> new BadRequestCustomException(NOT_EXIST_TIME)); // 예약한 매장의 수정하려는 시간을 조회 validateIsPreOccupied(reservationTime); // 예약시간이 선점되었는 지 확인 validateIsOccupied(reservationTime); // 예약시간이 이미 차지되었는 지 확인 - reservation.modifyReservation(reservationTime, request.peopleCount()); // 예약 필드 값 수정하는 엔티티의 메소드 + reservation.modifyReservation(reservationTime, + request.peopleCount()); // 예약 필드 값 수정하는 엔티티의 메소드 return toModifyReservationResponse(reservation); } @@ -122,7 +126,7 @@ private void validateIsPreOccupied(ReservationTime reservationTime) { } private void validateIsOccupied(ReservationTime reservationTime) { - if(reservationTime.isOccupied()){ + if (reservationTime.isOccupied()) { reservationLockRepository.unlock(reservationTime.getId()); throw new BadRequestCustomException(ALREADY_OCCUPIED_RESERVATION_TIME); } diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 4871a801..a90e7933 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -13,7 +13,6 @@ import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import org.springframework.stereotype.Component; @Configuration @RequiredArgsConstructor diff --git a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java index 6973411d..56f32d9a 100644 --- a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java +++ b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java @@ -10,7 +10,7 @@ public class TestController { @GetMapping("/testMember") - public ResponseEntity testMember(){ + public ResponseEntity testMember() { log.info("testMember"); return ResponseEntity.ok("testMember OK"); } diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java index f3de0c91..b2e47ce9 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.jwt.service; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index 0931a22b..f87676ae 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -20,7 +20,6 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -138,14 +137,15 @@ void modifyReservation() throws Exception { ReservationTime modifyReservationTime = reservationTimeRepository.findByIdAndShoId( request.reservationTimeId(), reservation.getShop().getId()).orElseThrow(); // 수정하려는 예약시간 - mockMvc.perform(patch("/reservations/{reservaionId}",savedReservation.getId()) - .contentType(APPLICATION_JSON) - .content(asJsonString(request))) + mockMvc.perform(patch("/reservations/{reservaionId}", savedReservation.getId()) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.date").value(modifyReservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); - assertThat(savedReservation.getReservationTime()).isEqualTo(modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 + assertThat(savedReservation.getReservationTime()).isEqualTo( + modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java index 0d9a71ad..5e1196fa 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTest.java @@ -1,10 +1,9 @@ package com.prgrms.catchtable.reservation.domain; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index ec0c3d45..5e6de7ff 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -56,7 +56,7 @@ public static CreateReservationRequest getCreateReservationRequest() { .build(); } - public static ModifyReservationRequest getModifyReservationRequest(Long reservationTimeId){ + public static ModifyReservationRequest getModifyReservationRequest(Long reservationTimeId) { return ModifyReservationRequest.builder() .reservationTimeId(reservationTimeId) .peopleCount(2) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index d4c4a4bf..92f08b01 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -14,15 +14,12 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import java.util.Optional; -import org.junit.Before; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; @DataJpaTest @AutoConfigureTestDatabase(replace = NONE) @@ -32,8 +29,9 @@ class ReservationTimeRepositoryTest { private ReservationTimeRepository reservationTimeRepository; @Autowired private ShopRepository shopRepository; + @BeforeEach - void setUp(){ + void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); @@ -41,6 +39,7 @@ void setUp(){ reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); } + @Test @DisplayName("예약시간과 그 시간의 매장까지 한번의 쿼리로 조회할 수 있다.") void findReservationTimeWithShop() { @@ -63,7 +62,7 @@ void findReservationTimeWithShop() { @Test @DisplayName("특정 매장에 특정 예약시간이 존재 하는지 조회할 수 있다") - void findReservationTimeByShop(){ + void findReservationTimeByShop() { //given List all = reservationTimeRepository.findAll(); ReservationTime reservationTime = all.get(0); @@ -82,7 +81,7 @@ void findReservationTimeByShop(){ @Test @DisplayName("조회하려는 예약시간이 해당 매장에 없는 시간이면 null이 반환된다.") - void findReservationTimeNotInShop(){ + void findReservationTimeNotInShop() { //given Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); @@ -90,7 +89,8 @@ void findReservationTimeNotInShop(){ //when Optional findReservationTime = reservationTimeRepository.findByIdAndShoId( - reservationTime.getId(), savedShop.getId()); // 해당 예약시간은 존재하지만 찾으려는 매장의 예약시간이 아니므로 null 리턴 예상 + reservationTime.getId(), + savedShop.getId()); // 해당 예약시간은 존재하지만 찾으려는 매장의 예약시간이 아니므로 null 리턴 예상 //then assertThat(findReservationTime).isEmpty(); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 508020d4..08af4eb7 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -162,7 +162,7 @@ void getAllReservationWithNoResult() { @Test @DisplayName("예약 수정을 성공한다.") - void modifyReservation(){ + void modifyReservation() { //given Shop shop = ShopData.getShop(); ReflectionTestUtils.setField(shop, "id", 1L); //shop 생성 @@ -178,8 +178,10 @@ void modifyReservation(){ ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( 2L); - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(2L, 1L)).thenReturn(Optional.of(modifyTime)); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(2L, 1L)).thenReturn( + Optional.of(modifyTime)); //when ModifyReservationResponse response = reservationService.modifyReservation( @@ -195,37 +197,45 @@ void modifyReservation(){ @Test @DisplayName("존재하지 않는 예약에 대한 수정을 요청할 경우 예외가 발생한다.") - void modifyReservationNotExist(){ + void modifyReservationNotExist() { ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.empty()); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.empty()); - assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L, request)); + assertThrows(BadRequestCustomException.class, + () -> reservationService.modifyReservation(1L, request)); } @Test @DisplayName("타인에게 선점된 상태인 예약시간으로 변경하려 하면 예외가 발생한다.") - void modifyReservationPreOccupied(){ + void modifyReservationPreOccupied() { ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); Reservation reservation = ReservationFixture.getReservation(reservationTime); - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(any(Long.class), + any(Long.class))).thenReturn(Optional.of(reservationTime)); - assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L ,request)); + assertThrows(BadRequestCustomException.class, + () -> reservationService.modifyReservation(1L, request)); } @Test @DisplayName("타인이 이미 예약한 시간으로 변경하려 하면 예외가 발생한다.") - void modifyReservationOccupied(){ + void modifyReservationOccupied() { ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); Reservation reservation = ReservationFixture.getReservation(reservationTime); - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.of(reservation)); + when(reservationTimeRepository.findByIdAndShoId(any(Long.class), + any(Long.class))).thenReturn(Optional.of(reservationTime)); - assertThrows(BadRequestCustomException.class, () -> reservationService.modifyReservation(1L ,request)); + assertThrows(BadRequestCustomException.class, + () -> reservationService.modifyReservation(1L, request)); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index fa9a37fc..b1222c44 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.security.controller; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; @@ -27,7 +27,7 @@ @Transactional @AutoConfigureMockMvc @WebAppConfiguration -class JwtAuthenticationTest{ +class JwtAuthenticationTest { @Autowired private WebApplicationContext webApplicationContext; From 616415f3a97cde0722dd5b60bca6e44008133e0c Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 00:59:46 +0900 Subject: [PATCH 242/603] =?UTF-8?q?feat=20:=20redis=20queue=20=EB=8C=80?= =?UTF-8?q?=EA=B8=B0=20=EC=A7=80=EC=97=B0=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/line/RedisWaitingLineRepository.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java index 3230ebda..63627a1e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java @@ -77,6 +77,8 @@ public Object execute(RedisOperations operations) public void postpone(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); + validateIfPostponeAvailable(shopId, waitingId); + if (Objects.equals(findRank(shopId, waitingId), findEndRank(shopId))) { throw new BadRequestCustomException(ALREADY_END_LINE); } @@ -105,6 +107,10 @@ public Long findRank(Long shopId, Long waitingId) { return findEndRank(shopId) - index; } + public Long findEndRank(Long shopId) { + return redisTemplate.opsForList().size("s" + shopId); + } + public void validateIfWaitingExists(Long shopId, Long waitingId) { Long index = redisTemplate.opsForList().indexOf("s" + shopId, waitingId.toString()); if (index == null) { @@ -112,8 +118,12 @@ public void validateIfWaitingExists(Long shopId, Long waitingId) { } } - public Long findEndRank(Long shopId) { - return redisTemplate.opsForList().size("s" + shopId); + private void validateIfPostponeAvailable(Long shopId, Long waitingId) { + if (Objects.equals(findRank(shopId, waitingId), findEndRank(shopId))) { + { + throw new BadRequestCustomException(ALREADY_END_LINE); + } + } } public void printWaitingLine(Long shopId) { From 7335ddb6420d029ed0b955f555e73e9ddc49e631 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 01:02:42 +0900 Subject: [PATCH 243/603] =?UTF-8?q?style=20:=20waitingLine=20size=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/line/RedisWaitingLineRepository.java | 8 ++++---- .../catchtable/waiting/line/WaitingLineRepository.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java index 63627a1e..949e2c2a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java @@ -79,7 +79,7 @@ public void postpone(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); validateIfPostponeAvailable(shopId, waitingId); - if (Objects.equals(findRank(shopId, waitingId), findEndRank(shopId))) { + if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { throw new BadRequestCustomException(ALREADY_END_LINE); } redisTemplate.execute(new SessionCallback<>() { @@ -104,10 +104,10 @@ public Long findRank(Long shopId, Long waitingId) { if (index == null) { throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); } - return findEndRank(shopId) - index; + return getWaitingLineSize(shopId) - index; } - public Long findEndRank(Long shopId) { + public Long getWaitingLineSize(Long shopId) { return redisTemplate.opsForList().size("s" + shopId); } @@ -119,7 +119,7 @@ public void validateIfWaitingExists(Long shopId, Long waitingId) { } private void validateIfPostponeAvailable(Long shopId, Long waitingId) { - if (Objects.equals(findRank(shopId, waitingId), findEndRank(shopId))) { + if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { { throw new BadRequestCustomException(ALREADY_END_LINE); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java index 3e74d9ce..9df0d9ff 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java @@ -70,7 +70,7 @@ public int findRank(Long shopId, Long waitingId) { return -1; } - public int findEndRank(Long shopId) { //postpone에서 사용 + public int getWaitingLineSize(Long shopId) { //postpone에서 사용 Queue waitingLine = waitingLines.get(shopId); return waitingLine != null ? waitingLine.size() : 0; } @@ -82,7 +82,7 @@ public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { } private void validateIfPostponeAvailable(Long shopId, Long waitingId) { - if (findRank(shopId, waitingId) == findEndRank(shopId)) { + if (findRank(shopId, waitingId) == getWaitingLineSize(shopId)) { { throw new BadRequestCustomException(ALREADY_END_LINE); } From 62380970a8e3d8c957db3ca9d2e6d89b4dda3904 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 01:09:14 +0900 Subject: [PATCH 244/603] =?UTF-8?q?rename=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/{line => }/config/RedisConfig.java | 2 +- .../waitingline}/RedisWaitingLineRepository.java | 2 +- .../waitingline}/WaitingLineRepository.java | 2 +- .../waitingline}/RedisWaitingLineRepositoryTest.java | 3 ++- .../waitingline}/WaitingLineRepositoryTest.java | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/{line => }/config/RedisConfig.java (92%) rename src/main/java/com/prgrms/catchtable/waiting/{line => repository/waitingline}/RedisWaitingLineRepository.java (98%) rename src/main/java/com/prgrms/catchtable/waiting/{line => repository/waitingline}/WaitingLineRepository.java (98%) rename src/test/java/com/prgrms/catchtable/waiting/{line => repository/waitingline}/RedisWaitingLineRepositoryTest.java (95%) rename src/test/java/com/prgrms/catchtable/waiting/{line => repository/waitingline}/WaitingLineRepositoryTest.java (95%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java b/src/main/java/com/prgrms/catchtable/waiting/config/RedisConfig.java similarity index 92% rename from src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java rename to src/main/java/com/prgrms/catchtable/waiting/config/RedisConfig.java index b3674380..2f254613 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/config/RedisConfig.java +++ b/src/main/java/com/prgrms/catchtable/waiting/config/RedisConfig.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.line.config; +package com.prgrms.catchtable.waiting.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java similarity index 98% rename from src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java rename to src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 949e2c2a..85ac86b0 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.line; +package com.prgrms.catchtable.waiting.repository.waitingline; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; diff --git a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java similarity index 98% rename from src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java rename to src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 9df0d9ff..98c0d554 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/line/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.line; +package com.prgrms.catchtable.waiting.repository.waitingline; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_ENTRY; diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java similarity index 95% rename from src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java rename to src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index ba9785d4..bc9a73ff 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/line/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -1,10 +1,11 @@ -package com.prgrms.catchtable.waiting.line; +package com.prgrms.catchtable.waiting.repository.waitingline; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java similarity index 95% rename from src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java rename to src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java index 1d1ce9c9..86c51950 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/line/WaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java @@ -1,9 +1,10 @@ -package com.prgrms.catchtable.waiting.line; +package com.prgrms.catchtable.waiting.repository.waitingline; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From e8fb6ce6f2abf15fbfb8a15d3c43e782fcdf11c1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 01:29:27 +0900 Subject: [PATCH 245/603] =?UTF-8?q?feat=20:=20WaitingLineRepository=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicWaitingLineRepository.java | 104 ++++++++++++++++ .../RedisWaitingLineRepository.java | 2 +- .../waitingline/WaitingLineRepository.java | 109 ++-------------- .../BasicWaitingLineRepositoryTest.java | 115 +++++++++++++++++ .../WaitingLineRepositoryTest.java | 116 ------------------ 5 files changed, 228 insertions(+), 218 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java create mode 100644 src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java delete mode 100644 src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java new file mode 100644 index 00000000..5fd9c0b5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -0,0 +1,104 @@ +package com.prgrms.catchtable.waiting.repository.waitingline; + +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; +import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_ENTRY; +import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.LinkedList; +import java.util.Map; +import java.util.Objects; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class BasicWaitingLineRepository implements WaitingLineRepository{ + + public final Map> waitingLines = new ConcurrentHashMap<>(); + + public void save(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.computeIfAbsent(shopId, k -> new LinkedList<>()); + waitingLine.add(waitingId); + } + + public void entry(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + if (!Objects.equals(waitingLine.peek(), waitingId)) { + throw new BadRequestCustomException(CAN_NOT_ENTRY); + } + waitingLine.remove(); + } + + public void cancel(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + validateIfWaitingExists(waitingLine, waitingId); + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + waitingLine.remove(waitingIdInLine); + break; + } + } + } + + public void postpone(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + validateIfWaitingExists(waitingLine, waitingId); + validateIfPostponeAvailable(shopId, waitingId); + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + waitingLine.remove(waitingIdInLine); + waitingLine.add(waitingIdInLine); + break; + } + } + } + + public Long findRank(Long shopId, Long waitingId) { + Queue waitingLine = waitingLines.get(shopId); + + int index = 0; + for (Long waitingIdInLine : waitingLine) { + if (Objects.equals(waitingIdInLine, waitingId)) { + return (long)index + 1; + } + index++; + } + return -1L; + } + + public Long getWaitingLineSize(Long shopId) { //postpone에서 사용 + Queue waitingLine = waitingLines.get(shopId); + return (long) (waitingLine != null ? waitingLine.size() : 0); + } + + public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { + if (!waitingLine.contains(waitingId)) { + throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); + } + } + + private void validateIfPostponeAvailable(Long shopId, Long waitingId) { + if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { + { + throw new BadRequestCustomException(ALREADY_END_LINE); + } + } + } + + public void clear() { + waitingLines.clear(); + } + + public void printWaitingLine(Long shopId) { + Queue waitingLine = waitingLines.get(shopId); + if (waitingLine != null) { + log.info("Queue: {}", waitingLine); + } else { + log.warn("Queue is empty or not found for Shop ID: {}", shopId); + } + } +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 85ac86b0..607069bc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -18,7 +18,7 @@ @Slf4j @RequiredArgsConstructor @Component -public class RedisWaitingLineRepository { +public class RedisWaitingLineRepository implements WaitingLineRepository{ private final StringRedisTemplate redisTemplate; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 98c0d554..6b258fab 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,104 +1,11 @@ package com.prgrms.catchtable.waiting.repository.waitingline; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; -import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_ENTRY; -import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; - -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; -import java.util.LinkedList; -import java.util.Map; -import java.util.Objects; -import java.util.Queue; -import java.util.concurrent.ConcurrentHashMap; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -public class WaitingLineRepository { - - public final Map> waitingLines = new ConcurrentHashMap<>(); - - public void save(Long shopId, Long waitingId) { - Queue waitingLine = waitingLines.computeIfAbsent(shopId, k -> new LinkedList<>()); - waitingLine.add(waitingId); - } - - public void entry(Long shopId, Long waitingId) { - Queue waitingLine = waitingLines.get(shopId); - if (!Objects.equals(waitingLine.peek(), waitingId)) { - throw new BadRequestCustomException(CAN_NOT_ENTRY); - } - waitingLine.remove(); - } - - public void cancel(Long shopId, Long waitingId) { - Queue waitingLine = waitingLines.get(shopId); - validateIfWaitingExists(waitingLine, waitingId); - for (Long waitingIdInLine : waitingLine) { - if (Objects.equals(waitingIdInLine, waitingId)) { - waitingLine.remove(waitingIdInLine); - break; - } - } - } - - public void postpone(Long shopId, Long waitingId) { - Queue waitingLine = waitingLines.get(shopId); - validateIfWaitingExists(waitingLine, waitingId); - validateIfPostponeAvailable(shopId, waitingId); - for (Long waitingIdInLine : waitingLine) { - if (Objects.equals(waitingIdInLine, waitingId)) { - waitingLine.remove(waitingIdInLine); - waitingLine.add(waitingIdInLine); - break; - } - } - } - - public int findRank(Long shopId, Long waitingId) { - Queue waitingLine = waitingLines.get(shopId); - - int index = 0; - for (Long waitingIdInLine : waitingLine) { - if (Objects.equals(waitingIdInLine, waitingId)) { - return index + 1; - } - index++; - } - return -1; - } - - public int getWaitingLineSize(Long shopId) { //postpone에서 사용 - Queue waitingLine = waitingLines.get(shopId); - return waitingLine != null ? waitingLine.size() : 0; - } - - public void validateIfWaitingExists(Queue waitingLine, Long waitingId) { - if (!waitingLine.contains(waitingId)) { - throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); - } - } - - private void validateIfPostponeAvailable(Long shopId, Long waitingId) { - if (findRank(shopId, waitingId) == getWaitingLineSize(shopId)) { - { - throw new BadRequestCustomException(ALREADY_END_LINE); - } - } - } - - public void clear() { - waitingLines.clear(); - } - - public void printWaitingLine(Long shopId) { - Queue waitingLine = waitingLines.get(shopId); - if (waitingLine != null) { - log.info("Queue: {}", waitingLine); - } else { - log.warn("Queue is empty or not found for Shop ID: {}", shopId); - } - } +public interface WaitingLineRepository { + void save(Long shopId, Long waitingId); + void entry(Long shopId, Long waitingId); + void cancel(Long shopId, Long waitingId); + void postpone(Long shopId, Long waitingId); + Long findRank(Long shopId, Long waitingId); + Long getWaitingLineSize(Long shopId); + void printWaitingLine(Long shopId); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java new file mode 100644 index 00000000..9dee40de --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -0,0 +1,115 @@ +package com.prgrms.catchtable.waiting.repository.waitingline; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class BasicWaitingLineRepositoryTest{ + + private final BasicWaitingLineRepository repository = new BasicWaitingLineRepository(); + + + @AfterEach() + void clear() { + repository.clear(); + } + + @DisplayName("입장 시 뒤 대기 순서 1씩 앞당겨짐") + @Test + void entry() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + + //when + repository.entry(1L, 1L); + + //then + assertThat(repository.findRank(1L, 1L)) + .isEqualTo(-1); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + } + + @DisplayName("저장 후 대기순서를 가져올 수 있다.") + @Test + void save() { + //given + Long shopId = 1L; + Long waitingId = 1L; + //when + repository.save(shopId, waitingId); + //then + Long waitingOrder = repository.findRank(1L, 1L); + assertThat(waitingOrder).isEqualTo(1L); + } + + @DisplayName("지연 시 대기 순서가 맨 뒤가 된다. 뒷 순서의 요소들은 한 칸씩 앞으로 이동한다.") + @Test + void postpone() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + + //when + repository.postpone(1L, 1L); + + //then + assertThat(repository.findRank(1L, 1L)) + .isEqualTo(3); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + + } + + @DisplayName("맨 뒤에 있을 시 대기 지연을 할 수 없다.") + @Test + void postpone_fails() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + + //when, then + assertThrows(BadRequestCustomException.class, + () -> repository.postpone(shopId, 3L)); + } + + @DisplayName("대기 취소를 할 수 있다.") + @Test + void cancel() { + //given + Long shopId = 1L; + + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + + //when + repository.cancel(1L, 1L); + //then + assertThat(repository.findRank(1L, 1L)) + .isEqualTo(-1); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(1); + assertThat(repository.findRank(1L, 3L)) + .isEqualTo(2); + } + +} \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java deleted file mode 100644 index 86c51950..00000000 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepositoryTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.prgrms.catchtable.waiting.repository.waitingline; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -class WaitingLineRepositoryTest { - - private final WaitingLineRepository waitingLineRepository = new WaitingLineRepository(); - - - @AfterEach() - void clear() { - waitingLineRepository.clear(); - } - - @DisplayName("입장 시 뒤 대기 순서 1씩 앞당겨짐") - @Test - void entry() { - //given - Long shopId = 1L; - - waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId, 2L); - waitingLineRepository.save(shopId, 3L); - - //when - waitingLineRepository.entry(1L, 1L); - - //then - assertThat(waitingLineRepository.findRank(1L, 1L)) - .isEqualTo(-1); - assertThat(waitingLineRepository.findRank(1L, 2L)) - .isEqualTo(1); - assertThat(waitingLineRepository.findRank(1L, 3L)) - .isEqualTo(2); - } - - @DisplayName("저장 후 대기순서를 가져올 수 있다.") - @Test - void save() { - //given - Long shopId = 1L; - Long waitingId = 1L; - //when - waitingLineRepository.save(shopId, waitingId); - //then - int waitingOrder = waitingLineRepository.findRank(1L, 1L); - assertThat(waitingOrder).isEqualTo(1); - } - - @DisplayName("지연 시 대기 순서가 맨 뒤가 된다. 뒷 순서의 요소들은 한 칸씩 앞으로 이동한다.") - @Test - void postpone() { - //given - Long shopId = 1L; - - waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId, 2L); - waitingLineRepository.save(shopId, 3L); - - //when - waitingLineRepository.postpone(1L, 1L); - - //then - assertThat(waitingLineRepository.findRank(1L, 1L)) - .isEqualTo(3); - assertThat(waitingLineRepository.findRank(1L, 2L)) - .isEqualTo(1); - assertThat(waitingLineRepository.findRank(1L, 3L)) - .isEqualTo(2); - - } - - @DisplayName("맨 뒤에 있을 시 대기 지연을 할 수 없다.") - @Test - void postpone_fails() { - //given - Long shopId = 1L; - - waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId, 2L); - waitingLineRepository.save(shopId, 3L); - - //when, then - assertThrows(BadRequestCustomException.class, - () -> waitingLineRepository.postpone(shopId, 3L)); - } - - @DisplayName("대기 취소를 할 수 있다.") - @Test - void cancel() { - //given - Long shopId = 1L; - - waitingLineRepository.save(shopId, 1L); - waitingLineRepository.save(shopId, 2L); - waitingLineRepository.save(shopId, 3L); - - //when - waitingLineRepository.cancel(1L, 1L); - //then - assertThat(waitingLineRepository.findRank(1L, 1L)) - .isEqualTo(-1); - assertThat(waitingLineRepository.findRank(1L, 2L)) - .isEqualTo(1); - assertThat(waitingLineRepository.findRank(1L, 3L)) - .isEqualTo(2); - } - -} \ No newline at end of file From 135068d5e8d06d345573c8168b2adc0ad644ab61 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 01:53:18 +0900 Subject: [PATCH 246/603] =?UTF-8?q?refactor=20:=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/service/OwnerService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index 464ebd7d..da30bcf8 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -27,9 +27,7 @@ public class OwnerService { public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { //이미 존재하는 이메일이라면 - if (ownerRepository.existsOwnerByEmail(joinOwnerRequest.email())) { - throw new BadRequestCustomException(ALREADY_EXIST_OWNER); - } + validateExistsOwner(joinOwnerRequest); String encodePassword = passwordEncoder.encode(joinOwnerRequest.password()); @@ -41,6 +39,12 @@ public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { } + private void validateExistsOwner(JoinOwnerRequest joinOwnerRequest) { + if (ownerRepository.existsOwnerByEmail(joinOwnerRequest.email())) { + throw new BadRequestCustomException(ALREADY_EXIST_OWNER); + } + } + public Token loginOwner(LoginOwnerRequest loginRequest){ //email 확인 @@ -48,11 +52,15 @@ public Token loginOwner(LoginOwnerRequest loginRequest){ .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD)); //password 확인 + validatePassword(loginRequest, loginOwner); + + return jwtTokenProvider.createToken(loginOwner.getEmail()); + } + + private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner){ if(passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())){ throw new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD); } - - return jwtTokenProvider.createToken(loginOwner.getEmail()); } } From a0f369038a467c2d85481e19fe616bdc594010e1 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 10:44:40 +0900 Subject: [PATCH 247/603] =?UTF-8?q?fix=20:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B2=80=EC=A6=9D=20=EB=85=BC=EB=A6=AC=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/owner/service/OwnerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index da30bcf8..095412d6 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -58,7 +58,7 @@ public Token loginOwner(LoginOwnerRequest loginRequest){ } private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner){ - if(passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())){ + if(!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())){ throw new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD); } } From 885b63d99a97832f2d893ca5a47e575b23d27823 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 10:45:10 +0900 Subject: [PATCH 248/603] =?UTF-8?q?feat=20:=20dto=20builder=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java | 2 ++ .../prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java index 80c67856..bc3adbdc 100644 --- a/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java +++ b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java @@ -4,7 +4,9 @@ import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Pattern; import java.time.LocalDate; +import lombok.Builder; +@Builder public record JoinOwnerRequest( String name, diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java b/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java index 91368d5f..a9a0d2e4 100644 --- a/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java +++ b/src/main/java/com/prgrms/catchtable/owner/dto/request/LoginOwnerRequest.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.owner.dto.request; import jakarta.validation.constraints.Email; +import lombok.Builder; +@Builder public record LoginOwnerRequest( @Email From 32a9584969fd7ea1a34fa011107ec8e13b7cdf3c Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 10:45:50 +0900 Subject: [PATCH 249/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9A=A9=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../owner/fixture/OwnerFixture.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java new file mode 100644 index 00000000..0959abb8 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -0,0 +1,39 @@ +package com.prgrms.catchtable.owner.fixture; + +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; +import java.time.LocalDate; + +public class OwnerFixture { + + public static Owner getOwner(String email, String encodePassword){ + return Owner.builder() + .name("test") + .email(email) + .password(encodePassword) + .phoneNumber("010-8830-4795") + .gender(Gender.MALE) + .dateBirth(LocalDate.of(1998,3,25)) + .build(); + } + + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + return JoinOwnerRequest.builder() + .name("test") + .email(email) + .password(password) + .phoneNumber("010-8830-4795") + .gender("male") + .dateBirth(LocalDate.of(1998,3,25)) + .build(); + } + + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + return LoginOwnerRequest.builder() + .email(email) + .password(password) + .build(); + } +} From 7ea8395e2d31eb1e4aec0c8cdfae07e364a803ff Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 10:46:08 +0900 Subject: [PATCH 250/603] feat : OwnerService Test --- .../owner/service/OwnerServiceTest.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java new file mode 100644 index 00000000..905a2940 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -0,0 +1,118 @@ +package com.prgrms.catchtable.owner.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; +import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +class OwnerServiceTest { + + private OwnerRepository ownerRepository = mock(OwnerRepository.class); + private JwtTokenProvider jwtTokenProvider = mock(JwtTokenProvider.class); + private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + + private OwnerService ownerService = new OwnerService(ownerRepository, passwordEncoder, + jwtTokenProvider); + + String email = "abc1234@gmail.com"; + String password = "qwer1234"; + String wrongPassword = "qwer12345"; + + + @Test + @DisplayName("유저의 회원가입이 성공한다.") + void joinSuccess() { + //given + JoinOwnerRequest joinOwnerRequest = OwnerFixture.getJoinOwnerRequest(email, password); + String encodePassword = passwordEncoder.encode(password); + + //when + when(ownerRepository.existsOwnerByEmail(joinOwnerRequest.email())).thenReturn(false); + when(ownerRepository.save(any(Owner.class))).thenReturn( + OwnerFixture.getOwner(email, encodePassword)); + JoinOwnerResponse joinOwnerResponse = ownerService.joinOwner(joinOwnerRequest); + + //then + assertThat(joinOwnerRequest.name()).isEqualTo(joinOwnerResponse.name()); + assertThat(joinOwnerRequest.email()).isEqualTo(joinOwnerResponse.email()); + assertThat(joinOwnerRequest.gender()).isEqualTo(joinOwnerResponse.gender()); + assertThat(joinOwnerRequest.phoneNumber()).isEqualTo(joinOwnerResponse.phoneNumber()); + assertThat(joinOwnerRequest.dateBirth()).isEqualTo(joinOwnerResponse.dateBirth()); + } + + @Test + @DisplayName("이미 회원가입한 이메일로 회원가입 시도 시, 예외 발생한다.") + void joinFailure() { + //given + JoinOwnerRequest joinOwnerRequest = OwnerFixture.getJoinOwnerRequest(email, password); + + //when + when(ownerRepository.existsOwnerByEmail(joinOwnerRequest.email())).thenReturn(true); + + //then + assertThatThrownBy(() -> ownerService.joinOwner(joinOwnerRequest)).isInstanceOf( + BadRequestCustomException.class); + } + + @Test + @DisplayName("로그인을 성공하면, 토큰을 반환한다") + void loginSuccess() { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); + String encodePassword = passwordEncoder.encode(password); + + //when + when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( + Optional.of(OwnerFixture.getOwner(email, encodePassword))); + when(jwtTokenProvider.createToken(loginOwnerRequest.email())).thenReturn(any(Token.class)); + + //then + assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(any(Token.class)); + } + + @Test + @DisplayName("해당 이메일의 유저가 존재하지 않으면 로그인을 실패한다") + void loginFailureId() { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); + + //when + when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( + Optional.empty()); + + //then + assertThatThrownBy(() -> ownerService.loginOwner(loginOwnerRequest)).isInstanceOf( + BadRequestCustomException.class); + } + + @Test + @DisplayName("비밀번호가 다르면 로그인을 실패한다.") + void loginFailurePassword() { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, wrongPassword); + String encodePassword = passwordEncoder.encode(password); + + //when + when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( + Optional.of(OwnerFixture.getOwner(email, encodePassword))); + + //then + assertThatThrownBy(() -> ownerService.loginOwner(loginOwnerRequest)).isInstanceOf( + BadRequestCustomException.class); + } +} \ No newline at end of file From e66166d5f0426627a6cae95a0c1ba945ef3ee81f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 13:40:36 +0900 Subject: [PATCH 251/603] =?UTF-8?q?style=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=BF=BC=EB=A6=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationTimeRepository.java | 2 +- .../catchtable/reservation/service/ReservationService.java | 2 +- .../reservation/controller/ReservationControllerTest.java | 2 +- .../repository/ReservationTimeRepositoryTest.java | 4 ++-- .../reservation/service/ReservationServiceTest.java | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 889b1f18..5d8f1b80 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -13,6 +13,6 @@ public interface ReservationTimeRepository extends JpaRepository findByIdAndShoId(@Param("reservationTimeId") Long reservationTimeId, + Optional findByIdAndShopId(@Param("reservationTimeId") Long reservationTimeId, @Param("shopId") Long shopId); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 2250df44..8730869d 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -106,7 +106,7 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_RESERVATION)); //예약 Id로 예약 조회 Shop shop = reservation.getShop(); - ReservationTime reservationTime = reservationTimeRepository.findByIdAndShoId( + ReservationTime reservationTime = reservationTimeRepository.findByIdAndShopId( request.reservationTimeId(), shop.getId()) .orElseThrow( () -> new BadRequestCustomException(NOT_EXIST_TIME)); // 예약한 매장의 수정하려는 시간을 조회 diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java index d0386ae4..b24c0a98 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java @@ -137,7 +137,7 @@ void modifyReservation() throws Exception { ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( reservationTime.getId()); - ReservationTime modifyReservationTime = reservationTimeRepository.findByIdAndShoId( + ReservationTime modifyReservationTime = reservationTimeRepository.findByIdAndShopId( request.reservationTimeId(), reservation.getShop().getId()).orElseThrow(); // 수정하려는 예약시간 mockMvc.perform(patch("/reservations/{reservaionId}", savedReservation.getId()) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java index 92f08b01..3f8e4f01 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepositoryTest.java @@ -69,7 +69,7 @@ void findReservationTimeByShop() { Shop shop = reservationTime.getShop(); //when - ReservationTime findReservationTime = reservationTimeRepository.findByIdAndShoId( + ReservationTime findReservationTime = reservationTimeRepository.findByIdAndShopId( reservationTime.getId(), shop.getId()).orElseThrow(); //then @@ -88,7 +88,7 @@ void findReservationTimeNotInShop() { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); //when - Optional findReservationTime = reservationTimeRepository.findByIdAndShoId( + Optional findReservationTime = reservationTimeRepository.findByIdAndShopId( reservationTime.getId(), savedShop.getId()); // 해당 예약시간은 존재하지만 찾으려는 매장의 예약시간이 아니므로 null 리턴 예상 diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 12dc4421..c56c5ba2 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -183,7 +183,7 @@ void modifyReservation() { when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(2L, 1L)).thenReturn( + when(reservationTimeRepository.findByIdAndShopId(2L, 1L)).thenReturn( Optional.of(modifyTime)); //when @@ -218,7 +218,7 @@ void modifyReservationPreOccupied() { when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(any(Long.class), + when(reservationTimeRepository.findByIdAndShopId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, @@ -234,7 +234,7 @@ void modifyReservationOccupied() { when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( Optional.of(reservation)); - when(reservationTimeRepository.findByIdAndShoId(any(Long.class), + when(reservationTimeRepository.findByIdAndShopId(any(Long.class), any(Long.class))).thenReturn(Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, From ea81cddf5291b81a99d1d120f0d1ce4d863b4b7a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 5 Jan 2024 14:22:07 +0900 Subject: [PATCH 252/603] refactor : ReservationService renaming --- .../controller/ReservationController.java | 13 +++++---- ...ice.java => MemberReservationService.java} | 2 +- ...berReservationServiceIntegrationTest.java} | 6 ++-- ...java => MemberReservationServiceTest.java} | 28 +++++++++---------- 4 files changed, 25 insertions(+), 24 deletions(-) rename src/main/java/com/prgrms/catchtable/reservation/service/{ReservationService.java => MemberReservationService.java} (99%) rename src/test/java/com/prgrms/catchtable/reservation/service/{ReservationServiceIntegrationTest.java => MemberReservationServiceIntegrationTest.java} (93%) rename src/test/java/com/prgrms/catchtable/reservation/service/{ReservationServiceTest.java => MemberReservationServiceTest.java} (91%) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 121873e9..fd8aa048 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -5,7 +5,7 @@ import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; -import com.prgrms.catchtable.reservation.service.ReservationService; +import com.prgrms.catchtable.reservation.service.MemberReservationService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -21,29 +21,30 @@ @RequiredArgsConstructor public class ReservationController { - private final ReservationService reservationService; + private final MemberReservationService memberReservationService; @PostMapping public ResponseEntity preOccupyReservation( @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(reservationService.preOccupyReservation(request)); + return ResponseEntity.ok(memberReservationService.preOccupyReservation(request)); } @PostMapping("/success") public ResponseEntity registerReservation( @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(reservationService.registerReservation(request)); + return ResponseEntity.ok(memberReservationService.registerReservation(request)); } @PatchMapping("/{reservationId}") public ResponseEntity modifyReservation( @PathVariable("reservationId") Long reservationTimeId, @RequestBody ModifyReservationRequest request) { - return ResponseEntity.ok(reservationService.modifyReservation(reservationTimeId, request)); + return ResponseEntity.ok( + memberReservationService.modifyReservation(reservationTimeId, request)); } @DeleteMapping("/{reservationId}") public ResponseEntity cancelReservation(@PathVariable("reservationId") Long reservationId){ - return ResponseEntity.ok(reservationService.cancelReservation(reservationId)); + return ResponseEntity.ok(memberReservationService.cancelReservation(reservationId)); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java similarity index 99% rename from src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java rename to src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 8730869d..e1e96402 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -33,7 +33,7 @@ @Service @RequiredArgsConstructor -public class ReservationService { +public class MemberReservationService { private final ReservationTimeRepository reservationTimeRepository; private final ReservationRepository reservationRepository; diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java similarity index 93% rename from src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java rename to src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index 123bc27c..681eae52 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -22,10 +22,10 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -public class ReservationServiceIntegrationTest { +public class MemberReservationServiceIntegrationTest { @Autowired - private ReservationService reservationService; + private MemberReservationService memberReservationService; @Autowired private ReservationTimeRepository reservationTimeRepository; @@ -59,7 +59,7 @@ void concurrencyTest() throws InterruptedException { for (int i = 0; i < threadCount; i++) { executorService.submit(() -> { try { - reservationService.preOccupyReservation(request); + memberReservationService.preOccupyReservation(request); } catch (BadRequestCustomException e) { errorCount.incrementAndGet(); } finally { diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java similarity index 91% rename from src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java rename to src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index c56c5ba2..68fe1679 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -37,7 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils; @ExtendWith(MockitoExtension.class) -class ReservationServiceTest { +class MemberReservationServiceTest { @Mock private ReservationRepository reservationRepository; @@ -48,7 +48,7 @@ class ReservationServiceTest { @Mock private ReservationTimeRepository reservationTimeRepository; @InjectMocks - private ReservationService reservationService; + private MemberReservationService memberReservationService; @Test @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") @@ -64,7 +64,7 @@ void validateReservation() { when(reservationLockRepository.unlock(1L)).thenReturn(TRUE); doNothing().when(reservationAsync).setPreOcuppied(reservationTime); //when - CreateReservationResponse response = reservationService.preOccupyReservation( + CreateReservationResponse response = memberReservationService.preOccupyReservation( request); //then @@ -91,7 +91,7 @@ void alreadyPreOccupied() { //when assertThrows(BadRequestCustomException.class, - () -> reservationService.preOccupyReservation(request)); + () -> memberReservationService.preOccupyReservation(request)); } @@ -111,7 +111,7 @@ void registerReservation() { Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); - CreateReservationResponse response = reservationService.registerReservation(request); + CreateReservationResponse response = memberReservationService.registerReservation(request); assertAll( () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), @@ -131,7 +131,7 @@ void registerReservationAlreadyOccupied() { Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, - () -> reservationService.registerReservation(request)); + () -> memberReservationService.registerReservation(request)); } @Test @@ -142,7 +142,7 @@ void getAllReservation() { when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn( List.of(reservation)); - List all = reservationService.getAllReservation(); + List all = memberReservationService.getAllReservation(); GetAllReservationResponse findReservation = all.get(0); assertAll( @@ -159,7 +159,7 @@ void getAllReservation() { void getAllReservationWithNoResult() { when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); - List all = reservationService.getAllReservation(); + List all = memberReservationService.getAllReservation(); assertThat(all).isEmpty(); } @@ -187,7 +187,7 @@ void modifyReservation() { Optional.of(modifyTime)); //when - ModifyReservationResponse response = reservationService.modifyReservation( + ModifyReservationResponse response = memberReservationService.modifyReservation( 1L, request); // 예약 id가 1인 예약 정보 변경 //then @@ -206,7 +206,7 @@ void modifyReservationNotExist() { Optional.empty()); assertThrows(BadRequestCustomException.class, - () -> reservationService.modifyReservation(1L, request)); + () -> memberReservationService.modifyReservation(1L, request)); } @Test @@ -222,7 +222,7 @@ void modifyReservationPreOccupied() { any(Long.class))).thenReturn(Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, - () -> reservationService.modifyReservation(1L, request)); + () -> memberReservationService.modifyReservation(1L, request)); } @Test @@ -238,7 +238,7 @@ void modifyReservationOccupied() { any(Long.class))).thenReturn(Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, - () -> reservationService.modifyReservation(1L, request)); + () -> memberReservationService.modifyReservation(1L, request)); } @Test @@ -253,7 +253,7 @@ void cancelReservation() { when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); //when - CancelReservationResponse response = reservationService.cancelReservation( + CancelReservationResponse response = memberReservationService.cancelReservation( reservation.getId()); //then @@ -270,7 +270,7 @@ void cancelReservation() { void cancelReservationNotExist(){ when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.empty()); - assertThrows(NotFoundCustomException.class, () -> reservationService.cancelReservation(1L)); + assertThrows(NotFoundCustomException.class, () -> memberReservationService.cancelReservation(1L)); } } \ No newline at end of file From 7b1923ecd83e4fa3520d8ac4235e57a1c847abdc Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 19:12:14 +0900 Subject: [PATCH 253/603] =?UTF-8?q?fix=20:=20=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?=EC=8B=9C=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=ED=8C=A8=ED=84=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java index bc3adbdc..536745cf 100644 --- a/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java +++ b/src/main/java/com/prgrms/catchtable/owner/dto/request/JoinOwnerRequest.java @@ -13,7 +13,7 @@ public record JoinOwnerRequest( @Email String email, String password, - @Pattern(regexp = "^(01[016789]){1}([0-9]{3,4}){1}([0-9]{4}){1}$") + @Pattern(regexp = "^(01[016789]){1}-([0-9]{3,4}){1}-([0-9]{4}){1}$") String phoneNumber, String gender, @JsonFormat(pattern = "yyyy-MM-dd") From e030fccb082332752d3bccc288bc3379941138f7 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 19:14:01 +0900 Subject: [PATCH 254/603] =?UTF-8?q?fix=20:=20LocalDateTime=EC=9D=84=20Json?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=ED=99=98=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EB=AA=A8=EB=93=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/base/BaseIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 1d86293a..0e2bc05c 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.common.base; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -15,6 +16,7 @@ public abstract class BaseIntegrationTest { public MockMvc mockMvc; public static String asJsonString(final Object object) throws Exception { + objectMapper.registerModule(new JavaTimeModule()); return objectMapper.writeValueAsString(object); } } From 86e1a5a6d5443af6ba8420fdd72f30b52c79fad8 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 20:06:46 +0900 Subject: [PATCH 255/603] feat : OwnerController Test --- .../owner/controller/OwnerControllerTest.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java new file mode 100644 index 00000000..d5d9dab2 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java @@ -0,0 +1,114 @@ +package com.prgrms.catchtable.owner.controller; + +import static org.springframework.http.MediaType.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; +import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.service.OwnerService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +class OwnerControllerTest extends BaseIntegrationTest { + + @Autowired + private OwnerService ownerService; + @Autowired + private JwtTokenProvider jwtTokenProvider; + + private final String joinEmail = "qwer@56782naver.com"; + private final String notJoinEmail = "abc1234@gmail.com"; + private final String password = "qwer1234"; + + @BeforeEach + public void init() { + ownerService.joinOwner(OwnerFixture.getJoinOwnerRequest(joinEmail, password)); + } + + @Test + @DisplayName("회원가입에 성공한다.") + void joinTest() throws Exception { + //given + JoinOwnerRequest joinOwnerRequest = OwnerFixture.getJoinOwnerRequest(notJoinEmail, + password); + + //then + mockMvc.perform(post("/owners/join") + .contentType(APPLICATION_JSON) + .content(asJsonString(joinOwnerRequest))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.name").value(joinOwnerRequest.name())) + .andExpect(jsonPath("$.email").value(joinOwnerRequest.email())) + .andExpect(jsonPath("$.phoneNumber").value(joinOwnerRequest.phoneNumber())) + .andExpect(jsonPath("$.gender").value(joinOwnerRequest.gender())) + .andExpect(jsonPath("$.dateBirth").value(joinOwnerRequest.dateBirth().toString())); + } + + @Test + @DisplayName("중복 이메일이 존재하여 테스트에 실패한다.") + void joinFailureTest() throws Exception { + //given + JoinOwnerRequest joinOwnerRequest = OwnerFixture.getJoinOwnerRequest(joinEmail, password); + + //then + mockMvc.perform(post("/owners/join") + .contentType(APPLICATION_JSON) + .content(asJsonString(joinOwnerRequest))) + .andExpect(status().isBadRequest()); + } + + @Test + @DisplayName("로그인이 정상적으로 작동한다.") + void loginTest() throws Exception { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(joinEmail, + password); + Token token = jwtTokenProvider.createToken(joinEmail); + + //then + mockMvc.perform(post("/owners/login") + .contentType(APPLICATION_JSON) + .content(asJsonString(loginOwnerRequest))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.email").value(token.getEmail())); + } + + @Test + @DisplayName("존재하지 않는 이메일로 로그인 시, 예외가 발생한다.") + void invalidatedEmail() throws Exception { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(notJoinEmail, + password); + + //then + mockMvc.perform(post("/owners/login") + .contentType(APPLICATION_JSON) + .content(asJsonString(loginOwnerRequest))) + .andExpect(status().isBadRequest()); + } + + @Test + @DisplayName("잘못된 비밀번호 입력 시, 예외가 발생한다.") + void invalidatedPassword() throws Exception { + //given + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(notJoinEmail, + "poiu0987"); + + //then + mockMvc.perform(post("/owners/login") + .contentType(APPLICATION_JSON) + .content(asJsonString(loginOwnerRequest))) + .andExpect(status().isBadRequest()); + + } +} \ No newline at end of file From 80aca16de0e361e17dbb826bf5be15a65b74d75d Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 20:08:14 +0900 Subject: [PATCH 256/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/member/domain/Gender.java | 6 +++--- .../catchtable/owner/controller/OwnerController.java | 5 +++-- .../com/prgrms/catchtable/owner/domain/Owner.java | 4 ++-- .../com/prgrms/catchtable/owner/dto/OwnerMapper.java | 5 +++-- .../catchtable/owner/service/OwnerService.java | 12 +++++++----- .../reservation/service/ReservationService.java | 3 ++- .../catchtable/security/config/SecurityConfig.java | 3 +-- .../security/controller/TestController.java | 2 +- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java index 999f8a71..a5449d29 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.member.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.BAD_REQUEST_INPUT_GENDER_TYPE; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import java.util.Arrays; @@ -15,14 +15,14 @@ public enum Gender { private final String type; - public static Gender of(String input){ + public static Gender of(String input) { return Arrays.stream(values()) .filter(gender -> gender.isEqual(input)) .findAny() .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_INPUT_GENDER_TYPE)); } - private boolean isEqual(String input){ + private boolean isEqual(String input) { return input.equals(this.type); } } diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java index 8a047521..a8e781df 100644 --- a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -22,14 +22,15 @@ public class OwnerController { private final OwnerService ownerService; @PostMapping("/join") - public ResponseEntity join(@Valid @RequestBody JoinOwnerRequest joinOwnerRequest){ + public ResponseEntity join( + @Valid @RequestBody JoinOwnerRequest joinOwnerRequest) { JoinOwnerResponse joinOwnerResponse = ownerService.joinOwner(joinOwnerRequest); return ResponseEntity.status(HttpStatus.CREATED).body(joinOwnerResponse); } @PostMapping("/login") - public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOwnerRequest){ + public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOwnerRequest) { Token responseToken = ownerService.loginOwner(loginOwnerRequest); return ResponseEntity.ok(responseToken); diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index 7d397eba..78c13636 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -12,7 +12,6 @@ import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; @@ -67,7 +66,8 @@ public class Owner extends BaseEntity implements UserDetails { private Shop shop; @Builder - public Owner(String name, String email, String password, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String password, String phoneNumber, Gender gender, + LocalDate dateBirth) { this.name = name; this.email = email; this.password = password; diff --git a/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java index 36386be2..33cf7ce7 100644 --- a/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java +++ b/src/main/java/com/prgrms/catchtable/owner/dto/OwnerMapper.java @@ -7,7 +7,8 @@ public class OwnerMapper { - public static Owner toEntity(JoinOwnerRequest joinOwnerRequest, String encodePassword, Gender gender){ + public static Owner toEntity(JoinOwnerRequest joinOwnerRequest, String encodePassword, + Gender gender) { return Owner.builder() .name(joinOwnerRequest.name()) .email(joinOwnerRequest.email()) @@ -18,7 +19,7 @@ public static Owner toEntity(JoinOwnerRequest joinOwnerRequest, String encodePas .build(); } - public static JoinOwnerResponse from(Owner owner){ + public static JoinOwnerResponse from(Owner owner) { return JoinOwnerResponse.builder() .name(owner.getName()) .email(owner.getEmail()) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index 095412d6..d8a12a97 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.owner.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_EXIST_OWNER; +import static com.prgrms.catchtable.common.exception.ErrorCode.BAD_REQUEST_EMAIL_OR_PASSWORD; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; @@ -33,7 +34,8 @@ public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { Gender gender = Gender.of(joinOwnerRequest.gender()); - Owner joinOwner = ownerRepository.save(OwnerMapper.toEntity(joinOwnerRequest, encodePassword, gender)); + Owner joinOwner = ownerRepository.save( + OwnerMapper.toEntity(joinOwnerRequest, encodePassword, gender)); return OwnerMapper.from(joinOwner); @@ -45,7 +47,7 @@ private void validateExistsOwner(JoinOwnerRequest joinOwnerRequest) { } } - public Token loginOwner(LoginOwnerRequest loginRequest){ + public Token loginOwner(LoginOwnerRequest loginRequest) { //email 확인 Owner loginOwner = ownerRepository.findOwnerByEmail(loginRequest.email()) @@ -57,8 +59,8 @@ public Token loginOwner(LoginOwnerRequest loginRequest){ return jwtTokenProvider.createToken(loginOwner.getEmail()); } - private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner){ - if(!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())){ + private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) { + if (!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())) { throw new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 83a4fd1b..00f3f124 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -70,7 +70,8 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r @Transactional public CreateReservationResponse registerReservation(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( //예약시간과 매장 한번에 가져옴 + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( + //예약시간과 매장 한번에 가져옴 request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 2dc6af45..e4c67aa6 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -15,7 +15,6 @@ import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import org.springframework.stereotype.Component; @Configuration @RequiredArgsConstructor @@ -27,7 +26,7 @@ public class SecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter; @Bean - public PasswordEncoder passwordEncoder(){ + public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } diff --git a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java index 6973411d..56f32d9a 100644 --- a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java +++ b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java @@ -10,7 +10,7 @@ public class TestController { @GetMapping("/testMember") - public ResponseEntity testMember(){ + public ResponseEntity testMember() { log.info("testMember"); return ResponseEntity.ok("testMember OK"); } From 4d234f9e873846c875a549cab89139b7b5edb78f Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 20:16:15 +0900 Subject: [PATCH 257/603] fix : conflict resolve --- .../catchtable/reservation/service/ReservationService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 00f3f124..bbe02070 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -71,7 +71,6 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r @Transactional public CreateReservationResponse registerReservation(CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( - //예약시간과 매장 한번에 가져옴 request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); From edd6a92cc87670cc3885f1a7e789a307b0e89bcf Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 20:22:51 +0900 Subject: [PATCH 258/603] =?UTF-8?q?feat=20:=20docs=20test=20API=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerDocsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java index 9fb4c6f3..3378327f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -41,7 +41,7 @@ void createWaiting() throws Exception { .shopId(1L) .shopName("shop1") .waitingNumber(324) - .waitingOrder(20) + .rank(20L) .peopleCount(2) .build(); @@ -69,7 +69,7 @@ void createWaiting() throws Exception { .description("인원 수"), fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) .description("웨이팅 고유 번호"), - fieldWithPath("waitingOrder").type(JsonFieldType.NUMBER) + fieldWithPath("rank").type(JsonFieldType.NUMBER) .description("웨이팅 순서") ) )); From bd3b603e6e912f72c6ffe74e995b11322d3bcd3a Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 5 Jan 2024 22:18:53 +0900 Subject: [PATCH 259/603] =?UTF-8?q?fix=20:=20=EC=9E=98=EB=AA=BB=EB=90=9C?= =?UTF-8?q?=20=EB=AC=B8=EB=B2=95=20=EC=82=AC=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/service/OwnerServiceTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 905a2940..dd8d297e 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -22,11 +22,11 @@ class OwnerServiceTest { - private OwnerRepository ownerRepository = mock(OwnerRepository.class); - private JwtTokenProvider jwtTokenProvider = mock(JwtTokenProvider.class); - private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + private final OwnerRepository ownerRepository = mock(OwnerRepository.class); + private final JwtTokenProvider jwtTokenProvider = mock(JwtTokenProvider.class); + private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); - private OwnerService ownerService = new OwnerService(ownerRepository, passwordEncoder, + private final OwnerService ownerService = new OwnerService(ownerRepository, passwordEncoder, jwtTokenProvider); String email = "abc1234@gmail.com"; @@ -75,14 +75,15 @@ void loginSuccess() { //given LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); String encodePassword = passwordEncoder.encode(password); + Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email()); //when when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( Optional.of(OwnerFixture.getOwner(email, encodePassword))); - when(jwtTokenProvider.createToken(loginOwnerRequest.email())).thenReturn(any(Token.class)); + when(jwtTokenProvider.createToken(loginOwnerRequest.email())).thenReturn(token); //then - assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(any(Token.class)); + assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(token); } @Test From 4eff971c0f961d0dab39d6c1a3b0544edd5abfcf Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 22:26:52 +0900 Subject: [PATCH 260/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=97=90=20=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaitingControllerTest.java | 33 ++++++++++++++----- .../waiting/service/WaitingServiceTest.java | 13 ++++++-- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 06d59f7b..76d55ee4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -15,50 +15,65 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.transaction.annotation.Transactional; @Transactional +@Disabled class WaitingControllerTest extends BaseIntegrationTest { @Autowired private MemberRepository memberRepository; @Autowired private WaitingRepository waitingRepository; - private List waitings; + + @Autowired + private WaitingLineRepository waitingLineRepository; @Autowired private ShopRepository shopRepository; private Shop shop; - private Member member1, member2, member3; + private Member member3; + private Waiting waiting1, waiting2; + private List waitings; + + @Autowired + private StringRedisTemplate redisTemplate; @BeforeEach void setUp() { + redisTemplate.delete("s1"); + shop = ShopFixture.shopWith24(); shopRepository.save(shop); - member1 = MemberFixture.member("test1@naver.com"); - member2 = MemberFixture.member("test2@naver.com"); + Member member1 = MemberFixture.member("test1@naver.com"); + Member member2 = MemberFixture.member("test2@naver.com"); member3 = MemberFixture.member("test3@naver.com"); memberRepository.saveAll(List.of(member1, member2, member3)); - Waiting waiting1 = Waiting.builder() + waiting1 = Waiting.builder() .member(member1) .shop(shop) .waitingNumber(1) .peopleCount(2) .build(); - Waiting waiting2 = Waiting.builder() + waiting2 = Waiting.builder() .member(member2) .shop(shop) .waitingNumber(2) .peopleCount(2) .build(); + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2)); - waiting2.completeWaiting(); + waitingLineRepository.save(shop.getId(), waiting1.getId()); + waitingLineRepository.save(shop.getId(), waiting2.getId()); } @@ -66,6 +81,8 @@ void setUp() { @Test void createWaiting() throws Exception { //given + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2)); + waitingLineRepository.printWaitingLine(shop.getId()); CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); @@ -76,7 +93,7 @@ void createWaiting() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) - .andExpect(jsonPath("$.waitingOrder").value(2)) + .andExpect(jsonPath("$.rank").value(3)) .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) .andDo(MockMvcResultHandlers.print()); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index c3775373..7713530b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -15,6 +15,7 @@ import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalTime; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -32,6 +33,9 @@ class WaitingServiceTest { private ShopRepository shopRepository; @Mock private MemberRepository memberRepository; + + @Mock + private WaitingLineRepository waitingLineRepository; @InjectMocks private WaitingService waitingService; @@ -51,16 +55,19 @@ void createWaiting() { .build(); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); - given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); + given(shop.getId()).willReturn(1L); + + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.existsByMember(member)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); + given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); //when - WaitingResponse response = waitingService.createWaiting(1L, member.getId(), request); + WaitingResponse response = waitingService.createWaiting(1L, 1L, request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), - () -> assertThat(response.waitingOrder()).isEqualTo(1), + () -> assertThat(response.rank()).isEqualTo(1L), () -> assertThat(response.waitingNumber()).isEqualTo(1) ); } From e753c013d17f2e856b958dc7780145016f98208b Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 22:37:03 +0900 Subject: [PATCH 261/603] =?UTF-8?q?feat=20:=20waitingRepository=20?= =?UTF-8?q?=EC=95=88=20=EC=93=B0=EB=8A=94=20=EC=A0=80=EC=9E=A5=EC=86=8C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 3 --- .../repository/WaitingRepositoryTest.java | 21 ++----------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 9a074017..9ce5d745 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -11,8 +11,5 @@ public interface WaitingRepository extends JpaRepository { boolean existsByMember(Member member); - Long countByShopAndStatusAndCreatedAtBetween(Shop shop, WaitingStatus status, - LocalDateTime start, LocalDateTime end); - Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index d352f53c..10330c77 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -79,23 +81,4 @@ void countByShopAndCreatedAtBetween() { //then assertThat(count).isEqualTo(2L); //waiting2, waiting3 } - - @DisplayName("특정 가게의 당일 대기 순서를 조회할 수 있다.") - @Test - void countByShopAndStatusAndCreatedAtBetween() { - yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); - completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); - normalWaiting = WaitingFixture.waiting(member3, shop, 3); - waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); - - ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", - LocalDateTime.now().minusDays(1)); - waitingRepository.save(yesterdayWaiting); - - //when - Long count = waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, PROGRESS, - START_DATE_TIME, END_DATE_TIME); - //then - assertThat(count).isEqualTo(1L); //waiting3 - } } \ No newline at end of file From fae1ed1843460fc47ea983fcec815b1626a17fef Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 22:44:59 +0900 Subject: [PATCH 262/603] =?UTF-8?q?feat=20:=20redis=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=81=B4=EB=A6=AC?= =?UTF-8?q?=EB=8B=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/RedisWaitingLineRepositoryTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index bc9a73ff..eb9a7246 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -5,8 +5,8 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; -import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -22,12 +22,9 @@ class RedisWaitingLineRepositoryTest { @Autowired private StringRedisTemplate redisTemplate; - @AfterEach void clear() { redisTemplate.delete("s1"); - redisTemplate.delete("s2"); - redisTemplate.delete("s3"); } @DisplayName("큐에 웨이팅을 추가한 후 순서를 반환받을 수 있다.") @@ -110,11 +107,10 @@ void postpone_fails() { void cancel() { //given Long shopId = 1L; - + repository.printWaitingLine(1L); repository.save(shopId, 1L); repository.save(shopId, 2L); repository.save(shopId, 3L); - //when repository.cancel(1L, 1L); //then From fbac6a04c8324612d87febf5b1954beae9d5b8ee Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 23:01:46 +0900 Subject: [PATCH 263/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EB=B9=84=EC=A7=80=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/dto/WaitingResponse.java | 2 +- .../catchtable/waiting/service/WaitingService.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java index 9b69282c..0cb73dee 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java @@ -9,7 +9,7 @@ public record WaitingResponse( String shopName, int peopleCount, int waitingNumber, - int waitingOrder + Long rank ) { } \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 79906f33..60ae49b7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -16,6 +16,7 @@ import com.prgrms.catchtable.waiting.dto.WaitingMapper; import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -33,6 +34,7 @@ public class WaitingService { private final WaitingRepository waitingRepository; private final MemberRepository memberRepository; private final ShopRepository shopRepository; + private final WaitingLineRepository waitingLineRepository; public WaitingResponse createWaiting(Long shopId, Long memberId, CreateWaitingRequest request) { @@ -50,15 +52,14 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, int waitingNumber = (waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; - // 대기 순서 생성 - int waitingOrder = (waitingRepository.countByShopAndStatusAndCreatedAtBetween(shop, - PROGRESS, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; - // waiting 저장 Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, member, shop); Waiting savedWaiting = waitingRepository.save(waiting); - return WaitingMapper.toCreateWaitingResponse(savedWaiting, waitingOrder); + waitingLineRepository.save(shopId, waiting.getId()); + Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); + + return WaitingMapper.toCreateWaitingResponse(savedWaiting, rank); } From 8523652b4195621b24d6e1617bb3e5ce5f040dac Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 23:39:07 +0900 Subject: [PATCH 264/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8=20disabled=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 76d55ee4..7d4dd911 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -17,8 +17,8 @@ import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +27,6 @@ import org.springframework.transaction.annotation.Transactional; @Transactional -@Disabled class WaitingControllerTest extends BaseIntegrationTest { @Autowired @@ -49,10 +48,9 @@ class WaitingControllerTest extends BaseIntegrationTest { @BeforeEach void setUp() { - redisTemplate.delete("s1"); - shop = ShopFixture.shopWith24(); shopRepository.save(shop); + redisTemplate.delete("s" + shop.getId()); Member member1 = MemberFixture.member("test1@naver.com"); Member member2 = MemberFixture.member("test2@naver.com"); member3 = MemberFixture.member("test3@naver.com"); @@ -76,6 +74,10 @@ void setUp() { waitingLineRepository.save(shop.getId(), waiting2.getId()); } + @AfterEach + void clear() { + redisTemplate.delete("s" + shop.getId()); + } @DisplayName("웨이팅 생성 API를 호출할 수 있다.") @Test From 0779f5f6b2aded3329cdf4af50e422ce5ff3c622 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 5 Jan 2024 23:54:12 +0900 Subject: [PATCH 265/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 4 ++-- .../catchtable/waiting/repository/WaitingRepository.java | 1 - .../repository/waitingline/BasicWaitingLineRepository.java | 4 ++-- .../repository/waitingline/RedisWaitingLineRepository.java | 4 +++- .../repository/waitingline/WaitingLineRepository.java | 7 +++++++ .../prgrms/catchtable/waiting/service/WaitingService.java | 1 - .../waiting/repository/WaitingRepositoryTest.java | 3 --- .../waitingline/BasicWaitingLineRepositoryTest.java | 2 +- .../waitingline/RedisWaitingLineRepositoryTest.java | 1 - 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 3c8836ba..3b8f7a18 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -21,14 +21,14 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static WaitingResponse toCreateWaitingResponse(Waiting waiting, int waitingOrder) { + public static WaitingResponse toCreateWaitingResponse(Waiting waiting, Long rank) { return WaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) .peopleCount(waiting.getPeopleCount()) .waitingNumber(waiting.getWaitingNumber()) - .waitingOrder(waitingOrder) + .rank(rank) .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 9ce5d745..974bd01a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -3,7 +3,6 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; import java.time.LocalDateTime; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 5fd9c0b5..090ef8e6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -16,7 +16,7 @@ @Slf4j @Component -public class BasicWaitingLineRepository implements WaitingLineRepository{ +public class BasicWaitingLineRepository implements WaitingLineRepository { public final Map> waitingLines = new ConcurrentHashMap<>(); @@ -63,7 +63,7 @@ public Long findRank(Long shopId, Long waitingId) { int index = 0; for (Long waitingIdInLine : waitingLine) { if (Objects.equals(waitingIdInLine, waitingId)) { - return (long)index + 1; + return (long) index + 1; } index++; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 607069bc..a3407dc6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -9,6 +9,7 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Primary; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.SessionCallback; @@ -17,8 +18,9 @@ @Slf4j @RequiredArgsConstructor +@Primary @Component -public class RedisWaitingLineRepository implements WaitingLineRepository{ +public class RedisWaitingLineRepository implements WaitingLineRepository { private final StringRedisTemplate redisTemplate; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 6b258fab..f80a9d5f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,11 +1,18 @@ package com.prgrms.catchtable.waiting.repository.waitingline; public interface WaitingLineRepository { + void save(Long shopId, Long waitingId); + void entry(Long shopId, Long waitingId); + void cancel(Long shopId, Long waitingId); + void postpone(Long shopId, Long waitingId); + Long findRank(Long shopId, Long waitingId); + Long getWaitingLineSize(Long shopId); + void printWaitingLine(Long shopId); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 60ae49b7..afda0827 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -3,7 +3,6 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 10330c77..235d142b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.waiting.repository; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import com.prgrms.catchtable.member.MemberFixture; @@ -21,8 +20,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Transactional; diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 9dee40de..1f40cc8c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class BasicWaitingLineRepositoryTest{ +class BasicWaitingLineRepositoryTest { private final BasicWaitingLineRepository repository = new BasicWaitingLineRepository(); diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index eb9a7246..e141c25e 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -6,7 +6,6 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; From 0eaddb4a3b4c55eb03a48c2afa1dc0b7eb291078 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 00:06:39 +0900 Subject: [PATCH 266/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20beforeEac?= =?UTF-8?q?h=20=ED=81=B4=EB=A6=AC=EB=8B=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/WaitingControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 7d4dd911..8dc583e8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -50,7 +50,6 @@ class WaitingControllerTest extends BaseIntegrationTest { void setUp() { shop = ShopFixture.shopWith24(); shopRepository.save(shop); - redisTemplate.delete("s" + shop.getId()); Member member1 = MemberFixture.member("test1@naver.com"); Member member2 = MemberFixture.member("test2@naver.com"); member3 = MemberFixture.member("test3@naver.com"); From c2aa30e9432395edaf2510a523a4c37c74f2728b Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 01:04:49 +0900 Subject: [PATCH 267/603] =?UTF-8?q?refactor=20:=20static=20import=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/service/WaitingService.java | 7 ++++--- .../waitingline/RedisWaitingLineRepositoryTest.java | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index afda0827..0966dac9 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -3,6 +3,8 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toCreateWaitingResponse; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -12,7 +14,6 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingMapper; import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; @@ -52,13 +53,13 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // waiting 저장 - Waiting waiting = WaitingMapper.toWaiting(request, waitingNumber, member, shop); + Waiting waiting = toWaiting(request, waitingNumber, member, shop); Waiting savedWaiting = waitingRepository.save(waiting); waitingLineRepository.save(shopId, waiting.getId()); Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); - return WaitingMapper.toCreateWaitingResponse(savedWaiting, rank); + return toCreateWaitingResponse(savedWaiting, rank); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index e141c25e..57b18eaf 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -106,7 +106,6 @@ void postpone_fails() { void cancel() { //given Long shopId = 1L; - repository.printWaitingLine(1L); repository.save(shopId, 1L); repository.save(shopId, 2L); repository.save(shopId, 3L); From 0b21e6186ab52b0bfb22dcc6ab6a2589d9edfadd Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:41:21 +0900 Subject: [PATCH 268/603] =?UTF-8?q?style=20:=20ReservationController=20->?= =?UTF-8?q?=20MemberReservationController=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...troller.java => MemberReservationController.java} | 2 +- ...est.java => MemberReservationControllerTest.java} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename src/main/java/com/prgrms/catchtable/reservation/controller/{ReservationController.java => MemberReservationController.java} (98%) rename src/test/java/com/prgrms/catchtable/reservation/controller/{ReservationControllerTest.java => MemberReservationControllerTest.java} (93%) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java similarity index 98% rename from src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java rename to src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index fd8aa048..36a96631 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -19,7 +19,7 @@ @RestController @RequestMapping("/reservations") @RequiredArgsConstructor -public class ReservationController { +public class MemberReservationController { private final MemberReservationService memberReservationService; diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java similarity index 93% rename from src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java rename to src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index b24c0a98..29ac7ed0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/ReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -30,7 +30,7 @@ import org.springframework.transaction.annotation.Transactional; @Transactional -class ReservationControllerTest extends BaseIntegrationTest { +class MemberReservationControllerTest extends BaseIntegrationTest { @Autowired private ReservationTimeRepository reservationTimeRepository; @@ -133,9 +133,16 @@ void modifyReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); Reservation reservation = ReservationFixture.getReservation(reservationTime); Reservation savedReservation = reservationRepository.save(reservation); + /** + * 수정하려는 예약시간 예제 데이터 생성 + */ + Shop findShop = shopRepository.findAll().get(0); + ReservationTime reservationTime1 = ReservationFixture.getReservationTimeNotPreOccupied(); + reservationTime1.insertShop(findShop); + ReservationTime savedReservationTime1 = reservationTimeRepository.save(reservationTime1); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( - reservationTime.getId()); + savedReservationTime1.getId()); ReservationTime modifyReservationTime = reservationTimeRepository.findByIdAndShopId( request.reservationTimeId(), reservation.getShop().getId()).orElseThrow(); // 수정하려는 예약시간 @@ -149,6 +156,7 @@ void modifyReservation() throws Exception { assertThat(savedReservation.getReservationTime()).isEqualTo( modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 + assertThat(savedReservation.getReservationTime().isOccupied()).isFalse(); } @Test From 3b5b28d0a566f0f31ad0b10691e4f0b3d8fea884 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:42:53 +0900 Subject: [PATCH 269/603] =?UTF-8?q?feat=20:=20Owner=EC=9D=98=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/ModifyReservationStatusRequest.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationStatusRequest.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationStatusRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationStatusRequest.java new file mode 100644 index 00000000..64b3964a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/ModifyReservationStatusRequest.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.reservation.dto.request; + +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import lombok.Builder; + +@Builder +public record ModifyReservationStatusRequest(ReservationStatus status) { + +} From 5f9204385fdd710f479e35f9199b255961234e5d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:43:09 +0900 Subject: [PATCH 270/603] =?UTF-8?q?feat=20:=20Owner=EC=9D=98=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A0=84=EC=B2=B4=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/OwnerGetAllReservationResponse.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/OwnerGetAllReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/OwnerGetAllReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/OwnerGetAllReservationResponse.java new file mode 100644 index 00000000..523d126f --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/OwnerGetAllReservationResponse.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record OwnerGetAllReservationResponse(Long reservationId, + @JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") + LocalDateTime date, + int peopleCount, + ReservationStatus status) { + +} From 1802f3fde92ca89add1b71b9fb419e2c2b489a18 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:43:42 +0900 Subject: [PATCH 271/603] =?UTF-8?q?feat=20:=20Owner=EC=9D=98=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EC=A0=95=EB=B3=B4=20=EC=A0=84=EC=B2=B4=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20dto=20mapper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/mapper/ReservationMapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index 536f1c8e..3f017e47 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -46,4 +47,13 @@ public static CancelReservationResponse toCancelReservationResponse (Reservation .build(); } + public static OwnerGetAllReservationResponse toOwnerGetAllReservationResponse(Reservation reservation){ + return OwnerGetAllReservationResponse.builder() + .reservationId(reservation.getId()) + .date(reservation.getReservationTime().getTime()) + .peopleCount(reservation.getPeopleCount()) + .status(reservation.getStatus()) + .build(); + } + } From 85e5d43ffc015f0b6e2b576cb134db4bd6a3f733 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:44:09 +0900 Subject: [PATCH 272/603] =?UTF-8?q?feat=20:=20Owner=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84=20=EB=B0=8F?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerReservationService.java | 62 ++++++++ .../service/OwnerReservationServiceTest.java | 137 ++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java new file mode 100644 index 00000000..4f2ffc38 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -0,0 +1,62 @@ +package com.prgrms.catchtable.reservation.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; + +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class OwnerReservationService { + + private final ReservationTimeRepository reservationTimeRepository; + private final ReservationRepository reservationRepository; + private final OwnerRepository ownerRepository; + + /** + * 예약 취소, 노쇼 처리 + * @param reservationId + * @param request + */ + @Transactional + public void modifyReservationStatus( + Long reservationId, + ModifyReservationStatusRequest request + ) { + ReservationStatus modifyStatus = request.status(); + + Reservation reservation = reservationRepository + .findByIdWithReservationTimeAndShop(reservationId) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_RESERVATION)); + + reservation.changeStatus(modifyStatus); + + reservation.getReservationTime().reverseOccupied(); + } + + /** + * owner가 자신의 가게에 등록된 예약 전체 조회 + * @return + */ + @Transactional(readOnly = true) + public List getAllReservation(Long ownerId){ + Owner owner = ownerRepository.findById(ownerId).orElseThrow(); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId(owner.getShop().getId()); + + return reservations.stream() + .map(ReservationMapper::toOwnerGetAllReservationResponse).toList(); + } +} diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java new file mode 100644 index 00000000..e6f5875b --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java @@ -0,0 +1,137 @@ +package com.prgrms.catchtable.reservation.service; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; +import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; +import org.testcontainers.shaded.org.checkerframework.checker.units.qual.A; + +@ExtendWith(MockitoExtension.class) +class OwnerReservationServiceTest { + @Mock + private ReservationRepository reservationRepository; + @Mock + private OwnerRepository ownerRepository; + @InjectMocks + private OwnerReservationService ownerReservationService; + + @Test + @DisplayName("점주는 특정 예약을 노쇼처리 할 수 있다.") + void noshowReservation(){ + ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( + NO_SHOW); + + when(reservationRepository.findByIdWithReservationTimeAndShop(any(Long.class))).thenReturn( + Optional.of(reservation)); + + ownerReservationService.modifyReservationStatus(1L, request); + + assertAll( + () -> assertThat(reservation.getStatus()).isEqualTo(NO_SHOW), // 예약 상태가 노쇼로 바뀌어야함 + () -> assertThat(reservation.getReservationTime().isOccupied()).isFalse() // 예약한 예약시간의 차지여부가 false가 되어야함 + ); + } + + @Test + @DisplayName("점주는 특정 예약을 취소처리 할 수 있다.") + void cancelReservation(){ + ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); + Reservation reservation = ReservationFixture.getReservation(reservationTime); + ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( + CANCELLED); + + when(reservationRepository.findByIdWithReservationTimeAndShop(any(Long.class))).thenReturn( + Optional.of(reservation)); + + ownerReservationService.modifyReservationStatus(1L, request); + + assertAll( + () -> assertThat(reservation.getStatus()).isEqualTo(CANCELLED), + () -> assertThat(reservation.getReservationTime().isOccupied()).isFalse() + ); + } + + @Test + @DisplayName("존재하지 않는 예약을 노쇼,취소 처리하려 하면 예외가 발생한다") + void modifyReservationNotExist(){ + ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( + CANCELLED); + + when(reservationRepository.findByIdWithReservationTimeAndShop(any(Long.class))).thenReturn( + Optional.empty()); + + assertThrows(NotFoundCustomException.class, + () -> ownerReservationService.modifyReservationStatus(1L, request)); + } + + @Test + @DisplayName("점주는 가게의 예약을 전체 조회할 수 있다") + void getAllReservation(){ + List reservations = new ArrayList<>(); + ReservationTime reservationTime1 = ReservationFixture.getReservationTimeNotPreOccupied(); + ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); + + Shop shop1 = reservationTime1.getShop(); + Shop shop2 = reservationTime2.getShop(); + ReflectionTestUtils.setField(shop1, "id", 1L); + ReflectionTestUtils.setField(shop2, "id", 2L); + + Reservation reservation1 = ReservationFixture.getReservation(reservationTime1); + Reservation reservation2 = ReservationFixture.getReservation(reservationTime2); + + reservations.add(reservation1); + reservations.add(reservation2); + Owner owner = OwnerFixture.getOwner(); + when(reservationRepository.findAllWithReservationTimeAndShopByShopId(any(Long.class))).thenReturn(reservations); + when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); + List allReservation = ownerReservationService.getAllReservation( + 1L); + + assertAll( + () -> assertThat(allReservation.get(0).date()).isEqualTo(reservation1.getReservationTime().getTime()), + () -> assertThat(allReservation.get(1).date()).isEqualTo(reservation2.getReservationTime().getTime()) + ); + } + + @Test + @DisplayName("매장에 예약이 없을 시 빈 리스트가 조회된다.") + void getAllReservationEmpty(){ + Owner owner = OwnerFixture.getOwner(); + + when(reservationRepository.findAllWithReservationTimeAndShopByShopId(any(Long.class))).thenReturn(List.of()); + when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); + + List allReservation = ownerReservationService.getAllReservation( + 1L); + + assertThat(allReservation).isEmpty(); + } + +} \ No newline at end of file From f3236683ab8bf7fa090fc452935a25df88864f5a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:45:00 +0900 Subject: [PATCH 273/603] =?UTF-8?q?feat=20:=20Owner=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index a13288b3..d9a432ad 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -5,6 +5,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface ReservationRepository extends JpaRepository { @@ -15,6 +16,12 @@ public interface ReservationRepository extends JpaRepository @Query("select r from Reservation r " + "join fetch r.reservationTime rt " - + "join fetch rt.shop") - Optional findByIdWithReservationTimeAndShop(Long reservationId); + + "join fetch rt.shop " + + "where r.id = :reservationId") + Optional findByIdWithReservationTimeAndShop(@Param("reservationId") Long reservationId); + @Query("select r from Reservation r " + + "join fetch r.reservationTime rt " + + "join fetch rt.shop s " + + "where s.id = :shopId") + List findAllWithReservationTimeAndShopByShopId(@Param("shopId") Long shopId); } From d77cf76ae4646d4d91a0be2ae29790a8704915f0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:45:16 +0900 Subject: [PATCH 274/603] =?UTF-8?q?feat=20:=20Owner=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepositoryTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index b855551b..9e5926f9 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -9,6 +9,7 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -48,5 +49,61 @@ void findAllWithReservationTimeAndShop() { () -> assertThat(findReservation.getShop()).isEqualTo(savedShop) ); } + @Test + @DisplayName("예약 Id를 통해 예약(예약시간, 매장까지)을 조회할 수 있다.") + void findByIdWithReservationTimeAndShop() { + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + reservationTime.insertShop(savedShop); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + + Reservation reservation = ReservationFixture.getReservation(savedReservationTime); + Reservation savedReservation = reservationRepository.save(reservation); + + Reservation findReservation = reservationRepository.findByIdWithReservationTimeAndShop( + savedReservation.getId()).orElseThrow(); + + assertAll( + () -> assertThat(findReservation.getReservationTime()).isEqualTo(savedReservationTime), + () -> assertThat(findReservation.getShop()).isEqualTo(savedShop), + () -> assertThat(findReservation.getPeopleCount()).isEqualTo(savedReservation.getPeopleCount()) + ); + } + + @Test + @DisplayName("가게 아이디와 일치하는 예약을 전체 조회할 수 있다") + void getAllReservationByShopId(){ + /** + * 첫번째 예제 예약 데이터 저장 + */ + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Shop shop = ShopData.getShop(); + Shop savedShop = shopRepository.save(shop); + reservationTime.insertShop(savedShop); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + Reservation reservation = ReservationFixture.getReservation(savedReservationTime); + + reservationRepository.save(reservation); + /** + * 두번째 예제 예약 데이터 저장 (점주의 가게 예약이 아닌 데이터) + */ + ReservationTime otherReservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + Shop otherShop = ShopFixture.shop(); + Shop otherSavedShop = shopRepository.save(otherShop); + otherReservationTime.insertShop(otherSavedShop); + ReservationTime otherSavedReservationTime = reservationTimeRepository.save(otherReservationTime); + Reservation otherReservation = ReservationFixture.getReservation(otherSavedReservationTime); + + reservationRepository.save(otherReservation); + + List all = reservationRepository.findAllWithReservationTimeAndShopByShopId( + savedShop.getId()); + + assertAll( + () -> assertThat(all).contains(reservation), + () -> assertThat(all).doesNotContain(otherReservation) + ); + } } \ No newline at end of file From 27480c5eede714c645bf90feea28e862a562fcc0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:45:49 +0900 Subject: [PATCH 275/603] =?UTF-8?q?feat=20:=20Owner=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20shop=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EB=A7=A4=ED=95=91=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/owner/domain/Owner.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index f6d09f8f..de87e201 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -56,4 +56,8 @@ public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth this.gender = gender; this.dateBirth = dateBirth; } + + public void insertShop(Shop shop){ + this.shop = shop; + } } From 6d7bc73eaf514abb67ea4a2c42ac7aad5dff6b24 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:46:09 +0900 Subject: [PATCH 276/603] =?UTF-8?q?feat=20:=20OwnerController=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerReservationController.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java new file mode 100644 index 00000000..3a35c41a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java @@ -0,0 +1,35 @@ +package com.prgrms.catchtable.reservation.controller; + +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; +import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; +import com.prgrms.catchtable.reservation.service.OwnerReservationService; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/owners/shop") +@RequiredArgsConstructor +public class OwnerReservationController { + private final OwnerReservationService ownerReservationService; + + @PostMapping("/{reservationId}") + public void modifyReservationStatus( + @PathVariable("reservationId") Long reservationId, + @RequestBody ModifyReservationStatusRequest request + ){ + ownerReservationService.modifyReservationStatus(reservationId, request); + } + + @GetMapping + public ResponseEntity> getAllReservation(@RequestBody Long ownerId){ + return ResponseEntity.ok(ownerReservationService.getAllReservation(ownerId)); + } +} From c4d513d97384c71e0af8fc603de939d30c762519 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:46:33 +0900 Subject: [PATCH 277/603] =?UTF-8?q?feat=20:=20OwnerFixture=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../owner/fixture/OwnerFixture.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java new file mode 100644 index 00000000..55d1fafd --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -0,0 +1,27 @@ +package com.prgrms.catchtable.owner.fixture; + +import static com.prgrms.catchtable.member.domain.Gender.*; + +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.member.domain.Gender; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.shop.domain.Shop; +import java.time.LocalDate; +import org.springframework.test.util.ReflectionTestUtils; + +public class OwnerFixture { + + public static Owner getOwner(){ + Owner owner = Owner.builder() + .name("ownerA") + .phoneNumber("010-3462-2480") + .gender(MALE) + .dateBirth(LocalDate.of(2000, 9, 13)) + .build(); + Shop shop = ShopData.getShop(); + ReflectionTestUtils.setField(shop, "id", 1L); + owner.insertShop(shop); + return owner; + } + +} From af40f00bf5b16079bc5425ff20a855e987307b82 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:46:59 +0900 Subject: [PATCH 278/603] =?UTF-8?q?feat=20:=20ReservationFixture=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=EC=96=BB=EC=96=B4=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/fixture/ReservationFixture.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index 5e6de7ff..773479c9 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -4,9 +4,11 @@ import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; @@ -15,6 +17,9 @@ public class ReservationFixture { public static Reservation getReservation(ReservationTime reservationTime) { + if(!reservationTime.isOccupied()){ + reservationTime.reverseOccupied(); + } return Reservation.builder() .status(COMPLETED) .peopleCount(4) @@ -83,4 +88,11 @@ public static ReservationTime getReservationTimeOccupied() { return reservationTime; } + public static ModifyReservationStatusRequest getModifyReservationStatusRequest( + ReservationStatus status){ + return ModifyReservationStatusRequest.builder() + .status(status) + .build(); + } + } From a77a3d6dbfc1da2a606eb9d08ab2a82ebf0ac101 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 02:47:26 +0900 Subject: [PATCH 279/603] =?UTF-8?q?feat=20:=20OwnerController=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerReservationControllerTest.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java new file mode 100644 index 00000000..2a8e12df --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -0,0 +1,110 @@ +package com.prgrms.catchtable.reservation.controller; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static org.assertj.core.api.Assertions.*; +import static org.springframework.http.MediaType.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationStatus; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Transactional +class OwnerReservationControllerTest extends BaseIntegrationTest { + @Autowired + private ReservationTimeRepository reservationTimeRepository; + @Autowired + private OwnerRepository ownerRepository; + + @Autowired + private ShopRepository shopRepository; + @Autowired + private ReservationRepository reservationRepository; + @BeforeEach + void setUp(){ + Shop shop = shopRepository.save(ShopData.getShop()); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); + reservationTime.insertShop(shop); + ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); + savedReservationTime.reverseOccupied(); + log.info("예약 시간 차지 여부 : {}", savedReservationTime.isOccupied()); + Reservation reservation = reservationRepository.save( + ReservationFixture.getReservation(savedReservationTime)); + + ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); + reservationTime2.insertShop(shop); + ReservationTime savedReservationTime2 = reservationTimeRepository.save(reservationTime2); + savedReservationTime2.reverseOccupied(); + log.info("예약 시간 차지 여부 : {}", savedReservationTime.isOccupied()); + Reservation reservation2 = reservationRepository.save( + ReservationFixture.getReservation(savedReservationTime2)); + + Owner owner = OwnerFixture.getOwner(); + owner.insertShop(shop); + ownerRepository.save(owner); + } + + @Test + @DisplayName("점주는 예약상태를 변경시킬 수 있다") + void modifyReservationStatus() throws Exception { + //given + Reservation reservation = reservationRepository.findAll().get(0); + + ModifyReservationStatusRequest request = ModifyReservationStatusRequest.builder() + .status(CANCELLED) + .build(); + + //then + assertThat(reservation.getReservationTime().isOccupied()).isTrue(); // 취소처리 전엔 예약시간 차있음 + mockMvc.perform(post("/owners/shop/{reservationId}", reservation.getId()) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) + .andExpect(status().isOk()); + + assertThat(reservation.getStatus()).isEqualTo(request.status()); + assertThat(reservation.getReservationTime().isOccupied()).isFalse(); // 취소처리 후엔 예약시간 비어있음 + } + + @Test + @DisplayName("점주는 예약된 정보들을 전체 조회할 수 있다.") + void getAllReservation() throws Exception { + List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + Reservation reservation1 = reservations.get(0); + Reservation reservation2 = reservations.get(1); + + Owner owner = ownerRepository.findAll().get(0); + + mockMvc.perform(get("/owners/shop") + .contentType(APPLICATION_JSON) + .content(asJsonString(owner.getId()))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$[0].date").value(reservation1.getReservationTime().getTime().toString())) + .andExpect(jsonPath("$[0].peopleCount").value(reservation1.getPeopleCount())) + .andExpect(jsonPath("$[1].date").value(reservation2.getReservationTime().getTime().toString())) + .andExpect(jsonPath("$[1].peopleCount").value(reservation2.getPeopleCount())); + } +} \ No newline at end of file From 80652f0e54bcc13cc97b3019cc2195c3aa8a758b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 03:04:51 +0900 Subject: [PATCH 280/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=85=B8=EC=87=BC,=20=EC=B7=A8=EC=86=8C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=97=90=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerReservationService.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 4f2ffc38..d6de6d48 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -1,7 +1,10 @@ package com.prgrms.catchtable.reservation.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; @@ -9,7 +12,6 @@ import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; -import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; @@ -22,12 +24,12 @@ @RequiredArgsConstructor public class OwnerReservationService { - private final ReservationTimeRepository reservationTimeRepository; private final ReservationRepository reservationRepository; private final OwnerRepository ownerRepository; /** * 예약 취소, 노쇼 처리 + * * @param reservationId * @param request */ @@ -36,25 +38,31 @@ public void modifyReservationStatus( Long reservationId, ModifyReservationStatusRequest request ) { - ReservationStatus modifyStatus = request.status(); + ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 + + if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + throw new BadRequestCustomException(ALREADY_COMPLETED); + } Reservation reservation = reservationRepository .findByIdWithReservationTimeAndShop(reservationId) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_RESERVATION)); - reservation.changeStatus(modifyStatus); + reservation.changeStatus(modifyStatus); // 해당 예약의 상태를 요청으로 들어온 상태로 변경 - reservation.getReservationTime().reverseOccupied(); + reservation.getReservationTime().reverseOccupied(); // 해당 예약의 예약시간을 빈 상태로 변경 } /** * owner가 자신의 가게에 등록된 예약 전체 조회 + * * @return */ @Transactional(readOnly = true) - public List getAllReservation(Long ownerId){ + public List getAllReservation(Long ownerId) { Owner owner = ownerRepository.findById(ownerId).orElseThrow(); - List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId(owner.getShop().getId()); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId( + owner.getShop().getId()); return reservations.stream() .map(ReservationMapper::toOwnerGetAllReservationResponse).toList(); From 8a93337da667492d542db63a7f0b3c28982f381c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 15:52:30 +0900 Subject: [PATCH 281/603] =?UTF-8?q?fix=20:=20Errorcode=20static=20import?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/OwnerReservationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index d6de6d48..fc2cc861 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -1,8 +1,9 @@ package com.prgrms.catchtable.reservation.service; + import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -14,7 +15,6 @@ import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; From 6fedbacd052a24d2ebccbdb0953211e5fe8f7e27 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 16:00:35 +0900 Subject: [PATCH 282/603] =?UTF-8?q?fix=20:=20Errorcode=20static=20import?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/OwnerReservationService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index fc2cc861..62d92c8b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -1,11 +1,8 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; @@ -40,9 +37,9 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 - if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 - throw new BadRequestCustomException(ALREADY_COMPLETED); - } +// if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 +// throw new BadRequestCustomException(ALREADY_COMPLETED); +// } Reservation reservation = reservationRepository .findByIdWithReservationTimeAndShop(reservationId) From aa3ef7cba062b30bdc916f21536b3aabd53b6c20 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 16:03:49 +0900 Subject: [PATCH 283/603] =?UTF-8?q?fix=20:=20Errorcode=20static=20import?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=EC=B5=9C=EC=A2=85?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/common/exception/ErrorCode.java | 1 + .../reservation/service/OwnerReservationService.java | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 8d8ffd24..aabcd0d4 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -16,6 +16,7 @@ public enum ErrorCode { NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), NOT_EXIST_RESERVATION("존재하지 않는 예약입니다"), EXCEED_PEOPLE_COUNT("예약인원이 해당 시간의 남은 수용가능 인원 수를 초과했습니다."), + ALREADY_COMPLETED("이미 예약 상태인 예약입니다."), CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 62d92c8b..fc2cc861 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -1,8 +1,11 @@ package com.prgrms.catchtable.reservation.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; @@ -37,9 +40,9 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 -// if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 -// throw new BadRequestCustomException(ALREADY_COMPLETED); -// } + if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + throw new BadRequestCustomException(ALREADY_COMPLETED); + } Reservation reservation = reservationRepository .findByIdWithReservationTimeAndShop(reservationId) From d2d62febe25f9b84acc350d85037e477c5571a19 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:15:19 +0900 Subject: [PATCH 284/603] =?UTF-8?q?style=20:=20WaitingMapper=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 2 +- .../com/prgrms/catchtable/waiting/service/WaitingService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 3b8f7a18..895c9996 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -21,7 +21,7 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static WaitingResponse toCreateWaitingResponse(Waiting waiting, Long rank) { + public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { return WaitingResponse.builder() .createdWaitingId(waiting.getId()) .shopId(waiting.getShop().getId()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 0966dac9..93c11042 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -3,7 +3,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; -import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toCreateWaitingResponse; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -59,7 +59,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, waitingLineRepository.save(shopId, waiting.getId()); Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); - return toCreateWaitingResponse(savedWaiting, rank); + return toWaitingResponse(savedWaiting, rank); } From 214714036a523a6e073df5cce471f93aadd50b4c Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:24:02 +0900 Subject: [PATCH 285/603] =?UTF-8?q?feat=20:=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EB=82=B4=20postpone=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/common/exception/ErrorCode.java | 7 +++++-- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 8d8ffd24..348bca68 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -19,7 +19,10 @@ public enum ErrorCode { CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), - ALREADY_END_LINE("이미 맨뒤라 지연할 수 없습니다."), + ALREADY_END_LINE("이미 맨뒤라 웨이팅을 미룰 수 없습니다."), + NOT_EXIST_WAITING("웨이팅이 존재하지 않습니다."), + + POSTPONE_REMAINING_CNT_0("이미 두 차례 대기를 미뤘습니다."), CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), @@ -27,4 +30,4 @@ public enum ErrorCode { INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); private final String message; -} +} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 84e537e0..2fe84914 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.domain; import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; +import static com.prgrms.catchtable.common.exception.ErrorCode.POSTPONE_REMAINING_CNT_0; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.NO_SHOW; @@ -69,6 +70,16 @@ public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { postponeRemainingCount = 2; } + public void validatePostponeRemainingCount() { + if (postponeRemainingCount==0){ + throw new BadRequestCustomException(POSTPONE_REMAINING_CNT_0); + } + } + + public void decreasePostponeRemainingCount(){ + postponeRemainingCount--; + } + public void completeWaiting() { if (status == NO_SHOW || status == CANCELED) { throw new BadRequestCustomException(CAN_NOT_COMPLETE_WAITING); From 9cb4c371a8bd3de5ff727c6110b83c4acf770b93 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:25:49 +0900 Subject: [PATCH 286/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=A7=80=EC=97=B0=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 3 ++ .../waiting/service/WaitingService.java | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 974bd01a..6ae84e55 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -4,11 +4,14 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import java.time.LocalDateTime; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface WaitingRepository extends JpaRepository { boolean existsByMember(Member member); + Optional findByMember(Member member); + Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 93c11042..764702f8 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_WAITING; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; @@ -42,9 +43,6 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, Member member = getMemberEntity(memberId); Shop shop = getShopEntity(shopId); - // shop 영업 중인지 검증 - shop.validateIfShopOpened(LocalTime.now()); - // 기존 waiting이 있는지 검증 validateIfMemberWaitingExists(member); @@ -62,7 +60,19 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, return toWaitingResponse(savedWaiting, rank); } + public WaitingResponse postponeWaiting(Long memberId){ + Member member = getMemberEntity(memberId); + Waiting waiting = getWaitingEntity(member); + + Shop shop = waiting.getShop(); + + waiting.validatePostponeRemainingCount(); + waitingLineRepository.postpone(shop.getId(), waiting.getId()); + Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + waiting.decreasePostponeRemainingCount(); + return toWaitingResponse(waiting, rank); + } private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); @@ -76,8 +86,16 @@ public Member getMemberEntity(Long memberId) { } public Shop getShopEntity(Long shopId) { - return shopRepository.findById(shopId).orElseThrow( + Shop shop = shopRepository.findById(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) ); + shop.validateIfShopOpened(LocalTime.now()); + return shop; + } + + public Waiting getWaitingEntity(Member member){ + return waitingRepository.findByMember(member).orElseThrow( + () -> new NotFoundCustomException(NOT_EXIST_WAITING) + ); } -} +} \ No newline at end of file From bdb2569db8f52c5ac96d0233715a9037293ab490 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:27:29 +0900 Subject: [PATCH 287/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=A7=80=EC=97=B0=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/WaitingServiceTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 7713530b..7bc24bed 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; @@ -18,6 +19,7 @@ import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalTime; import java.util.Optional; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -71,4 +73,29 @@ void createWaiting() { () -> assertThat(response.waitingNumber()).isEqualTo(1) ); } + + @DisplayName("대기 지연을 할 수 있다.") + @Test + void postponeWaiting() { + //given + Shop shop = mock(Shop.class); + Member member = mock(Member.class); + Waiting waiting = mock(Waiting.class); + + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); + given(waitingRepository.findByMember(member)).willReturn(Optional.of(waiting)); + given(waiting.getShop()).willReturn(shop); + given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); + doNothing().when(waiting).validatePostponeRemainingCount(); + doNothing().when(waiting).decreasePostponeRemainingCount(); + + //when + WaitingResponse response = waitingService.postponeWaiting(1L); + //then + assertAll( + assertThat(response.peopleCount())::isNotNull, + () -> assertThat(response.rank()).isNotNull(), + assertThat(response.waitingNumber())::isNotNull + ); + } } \ No newline at end of file From 6d8c88916d7f226ad4614b2e6bcc459f5c3eecb9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:30:39 +0900 Subject: [PATCH 288/603] =?UTF-8?q?refactor=20:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaitingControllerTest.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 8dc583e8..ef6518df 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -38,9 +38,9 @@ class WaitingControllerTest extends BaseIntegrationTest { private WaitingLineRepository waitingLineRepository; @Autowired private ShopRepository shopRepository; + private Member member1, member2, member3; private Shop shop; - private Member member3; - private Waiting waiting1, waiting2; + private Waiting waiting1, waiting2, waiting3; private List waitings; @Autowired @@ -48,13 +48,14 @@ class WaitingControllerTest extends BaseIntegrationTest { @BeforeEach void setUp() { - shop = ShopFixture.shopWith24(); - shopRepository.save(shop); - Member member1 = MemberFixture.member("test1@naver.com"); - Member member2 = MemberFixture.member("test2@naver.com"); + member1 = MemberFixture.member("test1@naver.com"); + member2 = MemberFixture.member("test2@naver.com"); member3 = MemberFixture.member("test3@naver.com"); memberRepository.saveAll(List.of(member1, member2, member3)); + shop = ShopFixture.shopWith24(); + shopRepository.save(shop); + waiting1 = Waiting.builder() .member(member1) .shop(shop) @@ -68,9 +69,17 @@ void setUp() { .peopleCount(2) .build(); - waitings = waitingRepository.saveAll(List.of(waiting1, waiting2)); + waiting3 = Waiting.builder() + .member(member3) + .shop(shop) + .waitingNumber(3) + .peopleCount(2) + .build(); + + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); waitingLineRepository.save(shop.getId(), waiting1.getId()); waitingLineRepository.save(shop.getId(), waiting2.getId()); + waitingLineRepository.save(shop.getId(), waiting3.getId()); } @AfterEach @@ -82,22 +91,24 @@ void clear() { @Test void createWaiting() throws Exception { //given - waitings = waitingRepository.saveAll(List.of(waiting1, waiting2)); - waitingLineRepository.printWaitingLine(shop.getId()); + Member member4 = MemberFixture.member("test4@naver.com"); + memberRepository.save(member4); CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); + // when, then - mockMvc.perform(post("/waitings/{shopId}/{memberId}", shop.getId(), member3.getId()) + mockMvc.perform(post("/waitings/{shopId}/{memberId}", shop.getId(), member4.getId()) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) - .andExpect(jsonPath("$.rank").value(3)) + .andExpect(jsonPath("$.rank").value(4)) .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) .andDo(MockMvcResultHandlers.print()); } + } From d4b64fbd5f4e9814db86f8b2c43e42432f7941da Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:35:19 +0900 Subject: [PATCH 289/603] =?UTF-8?q?feat=20:=20WaitingController=20?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=20=EC=A7=80=EC=97=B0=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/WaitingController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index a6f069f6..961e9f3d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -6,6 +6,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -26,4 +27,11 @@ public ResponseEntity createWaiting(@PathVariable("shopId") Lon WaitingResponse response = waitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } + + @PatchMapping("/{memberId}") + public ResponseEntity postponeWaiting( + @PathVariable("memberId") Long memberId) { + WaitingResponse response = waitingService.postponeWaiting(memberId); + return ResponseEntity.ok(response); + } } From f173ff42957e2ffaa254418d1028ecfaea14c5e2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:36:29 +0900 Subject: [PATCH 290/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=A7=80=EC=97=B0=20API=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaitingControllerTest.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index ef6518df..0c73c837 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.waiting.controller; import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -111,4 +111,28 @@ void createWaiting() throws Exception { } -} + @DisplayName("웨이팅 지연 API를 호출할 수 있다.") + @Test + void postponeWaiting() throws Exception{ + //when, then + mockMvc.perform(patch("/waitings/{memberId}",member2.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopId").value(shop.getId())) + .andExpect(jsonPath("$.shopName").value(shop.getName())) + .andExpect(jsonPath("$.rank").value(3)) + .andExpect(jsonPath("$.waitingNumber").value(waiting2.getWaitingNumber())) + .andExpect(jsonPath("$.peopleCount").value(waiting2.getPeopleCount())) + .andDo(MockMvcResultHandlers.print()); + } + + @DisplayName("맨 뒤의 멤버가 웨이팅 지연 API 호출 시 예외 반환") + @Test + void postponeWaiting_fails() throws Exception { + mockMvc.perform(patch("/waitings/{memberId}",member3.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("이미 맨뒤라 웨이팅을 미룰 수 없습니다.")) + .andDo(MockMvcResultHandlers.print()); + } +} \ No newline at end of file From e4df1e151dfdae6057bbe67b93c8189debc813a0 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 16:37:35 +0900 Subject: [PATCH 291/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 4 ++-- .../catchtable/waiting/service/WaitingService.java | 7 ++++--- .../waiting/controller/WaitingControllerTest.java | 9 +++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 2fe84914..8a1279ad 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -71,12 +71,12 @@ public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { } public void validatePostponeRemainingCount() { - if (postponeRemainingCount==0){ + if (postponeRemainingCount == 0) { throw new BadRequestCustomException(POSTPONE_REMAINING_CNT_0); } } - public void decreasePostponeRemainingCount(){ + public void decreasePostponeRemainingCount() { postponeRemainingCount--; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 764702f8..50a8a24c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -4,8 +4,8 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_WAITING; -import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -60,7 +60,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, return toWaitingResponse(savedWaiting, rank); } - public WaitingResponse postponeWaiting(Long memberId){ + public WaitingResponse postponeWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntity(member); @@ -73,6 +73,7 @@ public WaitingResponse postponeWaiting(Long memberId){ return toWaitingResponse(waiting, rank); } + private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); @@ -93,7 +94,7 @@ public Shop getShopEntity(Long shopId) { return shop; } - public Waiting getWaitingEntity(Member member){ + public Waiting getWaitingEntity(Member member) { return waitingRepository.findByMember(member).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_WAITING) ); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 0c73c837..fd640ba3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.waiting.controller; import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -113,9 +114,9 @@ void createWaiting() throws Exception { @DisplayName("웨이팅 지연 API를 호출할 수 있다.") @Test - void postponeWaiting() throws Exception{ + void postponeWaiting() throws Exception { //when, then - mockMvc.perform(patch("/waitings/{memberId}",member2.getId()) + mockMvc.perform(patch("/waitings/{memberId}", member2.getId()) .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) @@ -129,7 +130,7 @@ void postponeWaiting() throws Exception{ @DisplayName("맨 뒤의 멤버가 웨이팅 지연 API 호출 시 예외 반환") @Test void postponeWaiting_fails() throws Exception { - mockMvc.perform(patch("/waitings/{memberId}",member3.getId()) + mockMvc.perform(patch("/waitings/{memberId}", member3.getId()) .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 맨뒤라 웨이팅을 미룰 수 없습니다.")) From 1fdccbc1b5ff5aff363bb6c077b3581a0901f6a7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 20:53:00 +0900 Subject: [PATCH 292/603] =?UTF-8?q?style=20:=20=EC=97=90=EB=9F=AC=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 2 +- .../reservation/service/OwnerReservationService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index aabcd0d4..99cf0804 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -16,7 +16,7 @@ public enum ErrorCode { NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."), NOT_EXIST_RESERVATION("존재하지 않는 예약입니다"), EXCEED_PEOPLE_COUNT("예약인원이 해당 시간의 남은 수용가능 인원 수를 초과했습니다."), - ALREADY_COMPLETED("이미 예약 상태인 예약입니다."), + ALREADY_COMPLETED_RESERVATION("이미 예약 상태인 예약입니다."), CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index fc2cc861..6972ccf3 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_COMPLETED_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; @@ -41,7 +41,7 @@ public void modifyReservationStatus( ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 - throw new BadRequestCustomException(ALREADY_COMPLETED); + throw new BadRequestCustomException(ALREADY_COMPLETED_RESERVATION); } Reservation reservation = reservationRepository From 74093258b5d32782e1606abbc7633fe18af08f9d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 20:57:43 +0900 Subject: [PATCH 293/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/domain/Owner.java | 2 +- .../MemberReservationController.java | 3 +- .../OwnerReservationController.java | 7 ++-- .../reservation/domain/Reservation.java | 2 +- .../dto/mapper/ReservationMapper.java | 5 ++- .../repository/ReservationRepository.java | 4 +- .../service/MemberReservationService.java | 5 ++- .../BasicWaitingLineRepository.java | 4 +- .../RedisWaitingLineRepository.java | 2 +- .../waitingline/WaitingLineRepository.java | 7 ++++ .../owner/fixture/OwnerFixture.java | 5 +-- .../MemberReservationControllerTest.java | 5 +-- .../OwnerReservationControllerTest.java | 23 +++++------ .../fixture/ReservationFixture.java | 4 +- .../repository/ReservationRepositoryTest.java | 9 +++-- .../service/MemberReservationServiceTest.java | 11 ++++-- .../service/OwnerReservationServiceTest.java | 39 +++++++++++-------- .../BasicWaitingLineRepositoryTest.java | 2 +- .../RedisWaitingLineRepositoryTest.java | 1 - 19 files changed, 81 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index de87e201..a4e17aab 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -57,7 +57,7 @@ public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth this.dateBirth = dateBirth; } - public void insertShop(Shop shop){ + public void insertShop(Shop shop) { this.shop = shop; } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index 36a96631..ecbaa85e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -44,7 +44,8 @@ public ResponseEntity modifyReservation( } @DeleteMapping("/{reservationId}") - public ResponseEntity cancelReservation(@PathVariable("reservationId") Long reservationId){ + public ResponseEntity cancelReservation( + @PathVariable("reservationId") Long reservationId) { return ResponseEntity.ok(memberReservationService.cancelReservation(reservationId)); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java index 3a35c41a..ff24e8bd 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.reservation.controller; -import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; import com.prgrms.catchtable.reservation.service.OwnerReservationService; @@ -18,18 +17,20 @@ @RequestMapping("/owners/shop") @RequiredArgsConstructor public class OwnerReservationController { + private final OwnerReservationService ownerReservationService; @PostMapping("/{reservationId}") public void modifyReservationStatus( @PathVariable("reservationId") Long reservationId, @RequestBody ModifyReservationStatusRequest request - ){ + ) { ownerReservationService.modifyReservationStatus(reservationId, request); } @GetMapping - public ResponseEntity> getAllReservation(@RequestBody Long ownerId){ + public ResponseEntity> getAllReservation( + @RequestBody Long ownerId) { return ResponseEntity.ok(ownerReservationService.getAllReservation(ownerId)); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index 6cbeb67f..2a64ace1 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -65,7 +65,7 @@ public void modifyReservation(ReservationTime reservationTime, int peopleCount) this.peopleCount = peopleCount; } - public void changeStatus(ReservationStatus status){ + public void changeStatus(ReservationStatus status) { this.status = status; } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index 3f017e47..bd4dd02c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -41,13 +41,14 @@ public static ModifyReservationResponse toModifyReservationResponse(Reservation .build(); } - public static CancelReservationResponse toCancelReservationResponse (Reservation reservation){ + public static CancelReservationResponse toCancelReservationResponse(Reservation reservation) { return CancelReservationResponse.builder() .status(reservation.getStatus()) .build(); } - public static OwnerGetAllReservationResponse toOwnerGetAllReservationResponse(Reservation reservation){ + public static OwnerGetAllReservationResponse toOwnerGetAllReservationResponse( + Reservation reservation) { return OwnerGetAllReservationResponse.builder() .reservationId(reservation.getId()) .date(reservation.getReservationTime().getTime()) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index d9a432ad..b2168c26 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -18,7 +18,9 @@ public interface ReservationRepository extends JpaRepository + "join fetch r.reservationTime rt " + "join fetch rt.shop " + "where r.id = :reservationId") - Optional findByIdWithReservationTimeAndShop(@Param("reservationId") Long reservationId); + Optional findByIdWithReservationTimeAndShop( + @Param("reservationId") Long reservationId); + @Query("select r from Reservation r " + "join fetch r.reservationTime rt " + "join fetch rt.shop s " diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index e1e96402..82014fc7 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -122,8 +122,9 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, } @Transactional - public CancelReservationResponse cancelReservation(Long reservationId){ - Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop(reservationId) + public CancelReservationResponse cancelReservation(Long reservationId) { + Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop( + reservationId) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_RESERVATION)); reservation.changeStatus(CANCELLED); // 해당 예약 상태 취소로 변경 diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 5fd9c0b5..090ef8e6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -16,7 +16,7 @@ @Slf4j @Component -public class BasicWaitingLineRepository implements WaitingLineRepository{ +public class BasicWaitingLineRepository implements WaitingLineRepository { public final Map> waitingLines = new ConcurrentHashMap<>(); @@ -63,7 +63,7 @@ public Long findRank(Long shopId, Long waitingId) { int index = 0; for (Long waitingIdInLine : waitingLine) { if (Objects.equals(waitingIdInLine, waitingId)) { - return (long)index + 1; + return (long) index + 1; } index++; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 607069bc..d46c45b3 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -18,7 +18,7 @@ @Slf4j @RequiredArgsConstructor @Component -public class RedisWaitingLineRepository implements WaitingLineRepository{ +public class RedisWaitingLineRepository implements WaitingLineRepository { private final StringRedisTemplate redisTemplate; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 6b258fab..f80a9d5f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,11 +1,18 @@ package com.prgrms.catchtable.waiting.repository.waitingline; public interface WaitingLineRepository { + void save(Long shopId, Long waitingId); + void entry(Long shopId, Long waitingId); + void cancel(Long shopId, Long waitingId); + void postpone(Long shopId, Long waitingId); + Long findRank(Long shopId, Long waitingId); + Long getWaitingLineSize(Long shopId); + void printWaitingLine(Long shopId); } diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 55d1fafd..4a9adf7d 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,9 +1,8 @@ package com.prgrms.catchtable.owner.fixture; -import static com.prgrms.catchtable.member.domain.Gender.*; +import static com.prgrms.catchtable.member.domain.Gender.MALE; import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.shop.domain.Shop; import java.time.LocalDate; @@ -11,7 +10,7 @@ public class OwnerFixture { - public static Owner getOwner(){ + public static Owner getOwner() { Owner owner = Owner.builder() .name("ownerA") .phoneNumber("010-3462-2480") diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 29ac7ed0..23f6a36a 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.reservation.controller; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -13,7 +13,6 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; -import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; @@ -167,7 +166,7 @@ void cancelReservation() throws Exception { Reservation savedReservation = reservationRepository.save(reservation); mockMvc.perform(delete("/reservations/{reservationId}", savedReservation.getId()) - .contentType(APPLICATION_JSON)) + .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.status").value(CANCELLED.toString())); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index 2a8e12df..a0237637 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -1,8 +1,8 @@ package com.prgrms.catchtable.reservation.controller; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; -import static org.assertj.core.api.Assertions.*; -import static org.springframework.http.MediaType.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -14,7 +14,6 @@ import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; -import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; @@ -24,17 +23,16 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; @Slf4j @Transactional class OwnerReservationControllerTest extends BaseIntegrationTest { + @Autowired private ReservationTimeRepository reservationTimeRepository; @Autowired @@ -44,8 +42,9 @@ class OwnerReservationControllerTest extends BaseIntegrationTest { private ShopRepository shopRepository; @Autowired private ReservationRepository reservationRepository; + @BeforeEach - void setUp(){ + void setUp() { Shop shop = shopRepository.save(ShopData.getShop()); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(shop); @@ -81,8 +80,8 @@ void modifyReservationStatus() throws Exception { //then assertThat(reservation.getReservationTime().isOccupied()).isTrue(); // 취소처리 전엔 예약시간 차있음 mockMvc.perform(post("/owners/shop/{reservationId}", reservation.getId()) - .contentType(APPLICATION_JSON) - .content(asJsonString(request))) + .contentType(APPLICATION_JSON) + .content(asJsonString(request))) .andExpect(status().isOk()); assertThat(reservation.getStatus()).isEqualTo(request.status()); @@ -102,9 +101,11 @@ void getAllReservation() throws Exception { .contentType(APPLICATION_JSON) .content(asJsonString(owner.getId()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].date").value(reservation1.getReservationTime().getTime().toString())) + .andExpect( + jsonPath("$[0].date").value(reservation1.getReservationTime().getTime().toString())) .andExpect(jsonPath("$[0].peopleCount").value(reservation1.getPeopleCount())) - .andExpect(jsonPath("$[1].date").value(reservation2.getReservationTime().getTime().toString())) + .andExpect( + jsonPath("$[1].date").value(reservation2.getReservationTime().getTime().toString())) .andExpect(jsonPath("$[1].peopleCount").value(reservation2.getPeopleCount())); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index 773479c9..6346992f 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -17,7 +17,7 @@ public class ReservationFixture { public static Reservation getReservation(ReservationTime reservationTime) { - if(!reservationTime.isOccupied()){ + if (!reservationTime.isOccupied()) { reservationTime.reverseOccupied(); } return Reservation.builder() @@ -89,7 +89,7 @@ public static ReservationTime getReservationTimeOccupied() { } public static ModifyReservationStatusRequest getModifyReservationStatusRequest( - ReservationStatus status){ + ReservationStatus status) { return ModifyReservationStatusRequest.builder() .status(status) .build(); diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 9e5926f9..60c56962 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -49,6 +49,7 @@ void findAllWithReservationTimeAndShop() { () -> assertThat(findReservation.getShop()).isEqualTo(savedShop) ); } + @Test @DisplayName("예약 Id를 통해 예약(예약시간, 매장까지)을 조회할 수 있다.") void findByIdWithReservationTimeAndShop() { @@ -67,13 +68,14 @@ void findByIdWithReservationTimeAndShop() { assertAll( () -> assertThat(findReservation.getReservationTime()).isEqualTo(savedReservationTime), () -> assertThat(findReservation.getShop()).isEqualTo(savedShop), - () -> assertThat(findReservation.getPeopleCount()).isEqualTo(savedReservation.getPeopleCount()) + () -> assertThat(findReservation.getPeopleCount()).isEqualTo( + savedReservation.getPeopleCount()) ); } @Test @DisplayName("가게 아이디와 일치하는 예약을 전체 조회할 수 있다") - void getAllReservationByShopId(){ + void getAllReservationByShopId() { /** * 첫번째 예제 예약 데이터 저장 */ @@ -92,7 +94,8 @@ void getAllReservationByShopId(){ Shop otherShop = ShopFixture.shop(); Shop otherSavedShop = shopRepository.save(otherShop); otherReservationTime.insertShop(otherSavedShop); - ReservationTime otherSavedReservationTime = reservationTimeRepository.save(otherReservationTime); + ReservationTime otherSavedReservationTime = reservationTimeRepository.save( + otherReservationTime); Reservation otherReservation = ReservationFixture.getReservation(otherSavedReservationTime); reservationRepository.save(otherReservation); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 68fe1679..9b063755 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -250,7 +250,8 @@ void cancelReservation() { Reservation reservation = ReservationFixture.getReservation(reservationTime); ReflectionTestUtils.setField(reservation, "id", 1L); - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.of(reservation)); + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.of(reservation)); //when CancelReservationResponse response = memberReservationService.cancelReservation( @@ -267,10 +268,12 @@ void cancelReservation() { @Test @DisplayName("존재하지 않는 예약에 대한 삭제 요청 시 예외가 발생한다") - void cancelReservationNotExist(){ - when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn(Optional.empty()); + void cancelReservationNotExist() { + when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( + Optional.empty()); - assertThrows(NotFoundCustomException.class, () -> memberReservationService.cancelReservation(1L)); + assertThrows(NotFoundCustomException.class, + () -> memberReservationService.cancelReservation(1L)); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java index e6f5875b..f114d342 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.NO_SHOW; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -11,7 +13,6 @@ import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; -import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; @@ -21,7 +22,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,20 +29,20 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; -import org.testcontainers.shaded.org.checkerframework.checker.units.qual.A; @ExtendWith(MockitoExtension.class) class OwnerReservationServiceTest { + @Mock private ReservationRepository reservationRepository; @Mock private OwnerRepository ownerRepository; @InjectMocks private OwnerReservationService ownerReservationService; - + @Test @DisplayName("점주는 특정 예약을 노쇼처리 할 수 있다.") - void noshowReservation(){ + void noshowReservation() { ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); Reservation reservation = ReservationFixture.getReservation(reservationTime); ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( @@ -55,13 +55,14 @@ void noshowReservation(){ assertAll( () -> assertThat(reservation.getStatus()).isEqualTo(NO_SHOW), // 예약 상태가 노쇼로 바뀌어야함 - () -> assertThat(reservation.getReservationTime().isOccupied()).isFalse() // 예약한 예약시간의 차지여부가 false가 되어야함 + () -> assertThat(reservation.getReservationTime().isOccupied()).isFalse() + // 예약한 예약시간의 차지여부가 false가 되어야함 ); } @Test @DisplayName("점주는 특정 예약을 취소처리 할 수 있다.") - void cancelReservation(){ + void cancelReservation() { ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); Reservation reservation = ReservationFixture.getReservation(reservationTime); ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( @@ -80,7 +81,7 @@ void cancelReservation(){ @Test @DisplayName("존재하지 않는 예약을 노쇼,취소 처리하려 하면 예외가 발생한다") - void modifyReservationNotExist(){ + void modifyReservationNotExist() { ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( CANCELLED); @@ -93,7 +94,7 @@ void modifyReservationNotExist(){ @Test @DisplayName("점주는 가게의 예약을 전체 조회할 수 있다") - void getAllReservation(){ + void getAllReservation() { List reservations = new ArrayList<>(); ReservationTime reservationTime1 = ReservationFixture.getReservationTimeNotPreOccupied(); ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); @@ -109,23 +110,27 @@ void getAllReservation(){ reservations.add(reservation1); reservations.add(reservation2); Owner owner = OwnerFixture.getOwner(); - when(reservationRepository.findAllWithReservationTimeAndShopByShopId(any(Long.class))).thenReturn(reservations); + when(reservationRepository.findAllWithReservationTimeAndShopByShopId( + any(Long.class))).thenReturn(reservations); when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); List allReservation = ownerReservationService.getAllReservation( 1L); assertAll( - () -> assertThat(allReservation.get(0).date()).isEqualTo(reservation1.getReservationTime().getTime()), - () -> assertThat(allReservation.get(1).date()).isEqualTo(reservation2.getReservationTime().getTime()) + () -> assertThat(allReservation.get(0).date()).isEqualTo( + reservation1.getReservationTime().getTime()), + () -> assertThat(allReservation.get(1).date()).isEqualTo( + reservation2.getReservationTime().getTime()) ); } @Test @DisplayName("매장에 예약이 없을 시 빈 리스트가 조회된다.") - void getAllReservationEmpty(){ + void getAllReservationEmpty() { Owner owner = OwnerFixture.getOwner(); - when(reservationRepository.findAllWithReservationTimeAndShopByShopId(any(Long.class))).thenReturn(List.of()); + when(reservationRepository.findAllWithReservationTimeAndShopByShopId( + any(Long.class))).thenReturn(List.of()); when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); List allReservation = ownerReservationService.getAllReservation( diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 9dee40de..1f40cc8c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class BasicWaitingLineRepositoryTest{ +class BasicWaitingLineRepositoryTest { private final BasicWaitingLineRepository repository = new BasicWaitingLineRepository(); diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index bc9a73ff..52b34eea 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -5,7 +5,6 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; -import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From ba8c8e8e46e99835e5c18f72674ac665375252f4 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 21:43:09 +0900 Subject: [PATCH 294/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=20=EC=97=AC=EB=B6=80=20=EC=84=A4=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/ReservationTime.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 8b4f6e43..880cf168 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -58,4 +58,12 @@ public void reversePreOccupied() { public void insertShop(Shop shop) { this.shop = shop; } + + public void setOccupiedTrue() { + this.isOccupied = true; + } + + public void setOccupiedFalse() { + this.isOccupied = false; + } } From 17af3a4bcd9f3b3243d0962210e574e69c9dac43 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 21:43:24 +0900 Subject: [PATCH 295/603] =?UTF-8?q?feat=20:=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=98=88=EC=95=BD=EA=B0=80=EB=8A=A5=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 82014fc7..3943d68f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -113,6 +113,8 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, validateIsPreOccupied(reservationTime); // 예약시간이 선점되었는 지 확인 + reservation.getReservationTime().setOccupiedFalse(); // 기존 예약의 예약시간 예약가능으로 변경 + validateIsOccupied(reservationTime); // 예약시간이 이미 차지되었는 지 확인 reservation.modifyReservation(reservationTime, From 5b7e4c2c94ac67901b5cc5cabaa11ce236c3f6e1 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 21:44:05 +0900 Subject: [PATCH 296/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationServiceTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 9b063755..49b907b4 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -172,6 +172,7 @@ void modifyReservation() { ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(shop); + reservationTime.setOccupiedTrue(); // 수정 전 예약시간은 예약이 차있는 걸로 되어있어야함 ReflectionTestUtils.setField(reservationTime, "id", 1L); // 수정 전 예약시간 객체 -> Id : 1 ReservationTime modifyTime = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); @@ -192,6 +193,7 @@ void modifyReservation() { //then assertAll( + () -> assertThat(reservationTime.isOccupied()).isFalse(), // 수정 후 기존 예약시간이 예약가능으로 바뀌었는 지 검증 () -> assertThat(response.date()).isEqualTo(modifyTime.getTime()), () -> assertThat(response.peopleCount()).isEqualTo(reservation.getPeopleCount()), () -> assertThat(reservation.getReservationTime()).isEqualTo(modifyTime) From 00b80221597348d1609799d15197a303b004f5a7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 21:44:23 +0900 Subject: [PATCH 297/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationControllerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 23f6a36a..efadbc71 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -130,6 +130,7 @@ void registerReservationWithException() throws Exception { @DisplayName("예약 수정 api 호출에 성공한다.") void modifyReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); + reservationTime.setOccupiedTrue(); Reservation reservation = ReservationFixture.getReservation(reservationTime); Reservation savedReservation = reservationRepository.save(reservation); /** @@ -152,7 +153,7 @@ void modifyReservation() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.date").value(modifyReservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); - + assertThat(reservationTime.isOccupied()).isFalse(); // 기존 예약 시간 예약가능으로 변경되었는 지 검증 assertThat(savedReservation.getReservationTime()).isEqualTo( modifyReservationTime); // 수정하려는 예약시간으로 예약이 변경되었는 지 검증 assertThat(savedReservation.getReservationTime().isOccupied()).isFalse(); From a705e41aa32df87a764cdb79eb6d8eb89143af82 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 21:44:43 +0900 Subject: [PATCH 298/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/OwnerReservationService.java | 2 +- .../reservation/service/MemberReservationServiceTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 6972ccf3..085d99e4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -40,7 +40,7 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 - if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + if (modifyStatus == COMPLETED) { // 취소, 노쇼 처리가 아닌 경우 예외 throw new BadRequestCustomException(ALREADY_COMPLETED_RESERVATION); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 49b907b4..0f6abeb2 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -193,7 +193,8 @@ void modifyReservation() { //then assertAll( - () -> assertThat(reservationTime.isOccupied()).isFalse(), // 수정 후 기존 예약시간이 예약가능으로 바뀌었는 지 검증 + () -> assertThat(reservationTime.isOccupied()).isFalse(), + // 수정 후 기존 예약시간이 예약가능으로 바뀌었는 지 검증 () -> assertThat(response.date()).isEqualTo(modifyTime.getTime()), () -> assertThat(response.peopleCount()).isEqualTo(reservation.getPeopleCount()), () -> assertThat(reservation.getReservationTime()).isEqualTo(modifyTime) From 32480b7a7ed418196a6c4e55adf7962d17d96e82 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 6 Jan 2024 22:55:13 +0900 Subject: [PATCH 299/603] =?UTF-8?q?fix=20:=20=ED=83=80=EC=9D=B8=EC=9D=B4?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=20=EC=98=88=EC=95=BD=ED=95=9C=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20=EC=98=88=EC=99=B8=EA=B0=80=20=EB=B0=9C=EC=83=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20-=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=97=90=EC=84=9C=20=EC=B0=A8=EC=A7=80?= =?UTF-8?q?=EC=97=AC=EB=B6=80=EB=A5=BC=20=EA=B2=80=EC=A6=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=EA=B2=8C=20=EC=95=84=EB=8B=88=EB=9D=BC=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EC=97=AC=EB=B6=80=EB=A5=BC=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=EA=B1=B8=EB=A1=9C=20=EB=90=98=EC=96=B4?= =?UTF-8?q?=EC=9E=88=EC=96=B4=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 3943d68f..d696100b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -139,7 +139,7 @@ public CancelReservationResponse cancelReservation(Long reservationId) { } private void validateIsPreOccupied(ReservationTime reservationTime) { - if (reservationTime.isPreOccupied()) { + if (reservationTime.isOccupied()) { reservationLockRepository.unlock(reservationTime.getId()); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } From 56931734fb6d70d9b99bec9ee52e7f5f5ff07104 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 23:05:23 +0900 Subject: [PATCH 300/603] =?UTF-8?q?feat=20:=20response=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 3 ++- .../prgrms/catchtable/waiting/dto/WaitingResponse.java | 5 +++-- .../waiting/controller/WaitingControllerDocsTest.java | 9 ++++++--- .../waiting/controller/WaitingControllerTest.java | 8 +++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 895c9996..9d3a9b75 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -23,12 +23,13 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, // entity -> dto public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { return WaitingResponse.builder() - .createdWaitingId(waiting.getId()) + .waitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) .peopleCount(waiting.getPeopleCount()) .waitingNumber(waiting.getWaitingNumber()) .rank(rank) + .remainingPostponeCount(waiting.getPostponeRemainingCount()) .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java index 0cb73dee..0429b015 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java @@ -4,12 +4,13 @@ @Builder public record WaitingResponse( - Long createdWaitingId, + Long waitingId, Long shopId, String shopName, int peopleCount, int waitingNumber, - Long rank + Long rank, + int remainingPostponeCount ) { } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java index 3378327f..7e192080 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -37,12 +37,13 @@ void createWaiting() throws Exception { .builder() .peopleCount(2).build(); WaitingResponse response = WaitingResponse.builder() - .createdWaitingId(201L) + .waitingId(201L) .shopId(1L) .shopName("shop1") .waitingNumber(324) .rank(20L) .peopleCount(2) + .remainingPostponeCount(2) .build(); given(waitingService.createWaiting(1L, 1L, request)).willReturn(response); @@ -59,7 +60,7 @@ void createWaiting() throws Exception { .description("인원수") ), responseFields( - fieldWithPath("createdWaitingId").type(JsonFieldType.NUMBER) + fieldWithPath("waitingId").type(JsonFieldType.NUMBER) .description("생성된 웨이팅 아이디"), fieldWithPath("shopId").type(JsonFieldType.NUMBER) .description("상점 아이디"), @@ -70,7 +71,9 @@ void createWaiting() throws Exception { fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) .description("웨이팅 고유 번호"), fieldWithPath("rank").type(JsonFieldType.NUMBER) - .description("웨이팅 순서") + .description("웨이팅 순서"), + fieldWithPath("remainingPostponeCount").type(JsonFieldType.NUMBER) + .description("대기 지연 잔여 횟수") ) )); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index fd640ba3..00722a7b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -18,6 +18,9 @@ import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; +import java.util.Optional; +import lombok.extern.slf4j.Slf4j; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -26,7 +29,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.transaction.annotation.Transactional; - +@Slf4j @Transactional class WaitingControllerTest extends BaseIntegrationTest { @@ -135,5 +138,8 @@ void postponeWaiting_fails() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 맨뒤라 웨이팅을 미룰 수 없습니다.")) .andDo(MockMvcResultHandlers.print()); +// Waiting waiting = waitingRepository.findById(waiting3.getId()).orElse(null); +// Assertions.assertThat(waiting.getPostponeRemainingCount()).isEqualTo(2); } + } \ No newline at end of file From 3c91817de61fc8ac8f71a968543e3bcc8c9ee5ac Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 23:20:14 +0900 Subject: [PATCH 301/603] =?UTF-8?q?feat=20:=20waiting=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=8B=9C=20fetch=20join=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/repository/WaitingRepository.java | 5 ++++- .../prgrms/catchtable/waiting/service/WaitingService.java | 5 +++-- .../catchtable/waiting/service/WaitingServiceTest.java | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 6ae84e55..74c07d95 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -6,12 +6,15 @@ import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface WaitingRepository extends JpaRepository { boolean existsByMember(Member member); - Optional findByMember(Member member); + @Query("select w from Waiting w join fetch w.shop where w.member = :member") + Optional findByMemberWithShop(@Param("member")Member member); Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 50a8a24c..046a0339 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -23,6 +23,7 @@ import java.time.LocalTime; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service @@ -60,6 +61,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, return toWaitingResponse(savedWaiting, rank); } + @Transactional public WaitingResponse postponeWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntity(member); @@ -70,7 +72,6 @@ public WaitingResponse postponeWaiting(Long memberId) { waitingLineRepository.postpone(shop.getId(), waiting.getId()); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); waiting.decreasePostponeRemainingCount(); - return toWaitingResponse(waiting, rank); } @@ -95,7 +96,7 @@ public Shop getShopEntity(Long shopId) { } public Waiting getWaitingEntity(Member member) { - return waitingRepository.findByMember(member).orElseThrow( + return waitingRepository.findByMemberWithShop(member).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_WAITING) ); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 7bc24bed..7269a13b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -83,7 +83,7 @@ void postponeWaiting() { Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMember(member)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberWithShop(member)).willReturn(Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); doNothing().when(waiting).validatePostponeRemainingCount(); From 0758162acc8c540eb07d577cb16649fc4c87887d Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 23:30:45 +0900 Subject: [PATCH 302/603] =?UTF-8?q?style:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 10 +++++----- .../prgrms/catchtable/waiting/dto/WaitingMapper.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 8a1279ad..0aeecff5 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -49,8 +49,8 @@ public class Waiting extends BaseEntity { @Enumerated(STRING) private WaitingStatus status; - @Column(name = "postpone_remaining_count") - private int postponeRemainingCount; + @Column(name = "remaining_postpone_count") + private int remainingPostponeCount; @OneToOne(fetch = LAZY) @JoinColumn(name = "member_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) @@ -67,17 +67,17 @@ public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { this.member = member; this.shop = shop; status = PROGRESS; - postponeRemainingCount = 2; + remainingPostponeCount = 2; } public void validatePostponeRemainingCount() { - if (postponeRemainingCount == 0) { + if (remainingPostponeCount == 0) { throw new BadRequestCustomException(POSTPONE_REMAINING_CNT_0); } } public void decreasePostponeRemainingCount() { - postponeRemainingCount--; + remainingPostponeCount--; } public void completeWaiting() { diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 9d3a9b75..e3e9c725 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -29,7 +29,7 @@ public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { .peopleCount(waiting.getPeopleCount()) .waitingNumber(waiting.getWaitingNumber()) .rank(rank) - .remainingPostponeCount(waiting.getPostponeRemainingCount()) + .remainingPostponeCount(waiting.getRemainingPostponeCount()) .build(); } } From 87a5d559163992b722cb06b53468537435ff943e Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 23:31:05 +0900 Subject: [PATCH 303/603] =?UTF-8?q?feat=20:=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 00722a7b..e97895fe 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.transaction.annotation.Transactional; @Slf4j @@ -130,7 +131,7 @@ void postponeWaiting() throws Exception { .andDo(MockMvcResultHandlers.print()); } - @DisplayName("맨 뒤의 멤버가 웨이팅 지연 API 호출 시 예외 반환") + @DisplayName("맨 뒤의 멤버가 웨이팅 지연 API 호출 시 예외를 반환한다.") @Test void postponeWaiting_fails() throws Exception { mockMvc.perform(patch("/waitings/{memberId}", member3.getId()) @@ -142,4 +143,15 @@ void postponeWaiting_fails() throws Exception { // Assertions.assertThat(waiting.getPostponeRemainingCount()).isEqualTo(2); } + + @DisplayName("대기 지연 잔여 횟수를 소진 시, 더이상 지연이 불가하므로 예외를 반환한다.") + @Test + void postponeWaiting_fails2() throws Exception { + ReflectionTestUtils.setField(waiting1,"remainingPostponeCount",0); + mockMvc.perform(patch("/waitings/{memberId}", member1.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("이미 두 차례 대기를 미뤘습니다.")) + .andDo(MockMvcResultHandlers.print()); + } } \ No newline at end of file From 6375abc2a73c519646ab72ad9f7a4271aa6d1554 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 6 Jan 2024 23:32:11 +0900 Subject: [PATCH 304/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/repository/WaitingRepository.java | 2 +- .../catchtable/waiting/controller/WaitingControllerTest.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 74c07d95..bb407e95 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -14,7 +14,7 @@ public interface WaitingRepository extends JpaRepository { boolean existsByMember(Member member); @Query("select w from Waiting w join fetch w.shop where w.member = :member") - Optional findByMemberWithShop(@Param("member")Member member); + Optional findByMemberWithShop(@Param("member") Member member); Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index e97895fe..fc17d72c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -18,9 +18,7 @@ import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -30,6 +28,7 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.transaction.annotation.Transactional; + @Slf4j @Transactional class WaitingControllerTest extends BaseIntegrationTest { @@ -147,7 +146,7 @@ void postponeWaiting_fails() throws Exception { @DisplayName("대기 지연 잔여 횟수를 소진 시, 더이상 지연이 불가하므로 예외를 반환한다.") @Test void postponeWaiting_fails2() throws Exception { - ReflectionTestUtils.setField(waiting1,"remainingPostponeCount",0); + ReflectionTestUtils.setField(waiting1, "remainingPostponeCount", 0); mockMvc.perform(patch("/waitings/{memberId}", member1.getId()) .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) From 198d0e3f46062ba9e61c7db60f0fcec2aa71f648 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 00:22:09 +0900 Subject: [PATCH 305/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20errorCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 686a2544..72771ccd 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -24,7 +24,7 @@ public enum ErrorCode { NOT_EXIST_WAITING("웨이팅이 존재하지 않습니다."), POSTPONE_REMAINING_CNT_0("이미 두 차례 대기를 미뤘습니다."), - + CAN_NOT_CANCEL_WAITING("웨이팅 취소 처리가 불가한 상태입니다."), CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), From 3afed3873fd91921ae282cc849dd573b9835de11 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 00:22:59 +0900 Subject: [PATCH 306/603] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=98=88=EC=99=B8=20=EC=B7=A8=EC=86=8C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/WaitingController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index 961e9f3d..d19842d8 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -6,6 +6,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -34,4 +35,10 @@ public ResponseEntity postponeWaiting( WaitingResponse response = waitingService.postponeWaiting(memberId); return ResponseEntity.ok(response); } + + @DeleteMapping("/{memberId}") + public ResponseEntity cancelWaiting(@PathVariable Long memberId) { + WaitingResponse response = waitingService.cancelWaiting(memberId); + return ResponseEntity.ok(response); + } } From 943e65961ae246d90cf54a59d7955f9f829f17ca Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 00:23:39 +0900 Subject: [PATCH 307/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/domain/Waiting.java | 9 +++++++++ .../catchtable/waiting/service/WaitingService.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 0aeecff5..b1ea0b1d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.waiting.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_CANCEL_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.POSTPONE_REMAINING_CNT_0; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; @@ -86,4 +87,12 @@ public void completeWaiting() { } status = COMPLETED; } + + + public void cancelWaiting(){ + if (status != PROGRESS){ + throw new BadRequestCustomException(CAN_NOT_CANCEL_WAITING); + } + status = CANCELED; + } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 046a0339..bfcb4b3d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -22,6 +22,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -75,6 +76,19 @@ public WaitingResponse postponeWaiting(Long memberId) { return toWaitingResponse(waiting, rank); } + @Transactional + public WaitingResponse cancelWaiting(Long memberId) { + Member member = getMemberEntity(memberId); + Waiting waiting = getWaitingEntity(member); + + Shop shop = waiting.getShop(); + waiting.cancelWaiting(); + waitingLineRepository.cancel(shop.getId(), waiting.getId()); + Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + + return toWaitingResponse(waiting, rank); + } + private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); From a89d172e7a542eda698349cd2ea3b94435af9347 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 00:27:52 +0900 Subject: [PATCH 308/603] =?UTF-8?q?fix=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=98=20=EC=98=88=EC=95=BD=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EB=B0=94=EA=BE=B8=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=98=20=EC=88=9C=EC=84=9C=EA=B0=80=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=EB=90=98=EC=96=B4=EC=9E=88=EC=96=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=9C=EA=B2=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index d696100b..370ff11a 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -113,10 +113,10 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, validateIsPreOccupied(reservationTime); // 예약시간이 선점되었는 지 확인 - reservation.getReservationTime().setOccupiedFalse(); // 기존 예약의 예약시간 예약가능으로 변경 - validateIsOccupied(reservationTime); // 예약시간이 이미 차지되었는 지 확인 + reservation.getReservationTime().setOccupiedFalse(); // 기존 예약의 예약시간 예약가능으로 변경 + reservation.modifyReservation(reservationTime, request.peopleCount()); // 예약 필드 값 수정하는 엔티티의 메소드 @@ -139,7 +139,7 @@ public CancelReservationResponse cancelReservation(Long reservationId) { } private void validateIsPreOccupied(ReservationTime reservationTime) { - if (reservationTime.isOccupied()) { + if (reservationTime.isPreOccupied()) { reservationLockRepository.unlock(reservationTime.getId()); throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } From 57e15e5f4bbf3b5f856b161cb09ee4b1ec027617 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 01:33:36 +0900 Subject: [PATCH 309/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/domain/WaitingStatus.java | 7 ++++--- .../com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 1 + .../com/prgrms/catchtable/waiting/dto/WaitingResponse.java | 3 ++- .../waiting/controller/WaitingControllerDocsTest.java | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java index 07ee07a1..3d71c58f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java @@ -6,10 +6,11 @@ @Getter @RequiredArgsConstructor public enum WaitingStatus { - PROGRESS("웨이팅 진행 중"), - COMPLETED("웨이팅 입장"), - CANCELED("웨이팅 취소"), + PROGRESS("진행 중"), + COMPLETED("입장"), + CANCELED("취소"), NO_SHOW("노쇼"); private final String description; + } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index e3e9c725..5a11c521 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -30,6 +30,7 @@ public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { .waitingNumber(waiting.getWaitingNumber()) .rank(rank) .remainingPostponeCount(waiting.getRemainingPostponeCount()) + .status(waiting.getStatus().getDescription()) .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java index 0429b015..969c8e8c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java @@ -10,7 +10,8 @@ public record WaitingResponse( int peopleCount, int waitingNumber, Long rank, - int remainingPostponeCount + int remainingPostponeCount, + String status ) { } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java index 7e192080..c0236b46 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.restdocs.payload.JsonFieldType; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; class WaitingControllerDocsTest extends RestDocsSupport { @@ -44,6 +45,7 @@ void createWaiting() throws Exception { .rank(20L) .peopleCount(2) .remainingPostponeCount(2) + .status("진행 중") .build(); given(waitingService.createWaiting(1L, 1L, request)).willReturn(response); @@ -52,6 +54,7 @@ void createWaiting() throws Exception { .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) + .andDo(MockMvcResultHandlers.print()) .andDo(document("waiting-create", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), @@ -73,7 +76,9 @@ void createWaiting() throws Exception { fieldWithPath("rank").type(JsonFieldType.NUMBER) .description("웨이팅 순서"), fieldWithPath("remainingPostponeCount").type(JsonFieldType.NUMBER) - .description("대기 지연 잔여 횟수") + .description("대기 지연 잔여 횟수"), + fieldWithPath("status").type(JsonFieldType.STRING) + .description("대기 상태") ) )); From 4862da150a7f86dd8ccb8ab2885373e41783e94a Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 01:33:55 +0900 Subject: [PATCH 310/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/WaitingServiceTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 7269a13b..76efaeb7 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.waiting.service; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; @@ -13,6 +14,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; @@ -85,6 +87,7 @@ void postponeWaiting() { given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.findByMemberWithShop(member)).willReturn(Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); + given(waiting.getStatus()).willReturn(PROGRESS); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); doNothing().when(waiting).validatePostponeRemainingCount(); doNothing().when(waiting).decreasePostponeRemainingCount(); @@ -98,4 +101,29 @@ void postponeWaiting() { assertThat(response.waitingNumber())::isNotNull ); } + + @DisplayName("대기 취소를 할 수 있다.") + @Test + void cancelWaiting() { + //given + Shop shop = mock(Shop.class); + Member member = mock(Member.class); + Waiting waiting = mock(Waiting.class); + + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); + given(waitingRepository.findByMemberWithShop(member)).willReturn(Optional.of(waiting)); + given(waiting.getShop()).willReturn(shop); + given(waiting.getStatus()).willReturn(CANCELED); + doNothing().when(waiting).changeStatusCanceled(); + + //when + WaitingResponse response = waitingService.cancelWaiting(1L); + + //then + assertAll( + assertThat(response.peopleCount())::isNotNull, + () -> assertThat(response.rank()).isNull(), + assertThat(response.waitingNumber())::isNotNull + ); + } } \ No newline at end of file From 5c7c061440842380ec70153bb7c5a31a8dd50c59 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 01:35:04 +0900 Subject: [PATCH 311/603] =?UTF-8?q?style=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/domain/Waiting.java | 2 +- .../prgrms/catchtable/waiting/service/WaitingService.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index b1ea0b1d..999994dc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -89,7 +89,7 @@ public void completeWaiting() { } - public void cancelWaiting(){ + public void changeStatusCanceled(){ if (status != PROGRESS){ throw new BadRequestCustomException(CAN_NOT_CANCEL_WAITING); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index bfcb4b3d..2a6bc2fd 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -22,7 +22,6 @@ import java.time.LocalDateTime; import java.time.LocalTime; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -82,11 +81,10 @@ public WaitingResponse cancelWaiting(Long memberId) { Waiting waiting = getWaitingEntity(member); Shop shop = waiting.getShop(); - waiting.cancelWaiting(); + waiting.changeStatusCanceled(); waitingLineRepository.cancel(shop.getId(), waiting.getId()); - Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - return toWaitingResponse(waiting, rank); + return toWaitingResponse(waiting, null); } private void validateIfMemberWaitingExists(Member member) { From af0dcc02f1e29f13617081dcb6d40277f0901cde Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 02:22:43 +0900 Subject: [PATCH 312/603] =?UTF-8?q?feat=20:=20rank=20=EC=A3=BC=EC=9E=85?= =?UTF-8?q?=EA=B0=92=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20variable=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/controller/WaitingController.java | 2 +- .../com/prgrms/catchtable/waiting/service/WaitingService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java index d19842d8..af45c3fa 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java @@ -37,7 +37,7 @@ public ResponseEntity postponeWaiting( } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable Long memberId) { + public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { WaitingResponse response = waitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java index 2a6bc2fd..cdd16b5d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java @@ -84,7 +84,7 @@ public WaitingResponse cancelWaiting(Long memberId) { waiting.changeStatusCanceled(); waitingLineRepository.cancel(shop.getId(), waiting.getId()); - return toWaitingResponse(waiting, null); + return toWaitingResponse(waiting, -1L); } private void validateIfMemberWaitingExists(Member member) { From b8b7588c9ac549aafa3114e0788d7ee7bbfb660a Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 02:23:08 +0900 Subject: [PATCH 313/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/service/WaitingServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 76efaeb7..8ebb6060 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -97,7 +97,7 @@ void postponeWaiting() { //then assertAll( assertThat(response.peopleCount())::isNotNull, - () -> assertThat(response.rank()).isNotNull(), + assertThat(response.rank())::isNotNull, assertThat(response.waitingNumber())::isNotNull ); } @@ -122,7 +122,7 @@ void cancelWaiting() { //then assertAll( assertThat(response.peopleCount())::isNotNull, - () -> assertThat(response.rank()).isNull(), + assertThat(response.rank())::isNotNull, assertThat(response.waitingNumber())::isNotNull ); } From 1fb55680c932a15d9228b87009f85f25a9776ce1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 02:23:34 +0900 Subject: [PATCH 314/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WaitingControllerTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index fc17d72c..a9d44a64 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -1,6 +1,11 @@ package com.prgrms.catchtable.waiting.controller; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -14,6 +19,7 @@ import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; @@ -111,6 +117,7 @@ void createWaiting() throws Exception { .andExpect(jsonPath("$.rank").value(4)) .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) + .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) .andDo(MockMvcResultHandlers.print()); } @@ -153,4 +160,34 @@ void postponeWaiting_fails2() throws Exception { .andExpect(jsonPath("$.message").value("이미 두 차례 대기를 미뤘습니다.")) .andDo(MockMvcResultHandlers.print()); } + + @DisplayName("웨이팅을 취소할 수 있다. 취소 시 뒤에 있는 사람들은 rank가 1씩 증가한다.") + @Test + void cancelWaiting() throws Exception { + //when, then + mockMvc.perform(delete("/waitings/{memberId}", member1.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopId").value(shop.getId())) + .andExpect(jsonPath("$.shopName").value(shop.getName())) + .andExpect(jsonPath("$.rank").value(-1L)) + .andExpect(jsonPath("$.waitingNumber").value(waiting1.getWaitingNumber())) + .andExpect(jsonPath("$.peopleCount").value(waiting1.getPeopleCount())) + .andExpect(jsonPath("$.status").value(CANCELED.getDescription())) + .andDo(MockMvcResultHandlers.print()); + assertThat(waitingLineRepository.findRank(1L, 2L)).isEqualTo(1L); + assertThat(waitingLineRepository.findRank(1L, 3L)).isEqualTo(2L); + } + + @DisplayName("웨이팅 진행 상태가 아니면 취소가 불가하다.") + @Test + void cancelWaiting_fails_if_not_progress() throws Exception { + //when, then + ReflectionTestUtils.setField(waiting1, "status", COMPLETED); + mockMvc.perform(delete("/waitings/{memberId}", member1.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value("웨이팅 취소 처리가 불가한 상태입니다.")) + .andDo(MockMvcResultHandlers.print()); + } } \ No newline at end of file From dacf3b3d2564f144ad3e0b737a664479137d998a Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 02:24:42 +0900 Subject: [PATCH 315/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/domain/Waiting.java | 4 ++-- .../catchtable/waiting/controller/WaitingControllerTest.java | 3 +-- .../prgrms/catchtable/waiting/service/WaitingServiceTest.java | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 999994dc..6e2026dc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -89,8 +89,8 @@ public void completeWaiting() { } - public void changeStatusCanceled(){ - if (status != PROGRESS){ + public void changeStatusCanceled() { + if (status != PROGRESS) { throw new BadRequestCustomException(CAN_NOT_CANCEL_WAITING); } status = CANCELED; diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index a9d44a64..35171796 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.waiting.controller; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -19,7 +19,6 @@ import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java index 8ebb6060..4f7c43f4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.service; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; @@ -14,7 +15,6 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.WaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; From fd0a4ca00c1aea592546c4db423a09f84f72a778 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 02:33:23 +0900 Subject: [PATCH 316/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 35171796..3a374dd8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -4,6 +4,7 @@ import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; @@ -12,6 +13,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; @@ -160,7 +162,7 @@ void postponeWaiting_fails2() throws Exception { .andDo(MockMvcResultHandlers.print()); } - @DisplayName("웨이팅을 취소할 수 있다. 취소 시 뒤에 있는 사람들은 rank가 1씩 증가한다.") + @DisplayName("웨이팅 취소 API를 추가할 수 있다.") @Test void cancelWaiting() throws Exception { //when, then @@ -174,8 +176,11 @@ void cancelWaiting() throws Exception { .andExpect(jsonPath("$.peopleCount").value(waiting1.getPeopleCount())) .andExpect(jsonPath("$.status").value(CANCELED.getDescription())) .andDo(MockMvcResultHandlers.print()); + assertThat(waitingLineRepository.findRank(1L, 2L)).isEqualTo(1L); assertThat(waitingLineRepository.findRank(1L, 3L)).isEqualTo(2L); + assertThrows(NotFoundCustomException.class, + () -> waitingLineRepository.findRank(1L, 1L)); } @DisplayName("웨이팅 진행 상태가 아니면 취소가 불가하다.") From 6a074923176e8ac9a7f620ecadae79c316cfbd2d Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 03:15:23 +0900 Subject: [PATCH 317/603] =?UTF-8?q?fix=20:=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/WaitingControllerTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java index 3a374dd8..f82b532c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java @@ -66,7 +66,6 @@ void setUp() { shop = ShopFixture.shopWith24(); shopRepository.save(shop); - waiting1 = Waiting.builder() .member(member1) .shop(shop) @@ -176,11 +175,11 @@ void cancelWaiting() throws Exception { .andExpect(jsonPath("$.peopleCount").value(waiting1.getPeopleCount())) .andExpect(jsonPath("$.status").value(CANCELED.getDescription())) .andDo(MockMvcResultHandlers.print()); - - assertThat(waitingLineRepository.findRank(1L, 2L)).isEqualTo(1L); - assertThat(waitingLineRepository.findRank(1L, 3L)).isEqualTo(2L); + waitingLineRepository.printWaitingLine(shop.getId()); + assertThat(waitingLineRepository.findRank(shop.getId(), waiting2.getId())).isEqualTo(1L); + assertThat(waitingLineRepository.findRank(shop.getId(), waiting3.getId())).isEqualTo(2L); assertThrows(NotFoundCustomException.class, - () -> waitingLineRepository.findRank(1L, 1L)); + () -> waitingLineRepository.findRank(shop.getId(), waiting1.getId())); } @DisplayName("웨이팅 진행 상태가 아니면 취소가 불가하다.") From 0baf590b008cdb757212ef93981df47a0d739a13 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 03:17:45 +0900 Subject: [PATCH 318/603] =?UTF-8?q?rename=20:=20controller,=20service=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...gController.java => MemberWaitingController.java} | 12 ++++++------ ...WaitingService.java => MemberWaitingService.java} | 2 +- ...est.java => MemberWaitingControllerDocsTest.java} | 10 +++++----- ...lerTest.java => MemberWaitingControllerTest.java} | 2 +- ...erviceTest.java => MemberWaitingServiceTest.java} | 10 +++++----- 5 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/controller/{WaitingController.java => MemberWaitingController.java} (77%) rename src/main/java/com/prgrms/catchtable/waiting/service/{WaitingService.java => MemberWaitingService.java} (99%) rename src/test/java/com/prgrms/catchtable/waiting/controller/{WaitingControllerDocsTest.java => MemberWaitingControllerDocsTest.java} (90%) rename src/test/java/com/prgrms/catchtable/waiting/controller/{WaitingControllerTest.java => MemberWaitingControllerTest.java} (99%) rename src/test/java/com/prgrms/catchtable/waiting/service/{WaitingServiceTest.java => MemberWaitingServiceTest.java} (93%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java similarity index 77% rename from src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java rename to src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index af45c3fa..b12efabb 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/WaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -2,7 +2,7 @@ import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.WaitingResponse; -import com.prgrms.catchtable.waiting.service.WaitingService; +import com.prgrms.catchtable.waiting.service.MemberWaitingService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -17,28 +17,28 @@ @RequiredArgsConstructor @RequestMapping("/waitings") @RestController -public class WaitingController { +public class MemberWaitingController { - private final WaitingService waitingService; + private final MemberWaitingService memberWaitingService; @PostMapping("/{shopId}/{memberId}") public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - WaitingResponse response = waitingService.createWaiting(shopId, memberId, request); + WaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } @PatchMapping("/{memberId}") public ResponseEntity postponeWaiting( @PathVariable("memberId") Long memberId) { - WaitingResponse response = waitingService.postponeWaiting(memberId); + WaitingResponse response = memberWaitingService.postponeWaiting(memberId); return ResponseEntity.ok(response); } @DeleteMapping("/{memberId}") public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { - WaitingResponse response = waitingService.cancelWaiting(memberId); + WaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java similarity index 99% rename from src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java rename to src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index cdd16b5d..16624b38 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -27,7 +27,7 @@ @RequiredArgsConstructor @Service -public class WaitingService { +public class MemberWaitingService { private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0, 0)); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java similarity index 90% rename from src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java rename to src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index c0236b46..64e7fca8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -16,19 +16,19 @@ import com.prgrms.catchtable.common.restdocs.RestDocsSupport; import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.WaitingResponse; -import com.prgrms.catchtable.waiting.service.WaitingService; +import com.prgrms.catchtable.waiting.service.MemberWaitingService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -class WaitingControllerDocsTest extends RestDocsSupport { +class MemberWaitingControllerDocsTest extends RestDocsSupport { - private final WaitingService waitingService = mock(WaitingService.class); + private final MemberWaitingService memberWaitingService = mock(MemberWaitingService.class); @Override protected Object initController() { - return new WaitingController(waitingService); + return new MemberWaitingController(memberWaitingService); } @DisplayName("웨이팅 생성 API") @@ -48,7 +48,7 @@ void createWaiting() throws Exception { .status("진행 중") .build(); - given(waitingService.createWaiting(1L, 1L, request)).willReturn(response); + given(memberWaitingService.createWaiting(1L, 1L, request)).willReturn(response); mockMvc.perform(post("/waitings/{shopId}/{memberId}", 1, 1) .contentType(APPLICATION_JSON) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java similarity index 99% rename from src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java rename to src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index f82b532c..61244d25 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/WaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -38,7 +38,7 @@ @Slf4j @Transactional -class WaitingControllerTest extends BaseIntegrationTest { +class MemberWaitingControllerTest extends BaseIntegrationTest { @Autowired private MemberRepository memberRepository; diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java similarity index 93% rename from src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java rename to src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 4f7c43f4..9d7f4d39 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/WaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -29,7 +29,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class WaitingServiceTest { +class MemberWaitingServiceTest { @Mock private WaitingRepository waitingRepository; @@ -41,7 +41,7 @@ class WaitingServiceTest { @Mock private WaitingLineRepository waitingLineRepository; @InjectMocks - private WaitingService waitingService; + private MemberWaitingService memberWaitingService; @Test void createWaiting() { @@ -67,7 +67,7 @@ void createWaiting() { given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); //when - WaitingResponse response = waitingService.createWaiting(1L, 1L, request); + WaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), @@ -93,7 +93,7 @@ void postponeWaiting() { doNothing().when(waiting).decreasePostponeRemainingCount(); //when - WaitingResponse response = waitingService.postponeWaiting(1L); + WaitingResponse response = memberWaitingService.postponeWaiting(1L); //then assertAll( assertThat(response.peopleCount())::isNotNull, @@ -117,7 +117,7 @@ void cancelWaiting() { doNothing().when(waiting).changeStatusCanceled(); //when - WaitingResponse response = waitingService.cancelWaiting(1L); + WaitingResponse response = memberWaitingService.cancelWaiting(1L); //then assertAll( From 45ebb6780758a4deb18d8f1d0c75b2d85f9438c1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 13:58:42 +0900 Subject: [PATCH 319/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index b12efabb..e7dfb94a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -41,4 +42,10 @@ public ResponseEntity cancelWaiting(@PathVariable("memberId") L WaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } + + @GetMapping("/{memberId}") + public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + WaitingResponse response = memberWaitingService.getWaiting(memberId); + return ResponseEntity.ok(response); + } } From 9f432ace8c143abdf2e626ba2981403694dbf613 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 13:59:22 +0900 Subject: [PATCH 320/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 16624b38..fa08234f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -87,6 +87,17 @@ public WaitingResponse cancelWaiting(Long memberId) { return toWaitingResponse(waiting, -1L); } + @Transactional(readOnly = true) + public WaitingResponse getWaiting(Long memberId){ + Member member = getMemberEntity(memberId); + Waiting waiting = getWaitingEntity(member); + + Shop shop = waiting.getShop(); + Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + + return toWaitingResponse(waiting, rank); + } + private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); From cce9febaf63c28e79927b415c6a1baf691714126 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 15:17:20 +0900 Subject: [PATCH 321/603] =?UTF-8?q?feat=20:=20repository=20=20=EC=9B=A8?= =?UTF-8?q?=EC=9D=B4=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 8 +++--- .../waiting/service/MemberWaitingService.java | 27 ++++++------------- .../MemberWaitingControllerTest.java | 11 -------- .../service/MemberWaitingServiceTest.java | 10 ++++--- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index bb407e95..0ddd920c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -3,6 +3,7 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; import java.time.LocalDateTime; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,8 +14,9 @@ public interface WaitingRepository extends JpaRepository { boolean existsByMember(Member member); - @Query("select w from Waiting w join fetch w.shop where w.member = :member") - Optional findByMemberWithShop(@Param("member") Member member); - Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); + + @Query("select w from Waiting w join fetch w.shop " + + "where w.member = :member and w.status = :status") + Optional findByMemberAndStatusWithShop(@Param("member")Member member, @Param("status")WaitingStatus status); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index fa08234f..b7d5000d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -2,8 +2,9 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; -import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_WAITING; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; @@ -64,7 +65,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, @Transactional public WaitingResponse postponeWaiting(Long memberId) { Member member = getMemberEntity(memberId); - Waiting waiting = getWaitingEntity(member); + Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); @@ -78,26 +79,15 @@ public WaitingResponse postponeWaiting(Long memberId) { @Transactional public WaitingResponse cancelWaiting(Long memberId) { Member member = getMemberEntity(memberId); - Waiting waiting = getWaitingEntity(member); + Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); - waiting.changeStatusCanceled(); waitingLineRepository.cancel(shop.getId(), waiting.getId()); + waiting.changeStatusCanceled(); return toWaitingResponse(waiting, -1L); } - @Transactional(readOnly = true) - public WaitingResponse getWaiting(Long memberId){ - Member member = getMemberEntity(memberId); - Waiting waiting = getWaitingEntity(member); - - Shop shop = waiting.getShop(); - Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - - return toWaitingResponse(waiting, rank); - } - private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); @@ -118,9 +108,8 @@ public Shop getShopEntity(Long shopId) { return shop; } - public Waiting getWaitingEntity(Member member) { - return waitingRepository.findByMemberWithShop(member).orElseThrow( - () -> new NotFoundCustomException(NOT_EXIST_WAITING) - ); + public Waiting getWaitingEntityInProgress(Member member) { + return waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_PROGRESS_WAITING)); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 61244d25..30274744 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -182,15 +182,4 @@ void cancelWaiting() throws Exception { () -> waitingLineRepository.findRank(shop.getId(), waiting1.getId())); } - @DisplayName("웨이팅 진행 상태가 아니면 취소가 불가하다.") - @Test - void cancelWaiting_fails_if_not_progress() throws Exception { - //when, then - ReflectionTestUtils.setField(waiting1, "status", COMPLETED); - mockMvc.perform(delete("/waitings/{memberId}", member1.getId()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.message").value("웨이팅 취소 처리가 불가한 상태입니다.")) - .andDo(MockMvcResultHandlers.print()); - } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 9d7f4d39..1e940951 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -43,6 +43,7 @@ class MemberWaitingServiceTest { @InjectMocks private MemberWaitingService memberWaitingService; + @DisplayName("웨이팅을 생성할 수 있다.") @Test void createWaiting() { //given @@ -76,7 +77,7 @@ void createWaiting() { ); } - @DisplayName("대기 지연을 할 수 있다.") + @DisplayName("웨이팅을 연기할 수 있다.") @Test void postponeWaiting() { //given @@ -85,7 +86,7 @@ void postponeWaiting() { Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMemberWithShop(member)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); @@ -102,7 +103,7 @@ void postponeWaiting() { ); } - @DisplayName("대기 취소를 할 수 있다.") + @DisplayName("웨이팅을 취소할 수 있다.") @Test void cancelWaiting() { //given @@ -111,7 +112,7 @@ void cancelWaiting() { Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMemberWithShop(member)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(CANCELED); doNothing().when(waiting).changeStatusCanceled(); @@ -126,4 +127,5 @@ void cancelWaiting() { assertThat(response.waitingNumber())::isNotNull ); } + } \ No newline at end of file From 55127867c4aa5ffed9f6d9466205fb8d1a0dfb17 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 15:18:02 +0900 Subject: [PATCH 322/603] =?UTF-8?q?feat=20:=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=88=98=EC=A0=95=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20waiting=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=EA=B2=80=EC=A6=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/domain/Waiting.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 6e2026dc..421c1184 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -90,9 +90,6 @@ public void completeWaiting() { public void changeStatusCanceled() { - if (status != PROGRESS) { - throw new BadRequestCustomException(CAN_NOT_CANCEL_WAITING); - } status = CANCELED; } } From 4e9f960442210e45e57b85a34b4f26fbb287d77e Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 15:27:08 +0900 Subject: [PATCH 323/603] =?UTF-8?q?feat=20:=20=EC=A7=84=ED=96=89=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B0=8F=20=EB=8B=A8=EC=9C=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 2 +- .../waiting/service/MemberWaitingService.java | 12 +++++++++++ .../service/MemberWaitingServiceTest.java | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 72771ccd..969af5c4 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -21,7 +21,7 @@ public enum ErrorCode { CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), ALREADY_END_LINE("이미 맨뒤라 웨이팅을 미룰 수 없습니다."), - NOT_EXIST_WAITING("웨이팅이 존재하지 않습니다."), + NOT_EXIST_PROGRESS_WAITING("진행 중인 웨이팅이 존재하지 않습니다."), POSTPONE_REMAINING_CNT_0("이미 두 차례 대기를 미뤘습니다."), CAN_NOT_CANCEL_WAITING("웨이팅 취소 처리가 불가한 상태입니다."), diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index b7d5000d..57aefed5 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -88,6 +88,18 @@ public WaitingResponse cancelWaiting(Long memberId) { return toWaitingResponse(waiting, -1L); } + @Transactional(readOnly = true) + public WaitingResponse getWaiting(Long memberId) { + Member member = getMemberEntity(memberId); + Waiting waiting = getWaitingEntityInProgress(member); + + Shop shop = waiting.getShop(); + Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + + return toWaitingResponse(waiting, rank); + } + + private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 1e940951..c9f4b597 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -128,4 +128,24 @@ void cancelWaiting() { ); } + @DisplayName("웨이팅를 조회할 수 있다.") + @Test + void getWaiting(){ + //given + Shop shop = mock(Shop.class); + Member member = mock(Member.class); + Waiting waiting = mock(Waiting.class); + + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); + given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); + given(waiting.getShop()).willReturn(shop); + given(waiting.getStatus()).willReturn(PROGRESS); + //when + WaitingResponse response = memberWaitingService.getWaiting(1L); + + //then + + } + + } \ No newline at end of file From e313f89dc5a5404f3d5be48bb6d3de962d3a2512 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 17:27:16 +0900 Subject: [PATCH 324/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingControllerTest.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 30274744..1627b23b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -1,12 +1,12 @@ package com.prgrms.catchtable.waiting.controller; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -34,10 +34,8 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.transaction.annotation.Transactional; @Slf4j -@Transactional class MemberWaitingControllerTest extends BaseIntegrationTest { @Autowired @@ -95,6 +93,9 @@ void setUp() { @AfterEach void clear() { redisTemplate.delete("s" + shop.getId()); + memberRepository.deleteAll(); + shopRepository.deleteAll(); + waitingRepository.deleteAll(); } @DisplayName("웨이팅 생성 API를 호출할 수 있다.") @@ -145,23 +146,23 @@ void postponeWaiting_fails() throws Exception { .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 맨뒤라 웨이팅을 미룰 수 없습니다.")) .andDo(MockMvcResultHandlers.print()); -// Waiting waiting = waitingRepository.findById(waiting3.getId()).orElse(null); -// Assertions.assertThat(waiting.getPostponeRemainingCount()).isEqualTo(2); + assertThat(waiting3.getRemainingPostponeCount()).isEqualTo(2); } @DisplayName("대기 지연 잔여 횟수를 소진 시, 더이상 지연이 불가하므로 예외를 반환한다.") @Test void postponeWaiting_fails2() throws Exception { - ReflectionTestUtils.setField(waiting1, "remainingPostponeCount", 0); - mockMvc.perform(patch("/waitings/{memberId}", member1.getId()) + ReflectionTestUtils.setField(waiting2, "remainingPostponeCount", 0); + waitingRepository.save(waiting2); + mockMvc.perform(patch("/waitings/{memberId}", member2.getId()) .contentType(APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 두 차례 대기를 미뤘습니다.")) .andDo(MockMvcResultHandlers.print()); } - @DisplayName("웨이팅 취소 API를 추가할 수 있다.") + @DisplayName("웨이팅 취소 API를 호출할 수 있다.") @Test void cancelWaiting() throws Exception { //when, then @@ -182,4 +183,19 @@ void cancelWaiting() throws Exception { () -> waitingLineRepository.findRank(shop.getId(), waiting1.getId())); } + @DisplayName("웨이팅 조회 API를 호출할 수 있다.") + @Test + void getWaiting() throws Exception { + //when, then + mockMvc.perform(get("/waitings/{memberId}", member3.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopId").value(shop.getId())) + .andExpect(jsonPath("$.shopName").value(shop.getName())) + .andExpect(jsonPath("$.rank").value(3L)) + .andExpect(jsonPath("$.waitingNumber").value(waiting3.getWaitingNumber())) + .andExpect(jsonPath("$.peopleCount").value(waiting3.getPeopleCount())) + .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) + .andDo(MockMvcResultHandlers.print()); + } } \ No newline at end of file From dc95bcbc3ebc771fa5cc29a45474f4dd48516b20 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 7 Jan 2024 17:28:43 +0900 Subject: [PATCH 325/603] =?UTF-8?q?refactor=20:=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A7=80=EC=97=B0=20=EB=A1=9C=EC=A7=81=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/domain/Waiting.java | 8 ++------ .../waiting/repository/WaitingRepository.java | 3 ++- .../waiting/service/MemberWaitingService.java | 4 ++-- .../waiting/service/MemberWaitingServiceTest.java | 12 +++++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 421c1184..e953c7bc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.waiting.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_CANCEL_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.POSTPONE_REMAINING_CNT_0; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; @@ -71,13 +70,10 @@ public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { remainingPostponeCount = 2; } - public void validatePostponeRemainingCount() { - if (remainingPostponeCount == 0) { + public void decreasePostponeRemainingCount() { + if (remainingPostponeCount <= 0) { throw new BadRequestCustomException(POSTPONE_REMAINING_CNT_0); } - } - - public void decreasePostponeRemainingCount() { remainingPostponeCount--; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 0ddd920c..3ae6e878 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -18,5 +18,6 @@ public interface WaitingRepository extends JpaRepository { @Query("select w from Waiting w join fetch w.shop " + "where w.member = :member and w.status = :status") - Optional findByMemberAndStatusWithShop(@Param("member")Member member, @Param("status")WaitingStatus status); + Optional findByMemberAndStatusWithShop(@Param("member") Member member, + @Param("status") WaitingStatus status); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 57aefed5..4025e774 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -69,10 +69,10 @@ public WaitingResponse postponeWaiting(Long memberId) { Shop shop = waiting.getShop(); - waiting.validatePostponeRemainingCount(); + waiting.decreasePostponeRemainingCount(); waitingLineRepository.postpone(shop.getId(), waiting.getId()); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - waiting.decreasePostponeRemainingCount(); + return toWaitingResponse(waiting, rank); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index c9f4b597..d5a1d959 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -86,11 +86,11 @@ void postponeWaiting() { Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( + Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); - doNothing().when(waiting).validatePostponeRemainingCount(); doNothing().when(waiting).decreasePostponeRemainingCount(); //when @@ -112,7 +112,8 @@ void cancelWaiting() { Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( + Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(CANCELED); doNothing().when(waiting).changeStatusCanceled(); @@ -130,14 +131,15 @@ void cancelWaiting() { @DisplayName("웨이팅를 조회할 수 있다.") @Test - void getWaiting(){ + void getWaiting() { //given Shop shop = mock(Shop.class); Member member = mock(Member.class); Waiting waiting = mock(Waiting.class); given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(waitingRepository.findByMemberAndStatusWithShop(member,PROGRESS)).willReturn(Optional.of(waiting)); + given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( + Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); //when From d28e062a6d62d9ab0bd6951d99b5121500b7296a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:29:41 +0900 Subject: [PATCH 326/603] =?UTF-8?q?feat=20:=20=EA=B0=9C=EC=9D=B8=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/repository/NotificationMemberRepository.java | 4 +++- .../notification/repository/NotificationOwnerRepository.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index e9c5b5a7..0a2452eb 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.notification.repository; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.domain.NotificationMember; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { - + Optional findByMember(Member member); } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java index bca2921d..113323a4 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.notification.repository; import com.prgrms.catchtable.notification.domain.NotificationOwner; +import com.prgrms.catchtable.owner.domain.Owner; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationOwnerRepository extends JpaRepository { - + Optional findByOwner(Owner owner); } From 6dc7edefe6f90b6f548c1dbd0d8b134319707b45 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:09 +0900 Subject: [PATCH 327/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20enum=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/NotificationContent.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/NotificationContent.java diff --git a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java new file mode 100644 index 00000000..0a37bcf7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java @@ -0,0 +1,23 @@ +package com.prgrms.catchtable.common; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum NotificationContent { + RESERVATION_COMPLETED("예약이 완료되었습니다"), + RESERVATION_ONE_HOUR_LEFT("예약 시간 1시간 전입니다."), + RESERVATION_TIME_TO_ENTER("예약시간이 되었습니다"), + WAITING_REGISTER_COMPLETED("웨이팅 등록이 완료되었습니다"), + WAITING_RANK_THIRD("웨이팅 순서가 3번째가 되었습니다"), + WAITING_TIME_TO_ENTER("웨이팅이 끝났습니다. 입장 부탁드립니다."), + WAITING_CANCELLED_AUTOMATICALLY("웨이팅이 자동으로 취소되었습니다."); + + private final String message; + + + + + +} From fa47bf878bb019e304fe49a39e159b43583bce59 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:22 +0900 Subject: [PATCH 328/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=20=EC=9A=94=EC=B2=AD=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/dto/request/SendMessageRequest.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java new file mode 100644 index 00000000..7c2034f7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.notification.dto.request; + +import com.prgrms.catchtable.common.NotificationContent; + +public record SendMessageRequest(NotificationContent content) { + +} From eba16e1c189133109cab8ca8c5372c04100a4b7a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:44 +0900 Subject: [PATCH 329/603] =?UTF-8?q?feat=20:=20owner=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90=20?= =?UTF-8?q?owner=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/notification/domain/NotificationOwner.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java index 4f4c3935..4a3885e5 100644 --- a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java @@ -36,7 +36,8 @@ public class NotificationOwner extends BaseEntity { private Owner owner; @Builder - public NotificationOwner(String message) { + public NotificationOwner(Owner owner, String message) { + this.owner = owner; this.message = message; } } From b65ca72e09d05d43e3b081432ad6dbf6705c4389 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:12 +0900 Subject: [PATCH 330/603] =?UTF-8?q?feat=20:=20Owner=EC=97=90=20Email=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80(slack=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=B3=B4=EB=82=BC=20=EB=95=8C=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EC=B6=9C=EC=9D=84=20=EC=9C=84=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/owner/domain/Owner.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index a4e17aab..78c73348 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -35,6 +35,9 @@ public class Owner extends BaseEntity { @Column(name = "owner_name") private String name; + @Column(name = "email") + private String email; + @Column(name = "phone_number") private String phoneNumber; @@ -50,8 +53,9 @@ public class Owner extends BaseEntity { private Shop shop; @Builder - public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { this.name = name; + this.email = email; this.phoneNumber = phoneNumber; this.gender = gender; this.dateBirth = dateBirth; From 852b78ac41cad26812e2433e2f698bd98086b0ca Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:26 +0900 Subject: [PATCH 331/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationService.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java new file mode 100644 index 00000000..b6f364c4 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -0,0 +1,141 @@ +package com.prgrms.catchtable.notification.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static org.springframework.http.HttpMethod.*; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.notification.domain.NotificationMember; +import com.prgrms.catchtable.notification.domain.NotificationOwner; +import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; +import com.prgrms.catchtable.notification.repository.NotificationMemberRepository; +import com.prgrms.catchtable.notification.repository.NotificationOwnerRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import lombok.RequiredArgsConstructor; + +import lombok.extern.slf4j.Slf4j; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +@RequiredArgsConstructor +@Slf4j +public class NotificationService { + + @Value("${slack.token}") + private String slackToken; + + private final NotificationMemberRepository notificationMemberRepository; + private final NotificationOwnerRepository notificationOwnerRepository; + private final MemberRepository memberRepository; // 추후 삭제 예정 + private final OwnerRepository ownerRepository; // 추후 삭제 예정 + private JSONObject jsonObject; + + public void sendMessageToMemberAndSave(SendMessageRequest request) { + String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API + // member 예제 데이터 + Member member = Member.builder() + .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 + .build(); + + String email = member.getEmail(); + String message = request.content().getMessage(); + String slackId = getSlackIdByEmail(email); // 이메일을 통해 사용자의 슬랙 고유 ID 추출 + + requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 + + + NotificationMember notification = NotificationMember.builder() + .member(member) + .message(message) + .build(); + memberRepository.save(member); // 추후 삭제 예정 + notificationMemberRepository.save(notification); // 해당 사용자의 알림 생성 후 저장 + + } + + public void sendMessageToOwnerAndSave(SendMessageRequest request) { + String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API + //Owner 예제 데이터 + Owner owner = Owner.builder() + .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 + .build(); + + String email = owner.getEmail(); + String message = request.content().getMessage(); + String slackId = getSlackIdByEmail(email); + + requestToSendMessage(slackId, message); + + NotificationOwner notification = NotificationOwner.builder() + .owner(owner) + .message(message) + .build(); + ownerRepository.save(owner); //추후 삭제 예정 + notificationOwnerRepository.save(notification); + } + + private void requestToSendMessage(String slackId, String message){ + String url = "https://slack.com/api/chat.postMessage"; + + // 헤더에 캐치테이블 클론 슬랙 토큰 삽입 + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + slackToken); + headers.add("Content-type", "application/json; charset=utf-8"); + + + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("channel", slackId); // 채널 필드에 사용자의 슬랙 고유 ID + jsonObject.put("text", message); // 메세지 필드에 메세지 + String body = jsonObject.toString(); + + HttpEntity requestEntity = new HttpEntity<>(body, headers); + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity response = restTemplate.exchange( + url, + POST, + requestEntity, + String.class + );// post로 위에서 만든 Json body 전송 요청 + + jsonObject = new JSONObject(response.getBody()); + String result = jsonObject.get("ok").toString(); + + if(result.equals("false")){ // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 + throw new BadRequestCustomException(SLACK_ID_IS_WRONG); + } + + // ok 필드값이 true면 알림 전송 완료 된것임 + } + + public String getSlackIdByEmail(String email) { + String url = "https://slack.com/api/users.lookupByEmail?email=".concat(email); + + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + slackToken); + headers.add("Content-type", "application/x-www-form-urlencoded"); + + RestTemplate restTemplate = new RestTemplate(); + HttpEntity requestEntity = new HttpEntity<>(headers); + ResponseEntity responseEntity = restTemplate.exchange( + url, + GET, + requestEntity, + String.class + ); + jsonObject = new JSONObject(responseEntity.getBody()); + JSONObject profile = jsonObject.getJSONObject("user"); + + return profile.get("id").toString(); + } +} From fc7b0de73637311334c41589eccdb20b9c8deb36 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:44 +0900 Subject: [PATCH 332/603] =?UTF-8?q?feat=20:=20=EC=8A=AC=EB=9E=99=20Id=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EA=B4=80=EB=A0=A8=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 686a2544..d3252d30 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -28,7 +28,9 @@ public enum ErrorCode { CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), - INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); + INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), + + SLACK_ID_IS_WRONG("요청한 슬랙 Id를 찾을 수 없거나 잘못 되었습니다"); private final String message; } \ No newline at end of file From 3654d5fcfd3c5c9f2eb52dc8ca047cf6e2f5ecd7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:32:15 +0900 Subject: [PATCH 333/603] =?UTF-8?q?feat=20:=20api=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java diff --git a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java new file mode 100644 index 00000000..cf1ae996 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java @@ -0,0 +1,19 @@ +package com.prgrms.catchtable.notification.controller; + +import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; +import com.prgrms.catchtable.notification.service.NotificationService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class NotificationController { + private final NotificationService notificationService; + + @GetMapping("/test") + public void test(@RequestBody SendMessageRequest request){ + notificationService.sendMessageToMemberAndSave(request); + } +} From 57b44338474c71001f291a48b433622ab626f1f5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:32:34 +0900 Subject: [PATCH 334/603] =?UTF-8?q?chore=20:=20Json=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 758ad7da..4860a110 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,9 @@ dependencies { runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + implementation group: 'org.json', name: 'json', version: '20231013' + + } tasks.named('test') { From 0d7173c26824417bbd147140b91bfdbe4c9695a8 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:52:32 +0900 Subject: [PATCH 335/603] =?UTF-8?q?docs=20:=20test=20yaml=20=EC=8A=AC?= =?UTF-8?q?=EB=9E=99=20=ED=86=A0=ED=81=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml index 1beefa13..fdaaf576 100644 --- a/src/test/resources/application.yaml +++ b/src/test/resources/application.yaml @@ -44,4 +44,6 @@ jwt: logging.level: org.hibernate.SQL: debug org.hibernate.orm.jdbc.bind: trace +slack: + token: xoxb-6433151143155-6426645660710-QosE3VDLJM62hLgSISYqLTUu From 92e4f0e2a66ad7ea053cb4a52764d3fae46e5dc0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 18:53:59 +0900 Subject: [PATCH 336/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/NotificationContent.java | 3 --- .../controller/NotificationController.java | 3 ++- .../repository/NotificationMemberRepository.java | 1 + .../repository/NotificationOwnerRepository.java | 1 + .../notification/service/NotificationService.java | 14 +++++--------- .../com/prgrms/catchtable/owner/domain/Owner.java | 3 ++- .../service/OwnerReservationService.java | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java index 0a37bcf7..06af80c9 100644 --- a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java @@ -17,7 +17,4 @@ public enum NotificationContent { private final String message; - - - } diff --git a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java index cf1ae996..07007c94 100644 --- a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java +++ b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java @@ -10,10 +10,11 @@ @RestController @RequiredArgsConstructor public class NotificationController { + private final NotificationService notificationService; @GetMapping("/test") - public void test(@RequestBody SendMessageRequest request){ + public void test(@RequestBody SendMessageRequest request) { notificationService.sendMessageToMemberAndSave(request); } } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index 0a2452eb..44598e0e 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -6,5 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { + Optional findByMember(Member member); } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java index 113323a4..eb840345 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -6,5 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationOwnerRepository extends JpaRepository { + Optional findByOwner(Owner owner); } diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index b6f364c4..eb862c67 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.notification.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; -import static org.springframework.http.HttpMethod.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.SLACK_ID_IS_WRONG; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.POST; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.member.domain.Member; @@ -14,7 +15,6 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; import lombok.RequiredArgsConstructor; - import lombok.extern.slf4j.Slf4j; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Value; @@ -51,7 +51,6 @@ public void sendMessageToMemberAndSave(SendMessageRequest request) { requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 - NotificationMember notification = NotificationMember.builder() .member(member) .message(message) @@ -82,7 +81,7 @@ public void sendMessageToOwnerAndSave(SendMessageRequest request) { notificationOwnerRepository.save(notification); } - private void requestToSendMessage(String slackId, String message){ + private void requestToSendMessage(String slackId, String message) { String url = "https://slack.com/api/chat.postMessage"; // 헤더에 캐치테이블 클론 슬랙 토큰 삽입 @@ -90,8 +89,6 @@ private void requestToSendMessage(String slackId, String message){ headers.add("Authorization", "Bearer " + slackToken); headers.add("Content-type", "application/json; charset=utf-8"); - - JSONObject jsonObject = new JSONObject(); jsonObject.put("channel", slackId); // 채널 필드에 사용자의 슬랙 고유 ID jsonObject.put("text", message); // 메세지 필드에 메세지 @@ -110,7 +107,7 @@ private void requestToSendMessage(String slackId, String message){ jsonObject = new JSONObject(response.getBody()); String result = jsonObject.get("ok").toString(); - if(result.equals("false")){ // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 + if (result.equals("false")) { // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 throw new BadRequestCustomException(SLACK_ID_IS_WRONG); } @@ -120,7 +117,6 @@ private void requestToSendMessage(String slackId, String message){ public String getSlackIdByEmail(String email) { String url = "https://slack.com/api/users.lookupByEmail?email=".concat(email); - HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + slackToken); headers.add("Content-type", "application/x-www-form-urlencoded"); diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index 78c73348..7079b780 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -53,7 +53,8 @@ public class Owner extends BaseEntity { private Shop shop; @Builder - public Owner(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String phoneNumber, Gender gender, + LocalDate dateBirth) { this.name = name; this.email = email; this.phoneNumber = phoneNumber; diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 6972ccf3..085d99e4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -40,7 +40,7 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 - if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + if (modifyStatus == COMPLETED) { // 취소, 노쇼 처리가 아닌 경우 예외 throw new BadRequestCustomException(ALREADY_COMPLETED_RESERVATION); } From 845a49773c9aa59ed30ae421d93ed0f5a23461fa Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 7 Jan 2024 21:11:47 +0900 Subject: [PATCH 337/603] =?UTF-8?q?fix=20:=20=EC=A0=91=EA=B7=BC=20?= =?UTF-8?q?=EC=A0=9C=EC=96=B4=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/service/OwnerServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index dd8d297e..3c7e59e7 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -29,9 +29,9 @@ class OwnerServiceTest { private final OwnerService ownerService = new OwnerService(ownerRepository, passwordEncoder, jwtTokenProvider); - String email = "abc1234@gmail.com"; - String password = "qwer1234"; - String wrongPassword = "qwer12345"; + private final String email = "abc1234@gmail.com"; + private final String password = "qwer1234"; + private final String wrongPassword = "qwer12345"; @Test From 2a8801b5100681500873265c10fc7ffe4b0fc673 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 7 Jan 2024 21:40:02 +0900 Subject: [PATCH 338/603] fix : conflict resolve --- .../com/prgrms/catchtable/owner/fixture/OwnerFixture.java | 4 +++- .../controller/OwnerReservationControllerTest.java | 2 +- .../reservation/service/OwnerReservationServiceTest.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index f8cd2c02..5666f366 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -14,9 +14,11 @@ public class OwnerFixture { - public static Owner getOwner() { + public static Owner getOwner(String email, String password) { Owner owner = Owner.builder() .name("ownerA") + .email(email) + .password(password) .phoneNumber("010-3462-2480") .gender(MALE) .dateBirth(LocalDate.of(2000, 9, 13)) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index a0237637..e2d7ef7b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -62,7 +62,7 @@ void setUp() { Reservation reservation2 = reservationRepository.save( ReservationFixture.getReservation(savedReservationTime2)); - Owner owner = OwnerFixture.getOwner(); + Owner owner = OwnerFixture.getOwner("email", "password"); owner.insertShop(shop); ownerRepository.save(owner); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java index f114d342..96c21097 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java @@ -109,7 +109,7 @@ void getAllReservation() { reservations.add(reservation1); reservations.add(reservation2); - Owner owner = OwnerFixture.getOwner(); + Owner owner = OwnerFixture.getOwner("email", "password"); when(reservationRepository.findAllWithReservationTimeAndShopByShopId( any(Long.class))).thenReturn(reservations); when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); @@ -127,7 +127,7 @@ void getAllReservation() { @Test @DisplayName("매장에 예약이 없을 시 빈 리스트가 조회된다.") void getAllReservationEmpty() { - Owner owner = OwnerFixture.getOwner(); + Owner owner = OwnerFixture.getOwner("email", "password"); when(reservationRepository.findAllWithReservationTimeAndShopByShopId( any(Long.class))).thenReturn(List.of()); From 4b756c2a3891b6656608a80d01acd0ee2cbd391c Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 7 Jan 2024 21:47:09 +0900 Subject: [PATCH 339/603] fix : conflict resolve --- .../com/prgrms/catchtable/owner/fixture/OwnerFixture.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 5666f366..54089c3c 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -31,12 +31,12 @@ public static Owner getOwner(String email, String password) { public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ return JoinOwnerRequest.builder() - .name("test") + .name("ownerA") .email(email) .password(password) - .phoneNumber("010-8830-4795") + .phoneNumber("010-3462-2480") .gender("male") - .dateBirth(LocalDate.of(1998,3,25)) + .dateBirth(LocalDate.of(2000, 9, 13)) .build(); } From 40a528466d39e3ab975e24f348809ac9111f26d5 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 7 Jan 2024 23:34:22 +0900 Subject: [PATCH 340/603] =?UTF-8?q?fix=20:=20=EB=88=84=EB=9D=BD=20Transact?= =?UTF-8?q?ion=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/owner/service/OwnerService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index d8a12a97..e1854a7d 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -16,6 +16,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -25,6 +26,7 @@ public class OwnerService { private final PasswordEncoder passwordEncoder; private final JwtTokenProvider jwtTokenProvider; + @Transactional public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { //이미 존재하는 이메일이라면 @@ -47,6 +49,7 @@ private void validateExistsOwner(JoinOwnerRequest joinOwnerRequest) { } } + @Transactional public Token loginOwner(LoginOwnerRequest loginRequest) { //email 확인 From d0411463d95644a7028e9381a3bb5aab75d81fdc Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 00:19:27 +0900 Subject: [PATCH 341/603] =?UTF-8?q?rename=20:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 2 ++ .../waiting/dto/{ => request}/CreateWaitingRequest.java | 2 +- .../catchtable/waiting/dto/{ => response}/WaitingResponse.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/dto/{ => request}/CreateWaitingRequest.java (80%) rename src/main/java/com/prgrms/catchtable/waiting/dto/{ => response}/WaitingResponse.java (82%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 5a11c521..dbe2fc77 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -5,6 +5,8 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.WaitingResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java b/src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java similarity index 80% rename from src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java index 4b9f9205..09a05a70 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.dto; +package com.prgrms.catchtable.waiting.dto.request; import jakarta.validation.constraints.Positive; import lombok.Builder; diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java similarity index 82% rename from src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java index 969c8e8c..af4106dc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.dto; +package com.prgrms.catchtable.waiting.dto.response; import lombok.Builder; From a6a50b275aa927c6f15cd7c99d7abfcde6674ab0 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 00:22:06 +0900 Subject: [PATCH 342/603] =?UTF-8?q?style=20:=20dto=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingController.java | 20 +++++++++---------- .../catchtable/waiting/dto/WaitingMapper.java | 6 +++--- ...sponse.java => MemberWaitingResponse.java} | 2 +- .../waiting/service/MemberWaitingService.java | 12 +++++------ .../MemberWaitingControllerDocsTest.java | 6 +++--- .../MemberWaitingControllerTest.java | 2 +- .../service/MemberWaitingServiceTest.java | 12 +++++------ 7 files changed, 30 insertions(+), 30 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/dto/response/{WaitingResponse.java => MemberWaitingResponse.java} (87%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index e7dfb94a..6a0e32a1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.waiting.controller; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.service.MemberWaitingService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -23,29 +23,29 @@ public class MemberWaitingController { private final MemberWaitingService memberWaitingService; @PostMapping("/{shopId}/{memberId}") - public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, + public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - WaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } @PatchMapping("/{memberId}") - public ResponseEntity postponeWaiting( + public ResponseEntity postponeWaiting( @PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.postponeWaiting(memberId); + MemberWaitingResponse response = memberWaitingService.postponeWaiting(memberId); return ResponseEntity.ok(response); } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.cancelWaiting(memberId); + public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { + MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } @GetMapping("/{memberId}") - public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.getWaiting(memberId); + public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index dbe2fc77..725a0572 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -6,7 +6,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.response.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -23,8 +23,8 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { - return WaitingResponse.builder() + public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank) { + return MemberWaitingResponse.builder() .waitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java similarity index 87% rename from src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java index af4106dc..eaba99df 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java @@ -3,7 +3,7 @@ import lombok.Builder; @Builder -public record WaitingResponse( +public record MemberWaitingResponse( Long waitingId, Long shopId, String shopName, diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 4025e774..631dad9f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -15,8 +15,8 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalDate; @@ -39,7 +39,7 @@ public class MemberWaitingService { private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; - public WaitingResponse createWaiting(Long shopId, Long memberId, + public MemberWaitingResponse createWaiting(Long shopId, Long memberId, CreateWaitingRequest request) { // 연관 엔티티 조회 Member member = getMemberEntity(memberId); @@ -63,7 +63,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, } @Transactional - public WaitingResponse postponeWaiting(Long memberId) { + public MemberWaitingResponse postponeWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); @@ -77,7 +77,7 @@ public WaitingResponse postponeWaiting(Long memberId) { } @Transactional - public WaitingResponse cancelWaiting(Long memberId) { + public MemberWaitingResponse cancelWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); @@ -89,7 +89,7 @@ public WaitingResponse cancelWaiting(Long memberId) { } @Transactional(readOnly = true) - public WaitingResponse getWaiting(Long memberId) { + public MemberWaitingResponse getWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index 64e7fca8..6b7a0360 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -14,8 +14,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.restdocs.RestDocsSupport; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.service.MemberWaitingService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -37,7 +37,7 @@ void createWaiting() throws Exception { CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); - WaitingResponse response = WaitingResponse.builder() + MemberWaitingResponse response = MemberWaitingResponse.builder() .waitingId(201L) .shopId(1L) .shopName("shop1") diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 1627b23b..062c6098 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -21,7 +21,7 @@ import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index d5a1d959..18d29fc0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -15,8 +15,8 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalTime; @@ -68,7 +68,7 @@ void createWaiting() { given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); //when - WaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), @@ -94,7 +94,7 @@ void postponeWaiting() { doNothing().when(waiting).decreasePostponeRemainingCount(); //when - WaitingResponse response = memberWaitingService.postponeWaiting(1L); + MemberWaitingResponse response = memberWaitingService.postponeWaiting(1L); //then assertAll( assertThat(response.peopleCount())::isNotNull, @@ -119,7 +119,7 @@ void cancelWaiting() { doNothing().when(waiting).changeStatusCanceled(); //when - WaitingResponse response = memberWaitingService.cancelWaiting(1L); + MemberWaitingResponse response = memberWaitingService.cancelWaiting(1L); //then assertAll( @@ -143,7 +143,7 @@ void getWaiting() { given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); //when - WaitingResponse response = memberWaitingService.getWaiting(1L); + MemberWaitingResponse response = memberWaitingService.getWaiting(1L); //then From e647fdc1193e1c4c887d3ccddf86508363b981ce Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:02:55 +0900 Subject: [PATCH 343/603] =?UTF-8?q?refactor=20:=20waitingRepository=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/fixture/WaitingFixture.java | 8 ++++++-- .../waiting/repository/WaitingRepositoryTest.java | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index b27f5164..2f888593 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,8 +1,13 @@ package com.prgrms.catchtable.waiting.fixture; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; + import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import java.time.LocalDateTime; +import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -17,8 +22,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - waiting.completeWaiting(); + ReflectionTestUtils.setField(waiting, "status", COMPLETED) ; return waiting; } - } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 235d142b..f8beb3a5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -14,6 +14,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -40,7 +41,6 @@ class WaitingRepositoryTest { private ShopRepository shopRepository; private Shop shop; private Member member1, member2, member3; - private Waiting yesterdayWaiting, completedWaiting, normalWaiting; @BeforeEach void setUp() { @@ -63,9 +63,9 @@ void clear() { @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test void countByShopAndCreatedAtBetween() { - yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); - completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); - normalWaiting = WaitingFixture.waiting(member3, shop, 3); + Waiting yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); + Waiting completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); + Waiting normalWaiting = WaitingFixture.waiting(member3, shop, 3); waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", @@ -78,4 +78,5 @@ void countByShopAndCreatedAtBetween() { //then assertThat(count).isEqualTo(2L); //waiting2, waiting3 } + } \ No newline at end of file From 6ab5e4e7219a394518498ef94012d331692f2eca Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:16:22 +0900 Subject: [PATCH 344/603] =?UTF-8?q?feat=20:=20waitingRepository=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 7 +++++++ .../waiting/repository/WaitingRepositoryTest.java | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 3ae6e878..d07b806c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -20,4 +21,10 @@ public interface WaitingRepository extends JpaRepository { + "where w.member = :member and w.status = :status") Optional findByMemberAndStatusWithShop(@Param("member") Member member, @Param("status") WaitingStatus status); + + @Query("select w from Waiting w where w.id in :ids") + List findByIds(@Param("ids") List ids); + + @Query("select w from Waiting w join fetch w.member where w.id = :id") + Optional findWaitingWithMember(@Param("id") Long id); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index f8beb3a5..0e45655b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -79,4 +79,17 @@ void countByShopAndCreatedAtBetween() { assertThat(count).isEqualTo(2L); //waiting2, waiting3 } + @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") + @Test + void findByIdsWithMember(){ + Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); + Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); + waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); + List waitingIds = List.of(waiting1.getId(), waiting2.getId(), waiting3.getId()); + //when + List waitings = waitingRepository.findByIds(waitingIds); + //then + Assertions.assertThat(waitings).containsExactly(waiting1, waiting2, waiting3); + } } \ No newline at end of file From edab978cc7c9b4406e081c110419aca6890bab23 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:27:18 +0900 Subject: [PATCH 345/603] =?UTF-8?q?feat=20:=20waitingLineRepository=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/BasicWaitingLineRepository.java | 6 ++++++ .../waitingline/RedisWaitingLineRepository.java | 14 ++++++++++++++ .../waitingline/WaitingLineRepository.java | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 090ef8e6..3b0b8e11 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Queue; @@ -33,6 +34,11 @@ public void entry(Long shopId, Long waitingId) { waitingLine.remove(); } + public List getShopWaitingIdsInOrder(Long shopId) { + Queue waitingLine = waitingLines.get(shopId); + return waitingLine.stream().toList(); + } + public void cancel(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); validateIfWaitingExists(waitingLine, waitingId); diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index a3407dc6..92d7b09a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -5,6 +5,8 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import lombok.RequiredArgsConstructor; @@ -41,6 +43,18 @@ public Object execute(RedisOperations operations) }); } + public List getShopWaitingIdsInOrder(Long shopId){ + List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); + if (stringList == null) { + throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); + } + List longList = new ArrayList<>(stringList.stream() + .map(Long::parseLong) + .toList()); + Collections.reverse(longList); + return longList; + } + public void entry(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); redisTemplate.execute(new SessionCallback<>() { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index f80a9d5f..20960a0f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.waiting.repository.waitingline; +import java.util.List; + public interface WaitingLineRepository { void save(Long shopId, Long waitingId); @@ -14,5 +16,7 @@ public interface WaitingLineRepository { Long getWaitingLineSize(Long shopId); + List getShopWaitingIdsInOrder(Long shopId); + void printWaitingLine(Long shopId); } From 2e9f9f1bded75163b03d5e9042e86a6ddc0791c4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 11:27:27 +0900 Subject: [PATCH 346/603] =?UTF-8?q?style=20:=20=EC=A4=84=EB=B0=94=EA=BF=88?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/member/service/MemberService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 82d85412..42f79aea 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -17,10 +17,8 @@ public class MemberService { private final MemberRepository memberRepository; - - private final JwtTokenProvider jwtTokenProvider; - private final RefreshTokenService refreshTokenService; + private final JwtTokenProvider jwtTokenProvider; @Transactional public Token oauthLogin(OAuthAttribute attributes) { From e1017f00d496bd36379d7f3f83605cda5f99d2fe Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:27:45 +0900 Subject: [PATCH 347/603] =?UTF-8?q?feat=20:=20waitingLineRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=90=9C=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicWaitingLineRepositoryTest.java | 16 ++++++++++++++++ .../RedisWaitingLineRepositoryTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 1f40cc8c..ac7f77cd 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -112,4 +113,19 @@ void cancel() { .isEqualTo(2); } + @DisplayName("특정 가게의 웨이팅 아이디를 rank 순으로 가져온다.") + @Test + void getShopWaitingIdOrder() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + List waitingIds = repository.getShopWaitingIdsInOrder(shopId); + //then + System.out.println("waitingIds = " + waitingIds); + assertThat(waitingIds.get(0)).isEqualTo(1L); + } + } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 57b18eaf..15c2e311 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -119,4 +120,19 @@ void cancel() { assertThat(repository.findRank(1L, 3L)) .isEqualTo(2); } + + @DisplayName("특정 가게의 웨이팅 아이디를 rank 순으로 가져온다.") + @Test + void getShopWaitingIdOrder() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + List waitingIds = repository.getShopWaitingIdsInOrder(shopId); + //then + System.out.println("waitingIds = " + waitingIds); + assertThat(waitingIds.get(0)).isEqualTo(1L); + } } \ No newline at end of file From d0694f537fece4f29272b03afed31bd9014093a3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:30:38 +0900 Subject: [PATCH 348/603] =?UTF-8?q?feat=20:=20owner=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/OwnerWaitingListResponse.java | 9 +++++++++ .../waiting/dto/response/OwnerWaitingResponse.java | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java new file mode 100644 index 00000000..70af4cb2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import java.util.List; +import lombok.Builder; + +@Builder +public record OwnerWaitingListResponse ( + List shopWaitings +){} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java new file mode 100644 index 00000000..763236bb --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import lombok.Builder; + +@Builder +public record OwnerWaitingResponse ( + Long waitingId, + int waitingNumber, + Long rank, + int peopleCount +){} From 63e427ea050382f99555d556466a00277a08fc36 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 11:31:14 +0900 Subject: [PATCH 349/603] =?UTF-8?q?fix=20:=20Owner=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=8B=9C,=20RefreshToken=20DB=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/owner/service/OwnerService.java | 10 +++++++++- .../catchtable/owner/service/OwnerServiceTest.java | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index e1854a7d..a31e23ba 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; @@ -25,6 +26,7 @@ public class OwnerService { private final OwnerRepository ownerRepository; private final PasswordEncoder passwordEncoder; private final JwtTokenProvider jwtTokenProvider; + private final RefreshTokenService refreshTokenService; @Transactional public JoinOwnerResponse joinOwner(JoinOwnerRequest joinOwnerRequest) { @@ -59,7 +61,7 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { //password 확인 validatePassword(loginRequest, loginOwner); - return jwtTokenProvider.createToken(loginOwner.getEmail()); + return createTotalToken(loginOwner.getEmail()); } private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) { @@ -68,4 +70,10 @@ private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) } } + private Token createTotalToken(String email){ + Token totalToken = jwtTokenProvider.createToken(email); + refreshTokenService.saveRefreshToken(totalToken); + return totalToken; + } + } diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 3c7e59e7..7c42360f 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; @@ -24,10 +25,11 @@ class OwnerServiceTest { private final OwnerRepository ownerRepository = mock(OwnerRepository.class); private final JwtTokenProvider jwtTokenProvider = mock(JwtTokenProvider.class); + private final RefreshTokenService refreshTokenService = mock(RefreshTokenService.class); private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private final OwnerService ownerService = new OwnerService(ownerRepository, passwordEncoder, - jwtTokenProvider); + jwtTokenProvider, refreshTokenService); private final String email = "abc1234@gmail.com"; private final String password = "qwer1234"; From f494bcdcd179374fe279fbb102130bdef8e443be Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:35:49 +0900 Subject: [PATCH 350/603] =?UTF-8?q?feat=20:=20dto=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=A7=A4=ED=95=91=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/dto/WaitingMapper.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 725a0572..52416bf7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -7,6 +7,10 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; +import java.util.ArrayList; +import java.util.List; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -35,4 +39,22 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .status(waiting.getStatus().getDescription()) .build(); } + + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank){ + return OwnerWaitingResponse.builder() + .waitingId(waiting.getId()) + .waitingNumber(waiting.getWaitingNumber()) + .rank(rank) + .peopleCount(waiting.getPeopleCount()) + .build(); + } + + public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings){ + long rank=1L; + List list = new ArrayList<>(); + for (Waiting waiting : waitings){ + list.add(toOwnerWaitingResponse(waiting,rank++)); + } + return new OwnerWaitingListResponse(list); + } } From 46ace9bc5b249c2fcd7c7a0615cc48a78edff7b7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 12:09:58 +0900 Subject: [PATCH 351/603] =?UTF-8?q?feat=20:=20owner=20waiting=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/OwnerWaitingService.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java new file mode 100644 index 00000000..00681ac5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -0,0 +1,36 @@ +package com.prgrms.catchtable.waiting.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class OwnerWaitingService { + + private final WaitingRepository waitingRepository; + private final WaitingLineRepository waitingLineRepository; + private final OwnerRepository ownerRepository; + + @Transactional(readOnly = true) + public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { + Owner owner = ownerRepository.findById(ownerId) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); + List waitingIds = waitingLineRepository.getShopWaitingIdsInOrder( + owner.getShop().getId()); + List waitings = waitingRepository.findByIds(waitingIds); + return toOwnerWaitingListResponse(waitings); + } +} From 7c4962f76964e47376770cdf82bf270fcaa4e7ab Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 12:10:46 +0900 Subject: [PATCH 352/603] =?UTF-8?q?feat=20:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=88=84=EB=9D=BD=EB=90=9C=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingServiceTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 18d29fc0..0443b182 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -146,7 +146,11 @@ void getWaiting() { MemberWaitingResponse response = memberWaitingService.getWaiting(1L); //then - + assertAll( + assertThat(response.peopleCount())::isNotNull, + assertThat(response.rank())::isNotNull, + assertThat(response.waitingNumber())::isNotNull + ); } From cdfea7fcb4b568ee71d527554a5c9a5311d87133 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 13:21:47 +0900 Subject: [PATCH 353/603] =?UTF-8?q?fix=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=8B=9C,=20JWT=20=ED=86=A0=ED=81=B0=EC=9D=98=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=EB=8F=84=20=ED=95=A8=EA=BB=98=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/jwt/provider/JwtTokenProvider.java | 8 +++++--- src/main/java/com/prgrms/catchtable/jwt/token/Token.java | 3 +++ .../prgrms/catchtable/member/service/MemberService.java | 3 ++- .../com/prgrms/catchtable/owner/service/OwnerService.java | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 9bc8f529..891082a1 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.jwt.provider; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.config.JwtConfig; import com.prgrms.catchtable.jwt.service.JwtUserDetailsService; import com.prgrms.catchtable.jwt.token.Token; @@ -20,18 +21,19 @@ public class JwtTokenProvider { private final JwtConfig jwtConfig; - private final JwtUserDetailsService jwtUserDetailsService; + private final String JWT_ROLE= "ROLE"; - public Token createToken(String email) { + public Token createToken(String email, Role role) { Claims claims = Jwts.claims().setSubject(email); + claims.put(JWT_ROLE, role); Date now = new Date(); String accessToken = createAccessToken(claims, now); String refreshToken = createRefreshToken(claims, now); - return new Token(accessToken, refreshToken, email); + return new Token(accessToken, refreshToken, email, role); } private String createAccessToken(Claims claims, Date now) { diff --git a/src/main/java/com/prgrms/catchtable/jwt/token/Token.java b/src/main/java/com/prgrms/catchtable/jwt/token/Token.java index f2fe8093..3af585b7 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/token/Token.java +++ b/src/main/java/com/prgrms/catchtable/jwt/token/Token.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.jwt.token; +import com.prgrms.catchtable.common.Role; import lombok.AllArgsConstructor; import lombok.Getter; @@ -12,4 +13,6 @@ public class Token { private String refreshToken; private String email; + + private Role role; } diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 42f79aea..638c897c 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.member.service; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; @@ -34,7 +35,7 @@ public Token oauthLogin(OAuthAttribute attributes) { } private Token createTotalToken(String email) { - Token totalToken = jwtTokenProvider.createToken(email); + Token totalToken = jwtTokenProvider.createToken(email, Role.MEMBER); refreshTokenService.saveRefreshToken(totalToken); return totalToken; } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index a31e23ba..a3a79eab 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_EXIST_OWNER; import static com.prgrms.catchtable.common.exception.ErrorCode.BAD_REQUEST_EMAIL_OR_PASSWORD; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; @@ -71,7 +72,7 @@ private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) } private Token createTotalToken(String email){ - Token totalToken = jwtTokenProvider.createToken(email); + Token totalToken = jwtTokenProvider.createToken(email, Role.OWNER); refreshTokenService.saveRefreshToken(totalToken); return totalToken; } From 2ca04c692019a75c45da5bbdeeb251f71412e058 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:25:35 +0900 Subject: [PATCH 354/603] =?UTF-8?q?feat=20:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 + .../owner/fixture/OwnerFixture.java | 14 +++++ .../service/MemberWaitingServiceTest.java | 2 +- .../service/OwnerWaitingServiceTest.java | 59 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index a0b3afe4..b301f2e7 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -31,6 +31,7 @@ public enum ErrorCode { INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), + NOT_EXIST_OWNER("해당 아이디의 점주가 존재하지 않습니다."), BAD_REQUEST_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 54089c3c..570b7904 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -29,6 +29,20 @@ public static Owner getOwner(String email, String password) { return owner; } + public static Owner getOwner(Shop shop){ + Owner owner = Owner.builder() + .name("ownerA") + .email("email") + .password("password") + .phoneNumber("010-3462-2480") + .gender(MALE) + .dateBirth(LocalDate.of(2000, 9, 13)) + .build(); + ReflectionTestUtils.setField(shop, "id", 1L); + owner.insertShop(shop); + return owner; + } + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ return JoinOwnerRequest.builder() .name("ownerA") diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 0443b182..bcc35fc0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -129,7 +129,7 @@ void cancelWaiting() { ); } - @DisplayName("웨이팅를 조회할 수 있다.") + @DisplayName("점주의 웨이팅를 조회할 수 있다.") @Test void getWaiting() { //given diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java new file mode 100644 index 00000000..76d17a79 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -0,0 +1,59 @@ +package com.prgrms.catchtable.waiting.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class OwnerWaitingServiceTest { + + @Mock + private OwnerRepository ownerRepository; + + @Mock + private WaitingRepository waitingRepository; + + @Mock + private WaitingLineRepository waitingLineRepository; + + @InjectMocks + private OwnerWaitingService ownerWaitingService; + + @DisplayName("owner의 waiting 목록을 모두 가져온다.") + @Test + void getOwnerAllWaiting() { + //given + List waitingIds = List.of(1L); + Owner owner = mock(Owner.class); + Shop shop = mock(Shop.class); + Waiting waiting = mock(Waiting.class); + + given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); + given(owner.getShop()).willReturn(shop); + given(shop.getId()).willReturn(1L); + given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn(waitingIds); + given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); + + //when + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); + //then + assertThat(response).isNotNull(); + } +} \ No newline at end of file From 2f5829b81b7e6e3c7a95be8976e435d92c1d11d1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:26:59 +0900 Subject: [PATCH 355/603] =?UTF-8?q?feat=20:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20controller=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java new file mode 100644 index 00000000..c907e0d9 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -0,0 +1,25 @@ +package com.prgrms.catchtable.waiting.controller; + +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.service.OwnerWaitingService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RequestMapping("owner/waitings") +@RestController +public class OwnerWaitingController { + + private final OwnerWaitingService ownerWaitingService; + + @GetMapping("/{ownerId}") + public ResponseEntity getOwnerAllWaiting( + @PathVariable("ownerId") Long ownerId) { + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(ownerId); + return ResponseEntity.ok(response); + } +} From 7afb52a037d9e50860a68e9c4887e5f961029973 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:30:49 +0900 Subject: [PATCH 356/603] =?UTF-8?q?feat:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerWaitingControllerTest.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java new file mode 100644 index 00000000..6cdaf1c8 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -0,0 +1,120 @@ +package com.prgrms.catchtable.waiting.controller; + +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; + +class OwnerWaitingControllerTest extends BaseIntegrationTest { + @Autowired + private MemberRepository memberRepository; + @Autowired + private WaitingRepository waitingRepository; + + @Autowired + private OwnerRepository ownerRepository; + + @Autowired + private WaitingLineRepository waitingLineRepository; + @Autowired + private ShopRepository shopRepository; + @Autowired + private StringRedisTemplate redisTemplate; + + private Member member1, member2, member3; + private Shop shop; + private Owner owner; + private Waiting waiting1, waiting2, waiting3; + private List waitings; + + + @BeforeEach + void setUp() { + member1 = MemberFixture.member("test1@naver.com"); + member2 = MemberFixture.member("test2@naver.com"); + member3 = MemberFixture.member("test3@naver.com"); + memberRepository.saveAll(List.of(member1, member2, member3)); + + shop = ShopFixture.shopWith24(); + shopRepository.save(shop); + + owner = OwnerFixture.getOwner(shop); + ownerRepository.save(owner); + + waiting1 = Waiting.builder() + .member(member1) + .shop(shop) + .waitingNumber(1) + .peopleCount(2) + .build(); + waiting2 = Waiting.builder() + .member(member2) + .shop(shop) + .waitingNumber(2) + .peopleCount(2) + .build(); + + waiting3 = Waiting.builder() + .member(member3) + .shop(shop) + .waitingNumber(3) + .peopleCount(2) + .build(); + + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); + waitingLineRepository.save(shop.getId(), waiting1.getId()); + waitingLineRepository.save(shop.getId(), waiting2.getId()); + waitingLineRepository.save(shop.getId(), waiting3.getId()); + } + + @AfterEach + void clear() { + redisTemplate.delete("s" + shop.getId()); + memberRepository.deleteAll(); + shopRepository.deleteAll(); + ownerRepository.deleteAll(); + waitingRepository.deleteAll(); + } + + @DisplayName("웨이팅 조회 API를 호출할 수 있다.") + @Test + void getWaiting() throws Exception { + //when, then + mockMvc.perform(get("/owner/waitings/{ownerId}", owner.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopWaitings", hasSize(3))) + .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].waitingNumber").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].rank").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].waitingNumber").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].rank").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(2)) + ; + } + +} \ No newline at end of file From f18dbdcb156edd9d23fb6e6531c722f7847bd187 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:31:38 +0900 Subject: [PATCH 357/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 9 ++++++--- .../prgrms/catchtable/waiting/dto/WaitingMapper.java | 10 +++++----- .../dto/response/OwnerWaitingListResponse.java | 6 ++++-- .../waiting/dto/response/OwnerWaitingResponse.java | 6 ++++-- .../waitingline/RedisWaitingLineRepository.java | 2 +- .../waiting/service/OwnerWaitingService.java | 1 - .../prgrms/catchtable/owner/fixture/OwnerFixture.java | 11 +++++------ .../controller/OwnerWaitingControllerTest.java | 1 + .../catchtable/waiting/fixture/WaitingFixture.java | 6 ++---- .../waiting/repository/WaitingRepositoryTest.java | 2 +- .../waiting/service/OwnerWaitingServiceTest.java | 3 ++- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 6a0e32a1..dac21df7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -26,7 +26,8 @@ public class MemberWaitingController { public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, + request); return ResponseEntity.ok(response); } @@ -38,13 +39,15 @@ public ResponseEntity postponeWaiting( } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity cancelWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } @GetMapping("/{memberId}") - public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity getWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 52416bf7..75c0e134 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -40,7 +40,7 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .build(); } - public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank){ + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank) { return OwnerWaitingResponse.builder() .waitingId(waiting.getId()) .waitingNumber(waiting.getWaitingNumber()) @@ -49,11 +49,11 @@ public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long .build(); } - public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings){ - long rank=1L; + public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings) { + long rank = 1L; List list = new ArrayList<>(); - for (Waiting waiting : waitings){ - list.add(toOwnerWaitingResponse(waiting,rank++)); + for (Waiting waiting : waitings) { + list.add(toOwnerWaitingResponse(waiting, rank++)); } return new OwnerWaitingListResponse(list); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java index 70af4cb2..d02d6e81 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java @@ -4,6 +4,8 @@ import lombok.Builder; @Builder -public record OwnerWaitingListResponse ( +public record OwnerWaitingListResponse( List shopWaitings -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java index 763236bb..e3c04197 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -3,9 +3,11 @@ import lombok.Builder; @Builder -public record OwnerWaitingResponse ( +public record OwnerWaitingResponse( Long waitingId, int waitingNumber, Long rank, int peopleCount -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 92d7b09a..2a936994 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -43,7 +43,7 @@ public Object execute(RedisOperations operations) }); } - public List getShopWaitingIdsInOrder(Long shopId){ + public List getShopWaitingIdsInOrder(Long shopId) { List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); if (stringList == null) { throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 00681ac5..d99c5300 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -9,7 +9,6 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; -import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 570b7904..bc360e20 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.owner.fixture; +import static com.prgrms.catchtable.member.domain.Gender.MALE; + import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; @@ -9,8 +10,6 @@ import java.time.LocalDate; import org.springframework.test.util.ReflectionTestUtils; -import static com.prgrms.catchtable.member.domain.Gender.MALE; - public class OwnerFixture { @@ -29,7 +28,7 @@ public static Owner getOwner(String email, String password) { return owner; } - public static Owner getOwner(Shop shop){ + public static Owner getOwner(Shop shop) { Owner owner = Owner.builder() .name("ownerA") .email("email") @@ -43,7 +42,7 @@ public static Owner getOwner(Shop shop){ return owner; } - public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password) { return JoinOwnerRequest.builder() .name("ownerA") .email(email) @@ -54,7 +53,7 @@ public static JoinOwnerRequest getJoinOwnerRequest(String email, String password .build(); } - public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password) { return LoginOwnerRequest.builder() .email(email) .password(password) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 6cdaf1c8..c52a55a3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -28,6 +28,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; class OwnerWaitingControllerTest extends BaseIntegrationTest { + @Autowired private MemberRepository memberRepository; @Autowired diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index 2f888593..b663c2c6 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,12 +1,10 @@ package com.prgrms.catchtable.waiting.fixture; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -22,7 +20,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - ReflectionTestUtils.setField(waiting, "status", COMPLETED) ; + ReflectionTestUtils.setField(waiting, "status", COMPLETED); return waiting; } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 0e45655b..91d68de5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -81,7 +81,7 @@ void countByShopAndCreatedAtBetween() { @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") @Test - void findByIdsWithMember(){ + void findByIdsWithMember() { Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 76d17a79..49ee9e9c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -48,7 +48,8 @@ void getOwnerAllWaiting() { given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); - given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn(waitingIds); + given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( + waitingIds); given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); //when From 78b12a269a794e5f5be25e1865c16921f9cbf766 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 13:34:53 +0900 Subject: [PATCH 358/603] =?UTF-8?q?feat=20:=20RefreshToken=20Role=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/jwt/domain/RefreshToken.java | 10 +++++++++- .../catchtable/jwt/service/RefreshTokenService.java | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java index b6ef9087..cbac06d6 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java +++ b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java @@ -1,9 +1,12 @@ package com.prgrms.catchtable.jwt.domain; +import static jakarta.persistence.EnumType.*; import static lombok.AccessLevel.PROTECTED; +import com.prgrms.catchtable.common.Role; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @@ -26,10 +29,15 @@ public class RefreshToken { @Column(name = "email") private String email; + @Column(name = "role") + @Enumerated(STRING) + private Role role; + @Builder - public RefreshToken(String token, String email) { + public RefreshToken(String token, String email, Role role) { this.token = token; this.email = email; + this.role = role; } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index 4d993587..d505ed88 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -2,6 +2,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_FOUND_REFRESH_TOKEN; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; @@ -19,6 +20,7 @@ public class RefreshTokenService { @Transactional public void saveRefreshToken(Token totalToken) { String email = totalToken.getEmail(); + Role role = totalToken.getRole(); if (refreshTokenRepository.existsRefreshTokenByEmail(email)) { refreshTokenRepository.deleteRefreshTokenByEmail(email); @@ -27,6 +29,7 @@ public void saveRefreshToken(Token totalToken) { RefreshToken newRefreshToken = RefreshToken.builder() .token(totalToken.getRefreshToken()) .email(email) + .role(role) .build(); refreshTokenRepository.save(newRefreshToken); From ef15862d00e59b0997f494bb63f1f9ba5304d293 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 13:36:20 +0900 Subject: [PATCH 359/603] =?UTF-8?q?fix=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=8B=9C,=20RefreshToken=EC=9D=84=20=ED=86=B5=ED=95=B4=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=AC=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java index eb1781c5..e71bca0c 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/prgrms/catchtable/jwt/filter/JwtAuthenticationFilter.java @@ -2,6 +2,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.TOKEN_EXPIRES; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; @@ -48,7 +49,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha RefreshToken refreshTokenEntity = refreshTokenService.getRefreshTokenByToken( refreshToken); String email = refreshTokenEntity.getEmail(); - Token newToken = jwtTokenProvider.createToken(email); + Role role = refreshTokenEntity.getRole(); + Token newToken = jwtTokenProvider.createToken(email, role); ((HttpServletResponse) response).setHeader("AccessToken", newToken.getAccessToken()); From 643a0508a787940f8b3c11753ccd2aa1cb48c639 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 13:37:55 +0900 Subject: [PATCH 360/603] =?UTF-8?q?feat=20:=20Role=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20Member=EC=9D=B8=EC=A7=80=20Owner=EC=9D=B8=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EB=B6=84=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 + .../jwt/provider/JwtTokenProvider.java | 14 +++++++++++- .../jwt/service/JwtUserDetailsService.java | 22 ++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index a0b3afe4..c3bc04a7 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -7,6 +7,7 @@ @RequiredArgsConstructor public enum ErrorCode { NOT_EXIST_MEMBER("존재하지 않는 회원입니다."), + NOT_EXIST_OWNER("존재하지 않는 점주입니다."), NOT_FOUND_REFRESH_TOKEN("유효하지 않은 RefreshToken입니다."), TOKEN_EXPIRES("토큰이 만료되었습니다. 다시 로그인 해 주세요."), diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 891082a1..2b1b5808 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -75,7 +75,9 @@ public boolean validateToken(String token) { public Authentication getAuthentication(String token) { String email = getEmail(token); - UserDetails userDetails = jwtUserDetailsService.loadUserByUsername(email); + Role role = getRole(token); + + UserDetails userDetails = jwtUserDetailsService.loadUserByUsername(email, role); return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); } @@ -89,4 +91,14 @@ private String getEmail(String token) { return claims.getSubject(); } + + private Role getRole(String token){ + Claims claims = Jwts.parserBuilder() + .setSigningKey(jwtConfig.getClientSecret()) + .build() + .parseClaimsJws(token) + .getBody(); + + return (Role) claims.get(JWT_ROLE); + } } diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java index e445d69e..9d0b2398 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java @@ -1,24 +1,34 @@ package com.prgrms.catchtable.jwt.service; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor -public class JwtUserDetailsService implements UserDetailsService { +public class JwtUserDetailsService{ private final MemberRepository memberRepository; + private final OwnerRepository ownerRepository; - @Override - public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { - return memberRepository.findMemberByEmail(email) - .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_MEMBER)); + public UserDetails loadUserByUsername(String email, Role role) throws UsernameNotFoundException { + + if(role.equals(Role.MEMBER)){ + return memberRepository.findMemberByEmail(email) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_MEMBER)); + } + + else{ + return ownerRepository.findOwnerByEmail(email) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); + } } } From c2eb81e7c45faa7a87cbb0e772d80b9a685be37e Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 14:00:56 +0900 Subject: [PATCH 361/603] =?UTF-8?q?fix=20:=20ci=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingControllerTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index c52a55a3..a006ccde 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -107,14 +107,16 @@ void getWaiting() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopWaitings", hasSize(3))) - .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].waitingNumber").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].rank").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].waitingNumber").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].rank").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(2)) + .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(waiting1.getId())) + .andExpect( + jsonPath("$.shopWaitings[0].waitingNumber").value(waiting1.getWaitingNumber())) + .andExpect(jsonPath("$.shopWaitings[0].rank").value(1L)) + .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(waiting1.getPeopleCount())) + .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(waiting2.getId())) + .andExpect( + jsonPath("$.shopWaitings[1].waitingNumber").value(waiting2.getWaitingNumber())) + .andExpect(jsonPath("$.shopWaitings[1].rank").value(2L)) + .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(waiting2.getPeopleCount())) ; } From 54f28ee5be9f3ae9bcec9cd5924506a1cbe73df4 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:15:56 +0900 Subject: [PATCH 362/603] =?UTF-8?q?feat=20:=20=EC=A0=90=EC=A3=BC=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EC=A1=B0=ED=9A=8C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9E=98=EB=AA=BB=EB=90=98=EC=96=B4=EC=84=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerReservationControllerTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index e2d7ef7b..bfd436ed 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -91,11 +91,13 @@ void modifyReservationStatus() throws Exception { @Test @DisplayName("점주는 예약된 정보들을 전체 조회할 수 있다.") void getAllReservation() throws Exception { - List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + Owner owner = ownerRepository.findAll().get(0); + + List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId(owner.getShop().getId()); Reservation reservation1 = reservations.get(0); Reservation reservation2 = reservations.get(1); - Owner owner = ownerRepository.findAll().get(0); + mockMvc.perform(get("/owners/shop") .contentType(APPLICATION_JSON) From d799c9bcef7671c33b04f076be94e5204b3e0013 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:16:20 +0900 Subject: [PATCH 363/603] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=EC=9D=98?= =?UTF-8?q?=20=EC=98=88=EC=95=BD=20=EC=A0=84=EC=B2=B4=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index ecbaa85e..92f791b7 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -4,11 +4,14 @@ import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; import com.prgrms.catchtable.reservation.service.MemberReservationService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -48,4 +51,9 @@ public ResponseEntity cancelReservation( @PathVariable("reservationId") Long reservationId) { return ResponseEntity.ok(memberReservationService.cancelReservation(reservationId)); } + + @GetMapping + public ResponseEntity> getAllReservation(){ + return ResponseEntity.ok(memberReservationService.getAllReservation()); + } } From 380aa9891d81e782e3bc4647d8bda526160e789d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:16:31 +0900 Subject: [PATCH 364/603] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=EC=9D=98?= =?UTF-8?q?=20=EC=98=88=EC=95=BD=20=EC=A0=84=EC=B2=B4=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberReservationControllerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index efadbc71..51995833 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -172,4 +173,20 @@ void cancelReservation() throws Exception { .andExpect(jsonPath("$.status").value(CANCELLED.toString())); } + @Test + @DisplayName("회원은 자신의 예약내역을 조회할 수 있다.") + void getAllReservation() throws Exception { + Reservation reservation = ReservationFixture.getReservation( + reservationTimeRepository.findAll().get(0)); + + Reservation savedReservation = reservationRepository.save(reservation); + + mockMvc.perform(get("/reservations")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$[0].reservationId").value(savedReservation.getId())) + .andExpect(jsonPath("$[0].date").value(savedReservation.getReservationTime().getTime().toString())) + .andExpect(jsonPath("$[0].peopleCount").value(savedReservation.getPeopleCount())) + .andExpect(jsonPath("$[0].shopName").value(savedReservation.getShop().getName())); + } + } \ No newline at end of file From 69e2b4741092ab8135ad9b8a49b9ce1b34e11e32 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 14:16:49 +0900 Subject: [PATCH 365/603] =?UTF-8?q?fix=20:=20Test=20=EA=B9=A8=EC=A7=90=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/provider/JwtTokenProviderTest.java | 9 +++++---- .../jwt/service/JwtUserDetailsServiceTest.java | 5 +++-- .../catchtable/jwt/service/RefreshTokenServiceTest.java | 7 ++++--- .../catchtable/owner/controller/OwnerControllerTest.java | 3 ++- .../catchtable/owner/service/OwnerServiceTest.java | 5 +++-- .../security/controller/JwtAuthenticationTest.java | 3 ++- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java index 54c2a606..10c7d27d 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/provider/JwtTokenProviderTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.config.JwtConfig; import com.prgrms.catchtable.jwt.service.JwtUserDetailsService; import com.prgrms.catchtable.jwt.token.Token; @@ -34,7 +35,7 @@ void validToken() { when(config.getClientSecret()).thenReturn(clientKey); when(config.getExpiryMinute()).thenReturn(1); when(config.getExpiryMinuteRefresh()).thenReturn(1); - Token token = jwtTokenProvider.createToken(email); + Token token = jwtTokenProvider.createToken(email, Role.MEMBER); //then assertThat(jwtTokenProvider.validateToken(token.getAccessToken())).isTrue(); @@ -48,7 +49,7 @@ void invalidToken() { when(config.getClientSecret()).thenReturn(clientKey); when(config.getExpiryMinute()).thenReturn(0); when(config.getExpiryMinuteRefresh()).thenReturn(0); - Token token = jwtTokenProvider.createToken(email); + Token token = jwtTokenProvider.createToken(email, Role.OWNER); //then assertThat(jwtTokenProvider.validateToken(token.getAccessToken())).isFalse(); @@ -65,9 +66,9 @@ void getAuthenticationTest() { when(config.getClientSecret()).thenReturn(clientKey); when(config.getExpiryMinute()).thenReturn(1); when(config.getExpiryMinuteRefresh()).thenReturn(1); - Token token = jwtTokenProvider.createToken(email); + Token token = jwtTokenProvider.createToken(email, Role.MEMBER); - when(jwtUserDetailsService.loadUserByUsername(email)) + when(jwtUserDetailsService.loadUserByUsername(email, Role.MEMBER)) .thenReturn(member); //then diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java index b2e47ce9..c5655c04 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsServiceTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; @@ -37,9 +38,9 @@ void loadUserByUsernameTest() { when(memberRepository.findMemberByEmail(invalidEmail)).thenReturn(Optional.empty()); //then - assertThat(jwtUserDetailsService.loadUserByUsername(email)).isEqualTo(member); + assertThat(jwtUserDetailsService.loadUserByUsername(email, Role.MEMBER)).isEqualTo(member); assertThatThrownBy( - () -> jwtUserDetailsService.loadUserByUsername(invalidEmail)).isInstanceOf( + () -> jwtUserDetailsService.loadUserByUsername(invalidEmail, Role.MEMBER)).isInstanceOf( NotFoundCustomException.class); } diff --git a/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java b/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java index 06e57f20..f5cc9660 100644 --- a/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/jwt/service/RefreshTokenServiceTest.java @@ -9,6 +9,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.jwt.config.JwtConfig; import com.prgrms.catchtable.jwt.domain.RefreshToken; @@ -45,7 +46,7 @@ void init() { when(jwtConfig.getClientSecret()).thenReturn(clientSecretKey); when(jwtConfig.getExpiryMinute()).thenReturn(1); when(jwtConfig.getExpiryMinuteRefresh()).thenReturn(1); - token = jwtTokenProvider.createToken(email); + token = jwtTokenProvider.createToken(email, Role.OWNER); } @Test @@ -65,7 +66,7 @@ void saveRefreshTokenTest() { @DisplayName("이미 유효한 RefreshToken을 갖고 있는 유저가 RefreshToken을 새로 발급한다면, DB에서 삭제 후 저장해준다.") void deleteAndSaveRefreshToken() { //given - Token newToken = jwtTokenProvider.createToken(email); + Token newToken = jwtTokenProvider.createToken(email, Role.OWNER); //when when(refreshTokenRepository.existsRefreshTokenByEmail(email)).thenReturn(true); @@ -83,7 +84,7 @@ void deleteAndSaveRefreshToken() { void getRefreshTokenTest() { //given String invalidEmail = "qwer1234@naver.com"; - Token invalidToken = jwtTokenProvider.createToken(invalidEmail); + Token invalidToken = jwtTokenProvider.createToken(invalidEmail, Role.OWNER); RefreshToken refreshToken = RefreshToken.builder() .token(token.getRefreshToken()) diff --git a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java index d5d9dab2..10ab321b 100644 --- a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java @@ -5,6 +5,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.token.Token; @@ -73,7 +74,7 @@ void loginTest() throws Exception { //given LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(joinEmail, password); - Token token = jwtTokenProvider.createToken(joinEmail); + Token token = jwtTokenProvider.createToken(joinEmail, Role.OWNER); //then mockMvc.perform(post("/owners/login") diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 7c42360f..1ae96379 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; @@ -77,12 +78,12 @@ void loginSuccess() { //given LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); String encodePassword = passwordEncoder.encode(password); - Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email()); + Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email(), Role.OWNER); //when when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( Optional.of(OwnerFixture.getOwner(email, encodePassword))); - when(jwtTokenProvider.createToken(loginOwnerRequest.email())).thenReturn(token); + when(jwtTokenProvider.createToken(loginOwnerRequest.email(), Role.OWNER)).thenReturn(token); //then assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(token); diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index b1222c44..84403d07 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -3,6 +3,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; @@ -55,7 +56,7 @@ public void init() { memberRepository.save(loginMember); //토큰 발급 - token = jwtTokenProvider.createToken(email); + token = jwtTokenProvider.createToken(email, Role.MEMBER); refreshTokenService.saveRefreshToken(token); //필터 추가 From 74b370305aa44d9bc510a1ded925315867f567b2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:17:19 +0900 Subject: [PATCH 366/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationController.java | 2 +- .../catchtable/owner/controller/OwnerControllerTest.java | 2 +- .../prgrms/catchtable/owner/fixture/OwnerFixture.java | 9 ++++----- .../catchtable/owner/service/OwnerServiceTest.java | 6 ++++-- .../controller/MemberReservationControllerTest.java | 3 ++- .../controller/OwnerReservationControllerTest.java | 5 ++--- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index 92f791b7..3c60ec8c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -53,7 +53,7 @@ public ResponseEntity cancelReservation( } @GetMapping - public ResponseEntity> getAllReservation(){ + public ResponseEntity> getAllReservation() { return ResponseEntity.ok(memberReservationService.getAllReservation()); } } diff --git a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java index d5d9dab2..01d31e26 100644 --- a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.owner.controller; -import static org.springframework.http.MediaType.*; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 54089c3c..090a716a 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.owner.fixture; +import static com.prgrms.catchtable.member.domain.Gender.MALE; + import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; @@ -9,8 +10,6 @@ import java.time.LocalDate; import org.springframework.test.util.ReflectionTestUtils; -import static com.prgrms.catchtable.member.domain.Gender.MALE; - public class OwnerFixture { @@ -29,7 +28,7 @@ public static Owner getOwner(String email, String password) { return owner; } - public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password) { return JoinOwnerRequest.builder() .name("ownerA") .email(email) @@ -40,7 +39,7 @@ public static JoinOwnerRequest getJoinOwnerRequest(String email, String password .build(); } - public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password) { return LoginOwnerRequest.builder() .email(email) .password(password) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 3c7e59e7..3e313748 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.owner.service; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -105,7 +106,8 @@ void loginFailureId() { @DisplayName("비밀번호가 다르면 로그인을 실패한다.") void loginFailurePassword() { //given - LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, wrongPassword); + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, + wrongPassword); String encodePassword = passwordEncoder.encode(password); //when diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 51995833..a5971ca6 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -184,7 +184,8 @@ void getAllReservation() throws Exception { mockMvc.perform(get("/reservations")) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].reservationId").value(savedReservation.getId())) - .andExpect(jsonPath("$[0].date").value(savedReservation.getReservationTime().getTime().toString())) + .andExpect(jsonPath("$[0].date").value( + savedReservation.getReservationTime().getTime().toString())) .andExpect(jsonPath("$[0].peopleCount").value(savedReservation.getPeopleCount())) .andExpect(jsonPath("$[0].shopName").value(savedReservation.getShop().getName())); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index bfd436ed..18a452a4 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -93,12 +93,11 @@ void modifyReservationStatus() throws Exception { void getAllReservation() throws Exception { Owner owner = ownerRepository.findAll().get(0); - List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId(owner.getShop().getId()); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId( + owner.getShop().getId()); Reservation reservation1 = reservations.get(0); Reservation reservation2 = reservations.get(1); - - mockMvc.perform(get("/owners/shop") .contentType(APPLICATION_JSON) .content(asJsonString(owner.getId()))) From cc2196386eed5441698cb4ea358c218d68bed276 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:32:26 +0900 Subject: [PATCH 367/603] =?UTF-8?q?refactor=20:=20=EC=84=A0=EC=A0=90?= =?UTF-8?q?=EC=97=AC=EB=B6=80,=20=EC=B0=A8=EC=A7=80=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/domain/ReservationTime.java | 16 ++++++++-------- .../service/MemberReservationService.java | 4 ++-- .../service/OwnerReservationService.java | 2 +- .../reservation/service/ReservationAsync.java | 4 ++-- .../MemberReservationControllerTest.java | 2 +- .../OwnerReservationControllerTest.java | 4 ++-- .../reservation/domain/ReservationTimeTest.java | 4 ++-- .../reservation/fixture/ReservationFixture.java | 6 +++--- .../service/MemberReservationServiceTest.java | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 880cf168..11852b38 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -47,14 +47,6 @@ public ReservationTime(LocalDateTime time) { this.isOccupied = false; } - public void reverseOccupied() { - this.isOccupied = !this.isOccupied; - } - - public void reversePreOccupied() { - this.isPreOccupied = !this.isPreOccupied; - } - public void insertShop(Shop shop) { this.shop = shop; } @@ -66,4 +58,12 @@ public void setOccupiedTrue() { public void setOccupiedFalse() { this.isOccupied = false; } + + public void setPreOccupiedTrue(){ + this.isPreOccupied = true; + } + + public void setPreOccupiedFalse(){ + this.isPreOccupied = false; + } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 370ff11a..26c93b61 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -79,7 +79,7 @@ public CreateReservationResponse registerReservation(CreateReservationRequest re validateIsOccupied(reservationTime); - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); Reservation reservation = Reservation.builder() .status(COMPLETED) @@ -133,7 +133,7 @@ public CancelReservationResponse cancelReservation(Long reservationId) { ReservationTime reservationTime = reservation.getReservationTime(); // 해당 예약의 예약시간 차지 여부 true로 변경 - reservationTime.reverseOccupied(); + reservationTime.setOccupiedFalse(); return toCancelReservationResponse(reservation); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 085d99e4..68398914 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -50,7 +50,7 @@ public void modifyReservationStatus( reservation.changeStatus(modifyStatus); // 해당 예약의 상태를 요청으로 들어온 상태로 변경 - reservation.getReservationTime().reverseOccupied(); // 해당 예약의 예약시간을 빈 상태로 변경 + reservation.getReservationTime().setOccupiedFalse(); // 해당 예약의 예약시간을 빈 상태로 변경 } /** diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index e8a82518..54fc2ff6 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -14,10 +14,10 @@ public class ReservationAsync { @Transactional public void setPreOcuppied(ReservationTime reservationTime) { - reservationTime.reversePreOccupied(); + reservationTime.setPreOccupiedTrue(); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - scheduler.schedule(reservationTime::reversePreOccupied, 2, TimeUnit.SECONDS); + scheduler.schedule(reservationTime::setPreOccupiedFalse, 2, TimeUnit.SECONDS); scheduler.shutdown(); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index efadbc71..bb988c5c 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -109,7 +109,7 @@ void resigerReservation() throws Exception { @DisplayName("이미 예약이 된 시간에 대해 예약 등록 api 호출 시 에러 메세지가 반환된다.") void registerReservationWithException() throws Exception { ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); List shops = shopRepository.findAll(); Shop shop = shops.get(0); reservationTime.insertShop(shop); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index e2d7ef7b..d474e31e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -49,7 +49,7 @@ void setUp() { ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(shop); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - savedReservationTime.reverseOccupied(); + savedReservationTime.setOccupiedTrue(); log.info("예약 시간 차지 여부 : {}", savedReservationTime.isOccupied()); Reservation reservation = reservationRepository.save( ReservationFixture.getReservation(savedReservationTime)); @@ -57,7 +57,7 @@ void setUp() { ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); reservationTime2.insertShop(shop); ReservationTime savedReservationTime2 = reservationTimeRepository.save(reservationTime2); - savedReservationTime2.reverseOccupied(); + savedReservationTime2.setOccupiedTrue(); log.info("예약 시간 차지 여부 : {}", savedReservationTime.isOccupied()); Reservation reservation2 = reservationRepository.save( ReservationFixture.getReservation(savedReservationTime2)); diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java index a79fc8c4..91a38a0d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -12,7 +12,7 @@ class ReservationTimeTest { @DisplayName("예약 선점 여부 변경에 성공한다") void reversePreOccupied() { ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - reservationTime.reversePreOccupied(); + reservationTime.setPreOccupiedTrue(); assertThat(reservationTime.isPreOccupied()).isTrue(); } @@ -21,7 +21,7 @@ void reversePreOccupied() { @DisplayName("예약 여부 변경에 성공한다.") void reverseOccupied() { ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); assertThat(reservationTime.isOccupied()).isTrue(); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index 6346992f..e299f0c7 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -18,7 +18,7 @@ public class ReservationFixture { public static Reservation getReservation(ReservationTime reservationTime) { if (!reservationTime.isOccupied()) { - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); } return Reservation.builder() .status(COMPLETED) @@ -42,7 +42,7 @@ public static ReservationTime getReservationTimePreOccupied() { Shop shop = ShopData.getShop(); ReflectionTestUtils.setField(shop, "id", 1L); reservationTime.insertShop(shop); - reservationTime.reversePreOccupied(); + reservationTime.setPreOccupiedTrue(); return reservationTime; } @@ -84,7 +84,7 @@ public static ReservationTime getReservationTimeOccupied() { Shop shop = ShopData.getShop(); ReflectionTestUtils.setField(shop, "id", 1L); reservationTime.insertShop(shop); - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); return reservationTime; } diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 0f6abeb2..02b110db 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -126,7 +126,7 @@ void registerReservationAlreadyOccupied() { ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); - reservationTime.reverseOccupied(); + reservationTime.setOccupiedTrue(); when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( Optional.of(reservationTime)); From 2baa5ce80bd0a4eadc61acd704b40e6ad217f209 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:35:48 +0900 Subject: [PATCH 368/603] =?UTF-8?q?refactor=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20Disabled(=EB=B9=8C?= =?UTF-8?q?=EB=93=9C=20=EC=86=8D=EB=8F=84=20=ED=96=A5=EC=83=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationControllerTest.java | 3 ++- .../service/MemberReservationServiceIntegrationTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index bb988c5c..d4325dff 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -23,6 +23,7 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +67,7 @@ void preOccupyReservation() throws Exception { .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); } - + @Disabled @Test @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") void schedulerTest() throws Exception { diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index 681eae52..afedc84a 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -16,6 +16,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -41,7 +42,7 @@ void setUp() { reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); } - + @Disabled @Test @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") void concurrencyTest() throws InterruptedException { From 1a411c474205edeca4d63ba1c357c6d7605756ad Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 14:36:28 +0900 Subject: [PATCH 369/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/ReservationTime.java | 4 ++-- .../catchtable/owner/controller/OwnerControllerTest.java | 2 +- .../prgrms/catchtable/owner/fixture/OwnerFixture.java | 9 ++++----- .../catchtable/owner/service/OwnerServiceTest.java | 6 ++++-- .../controller/MemberReservationControllerTest.java | 1 + .../service/MemberReservationServiceIntegrationTest.java | 1 + 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 11852b38..28d52594 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -59,11 +59,11 @@ public void setOccupiedFalse() { this.isOccupied = false; } - public void setPreOccupiedTrue(){ + public void setPreOccupiedTrue() { this.isPreOccupied = true; } - public void setPreOccupiedFalse(){ + public void setPreOccupiedFalse() { this.isPreOccupied = false; } } diff --git a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java index d5d9dab2..01d31e26 100644 --- a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.owner.controller; -import static org.springframework.http.MediaType.*; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 54089c3c..090a716a 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.owner.fixture; +import static com.prgrms.catchtable.member.domain.Gender.MALE; + import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; @@ -9,8 +10,6 @@ import java.time.LocalDate; import org.springframework.test.util.ReflectionTestUtils; -import static com.prgrms.catchtable.member.domain.Gender.MALE; - public class OwnerFixture { @@ -29,7 +28,7 @@ public static Owner getOwner(String email, String password) { return owner; } - public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password) { return JoinOwnerRequest.builder() .name("ownerA") .email(email) @@ -40,7 +39,7 @@ public static JoinOwnerRequest getJoinOwnerRequest(String email, String password .build(); } - public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password) { return LoginOwnerRequest.builder() .email(email) .password(password) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 3c7e59e7..3e313748 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.owner.service; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -105,7 +106,8 @@ void loginFailureId() { @DisplayName("비밀번호가 다르면 로그인을 실패한다.") void loginFailurePassword() { //given - LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, wrongPassword); + LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, + wrongPassword); String encodePassword = passwordEncoder.encode(password); //when diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index d4325dff..a2b5a1b8 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -67,6 +67,7 @@ void preOccupyReservation() throws Exception { .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); } + @Disabled @Test @DisplayName("선점 api 호출 시 선점권이 획득 되었다가 지정 시간 이후에 획득이 풀린다.") diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index afedc84a..c6a5f337 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -42,6 +42,7 @@ void setUp() { reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); } + @Disabled @Test @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") From 259d358dc945da73ac11379b80f8a1edca782a4b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 14:49:20 +0900 Subject: [PATCH 370/603] =?UTF-8?q?feat=20:=20ErrorCode=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20&=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 ++-- .../java/com/prgrms/catchtable/member/domain/Gender.java | 4 ++-- .../com/prgrms/catchtable/owner/service/OwnerService.java | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index c3bc04a7..295993f8 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -32,8 +32,8 @@ public enum ErrorCode { INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), - BAD_REQUEST_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), - BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); + INVALID_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), + INVALID_INPUT_TYPE("잘못된 타입입니다."); private final String message; } \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java index a5449d29..a5d2e1cf 100644 --- a/src/main/java/com/prgrms/catchtable/member/domain/Gender.java +++ b/src/main/java/com/prgrms/catchtable/member/domain/Gender.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.member.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.BAD_REQUEST_INPUT_GENDER_TYPE; +import static com.prgrms.catchtable.common.exception.ErrorCode.INVALID_INPUT_TYPE; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import java.util.Arrays; @@ -19,7 +19,7 @@ public static Gender of(String input) { return Arrays.stream(values()) .filter(gender -> gender.isEqual(input)) .findAny() - .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_INPUT_GENDER_TYPE)); + .orElseThrow(() -> new BadRequestCustomException(INVALID_INPUT_TYPE)); } private boolean isEqual(String input) { diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index a3a79eab..e1e9bf91 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.owner.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_EXIST_OWNER; -import static com.prgrms.catchtable.common.exception.ErrorCode.BAD_REQUEST_EMAIL_OR_PASSWORD; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -57,7 +56,7 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { //email 확인 Owner loginOwner = ownerRepository.findOwnerByEmail(loginRequest.email()) - .orElseThrow(() -> new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD)); + .orElseThrow(() -> new BadRequestCustomException(INVALID_EMAIL_OR_PASSWORD)); //password 확인 validatePassword(loginRequest, loginOwner); @@ -67,7 +66,7 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) { if (!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())) { - throw new BadRequestCustomException(BAD_REQUEST_EMAIL_OR_PASSWORD); + throw new BadRequestCustomException(INVALID_EMAIL_OR_PASSWORD); } } From 53ab8d50e829c88fb3c734bb02c9f085fbfac3ff Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 14:49:54 +0900 Subject: [PATCH 371/603] =?UTF-8?q?feat=20:=20Enum=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/Role.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/common/Role.java b/src/main/java/com/prgrms/catchtable/common/Role.java index b8b13051..487d631a 100644 --- a/src/main/java/com/prgrms/catchtable/common/Role.java +++ b/src/main/java/com/prgrms/catchtable/common/Role.java @@ -1,5 +1,9 @@ package com.prgrms.catchtable.common; +import static com.prgrms.catchtable.common.exception.ErrorCode.INVALID_INPUT_TYPE; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import java.util.Arrays; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,4 +15,15 @@ public enum Role { OWNER("ROLE_OWNER"); private final String role; + + public static Role of(String type){ + return Arrays.stream(values()) + .filter(role -> role.isEqual(type)) + .findAny() + .orElseThrow(() -> new BadRequestCustomException(INVALID_INPUT_TYPE)); + } + + private boolean isEqual(String input) { + return input.equals(this.role); + } } From bb18e67f60ca16bcf948f39753f367180379ddd2 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 14:50:28 +0900 Subject: [PATCH 372/603] =?UTF-8?q?fix=20:=20JWT=EC=97=90=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=EC=9D=84=20=EB=AC=B8=EC=9E=90=EC=97=B4=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/jwt/provider/JwtTokenProvider.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 2b1b5808..54b73646 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -27,7 +27,7 @@ public class JwtTokenProvider { public Token createToken(String email, Role role) { Claims claims = Jwts.claims().setSubject(email); - claims.put(JWT_ROLE, role); + claims.put(JWT_ROLE, role.getRole()); Date now = new Date(); String accessToken = createAccessToken(claims, now); @@ -99,6 +99,8 @@ private Role getRole(String token){ .parseClaimsJws(token) .getBody(); - return (Role) claims.get(JWT_ROLE); + String role = (String) claims.get(JWT_ROLE); + + return Role.of(role); } } From 7379d2c91cc762968358e3605367de8b383cdd53 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 14:57:59 +0900 Subject: [PATCH 373/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/common/Role.java | 2 +- .../prgrms/catchtable/jwt/domain/RefreshToken.java | 2 +- .../catchtable/jwt/provider/JwtTokenProvider.java | 4 ++-- .../catchtable/jwt/service/JwtUserDetailsService.java | 11 +++++------ .../prgrms/catchtable/owner/service/OwnerService.java | 5 +++-- .../reservation/service/OwnerReservationService.java | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/Role.java b/src/main/java/com/prgrms/catchtable/common/Role.java index 487d631a..f2e3d637 100644 --- a/src/main/java/com/prgrms/catchtable/common/Role.java +++ b/src/main/java/com/prgrms/catchtable/common/Role.java @@ -16,7 +16,7 @@ public enum Role { private final String role; - public static Role of(String type){ + public static Role of(String type) { return Arrays.stream(values()) .filter(role -> role.isEqual(type)) .findAny() diff --git a/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java index cbac06d6..b53ca7b9 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java +++ b/src/main/java/com/prgrms/catchtable/jwt/domain/RefreshToken.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.jwt.domain; -import static jakarta.persistence.EnumType.*; +import static jakarta.persistence.EnumType.STRING; import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.Role; diff --git a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java index 54b73646..fe46bf71 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java +++ b/src/main/java/com/prgrms/catchtable/jwt/provider/JwtTokenProvider.java @@ -22,7 +22,7 @@ public class JwtTokenProvider { private final JwtConfig jwtConfig; private final JwtUserDetailsService jwtUserDetailsService; - private final String JWT_ROLE= "ROLE"; + private final String JWT_ROLE = "ROLE"; public Token createToken(String email, Role role) { @@ -92,7 +92,7 @@ private String getEmail(String token) { return claims.getSubject(); } - private Role getRole(String token){ + private Role getRole(String token) { Claims claims = Jwts.parserBuilder() .setSigningKey(jwtConfig.getClientSecret()) .build() diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java index 9d0b2398..04caf6b4 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/JwtUserDetailsService.java @@ -14,19 +14,18 @@ @Service @RequiredArgsConstructor -public class JwtUserDetailsService{ +public class JwtUserDetailsService { private final MemberRepository memberRepository; private final OwnerRepository ownerRepository; - public UserDetails loadUserByUsername(String email, Role role) throws UsernameNotFoundException { + public UserDetails loadUserByUsername(String email, Role role) + throws UsernameNotFoundException { - if(role.equals(Role.MEMBER)){ + if (role.equals(Role.MEMBER)) { return memberRepository.findMemberByEmail(email) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_MEMBER)); - } - - else{ + } else { return ownerRepository.findOwnerByEmail(email) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index e1e9bf91..3998044c 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.owner.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_EXIST_OWNER; +import static com.prgrms.catchtable.common.exception.ErrorCode.INVALID_EMAIL_OR_PASSWORD; import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -70,7 +71,7 @@ private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) } } - private Token createTotalToken(String email){ + private Token createTotalToken(String email) { Token totalToken = jwtTokenProvider.createToken(email, Role.OWNER); refreshTokenService.saveRefreshToken(totalToken); return totalToken; diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 6972ccf3..085d99e4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -40,7 +40,7 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 - if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + if (modifyStatus == COMPLETED) { // 취소, 노쇼 처리가 아닌 경우 예외 throw new BadRequestCustomException(ALREADY_COMPLETED_RESERVATION); } From 5616b5f8bf390d9066a027a2e303edc5b551c313 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 15:17:01 +0900 Subject: [PATCH 374/603] fix : conflict resolve --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 295993f8..8b9662cd 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -18,6 +18,7 @@ public enum ErrorCode { NOT_EXIST_RESERVATION("존재하지 않는 예약입니다"), EXCEED_PEOPLE_COUNT("예약인원이 해당 시간의 남은 수용가능 인원 수를 초과했습니다."), ALREADY_COMPLETED_RESERVATION("이미 예약 상태인 예약입니다."), + SLACK_ID_IS_WRONG("요청한 슬랙 Id를 찾을 수 없거나 잘못 되었습니다"), CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), @@ -33,7 +34,7 @@ public enum ErrorCode { ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), INVALID_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), - INVALID_INPUT_TYPE("잘못된 타입입니다."); + INVALID_INPUT_TYPE("성별 타입을 양식대로 입력해주세요"); private final String message; } \ No newline at end of file From e1e91da40c06e707fb19ea9fc9d5c1560cf4293e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Mon, 8 Jan 2024 16:01:30 +0900 Subject: [PATCH 375/603] =?UTF-8?q?feat=20:=20=EB=8F=99=EC=8B=9C=EC=84=B1?= =?UTF-8?q?=20=EC=9D=B4=EC=8A=88=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=97=86?= =?UTF-8?q?=EC=95=A0=EB=8A=94=20=EA=B2=8C=20=EC=95=84=EB=8B=8C=20spin=20lo?= =?UTF-8?q?ck=20=EC=8B=9C=20=EC=8A=A4=EB=A0=88=EB=93=9C=20=EB=8C=80?= =?UTF-8?q?=EA=B8=B0=20=EC=8B=9C=EA=B0=84=20=EA=B0=90=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 2 +- .../service/MemberReservationServiceIntegrationTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 26c93b61..4505a24b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -45,7 +45,7 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r Long reservationTimeId = request.reservationTimeId(); while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { try { - Thread.sleep(1_500); + Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index c6a5f337..80bd26e0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -43,7 +43,6 @@ void setUp() { reservationTimeRepository.save(reservationTime); } - @Disabled @Test @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") void concurrencyTest() throws InterruptedException { From 5cdfadc45f3d9f6081de69b03115028d7c6454d8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:35:48 +0900 Subject: [PATCH 376/603] =?UTF-8?q?feat=20:=20basicWaitingLine=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20=EA=B2=80=EC=A6=9D=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/BasicWaitingLineRepositoryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index ac7f77cd..5be42490 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -124,8 +124,9 @@ void getShopWaitingIdOrder() { //when List waitingIds = repository.getShopWaitingIdsInOrder(shopId); //then - System.out.println("waitingIds = " + waitingIds); assertThat(waitingIds.get(0)).isEqualTo(1L); + assertThat(waitingIds.get(1)).isEqualTo(2L); + assertThat(waitingIds.get(2)).isEqualTo(3L); } } \ No newline at end of file From ec30c7ce491b0a3377891ffb52adc0d9b2aa2e89 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:47:14 +0900 Subject: [PATCH 377/603] =?UTF-8?q?refactor=20:=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=95=A8=EC=88=98=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EA=B2=80=EC=A6=9D=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index e953c7bc..f9ea780b 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,10 +1,8 @@ package com.prgrms.catchtable.waiting.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.POSTPONE_REMAINING_CNT_0; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.NO_SHOW; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; import static jakarta.persistence.EnumType.STRING; @@ -77,14 +75,10 @@ public void decreasePostponeRemainingCount() { remainingPostponeCount--; } - public void completeWaiting() { - if (status == NO_SHOW || status == CANCELED) { - throw new BadRequestCustomException(CAN_NOT_COMPLETE_WAITING); - } + public void changeStatusCompleted() { status = COMPLETED; } - public void changeStatusCanceled() { status = CANCELED; } From 08da5a3697c6d277c369816235ae6412a4fbbf34 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:51:37 +0900 Subject: [PATCH 378/603] =?UTF-8?q?refactor=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20fixture=20reflectionUtil=20=EB=8C=80=EC=8B=A0=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/fixture/WaitingFixture.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index b663c2c6..399bf936 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,11 +1,8 @@ package com.prgrms.catchtable.waiting.fixture; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; - import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -20,7 +17,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - ReflectionTestUtils.setField(waiting, "status", COMPLETED); + waiting.changeStatusCompleted(); return waiting; } } \ No newline at end of file From 5344cf7db3a03a100d3dabc756eda84cec540ac9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:05:31 +0900 Subject: [PATCH 379/603] =?UTF-8?q?feat=20:=20owner=20waiting=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerWaitingServiceTest.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 49ee9e9c..be5e82b5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -5,11 +5,13 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; @@ -40,21 +42,31 @@ class OwnerWaitingServiceTest { @Test void getOwnerAllWaiting() { //given - List waitingIds = List.of(1L); + List waitingIds = List.of(1L,2L); + Member member1 = mock(Member.class); + Member member2 = mock(Member.class); Owner owner = mock(Owner.class); Shop shop = mock(Shop.class); - Waiting waiting = mock(Waiting.class); + Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( waitingIds); - given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); + given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting1, waiting2)); //when OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); + //then - assertThat(response).isNotNull(); + assertThat(response.shopWaitings()).hasSize(2); + + assertThat(response.shopWaitings().get(0).waitingId()).isEqualTo(waiting1.getId()); + assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo(waiting1.getWaitingNumber()); + + assertThat(response.shopWaitings().get(1).waitingId()).isEqualTo(waiting2.getId()); + assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo(waiting2.getWaitingNumber()); } } \ No newline at end of file From c7477428cdba1f4ad5824bdd39209c2791cfbef5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:42:05 +0900 Subject: [PATCH 380/603] =?UTF-8?q?refactor=20:=20redis=20rank=20=EC=98=A4?= =?UTF-8?q?=EB=A6=84=EC=B0=A8=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=B4=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/RedisWaitingLineRepository.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 2a936994..e1124b5e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -44,15 +44,14 @@ public Object execute(RedisOperations operations) } public List getShopWaitingIdsInOrder(Long shopId) { - List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); - if (stringList == null) { + List waitingIds = redisTemplate.opsForList().range("s" + shopId, 0, -1); + if (waitingIds == null) { throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); } - List longList = new ArrayList<>(stringList.stream() + Collections.reverse(waitingIds); + return new ArrayList<>(waitingIds.stream() .map(Long::parseLong) .toList()); - Collections.reverse(longList); - return longList; } public void entry(Long shopId, Long waitingId) { From 0939180795ddd69c849b54d2bd60b31d3e0c69a5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:43:11 +0900 Subject: [PATCH 381/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/OwnerWaitingServiceTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index be5e82b5..d2ce0887 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -42,7 +42,7 @@ class OwnerWaitingServiceTest { @Test void getOwnerAllWaiting() { //given - List waitingIds = List.of(1L,2L); + List waitingIds = List.of(1L, 2L); Member member1 = mock(Member.class); Member member2 = mock(Member.class); Owner owner = mock(Owner.class); @@ -64,9 +64,11 @@ void getOwnerAllWaiting() { assertThat(response.shopWaitings()).hasSize(2); assertThat(response.shopWaitings().get(0).waitingId()).isEqualTo(waiting1.getId()); - assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo(waiting1.getWaitingNumber()); + assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo( + waiting1.getWaitingNumber()); assertThat(response.shopWaitings().get(1).waitingId()).isEqualTo(waiting2.getId()); - assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo(waiting2.getWaitingNumber()); + assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo( + waiting2.getWaitingNumber()); } } \ No newline at end of file From d754df39645a5409102d618bb178f85dbcfb08bc Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 8 Jan 2024 19:33:34 +0900 Subject: [PATCH 382/603] =?UTF-8?q?feat=20:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(@LogIn)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/common/login/LogIn.java | 12 +++++++ .../common/login/LogInArgumentResolver.java | 32 +++++++++++++++++++ .../catchtable/common/login/WebConfig.java | 16 ++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/login/LogIn.java create mode 100644 src/main/java/com/prgrms/catchtable/common/login/LogInArgumentResolver.java create mode 100644 src/main/java/com/prgrms/catchtable/common/login/WebConfig.java diff --git a/src/main/java/com/prgrms/catchtable/common/login/LogIn.java b/src/main/java/com/prgrms/catchtable/common/login/LogIn.java new file mode 100644 index 00000000..5a22780e --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/login/LogIn.java @@ -0,0 +1,12 @@ +package com.prgrms.catchtable.common.login; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface LogIn { + +} diff --git a/src/main/java/com/prgrms/catchtable/common/login/LogInArgumentResolver.java b/src/main/java/com/prgrms/catchtable/common/login/LogInArgumentResolver.java new file mode 100644 index 00000000..1b7cd6ef --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/login/LogInArgumentResolver.java @@ -0,0 +1,32 @@ +package com.prgrms.catchtable.common.login; + +import lombok.RequiredArgsConstructor; +import org.springframework.core.MethodParameter; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; + +@Component +@RequiredArgsConstructor +public class LogInArgumentResolver implements HandlerMethodArgumentResolver { + + @Override + public boolean supportsParameter(MethodParameter parameter) { + boolean hasLoginAnnotation = parameter.hasParameterAnnotation(LogIn.class); + boolean hasUserDetails = UserDetails.class.isAssignableFrom(parameter.getParameterType()); + + return hasLoginAnnotation && hasUserDetails; + } + + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + return authentication.getPrincipal(); + } +} diff --git a/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java new file mode 100644 index 00000000..58418bc5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java @@ -0,0 +1,16 @@ +package com.prgrms.catchtable.common.login; + +import java.util.List; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addArgumentResolvers(List resolvers){ + resolvers.add(new LogInArgumentResolver()); + } + +} From 7894d1f788e2e848672d0bccef865e1686757a2f Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 21:17:39 +0900 Subject: [PATCH 383/603] =?UTF-8?q?feat=20:=20waitingRepository=20?= =?UTF-8?q?=EC=9E=85=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/BasicWaitingLineRepository.java | 7 ++----- .../waitingline/RedisWaitingLineRepository.java | 7 ++++--- .../waitingline/WaitingLineRepository.java | 2 +- .../RedisWaitingLineRepositoryTest.java | 14 ++++++++++++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 3b0b8e11..07360875 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -26,12 +26,9 @@ public void save(Long shopId, Long waitingId) { waitingLine.add(waitingId); } - public void entry(Long shopId, Long waitingId) { + public Long entry(Long shopId) { Queue waitingLine = waitingLines.get(shopId); - if (!Objects.equals(waitingLine.peek(), waitingId)) { - throw new BadRequestCustomException(CAN_NOT_ENTRY); - } - waitingLine.remove(); + return waitingLine.remove(); } public List getShopWaitingIdsInOrder(Long shopId) { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index e1124b5e..3c5fa812 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -2,6 +2,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; +import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_LINE_EMPTY; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -54,8 +55,8 @@ public List getShopWaitingIdsInOrder(Long shopId) { .toList()); } - public void entry(Long shopId, Long waitingId) { - validateIfWaitingExists(shopId, waitingId); + public Long entry(Long shopId) { + Long waitingId = getShopWaitingIdsInOrder(shopId).get(0); redisTemplate.execute(new SessionCallback<>() { @Override public Object execute(RedisOperations operations) @@ -70,8 +71,8 @@ public Object execute(RedisOperations operations) return operations.exec(); } }); + return waitingId; } - public void cancel(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); redisTemplate.execute(new SessionCallback<>() { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 20960a0f..fe95d74e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -6,7 +6,7 @@ public interface WaitingLineRepository { void save(Long shopId, Long waitingId); - void entry(Long shopId, Long waitingId); + Long entry(Long shopId); void cancel(Long shopId, Long waitingId); diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 15c2e311..8d71cc5c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -52,10 +52,9 @@ void entry() { repository.save(shopId, 3L); //when - repository.entry(1L, 1L); + repository.entry(1L); //then - assertThrows(NotFoundCustomException.class, () -> repository.findRank(1L, 1L)); assertThat(repository.findRank(1L, 2L)) @@ -135,4 +134,15 @@ void getShopWaitingIdOrder() { System.out.println("waitingIds = " + waitingIds); assertThat(waitingIds.get(0)).isEqualTo(1L); } + + @DisplayName("웨이팅이 없으면 웨이팅 사이즈 0을 반환한다.") + @Test + void getWaitingLineSize(){ + //given + Long shopId = 1L; + //when + Long waitingLineSize = repository.getWaitingLineSize(shopId); + //then + assertThat(waitingLineSize).isZero(); + } } \ No newline at end of file From 89dbdc0abe82ddcfed24f7bf221a8996915be9dd Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 21:50:39 +0900 Subject: [PATCH 384/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9E=85=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/OwnerWaitingService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index d99c5300..a1b5f2b5 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -1,13 +1,17 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; +import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingResponse; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; @@ -32,4 +36,15 @@ public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { List waitings = waitingRepository.findByIds(waitingIds); return toOwnerWaitingListResponse(waitings); } + + @Transactional + public OwnerWaitingResponse entryWaiting(Long ownerId){ + Owner owner = ownerRepository.findById(ownerId) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); + Long enteredWaitingId = waitingLineRepository.entry(owner.getShop().getId()); + Waiting waiting = waitingRepository.findById(enteredWaitingId) + .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); + waiting.changeStatusCompleted(); + return toOwnerWaitingResponse(waiting, 0L); + } } From 1cbc8f206c1460bf4de77e815ecc920f9fd9a2de Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 21:51:10 +0900 Subject: [PATCH 385/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9E=85=EC=9E=A5=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerWaitingServiceTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index d2ce0887..558cf3b7 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -11,6 +11,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; @@ -71,4 +72,27 @@ void getOwnerAllWaiting() { assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo( waiting2.getWaitingNumber()); } + + @DisplayName("웨이팅 손님을 입장시킬 수 있다.") + @Test + void entryWaiting() { + //given + Member member = mock(Member.class); + Owner owner = mock(Owner.class); + Shop shop = mock(Shop.class); + Waiting waiting = WaitingFixture.waiting(member, shop, 1); + + given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); + given(owner.getShop()).willReturn(shop); + given(waitingLineRepository.entry(any(Long.class))).willReturn(1L); + given(waitingRepository.findById(1L)).willReturn(Optional.of(waiting)); + //when + OwnerWaitingResponse response = ownerWaitingService.entryWaiting(1L); + //then + assertThat(response.waitingId()).isEqualTo(waiting.getId()); + assertThat(response.peopleCount()).isEqualTo(2); + assertThat(response.rank()).isZero(); + assertThat(response.waitingNumber()).isEqualTo(waiting.getWaitingNumber()); + + } } \ No newline at end of file From f48f6993e1e854ae59b83f04e0353ebb2f57dcff Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 21:53:13 +0900 Subject: [PATCH 386/603] =?UTF-8?q?feat=20:=20errorCode=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 3 ++- .../repository/waitingline/BasicWaitingLineRepositoryTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index d9349316..a0b78722 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -27,7 +27,8 @@ public enum ErrorCode { POSTPONE_REMAINING_CNT_0("이미 두 차례 대기를 미뤘습니다."), CAN_NOT_CANCEL_WAITING("웨이팅 취소 처리가 불가한 상태입니다."), CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), - WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), + WAITING_DOES_NOT_EXIST("해당 아이디의 웨이팅이 존재하지 않습니다."), + WAITING_LINE_EMPTY("가게에 웨이팅이 존재하지 않습니다."), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 5be42490..89f925fb 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -30,9 +30,10 @@ void entry() { repository.save(shopId, 3L); //when - repository.entry(1L, 1L); + Long enteredWaitingId = repository.entry(1L); //then + assertThat(enteredWaitingId).isEqualTo(1L); assertThat(repository.findRank(1L, 1L)) .isEqualTo(-1); assertThat(repository.findRank(1L, 2L)) From 7f7f417224be3ac8e043fa6c914cfb681cf1384b Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 22:01:25 +0900 Subject: [PATCH 387/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9E=85=EC=9E=A5=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/OwnerWaitingController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index c907e0d9..0acc34d4 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -1,10 +1,12 @@ package com.prgrms.catchtable.waiting.controller; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.service.OwnerWaitingService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,4 +24,10 @@ public ResponseEntity getOwnerAllWaiting( OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(ownerId); return ResponseEntity.ok(response); } + + @PatchMapping("/{ownerId}") + public ResponseEntity entryWaiting(@PathVariable("ownerId") Long ownerId){ + OwnerWaitingResponse response = ownerWaitingService.entryWaiting(ownerId); + return ResponseEntity.ok(response); + } } From c383a34cf8a7aec532d7f913fe2588946ea34443 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 22:20:43 +0900 Subject: [PATCH 388/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9E=85=EC=9E=A5=20=ED=86=B5=ED=95=A9=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerWaitingControllerTest.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index a006ccde..507c6547 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.waiting.controller; +import static org.assertj.core.api.Assertions.*; import static org.hamcrest.Matchers.hasSize; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -20,12 +22,14 @@ import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; class OwnerWaitingControllerTest extends BaseIntegrationTest { @@ -44,18 +48,16 @@ class OwnerWaitingControllerTest extends BaseIntegrationTest { @Autowired private StringRedisTemplate redisTemplate; - private Member member1, member2, member3; private Shop shop; private Owner owner; private Waiting waiting1, waiting2, waiting3; - private List waitings; @BeforeEach void setUp() { - member1 = MemberFixture.member("test1@naver.com"); - member2 = MemberFixture.member("test2@naver.com"); - member3 = MemberFixture.member("test3@naver.com"); + Member member1 = MemberFixture.member("test1@naver.com"); + Member member2 = MemberFixture.member("test2@naver.com"); + Member member3 = MemberFixture.member("test3@naver.com"); memberRepository.saveAll(List.of(member1, member2, member3)); shop = ShopFixture.shopWith24(); @@ -84,7 +86,7 @@ void setUp() { .peopleCount(2) .build(); - waitings = waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); + waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); waitingLineRepository.save(shop.getId(), waiting1.getId()); waitingLineRepository.save(shop.getId(), waiting2.getId()); waitingLineRepository.save(shop.getId(), waiting3.getId()); @@ -120,4 +122,21 @@ void getWaiting() throws Exception { ; } + @DisplayName("웨이팅 입장 API를 호출할 수 있다.") + @Test + void entryWaiting() throws Exception { + //when, then + mockMvc.perform(patch("/owner/waitings/{ownerId}", owner.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.waitingId").value(waiting1.getId())) + .andExpect(jsonPath("$.waitingNumber").value(waiting1.getWaitingNumber())) + .andExpect(jsonPath("$.peopleCount").value(waiting1.getPeopleCount())) + .andExpect(jsonPath("$.rank").value(0)) + .andDo(MockMvcResultHandlers.print()); + assertThat(waitingLineRepository.getWaitingLineSize(shop.getId())).isEqualTo(2); + assertThat(waitingLineRepository.findRank(shop.getId(), waiting2.getId())).isEqualTo(1L); + assertThat(waitingLineRepository.findRank(shop.getId(), waiting3.getId())).isEqualTo(2L); + } + } \ No newline at end of file From 8fbb0c6d7c6fadbb2ff3ac6aa387fef9fb5cac2a Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 22:21:46 +0900 Subject: [PATCH 389/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/OwnerWaitingController.java | 3 ++- .../repository/waitingline/BasicWaitingLineRepository.java | 1 - .../repository/waitingline/RedisWaitingLineRepository.java | 2 +- .../prgrms/catchtable/waiting/service/OwnerWaitingService.java | 2 +- .../waiting/controller/OwnerWaitingControllerTest.java | 3 +-- .../repository/waitingline/RedisWaitingLineRepositoryTest.java | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index 0acc34d4..ee3fbfec 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -26,7 +26,8 @@ public ResponseEntity getOwnerAllWaiting( } @PatchMapping("/{ownerId}") - public ResponseEntity entryWaiting(@PathVariable("ownerId") Long ownerId){ + public ResponseEntity entryWaiting( + @PathVariable("ownerId") Long ownerId) { OwnerWaitingResponse response = ownerWaitingService.entryWaiting(ownerId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 07360875..c4acade0 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.waiting.repository.waitingline; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; -import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_ENTRY; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 3c5fa812..59df16d6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -2,7 +2,6 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_END_LINE; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; -import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_LINE_EMPTY; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -73,6 +72,7 @@ public Object execute(RedisOperations operations) }); return waitingId; } + public void cancel(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); redisTemplate.execute(new SessionCallback<>() { diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index a1b5f2b5..39bfff51 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -38,7 +38,7 @@ public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { } @Transactional - public OwnerWaitingResponse entryWaiting(Long ownerId){ + public OwnerWaitingResponse entryWaiting(Long ownerId) { Owner owner = ownerRepository.findById(ownerId) .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); Long enteredWaitingId = waitingLineRepository.entry(owner.getShop().getId()); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 507c6547..9823aeed 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.waiting.controller; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -22,7 +22,6 @@ import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 8d71cc5c..1c7761e0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -137,7 +137,7 @@ void getShopWaitingIdOrder() { @DisplayName("웨이팅이 없으면 웨이팅 사이즈 0을 반환한다.") @Test - void getWaitingLineSize(){ + void getWaitingLineSize() { //given Long shopId = 1L; //when From 2e723d0e94329be909dc06dec1dc0656c8c1da3c Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:20:39 +0900 Subject: [PATCH 390/603] =?UTF-8?q?feat=20:=20waitingFixture=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/fixture/WaitingFixture.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index 399bf936..e686972c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -6,7 +6,7 @@ public class WaitingFixture { - public static Waiting waiting(Member member, Shop shop, int waitingNumber) { + public static Waiting progressWaiting(Member member, Shop shop, int waitingNumber) { return Waiting.builder() .member(member) .shop(shop) @@ -16,8 +16,14 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { } public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { - Waiting waiting = waiting(member, shop, waitingNumber); + Waiting waiting = progressWaiting(member, shop, waitingNumber); waiting.changeStatusCompleted(); return waiting; } + + public static Waiting canceledWaiting(Member member, Shop shop, int waitingNumber) { + Waiting waiting = progressWaiting(member, shop, waitingNumber); + waiting.changeStatusCanceled(); + return waiting; + } } \ No newline at end of file From fa3f80f51f46500eeffee381e656ea3a8a248c29 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:24:12 +0900 Subject: [PATCH 391/603] =?UTF-8?q?feat=20:=20repository=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/repository/WaitingRepository.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index d07b806c..db1c814b 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -25,6 +25,8 @@ Optional findByMemberAndStatusWithShop(@Param("member") Member member, @Query("select w from Waiting w where w.id in :ids") List findByIds(@Param("ids") List ids); - @Query("select w from Waiting w join fetch w.member where w.id = :id") - Optional findWaitingWithMember(@Param("id") Long id); + @Query("select w from Waiting w " + + "join fetch w.shop " + + "join fetch w.member where w.member = :member") + List findWaitingWithMember(@Param("member") Member member); } From f8b110e21c4de57bfa6ef39cf59867c33f1a9af7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:24:56 +0900 Subject: [PATCH 392/603] =?UTF-8?q?feat=20:=20repository=20test=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B3=B4?= =?UTF-8?q?=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/WaitingRepositoryTest.java | 48 +++++++++++++++---- .../service/OwnerWaitingServiceTest.java | 6 +-- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 91d68de5..fa73759c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.waiting.repository; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static org.assertj.core.api.Assertions.assertThat; import com.prgrms.catchtable.member.MemberFixture; @@ -14,7 +15,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import org.assertj.core.api.Assertions; +import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -63,9 +64,10 @@ void clear() { @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test void countByShopAndCreatedAtBetween() { - Waiting yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); + //given + Waiting yesterdayWaiting = WaitingFixture.progressWaiting(member1, shop, 1); Waiting completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); - Waiting normalWaiting = WaitingFixture.waiting(member3, shop, 3); + Waiting normalWaiting = WaitingFixture.progressWaiting(member3, shop, 3); waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", @@ -79,17 +81,47 @@ void countByShopAndCreatedAtBetween() { assertThat(count).isEqualTo(2L); //waiting2, waiting3 } - @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") + @DisplayName("멤버의 아이디 리스트로 waiting 목록을 조회 가능하다.") @Test void findByIdsWithMember() { - Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); - Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); - Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); + Waiting waiting1 = WaitingFixture.progressWaiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.progressWaiting(member2, shop, 2); + Waiting waiting3 = WaitingFixture.progressWaiting(member3, shop, 3); waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); List waitingIds = List.of(waiting1.getId(), waiting2.getId(), waiting3.getId()); //when List waitings = waitingRepository.findByIds(waitingIds); //then - Assertions.assertThat(waitings).containsExactly(waiting1, waiting2, waiting3); + assertThat(waitings).containsExactly(waiting1, waiting2, waiting3); + } + + @DisplayName("멤버의 진행 중인 웨이팅을 조회할 수 있다.") + @Test + void findByMemberAndStatusWithShop() { + //given + Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 1); + Waiting progressWaiting = WaitingFixture.progressWaiting(member1, shop, 2); + waitingRepository.saveAll(List.of(completedWaiting, progressWaiting)); + //when + Waiting waiting = waitingRepository.findByMemberAndStatusWithShop( + member1, PROGRESS).orElseThrow(); + + //then + assertThat(waiting.getWaitingNumber()).isEqualTo(2); + } + + @DisplayName("특정 멤버의 웨이팅 목록을 조회할 수 있다.") + @Test + void findWaitingWithMember() { + //given + Waiting canceledWaiting = WaitingFixture.canceledWaiting(member1, shop, 1); + Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 2); + Waiting progressWaiting = WaitingFixture.progressWaiting(member1, shop, 3); + + waitingRepository.saveAll(List.of(canceledWaiting, completedWaiting, progressWaiting)); + //when + List memberAllWaitings = waitingRepository.findWaitingWithMember(member1); + //then + assertThat(memberAllWaitings).containsExactly(canceledWaiting, completedWaiting, progressWaiting); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 558cf3b7..844c7d02 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -48,8 +48,8 @@ void getOwnerAllWaiting() { Member member2 = mock(Member.class); Owner owner = mock(Owner.class); Shop shop = mock(Shop.class); - Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); - Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); + Waiting waiting1 = WaitingFixture.progressWaiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.progressWaiting(member2, shop, 2); given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); @@ -80,7 +80,7 @@ void entryWaiting() { Member member = mock(Member.class); Owner owner = mock(Owner.class); Shop shop = mock(Shop.class); - Waiting waiting = WaitingFixture.waiting(member, shop, 1); + Waiting waiting = WaitingFixture.progressWaiting(member, shop, 1); given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); From fdcec2736bb0fd3148af43bcbd2880f79e797e07 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:25:46 +0900 Subject: [PATCH 393/603] =?UTF-8?q?feat=20:=20=EC=9D=91=EB=8B=B5=20dto=20?= =?UTF-8?q?=EB=B0=8F=20mapper=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/dto/WaitingMapper.java | 23 ++++++++++++++++++- .../MemberWaitingHistoryListResponse.java | 8 +++++++ .../MemberWaitingHistoryResponse.java | 13 +++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 75c0e134..50e89d92 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -6,6 +6,8 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; @@ -27,7 +29,7 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank) { + public static MemberWaitingResponse toMemberWaitingResponse(Waiting waiting, Long rank) { return MemberWaitingResponse.builder() .waitingId(waiting.getId()) .shopId(waiting.getShop().getId()) @@ -40,6 +42,25 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .build(); } + public static MemberWaitingHistoryResponse toMemberWaitingHistoryResponse(Waiting waiting) { + return MemberWaitingHistoryResponse.builder() + .waitingId(waiting.getId()) + .shopId(waiting.getShop().getId()) + .shopName(waiting.getShop().getName()) + .peopleCount(waiting.getPeopleCount()) + .waitingNumber(waiting.getWaitingNumber()) + .status(waiting.getStatus().getDescription()) + .build(); + } + + public static MemberWaitingHistoryListResponse toMemberWaitingListResponse(List waitings){ + List list = new ArrayList<>(); + for (Waiting waiting : waitings) { + list.add(toMemberWaitingHistoryResponse(waiting)); + } + return new MemberWaitingHistoryListResponse(list); + } + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank) { return OwnerWaitingResponse.builder() .waitingId(waiting.getId()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java new file mode 100644 index 00000000..225ca231 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import java.util.List; + +public record MemberWaitingHistoryListResponse( + List memberWaitings +){ +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java new file mode 100644 index 00000000..737318ca --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java @@ -0,0 +1,13 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import lombok.Builder; + +@Builder +public record MemberWaitingHistoryResponse ( + Long waitingId, + Long shopId, + String shopName, + int peopleCount, + int waitingNumber, + String status +){} From 1125c5e610a082176eb110be078cb23da7f1a8a2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:26:55 +0900 Subject: [PATCH 394/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20-=20=ED=9A=8C=EC=9B=90=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EB=A7=A4=ED=95=91=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index f9ea780b..3146117d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -50,7 +50,7 @@ public class Waiting extends BaseEntity { @Column(name = "remaining_postpone_count") private int remainingPostponeCount; - @OneToOne(fetch = LAZY) + @ManyToOne(fetch = LAZY) @JoinColumn(name = "member_id", foreignKey = @ForeignKey(NO_CONSTRAINT)) private Member member; From ef6341fafcdfa0766760a48200aec9b4db869ddd Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:29:14 +0900 Subject: [PATCH 395/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index dac21df7..c69c6cdf 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.controller; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.service.MemberWaitingService; import jakarta.validation.Valid; @@ -51,4 +52,11 @@ public ResponseEntity getWaiting( MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } + + @GetMapping("/all/{memberId}") + public ResponseEntity getMemberAllWaiting( + @PathVariable("memberId") Long memberId) { + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberAllWaiting(memberId); + return ResponseEntity.ok(response); + } } From 61b85c70aa19f0858f69d7bc8fc059d9698cdb2b Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 01:30:06 +0900 Subject: [PATCH 396/603] =?UTF-8?q?feat=20:=20=EB=A9=A4=EB=B2=84=20?= =?UTF-8?q?=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EB=AA=A8=EB=91=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 631dad9f..ab6bf790 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -5,8 +5,9 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; -import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaitingResponse; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -16,12 +17,14 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -59,7 +62,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Long memberId, waitingLineRepository.save(shopId, waiting.getId()); Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); - return toWaitingResponse(savedWaiting, rank); + return toMemberWaitingResponse(savedWaiting, rank); } @Transactional @@ -73,7 +76,7 @@ public MemberWaitingResponse postponeWaiting(Long memberId) { waitingLineRepository.postpone(shop.getId(), waiting.getId()); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - return toWaitingResponse(waiting, rank); + return toMemberWaitingResponse(waiting, rank); } @Transactional @@ -85,7 +88,7 @@ public MemberWaitingResponse cancelWaiting(Long memberId) { waitingLineRepository.cancel(shop.getId(), waiting.getId()); waiting.changeStatusCanceled(); - return toWaitingResponse(waiting, -1L); + return toMemberWaitingResponse(waiting, -1L); } @Transactional(readOnly = true) @@ -96,7 +99,14 @@ public MemberWaitingResponse getWaiting(Long memberId) { Shop shop = waiting.getShop(); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - return toWaitingResponse(waiting, rank); + return toMemberWaitingResponse(waiting, rank); + } + + @Transactional(readOnly = true) + public MemberWaitingHistoryListResponse getMemberAllWaiting(Long memberId) { + Member member = getMemberEntity(memberId); + List waitings = waitingRepository.findWaitingWithMember(member); + return toMemberWaitingListResponse(waitings); } From c4fd099a1cf81e5a7dbe1a7b34f70417cc86d654 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 12:39:38 +0900 Subject: [PATCH 397/603] =?UTF-8?q?refactor=20:=20=EA=B8=B0=EC=A1=B4=20own?= =?UTF-8?q?er=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20assertAll=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerWaitingServiceTest.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 844c7d02..4d7c59ef 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.service; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -62,15 +63,17 @@ void getOwnerAllWaiting() { OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); //then - assertThat(response.shopWaitings()).hasSize(2); - - assertThat(response.shopWaitings().get(0).waitingId()).isEqualTo(waiting1.getId()); - assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo( - waiting1.getWaitingNumber()); - - assertThat(response.shopWaitings().get(1).waitingId()).isEqualTo(waiting2.getId()); - assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo( - waiting2.getWaitingNumber()); + assertAll( + () -> assertThat(response.shopWaitings()).hasSize(2), + () -> assertThat(response.shopWaitings().get(0).waitingId()) + .isEqualTo(waiting1.getId()), + () -> assertThat(response.shopWaitings().get(0).waitingNumber()) + .isEqualTo(waiting1.getWaitingNumber()), + () -> assertThat(response.shopWaitings().get(1).waitingId()) + .isEqualTo(waiting2.getId()), + () -> assertThat(response.shopWaitings().get(1).waitingNumber()) + .isEqualTo(waiting2.getWaitingNumber()) + ); } @DisplayName("웨이팅 손님을 입장시킬 수 있다.") @@ -89,10 +92,11 @@ void entryWaiting() { //when OwnerWaitingResponse response = ownerWaitingService.entryWaiting(1L); //then - assertThat(response.waitingId()).isEqualTo(waiting.getId()); - assertThat(response.peopleCount()).isEqualTo(2); - assertThat(response.rank()).isZero(); - assertThat(response.waitingNumber()).isEqualTo(waiting.getWaitingNumber()); - + assertAll( + () -> assertThat(response.waitingId()).isEqualTo(waiting.getId()), + () -> assertThat(response.peopleCount()).isEqualTo(2), + () -> assertThat(response.rank()).isZero(), + () -> assertThat(response.waitingNumber()).isEqualTo(waiting.getWaitingNumber()) + ); } } \ No newline at end of file From 499ffbaf202a15533840c8451085238280b71da3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 12:41:09 +0900 Subject: [PATCH 398/603] =?UTF-8?q?feat=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EB=AA=A8=EB=91=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberWaitingServiceTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index bcc35fc0..f6a7efb8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -16,10 +16,12 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalTime; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -129,7 +131,7 @@ void cancelWaiting() { ); } - @DisplayName("점주의 웨이팅를 조회할 수 있다.") + @DisplayName("회원의 진행 중인 웨이팅를 조회할 수 있다.") @Test void getWaiting() { //given @@ -153,5 +155,29 @@ void getWaiting() { ); } + @DisplayName("회원의 웨이팅 목록을 모두 조회할 수 있다.") + @Test + void getMemberAllWaiting() { + //given + Member member = mock(Member.class); + Shop shop = mock(Shop.class); + Waiting waiting = mock(Waiting.class); + given(memberRepository.findById(1L)).willReturn(Optional.of(member)); + given(waitingRepository.findWaitingWithMember(member)).willReturn( + List.of(waiting)); + given(waiting.getShop()).willReturn(shop); + given(waiting.getStatus()).willReturn(CANCELED); + + //when + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberAllWaiting( + 1L); + + //then + assertAll( + assertThat(response.memberWaitings().get(0).peopleCount())::isNotNull, + assertThat(response.memberWaitings().get(0).waitingNumber())::isNotNull, + assertThat(response.memberWaitings().get(0).status())::isNotNull + ); + } } \ No newline at end of file From dbe414190def70d4164b11ebd008abb0816f77a9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:31:09 +0900 Subject: [PATCH 399/603] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=97=90=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index 3c60ec8c..f7ee8b26 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.reservation.controller; +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; @@ -28,14 +30,16 @@ public class MemberReservationController { @PostMapping public ResponseEntity preOccupyReservation( + @LogIn Member member, @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(memberReservationService.preOccupyReservation(request)); + return ResponseEntity.ok(memberReservationService.preOccupyReservation(member, request)); } @PostMapping("/success") public ResponseEntity registerReservation( + @LogIn Member member, @RequestBody CreateReservationRequest request) { - return ResponseEntity.ok(memberReservationService.registerReservation(request)); + return ResponseEntity.ok(memberReservationService.registerReservation(member, request)); } @PatchMapping("/{reservationId}") From 703982b5dbf079abe4087ca4ef27ed22eff08bbc Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:32:13 +0900 Subject: [PATCH 400/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20=EC=98=88=EC=95=BD=EA=B3=BC=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 4505a24b..fc45c755 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -13,6 +13,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; @@ -41,7 +42,7 @@ public class MemberReservationService { private final ReservationLockRepository reservationLockRepository; @Transactional - public CreateReservationResponse preOccupyReservation(CreateReservationRequest request) { + public CreateReservationResponse preOccupyReservation(Member member, CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { try { @@ -65,14 +66,14 @@ public CreateReservationResponse preOccupyReservation(CreateReservationRequest r return CreateReservationResponse.builder() .shopName(shop.getName()) - .memberName("memberA") + .memberName(member.getName()) .date(reservationTime.getTime()) .peopleCount(request.peopleCount()) .build(); } @Transactional - public CreateReservationResponse registerReservation(CreateReservationRequest request) { + public CreateReservationResponse registerReservation(Member member, CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); @@ -85,6 +86,7 @@ public CreateReservationResponse registerReservation(CreateReservationRequest re .status(COMPLETED) .peopleCount(request.peopleCount()) .reservationTime(reservationTime) + .member(member) .build(); Reservation savedReservation = reservationRepository.save(reservation); return toCreateReservationResponse(savedReservation); From 25633e3d26ad0144cd0c6f75a8db99bc2a539433 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:32:24 +0900 Subject: [PATCH 401/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20=EC=98=88=EC=95=BD=EA=B3=BC=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EB=A7=A4=ED=95=91=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberReservationServiceIntegrationTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index 80bd26e0..79437015 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -4,6 +4,9 @@ import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; @@ -33,11 +36,18 @@ public class MemberReservationServiceIntegrationTest { @Autowired private ShopRepository shopRepository; + @Autowired + private MemberRepository memberRepository; + @BeforeEach void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); + Member member = MemberFixture.member("dlswns661035@gmail.com"); + memberRepository.save(member); + + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); @@ -46,6 +56,7 @@ void setUp() { @Test @DisplayName("동시에 요청이 들어오면 하나만 선점권이 true로 바뀌고 나머진 예외가 발생한다.") void concurrencyTest() throws InterruptedException { + Member member = memberRepository.findAll().get(0); AtomicInteger errorCount = new AtomicInteger(0); List all = reservationTimeRepository.findAll(); @@ -60,7 +71,7 @@ void concurrencyTest() throws InterruptedException { for (int i = 0; i < threadCount; i++) { executorService.submit(() -> { try { - memberReservationService.preOccupyReservation(request); + memberReservationService.preOccupyReservation(member, request); } catch (BadRequestCustomException e) { errorCount.incrementAndGet(); } finally { From 2a391aaa8c5e481696cfa1deaa1c1f369db5e83d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:33:36 +0900 Subject: [PATCH 402/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=EC=97=90=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index 2a64ace1..39ab0258 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -53,11 +53,12 @@ public class Reservation extends BaseEntity { @Builder public Reservation(ReservationStatus status, int peopleCount, - ReservationTime reservationTime) { + ReservationTime reservationTime, Member member) { this.status = status; this.peopleCount = peopleCount; this.reservationTime = reservationTime; this.shop = reservationTime.getShop(); + this.member = member; } public void modifyReservation(ReservationTime reservationTime, int peopleCount) { From a4003716e1be96bc6a884b38a47e2f52c3f23397 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:33:47 +0900 Subject: [PATCH 403/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationServiceTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 02b110db..7b548ac8 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -13,6 +13,8 @@ import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -54,6 +56,7 @@ class MemberReservationServiceTest { @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { //given + Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( @@ -64,7 +67,7 @@ void validateReservation() { when(reservationLockRepository.unlock(1L)).thenReturn(TRUE); doNothing().when(reservationAsync).setPreOcuppied(reservationTime); //when - CreateReservationResponse response = memberReservationService.preOccupyReservation( + CreateReservationResponse response = memberReservationService.preOccupyReservation(member, request); //then @@ -81,6 +84,7 @@ void validateReservation() { @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") void alreadyPreOccupied() { //given + Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( @@ -91,7 +95,7 @@ void alreadyPreOccupied() { //when assertThrows(BadRequestCustomException.class, - () -> memberReservationService.preOccupyReservation(request)); + () -> memberReservationService.preOccupyReservation(member, request)); } @@ -99,19 +103,21 @@ void alreadyPreOccupied() { @Test @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") void registerReservation() { + Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); Reservation reservation = Reservation.builder() .status(COMPLETED) .peopleCount(request.peopleCount()) .reservationTime(reservationTime) + .member(member) .build(); when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); - CreateReservationResponse response = memberReservationService.registerReservation(request); + CreateReservationResponse response = memberReservationService.registerReservation(member, request); assertAll( () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), @@ -123,6 +129,7 @@ void registerReservation() { @Test @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") void registerReservationAlreadyOccupied() { + Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); @@ -131,7 +138,7 @@ void registerReservationAlreadyOccupied() { Optional.of(reservationTime)); assertThrows(BadRequestCustomException.class, - () -> memberReservationService.registerReservation(request)); + () -> memberReservationService.registerReservation(member, request)); } @Test From 3df4196ff8b10bff7160e576930e214f37476025 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:34:10 +0900 Subject: [PATCH 404/603] =?UTF-8?q?feat=20:=20BaseIntegration=EC=97=90=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EA=B4=80=EB=A0=A8=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/base/BaseIntegrationTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 0e2bc05c..cbf75673 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -2,16 +2,24 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpHeaders; import org.springframework.test.web.servlet.MockMvc; @SpringBootTest @AutoConfigureMockMvc public abstract class BaseIntegrationTest { + @Autowired + public JwtTokenProvider jwtTokenProvider; + public static ObjectMapper objectMapper = new ObjectMapper(); + + public HttpHeaders httpHeaders = new HttpHeaders(); @Autowired public MockMvc mockMvc; From 237928b4370b3e12c2ddf92922f67fb7eab29df5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 13:35:25 +0900 Subject: [PATCH 405/603] =?UTF-8?q?feat=20:=20BaseIntegration=EC=97=90=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EA=B4=80=EB=A0=A8=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberReservationControllerTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 59419010..e115b56a 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -13,6 +13,10 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -40,15 +44,26 @@ class MemberReservationControllerTest extends BaseIntegrationTest { private ShopRepository shopRepository; @Autowired private ReservationRepository reservationRepository; + @Autowired + private MemberRepository memberRepository; + + @BeforeEach void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); + Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member savedMember = memberRepository.save(member); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); + + Token token = jwtTokenProvider.createToken(savedMember.getEmail()); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken",token.getRefreshToken()); } @Test @@ -62,6 +77,7 @@ void preOccupyReservation() throws Exception { mockMvc.perform(post("/reservations") .contentType(APPLICATION_JSON) + .headers(httpHeaders) .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) @@ -80,6 +96,7 @@ void schedulerTest() throws Exception { reservationTime.getId()); mockMvc.perform(post("/reservations") + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))); @@ -98,6 +115,7 @@ void resigerReservation() throws Exception { reservationTime.getId()); mockMvc.perform(post("/reservations/success") + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()) From 9ac3382ec357dbb9f3710057b7878bb22e71db7a Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 13:48:16 +0900 Subject: [PATCH 406/603] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index c69c6cdf..9a33efd8 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -54,9 +54,9 @@ public ResponseEntity getWaiting( } @GetMapping("/all/{memberId}") - public ResponseEntity getMemberAllWaiting( + public ResponseEntity getMemberWaitingHistory( @PathVariable("memberId") Long memberId) { - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberAllWaiting(memberId); + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory(memberId); return ResponseEntity.ok(response); } } From dfb85dd404461f08d86d25cae94bb9933c79709c Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 13:49:08 +0900 Subject: [PATCH 407/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=9D=B4=EB=A0=A5=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingControllerTest.java | 24 +++++++++++++++++++ .../service/MemberWaitingServiceTest.java | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 062c6098..d1bf241b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.waiting.controller; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -22,6 +24,7 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; @@ -198,4 +201,25 @@ void getWaiting() throws Exception { .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) .andDo(MockMvcResultHandlers.print()); } + + @DisplayName("회원의 웨이팅 이력 조회 API를 호출할 수 있다.") + @Test + void getMemberWaitingHistory() throws Exception { + //when, then + Waiting canceledWaiting = WaitingFixture.canceledWaiting(member1, shop, 23); + Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 233); + waitingRepository.saveAll(List.of(canceledWaiting, completedWaiting)); + mockMvc.perform(get("/waitings/all/{memberId}", member1.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.memberWaitings", hasSize(3))) + .andExpect(jsonPath("$.memberWaitings[0].waitingId").value(waiting1.getId())) + .andExpect(jsonPath("$.memberWaitings[0].status").value(PROGRESS.getDescription())) + .andExpect(jsonPath("$.memberWaitings[1].waitingId").value(canceledWaiting.getId())) + .andExpect(jsonPath("$.memberWaitings[1].status").value(CANCELED.getDescription())) + .andExpect(jsonPath("$.memberWaitings[2].waitingId").value(completedWaiting.getId())) + .andExpect(jsonPath("$.memberWaitings[2].status").value(COMPLETED.getDescription())) + .andDo(MockMvcResultHandlers.print()) + ; + } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index f6a7efb8..01914252 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -170,7 +170,7 @@ void getMemberAllWaiting() { given(waiting.getStatus()).willReturn(CANCELED); //when - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberAllWaiting( + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( 1L); //then From e1c49bf4a2ea1ae0bb81495f162bfdd64a6d4c83 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 13:49:50 +0900 Subject: [PATCH 408/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 3 ++- .../java/com/prgrms/catchtable/waiting/domain/Waiting.java | 1 - .../com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 3 ++- .../dto/response/MemberWaitingHistoryListResponse.java | 3 ++- .../waiting/dto/response/MemberWaitingHistoryResponse.java | 6 ++++-- .../catchtable/waiting/service/MemberWaitingService.java | 4 ++-- .../waiting/repository/WaitingRepositoryTest.java | 6 +++--- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 9a33efd8..7e757e41 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -56,7 +56,8 @@ public ResponseEntity getWaiting( @GetMapping("/all/{memberId}") public ResponseEntity getMemberWaitingHistory( @PathVariable("memberId") Long memberId) { - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory(memberId); + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( + memberId); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index 3146117d..e6e4fe70 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -22,7 +22,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 50e89d92..5620f06d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -53,7 +53,8 @@ public static MemberWaitingHistoryResponse toMemberWaitingHistoryResponse(Waitin .build(); } - public static MemberWaitingHistoryListResponse toMemberWaitingListResponse(List waitings){ + public static MemberWaitingHistoryListResponse toMemberWaitingListResponse( + List waitings) { List list = new ArrayList<>(); for (Waiting waiting : waitings) { list.add(toMemberWaitingHistoryResponse(waiting)); diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java index 225ca231..5cbd4b01 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java @@ -4,5 +4,6 @@ public record MemberWaitingHistoryListResponse( List memberWaitings -){ +) { + } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java index 737318ca..bdcd9872 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java @@ -3,11 +3,13 @@ import lombok.Builder; @Builder -public record MemberWaitingHistoryResponse ( +public record MemberWaitingHistoryResponse( Long waitingId, Long shopId, String shopName, int peopleCount, int waitingNumber, String status -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index ab6bf790..b740f60b 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -6,8 +6,8 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; -import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toWaiting; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; @@ -103,7 +103,7 @@ public MemberWaitingResponse getWaiting(Long memberId) { } @Transactional(readOnly = true) - public MemberWaitingHistoryListResponse getMemberAllWaiting(Long memberId) { + public MemberWaitingHistoryListResponse getMemberWaitingHistory(Long memberId) { Member member = getMemberEntity(memberId); List waitings = waitingRepository.findWaitingWithMember(member); return toMemberWaitingListResponse(waitings); diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index fa73759c..da4f7f27 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.waiting.repository; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import com.prgrms.catchtable.member.MemberFixture; @@ -15,7 +15,6 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -122,6 +121,7 @@ void findWaitingWithMember() { //when List memberAllWaitings = waitingRepository.findWaitingWithMember(member1); //then - assertThat(memberAllWaitings).containsExactly(canceledWaiting, completedWaiting, progressWaiting); + assertThat(memberAllWaitings).containsExactly(canceledWaiting, completedWaiting, + progressWaiting); } } \ No newline at end of file From ea664b7eee85c5fb44fef4456c6da5733f9f93f0 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 14:09:03 +0900 Subject: [PATCH 409/603] =?UTF-8?q?feat=20:=20Shop=20dto=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20&=20mapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/dto/RegistShopRequest.java | 25 ++++++++++++ .../shop/dto/RegistShopResponse.java | 22 +++++++++++ .../catchtable/shop/dto/ShopMapper.java | 39 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java new file mode 100644 index 00000000..6631c8e5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java @@ -0,0 +1,25 @@ +package com.prgrms.catchtable.shop.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import java.time.LocalTime; + +public record RegistShopRequest( + + String name, + @Min(0) + @Max(5) + int rating, + String category, + String city, + String district, + int capacity, + @JsonFormat(pattern = "kk:mm:ss") + LocalTime openingTime, + @JsonFormat(pattern = "kk:mm:ss") + LocalTime closingTime + +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java new file mode 100644 index 00000000..f68c8f21 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java @@ -0,0 +1,22 @@ +package com.prgrms.catchtable.shop.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import java.time.LocalTime; +import lombok.Builder; + +@Builder +public record RegistShopResponse( + + String name, + int rating, + String category, + String city, + String district, + int capacity, + @JsonFormat(pattern = "kk:mm:ss") + LocalTime openingTime, + @JsonFormat(pattern = "kk:mm:ss") + LocalTime closingTime +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java new file mode 100644 index 00000000..24bcfe53 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -0,0 +1,39 @@ +package com.prgrms.catchtable.shop.dto; + +import com.prgrms.catchtable.shop.domain.Address; +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import java.math.BigDecimal; + +public class ShopMapper { + + public static Shop toEntity(RegistShopRequest registShopRequest){ + + return Shop.builder() + .name(registShopRequest.name()) + .rating(BigDecimal.valueOf(registShopRequest.rating())) + .category(Category.of(registShopRequest.category())) + .address(Address.builder() + .city(registShopRequest.city()) + .district(registShopRequest.district()) + .build()) + .capacity(registShopRequest.capacity()) + .openingTime(registShopRequest.openingTime()) + .closingTime(registShopRequest.closingTime()) + .build(); + } + + public static RegistShopResponse of(Shop shop){ + return RegistShopResponse.builder() + .name(shop.getName()) + .rating(Integer.parseInt(String.valueOf(shop.getRating()))) + .category(shop.getCategory().getType()) + .city(shop.getAddress().getCity()) + .district(shop.getAddress().getDistrict()) + .capacity(shop.getCapacity()) + .openingTime(shop.getOpeningTime()) + .closingTime(shop.getClosingTime()) + .build(); + } + +} From d93b70ce1341735a2a8163bb95110e2ff0e727bd Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 14:09:21 +0900 Subject: [PATCH 410/603] =?UTF-8?q?fix=20:=20Category=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/domain/Category.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java index 7cfb6af8..c3e680a4 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java @@ -1,5 +1,8 @@ package com.prgrms.catchtable.shop.domain; +import com.prgrms.catchtable.common.exception.ErrorCode; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import java.util.Arrays; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -11,6 +14,16 @@ public enum Category { CHINESE_FOOD("중식"), WESTERN_FOOD("양식"); - private final String description; + private final String type; + public static Category of(String input){ + return Arrays.stream(values()) + .filter(category -> category.isEqual(input)) + .findAny() + .orElseThrow(() -> new BadRequestCustomException(ErrorCode.INVALID_INPUT_TYPE)); + } + + private boolean isEqual(String input){ + return type.equals(input); + } } From ad58aadabe3fcf10cbc4fb0040f91404378ae01a Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 14:10:04 +0900 Subject: [PATCH 411/603] =?UTF-8?q?feat=20:=20Shop=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20&=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/OwnerShopController.java | 31 +++++++++++++++++++ .../catchtable/shop/service/ShopService.java | 27 ++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/service/ShopService.java diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java new file mode 100644 index 00000000..bddd92bd --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java @@ -0,0 +1,31 @@ +package com.prgrms.catchtable.shop.controller; + +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.shop.dto.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.RegistShopResponse; +import com.prgrms.catchtable.shop.service.ShopService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/owners") +public class OwnerShopController { + + private final ShopService shopService; + + @PostMapping("/shops") + public ResponseEntity registShop(@Valid @RequestBody RegistShopRequest request, @LogIn + Owner owner){ + RegistShopResponse registShopResponse = shopService.registShop(request, owner); + return ResponseEntity.status(HttpStatus.CREATED).body(registShopResponse); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/service/ShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/ShopService.java new file mode 100644 index 00000000..188dc368 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/service/ShopService.java @@ -0,0 +1,27 @@ +package com.prgrms.catchtable.shop.service; + +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.ShopMapper; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ShopService { + + private final ShopRepository shopRepository; + + public RegistShopResponse registShop(RegistShopRequest registShopRequest, Owner owner){ + + Shop registShop = shopRepository.save(ShopMapper.toEntity(registShopRequest)); + owner.insertShop(registShop); + + return ShopMapper.of(registShop); + + } + +} From 0141c58fd200db833fe36d1f090cac7c30768d99 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:10:44 +0900 Subject: [PATCH 412/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80=20->=20=EC=9D=B8=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EB=93=A4=EC=96=B4=EC=98=A8=20Member=EC=99=80=20?= =?UTF-8?q?=EC=9D=BC=EC=B9=98=ED=95=98=EB=8A=94=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index b2168c26..cf51a4c9 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.reservation.repository; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import java.util.List; import java.util.Optional; @@ -11,8 +12,9 @@ public interface ReservationRepository extends JpaRepository @Query("select r from Reservation r " + "join fetch r.reservationTime rt " - + "join fetch rt.shop") - List findAllWithReservationTimeAndShop(); + + "join fetch rt.shop " + + "where r.member = :member") + List findAllWithReservationTimeAndShopByMemberId(@Param("member") Member member); @Query("select r from Reservation r " + "join fetch r.reservationTime rt " From 0ee8ac0149c0ef42aa9b65a52d3b30e385e8ca11 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:10:54 +0900 Subject: [PATCH 413/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepositoryTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 60c56962..4b1a8a1b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -5,6 +5,9 @@ import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.fixture.ReservationFixture; @@ -28,25 +31,31 @@ class ReservationRepositoryTest { private ShopRepository shopRepository; @Autowired private ReservationTimeRepository reservationTimeRepository; + @Autowired + private MemberRepository memberRepository; @Test @DisplayName("예약 엔티티 조회 시 페치 조인을 통해 예약시간과 매장 엔티티를 한번에 조회한다.") void findAllWithReservationTimeAndShop() { + Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member savedMember = memberRepository.save(member); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); reservationTime.insertShop(savedShop); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - Reservation reservation = ReservationFixture.getReservation(savedReservationTime); + Reservation reservation = ReservationFixture.getReservation(savedReservationTime, member); reservationRepository.save(reservation); - List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId(savedMember); Reservation findReservation = reservations.get(0); assertAll( () -> assertThat(findReservation.getReservationTime()).isEqualTo(savedReservationTime), - () -> assertThat(findReservation.getShop()).isEqualTo(savedShop) + () -> assertThat(findReservation.getShop()).isEqualTo(savedShop), + () -> assertThat(findReservation.getMember()).isEqualTo(savedMember) ); } From 0ece307b09c2370e22fb095664190442d8fc46cb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:11:29 +0900 Subject: [PATCH 414/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=ED=9A=8C=EC=9B=90=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EB=A7=8C=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index fc45c755..6307cfa7 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -93,8 +93,8 @@ public CreateReservationResponse registerReservation(Member member, CreateReserv } @Transactional(readOnly = true) - public List getAllReservation() { - List reservations = reservationRepository.findAllWithReservationTimeAndShop(); + public List getAllReservation(Member member) { + List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId(member); return reservations.stream() .map(ReservationMapper::toGetAllReservationRepsonse) .toList(); From f4c88a805581863f804a0dbb1ccb0193e64eb8ca Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:11:37 +0900 Subject: [PATCH 415/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationServiceTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 7b548ac8..95367806 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -144,12 +144,14 @@ void registerReservationAlreadyOccupied() { @Test @DisplayName("예약 전체 조회를 할 수 있다") void getAllReservation() { + Member member = MemberFixture.member("dlswns661035@gmail.com"); + ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - Reservation reservation = ReservationFixture.getReservation(reservationTime); + Reservation reservation = ReservationFixture.getReservation(reservationTime,member); - when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn( + when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn( List.of(reservation)); - List all = memberReservationService.getAllReservation(); + List all = memberReservationService.getAllReservation(member); GetAllReservationResponse findReservation = all.get(0); assertAll( @@ -164,9 +166,10 @@ void getAllReservation() { @Test @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") void getAllReservationWithNoResult() { - when(reservationRepository.findAllWithReservationTimeAndShop()).thenReturn(List.of()); + Member member = MemberFixture.member("dlswns661035@gmail.com"); + when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn(List.of()); - List all = memberReservationService.getAllReservation(); + List all = memberReservationService.getAllReservation(member); assertThat(all).isEmpty(); } From 3b28425ee8a677aa18a8e19a28ae784f30fbf852 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:12:39 +0900 Subject: [PATCH 416/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationController.java | 4 ++-- .../controller/MemberReservationControllerTest.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index f7ee8b26..3cbaa1a9 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -57,7 +57,7 @@ public ResponseEntity cancelReservation( } @GetMapping - public ResponseEntity> getAllReservation() { - return ResponseEntity.ok(memberReservationService.getAllReservation()); + public ResponseEntity> getAllReservation(@LogIn Member member) { + return ResponseEntity.ok(memberReservationService.getAllReservation(member)); } } diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index e115b56a..cf4733e6 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -1,16 +1,19 @@ package com.prgrms.catchtable.reservation.controller; +import static com.prgrms.catchtable.common.Role.*; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.jwt.token.Token; @@ -61,7 +64,7 @@ void setUp() { reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); - Token token = jwtTokenProvider.createToken(savedMember.getEmail()); + Token token = jwtTokenProvider.createToken(savedMember.getEmail(), MEMBER); httpHeaders.add("AccessToken", token.getAccessToken()); httpHeaders.add("RefreshToken",token.getRefreshToken()); } @@ -140,6 +143,7 @@ void registerReservationWithException() throws Exception { CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( savedReservationTime.getId()); mockMvc.perform(post("/reservations/success") + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isBadRequest()) @@ -196,12 +200,14 @@ void cancelReservation() throws Exception { @Test @DisplayName("회원은 자신의 예약내역을 조회할 수 있다.") void getAllReservation() throws Exception { + Member member = memberRepository.findAll().get(0); Reservation reservation = ReservationFixture.getReservation( - reservationTimeRepository.findAll().get(0)); + reservationTimeRepository.findAll().get(0), member); Reservation savedReservation = reservationRepository.save(reservation); - mockMvc.perform(get("/reservations")) + mockMvc.perform(get("/reservations") + .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].reservationId").value(savedReservation.getId())) .andExpect(jsonPath("$[0].date").value( From 3a30484ad69d6a44fb0c825826871a39d89d56bb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:12:50 +0900 Subject: [PATCH 417/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/fixture/ReservationFixture.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index e299f0c7..af468e84 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationStatus; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -95,4 +96,16 @@ public static ModifyReservationStatusRequest getModifyReservationStatusRequest( .build(); } + public static Reservation getReservation(ReservationTime reservationTime, Member member) { + if (!reservationTime.isOccupied()) { + reservationTime.setOccupiedTrue(); + } + return Reservation.builder() + .status(COMPLETED) + .peopleCount(4) + .reservationTime(reservationTime) + .member(member) + .build(); + } + } From f13b9b366b43e619984cbb1de845b40e60ac1fcb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:27:42 +0900 Subject: [PATCH 418/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/login/WebConfig.java | 2 +- .../reservation/service/MemberReservationService.java | 9 ++++++--- .../catchtable/common/base/BaseIntegrationTest.java | 1 - .../catchtable/owner/service/OwnerServiceTest.java | 3 ++- .../controller/MemberReservationControllerTest.java | 9 +++------ .../repository/ReservationRepositoryTest.java | 3 ++- .../service/MemberReservationServiceIntegrationTest.java | 2 -- .../service/MemberReservationServiceTest.java | 8 +++++--- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java index 58418bc5..f5dbb6e1 100644 --- a/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java +++ b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java @@ -9,7 +9,7 @@ public class WebConfig implements WebMvcConfigurer { @Override - public void addArgumentResolvers(List resolvers){ + public void addArgumentResolvers(List resolvers) { resolvers.add(new LogInArgumentResolver()); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 6307cfa7..ee07abdc 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -42,7 +42,8 @@ public class MemberReservationService { private final ReservationLockRepository reservationLockRepository; @Transactional - public CreateReservationResponse preOccupyReservation(Member member, CreateReservationRequest request) { + public CreateReservationResponse preOccupyReservation(Member member, + CreateReservationRequest request) { Long reservationTimeId = request.reservationTimeId(); while (FALSE.equals(reservationLockRepository.lock(reservationTimeId))) { try { @@ -73,7 +74,8 @@ public CreateReservationResponse preOccupyReservation(Member member, CreateReser } @Transactional - public CreateReservationResponse registerReservation(Member member, CreateReservationRequest request) { + public CreateReservationResponse registerReservation(Member member, + CreateReservationRequest request) { ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( request.reservationTimeId()). orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); @@ -94,7 +96,8 @@ public CreateReservationResponse registerReservation(Member member, CreateReserv @Transactional(readOnly = true) public List getAllReservation(Member member) { - List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId(member); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId( + member); return reservations.stream() .map(ReservationMapper::toGetAllReservationRepsonse) .toList(); diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index cbf75673..3841e406 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpHeaders; diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index ebb385c1..0758a08b 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -79,7 +79,8 @@ void loginSuccess() { //given LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); String encodePassword = passwordEncoder.encode(password); - Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email(), Role.OWNER); + Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email(), + Role.OWNER); //when when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index cf4733e6..f9d1ec98 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -1,19 +1,17 @@ package com.prgrms.catchtable.reservation.controller; -import static com.prgrms.catchtable.common.Role.*; +import static com.prgrms.catchtable.common.Role.MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.head; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.jwt.token.Token; @@ -51,7 +49,6 @@ class MemberReservationControllerTest extends BaseIntegrationTest { private MemberRepository memberRepository; - @BeforeEach void setUp() { Shop shop = ShopData.getShop(); @@ -66,7 +63,7 @@ void setUp() { Token token = jwtTokenProvider.createToken(savedMember.getEmail(), MEMBER); httpHeaders.add("AccessToken", token.getAccessToken()); - httpHeaders.add("RefreshToken",token.getRefreshToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); } @Test @@ -99,7 +96,7 @@ void schedulerTest() throws Exception { reservationTime.getId()); mockMvc.perform(post("/reservations") - .headers(httpHeaders) + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))); diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 4b1a8a1b..317502c3 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -49,7 +49,8 @@ void findAllWithReservationTimeAndShop() { Reservation reservation = ReservationFixture.getReservation(savedReservationTime, member); reservationRepository.save(reservation); - List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId(savedMember); + List reservations = reservationRepository.findAllWithReservationTimeAndShopByMemberId( + savedMember); Reservation findReservation = reservations.get(0); assertAll( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index 79437015..c42eb129 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -19,7 +19,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -47,7 +46,6 @@ void setUp() { Member member = MemberFixture.member("dlswns661035@gmail.com"); memberRepository.save(member); - ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); reservationTime.insertShop(savedShop); reservationTimeRepository.save(reservationTime); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 95367806..5d837e4e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -117,7 +117,8 @@ void registerReservation() { Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); - CreateReservationResponse response = memberReservationService.registerReservation(member, request); + CreateReservationResponse response = memberReservationService.registerReservation(member, + request); assertAll( () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), @@ -147,7 +148,7 @@ void getAllReservation() { Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); - Reservation reservation = ReservationFixture.getReservation(reservationTime,member); + Reservation reservation = ReservationFixture.getReservation(reservationTime, member); when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn( List.of(reservation)); @@ -167,7 +168,8 @@ void getAllReservation() { @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") void getAllReservationWithNoResult() { Member member = MemberFixture.member("dlswns661035@gmail.com"); - when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn(List.of()); + when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn( + List.of()); List all = memberReservationService.getAllReservation(member); assertThat(all).isEmpty(); From 051a5938c759bde7290c507206124a4b57ceee12 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 14:56:56 +0900 Subject: [PATCH 419/603] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=EC=9A=94=EC=86=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationControllerTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index f9d1ec98..e9f0e0a2 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -47,14 +47,14 @@ class MemberReservationControllerTest extends BaseIntegrationTest { private ReservationRepository reservationRepository; @Autowired private MemberRepository memberRepository; - + private Member member = MemberFixture.member("dlswns661035@gmail.com"); @BeforeEach void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member savedMember = memberRepository.save(member); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); @@ -81,6 +81,7 @@ void preOccupyReservation() throws Exception { .content(asJsonString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) + .andExpect(jsonPath("$.memberName").value(member.getName())) .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); } @@ -122,8 +123,11 @@ void resigerReservation() throws Exception { .andExpect(jsonPath("$.shopName").value(reservationTime.getShop().getName())) .andExpect(jsonPath("$.date").value(reservationTime.getTime().toString())) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())); - + Reservation reservation = reservationRepository.findAllWithReservationTimeAndShopByMemberId( + member).get(0); assertThat(reservationTime.isOccupied()).isTrue(); + assertThat(reservation.getReservationTime()).isEqualTo(reservationTime); + assertThat(reservation.getShop()).isEqualTo(reservationTime.getShop()); } @Test From 9f8b5ccc757b305d0b84a4a458c26f4c6b272148 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:17:12 +0900 Subject: [PATCH 420/603] =?UTF-8?q?feat=20:=20=EB=B9=84=EB=8F=99=EA=B8=B0?= =?UTF-8?q?=20config=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/config/AsyncConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java diff --git a/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java b/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java new file mode 100644 index 00000000..2f5b7012 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.common.config; + +import org.springframework.context.annotation.Configuration; + +@Configuration +@org.springframework.scheduling.annotation.EnableAsync +public class AsyncConfig { + +} From ea50a628e36fc730f26aaa8601dbd12f773860ec Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:17:22 +0900 Subject: [PATCH 421/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=A6=AC=EC=8A=A4=EB=84=88=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationEvent.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java new file mode 100644 index 00000000..e8947663 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -0,0 +1,32 @@ +package com.prgrms.catchtable.common.notification; + +import static org.springframework.transaction.event.TransactionPhase.*; + +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.notification.service.NotificationService; +import com.prgrms.catchtable.owner.domain.Owner; +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; + +@Component +@RequiredArgsConstructor +public class NotificationEvent { + + private final NotificationService notificationService; + + @Async + @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 + public void sentMessage(Member member, NotificationContent content){ + notificationService.sendMessageAndSave(member, content); + } + + @Async + @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 + public void sentMessage(Owner owner, NotificationContent content){ + notificationService.sendMessageAndSave(owner, content); + } +} From de0b118ae0d7f2e145d8aac33e923f847cab5dea Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:17:37 +0900 Subject: [PATCH 422/603] =?UTF-8?q?remove=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=B0=8F=20dto=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 20 ------------------- .../dto/request/SendMessageRequest.java | 7 ------- 2 files changed, 27 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java delete mode 100644 src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java diff --git a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java deleted file mode 100644 index 07007c94..00000000 --- a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.prgrms.catchtable.notification.controller; - -import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; -import com.prgrms.catchtable.notification.service.NotificationService; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -public class NotificationController { - - private final NotificationService notificationService; - - @GetMapping("/test") - public void test(@RequestBody SendMessageRequest request) { - notificationService.sendMessageToMemberAndSave(request); - } -} diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java deleted file mode 100644 index 7c2034f7..00000000 --- a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.prgrms.catchtable.notification.dto.request; - -import com.prgrms.catchtable.common.NotificationContent; - -public record SendMessageRequest(NotificationContent content) { - -} From 6e64acdd9beb5a44b43ed9ae414e510fbeae1e2e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:17:56 +0900 Subject: [PATCH 423/603] =?UTF-8?q?refactor=20:=20NotificationContent=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/{ => notification}/NotificationContent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/prgrms/catchtable/common/{ => notification}/NotificationContent.java (93%) diff --git a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java similarity index 93% rename from src/main/java/com/prgrms/catchtable/common/NotificationContent.java rename to src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java index 06af80c9..54b616eb 100644 --- a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.common; +package com.prgrms.catchtable.common.notification; import lombok.Getter; import lombok.RequiredArgsConstructor; From a9191ed5808cf6bbd37b420696c5b4fb6de793fb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:18:29 +0900 Subject: [PATCH 424/603] =?UTF-8?q?style=20:=20NotificationService=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationService.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index eb862c67..5e298cd1 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -5,11 +5,11 @@ import static org.springframework.http.HttpMethod.POST; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.notification.domain.NotificationMember; import com.prgrms.catchtable.notification.domain.NotificationOwner; -import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; import com.prgrms.catchtable.notification.repository.NotificationMemberRepository; import com.prgrms.catchtable.notification.repository.NotificationOwnerRepository; import com.prgrms.catchtable.owner.domain.Owner; @@ -38,15 +38,11 @@ public class NotificationService { private final OwnerRepository ownerRepository; // 추후 삭제 예정 private JSONObject jsonObject; - public void sendMessageToMemberAndSave(SendMessageRequest request) { + public void sendMessageAndSave(Member member, NotificationContent content) { String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API - // member 예제 데이터 - Member member = Member.builder() - .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 - .build(); String email = member.getEmail(); - String message = request.content().getMessage(); + String message = content.getMessage(); String slackId = getSlackIdByEmail(email); // 이메일을 통해 사용자의 슬랙 고유 ID 추출 requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 @@ -60,15 +56,11 @@ public void sendMessageToMemberAndSave(SendMessageRequest request) { } - public void sendMessageToOwnerAndSave(SendMessageRequest request) { + public void sendMessageAndSave(Owner owner, NotificationContent content) { String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API - //Owner 예제 데이터 - Owner owner = Owner.builder() - .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 - .build(); String email = owner.getEmail(); - String message = request.content().getMessage(); + String message = content.getMessage(); String slackId = getSlackIdByEmail(email); requestToSendMessage(slackId, message); From 1f757eeb240c837b14988aa5d60b2316c09cf33c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:18:50 +0900 Subject: [PATCH 425/603] =?UTF-8?q?style=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=BF=BC=EB=A6=AC=20=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=ED=98=95=20List=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/repository/NotificationMemberRepository.java | 3 ++- .../notification/repository/NotificationOwnerRepository.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index 44598e0e..223313cb 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -2,10 +2,11 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.domain.NotificationMember; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { - Optional findByMember(Member member); + List findByMember(Member member); } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java index eb840345..8bdfacf0 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -2,10 +2,10 @@ import com.prgrms.catchtable.notification.domain.NotificationOwner; import com.prgrms.catchtable.owner.domain.Owner; -import java.util.Optional; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationOwnerRepository extends JpaRepository { - Optional findByOwner(Owner owner); + List findByOwner(Owner owner); } From c1b66e7a71552ba10adb83341d83f57a2503c83f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:19:10 +0900 Subject: [PATCH 426/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/login/WebConfig.java | 2 +- .../catchtable/common/notification/NotificationEvent.java | 8 +++----- .../repository/NotificationMemberRepository.java | 1 - .../prgrms/catchtable/owner/service/OwnerServiceTest.java | 3 ++- .../service/MemberReservationServiceIntegrationTest.java | 1 - 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java index 58418bc5..f5dbb6e1 100644 --- a/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java +++ b/src/main/java/com/prgrms/catchtable/common/login/WebConfig.java @@ -9,7 +9,7 @@ public class WebConfig implements WebMvcConfigurer { @Override - public void addArgumentResolvers(List resolvers){ + public void addArgumentResolvers(List resolvers) { resolvers.add(new LogInArgumentResolver()); } diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java index e8947663..93ddb465 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -1,15 +1,13 @@ package com.prgrms.catchtable.common.notification; -import static org.springframework.transaction.event.TransactionPhase.*; +import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.service.NotificationService; import com.prgrms.catchtable.owner.domain.Owner; import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalEventListener; @Component @@ -20,13 +18,13 @@ public class NotificationEvent { @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sentMessage(Member member, NotificationContent content){ + public void sentMessage(Member member, NotificationContent content) { notificationService.sendMessageAndSave(member, content); } @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sentMessage(Owner owner, NotificationContent content){ + public void sentMessage(Owner owner, NotificationContent content) { notificationService.sendMessageAndSave(owner, content); } } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index 223313cb..67e1c532 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -3,7 +3,6 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.domain.NotificationMember; import java.util.List; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index ebb385c1..0758a08b 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -79,7 +79,8 @@ void loginSuccess() { //given LoginOwnerRequest loginOwnerRequest = OwnerFixture.getLoginOwnerRequest(email, password); String encodePassword = passwordEncoder.encode(password); - Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email(), Role.OWNER); + Token token = new Token("AccessToken", "RefreshToken", loginOwnerRequest.email(), + Role.OWNER); //when when(ownerRepository.findOwnerByEmail(loginOwnerRequest.email())).thenReturn( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java index 80bd26e0..681eae52 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceIntegrationTest.java @@ -16,7 +16,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; From 0a8352b1118c2fd3e15c751f92fcfba06b2d6989 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 15:30:44 +0900 Subject: [PATCH 427/603] =?UTF-8?q?style=20:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/notification/NotificationEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java index 93ddb465..43b75ef9 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -18,13 +18,13 @@ public class NotificationEvent { @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sentMessage(Member member, NotificationContent content) { + public void sendMessage(Member member, NotificationContent content) { notificationService.sendMessageAndSave(member, content); } @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sentMessage(Owner owner, NotificationContent content) { + public void sendMessage(Owner owner, NotificationContent content) { notificationService.sendMessageAndSave(owner, content); } } From 1356da7e6082a63050acf4402e902905969fe0b6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 16:05:06 +0900 Subject: [PATCH 428/603] =?UTF-8?q?feat=20:=20=EB=A9=94=EC=84=B8=EC=A7=80?= =?UTF-8?q?=20=EB=B3=B4=EB=82=B4=EB=8A=94=20=EC=9A=94=EC=B2=AD=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/SendMessageToMemberRequest.java | 11 +++++++++++ .../dto/request/SendMessageToOwnerRequest.java | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java new file mode 100644 index 00000000..4e9fb6f7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.notification.dto.request; + +import com.prgrms.catchtable.common.notification.NotificationContent; +import com.prgrms.catchtable.member.domain.Member; +import lombok.Builder; + +@Builder +public record SendMessageToMemberRequest(Member member, + NotificationContent content) { + +} diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java new file mode 100644 index 00000000..ae80ddef --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.notification.dto.request; + +import com.prgrms.catchtable.common.notification.NotificationContent; +import com.prgrms.catchtable.owner.domain.Owner; +import lombok.Builder; + +@Builder +public record SendMessageToOwnerRequest(Owner owner, + NotificationContent content) { + +} From 3750c7641dd4bdd795e3f9c77af9b8e0c56e40c7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 16:05:40 +0900 Subject: [PATCH 429/603] =?UTF-8?q?feat=20:=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=EB=84=88=20=EC=9D=B8=EC=9E=90=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/notification/NotificationEvent.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java index 43b75ef9..eba2c6e1 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -2,9 +2,9 @@ import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; -import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; +import com.prgrms.catchtable.notification.dto.request.SendMessageToOwnerRequest; import com.prgrms.catchtable.notification.service.NotificationService; -import com.prgrms.catchtable.owner.domain.Owner; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -18,13 +18,13 @@ public class NotificationEvent { @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sendMessage(Member member, NotificationContent content) { - notificationService.sendMessageAndSave(member, content); + public void sendMessage(SendMessageToMemberRequest request) { + notificationService.sendMessageAndSave(request.member(), request.content()); } @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 - public void sendMessage(Owner owner, NotificationContent content) { - notificationService.sendMessageAndSave(owner, content); + public void sendMessage(SendMessageToOwnerRequest request) { + notificationService.sendMessageAndSave(request.owner(), request.content()); } } From dedf3268e38e7733655f2031f5d143ad5a05644a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 16:06:05 +0900 Subject: [PATCH 430/603] =?UTF-8?q?refactor=20:=20@EnableAsync=20import=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/config/AsyncConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java b/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java index 2f5b7012..27656f37 100644 --- a/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java +++ b/src/main/java/com/prgrms/catchtable/common/config/AsyncConfig.java @@ -1,9 +1,10 @@ package com.prgrms.catchtable.common.config; import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +@EnableAsync @Configuration -@org.springframework.scheduling.annotation.EnableAsync public class AsyncConfig { } From 06820f7a5b687c013555e2c4044e67282baabeb7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 9 Jan 2024 16:12:19 +0900 Subject: [PATCH 431/603] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20email=20=EB=84=A3=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=83=81=EC=88=98=EB=A1=9C=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationServiceTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 5d837e4e..cf3ead87 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -51,12 +51,13 @@ class MemberReservationServiceTest { private ReservationTimeRepository reservationTimeRepository; @InjectMocks private MemberReservationService memberReservationService; + private final String email = "dlswns661035@gmail.com"; @Test @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { //given - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( @@ -84,7 +85,7 @@ void validateReservation() { @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") void alreadyPreOccupied() { //given - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); ReflectionTestUtils.setField(reservationTime, "id", 1L); CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( @@ -103,7 +104,7 @@ void alreadyPreOccupied() { @Test @DisplayName("최종예약을 등록할 때 예약시간이 비었으면 성공적으로 예약 등록을 완료한다.") void registerReservation() { - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); Reservation reservation = Reservation.builder() @@ -130,7 +131,7 @@ void registerReservation() { @Test @DisplayName("최종예약을 등록할 때 타인이 이미 예약한 경우 예외가 발생한다.") void registerReservationAlreadyOccupied() { - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); @@ -145,7 +146,7 @@ void registerReservationAlreadyOccupied() { @Test @DisplayName("예약 전체 조회를 할 수 있다") void getAllReservation() { - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); Reservation reservation = ReservationFixture.getReservation(reservationTime, member); @@ -167,7 +168,7 @@ void getAllReservation() { @Test @DisplayName("예약 내역이 하나도 없을 시 조회되는 예약이 없다.") void getAllReservationWithNoResult() { - Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member member = MemberFixture.member(email); when(reservationRepository.findAllWithReservationTimeAndShopByMemberId(member)).thenReturn( List.of()); From 2aa01a8259199fd4f3426b52fdf30f4baefad71d Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:11:50 +0900 Subject: [PATCH 432/603] =?UTF-8?q?fix=20:=20Service=EB=A5=BC=20Member?= =?UTF-8?q?=EC=99=80=20Owner=20=EA=B0=81=EA=B0=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/controller/OwnerShopController.java | 4 ++-- .../service/{ShopService.java => OwnerShopService.java} | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) rename src/main/java/com/prgrms/catchtable/shop/service/{ShopService.java => OwnerShopService.java} (81%) diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java index bddd92bd..52fd02d0 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java @@ -4,7 +4,7 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.shop.dto.RegistShopRequest; import com.prgrms.catchtable.shop.dto.RegistShopResponse; -import com.prgrms.catchtable.shop.service.ShopService; +import com.prgrms.catchtable.shop.service.OwnerShopService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -19,7 +19,7 @@ @RequestMapping("/owners") public class OwnerShopController { - private final ShopService shopService; + private final OwnerShopService shopService; @PostMapping("/shops") public ResponseEntity registShop(@Valid @RequestBody RegistShopRequest request, @LogIn diff --git a/src/main/java/com/prgrms/catchtable/shop/service/ShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java similarity index 81% rename from src/main/java/com/prgrms/catchtable/shop/service/ShopService.java rename to src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index 188dc368..f42af3e1 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/ShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -8,19 +8,21 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor -public class ShopService { +public class OwnerShopService { private final ShopRepository shopRepository; + @Transactional public RegistShopResponse registShop(RegistShopRequest registShopRequest, Owner owner){ Shop registShop = shopRepository.save(ShopMapper.toEntity(registShopRequest)); owner.insertShop(registShop); - return ShopMapper.of(registShop); + return ShopMapper.toRegistShopResponse(registShop); } From 6ee473f1f9bcd108c7de377527949a48775ac762 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:14:16 +0900 Subject: [PATCH 433/603] =?UTF-8?q?feat=20:=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/dto/GetAllShopResponse.java | 9 ++++++++ .../catchtable/shop/dto/GetShopResponse.java | 22 ++++++++++++++++++ .../catchtable/shop/dto/ShopMapper.java | 23 ++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java new file mode 100644 index 00000000..806e607a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.shop.dto; + +import java.util.List; + +public record GetAllShopResponse( + List shopResponses +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java new file mode 100644 index 00000000..54661903 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java @@ -0,0 +1,22 @@ +package com.prgrms.catchtable.shop.dto; + +import java.math.BigDecimal; +import java.time.LocalTime; +import lombok.Builder; + +@Builder +public record GetShopResponse( + + Long id, + String name, + BigDecimal rating, + String category, + String city, + String district, + int capacity, + LocalTime openingTime, + LocalTime closingTime + +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 24bcfe53..d77e2227 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; import java.math.BigDecimal; +import java.util.List; public class ShopMapper { @@ -23,7 +24,7 @@ public static Shop toEntity(RegistShopRequest registShopRequest){ .build(); } - public static RegistShopResponse of(Shop shop){ + public static RegistShopResponse toRegistShopResponse(Shop shop){ return RegistShopResponse.builder() .name(shop.getName()) .rating(Integer.parseInt(String.valueOf(shop.getRating()))) @@ -36,4 +37,24 @@ public static RegistShopResponse of(Shop shop){ .build(); } + public static GetAllShopResponse toGetAllShopResponse(List shops){ + return new GetAllShopResponse(shops.stream() + .map(ShopMapper::toGetShopResponse) + .toList()); + } + + public static GetShopResponse toGetShopResponse(Shop shop){ + return GetShopResponse.builder() + .id(shop.getId()) + .name(shop.getName()) + .rating(shop.getRating()) + .category(shop.getCategory().getType()) + .city(shop.getAddress().getCity()) + .district(shop.getAddress().getDistrict()) + .capacity(shop.getCapacity()) + .openingTime(shop.getOpeningTime()) + .closingTime(shop.getClosingTime()) + .build(); + } + } From 770d912bc96084ad51814e7aff2c67e183799f7c Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:15:33 +0900 Subject: [PATCH 434/603] =?UTF-8?q?feat=20:=20Shop=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20&=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/MemberShopController.java | 24 +++++++++++++++++++ .../shop/service/MemberShopService.java | 23 ++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java new file mode 100644 index 00000000..3c7cf533 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -0,0 +1,24 @@ +package com.prgrms.catchtable.shop.controller; + +import com.prgrms.catchtable.shop.dto.GetAllShopResponse; +import com.prgrms.catchtable.shop.service.MemberShopService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/shops/") +public class MemberShopController { + + private final MemberShopService memberShopService; + + @GetMapping + public GetAllShopResponse getAll(){ + return memberShopService.getAll(); + } + + + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java new file mode 100644 index 00000000..cc3644b0 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -0,0 +1,23 @@ +package com.prgrms.catchtable.shop.service; + +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.ShopMapper; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberShopService { + + private final ShopRepository shopRepository; + + @Transactional(readOnly = true) + public GetAllShopResponse getAll() { + List allShop = shopRepository.findAll(); + return ShopMapper.toGetAllShopResponse(allShop); + } +} From 319a8b944d2139b5f5974fb37751ef36f57bce2e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:19:10 +0900 Subject: [PATCH 435/603] =?UTF-8?q?feat=20:=20Shop=20=EB=8B=A8=EA=B1=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20&=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/MemberShopController.java | 6 ++++++ .../catchtable/shop/service/MemberShopService.java | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index 3c7cf533..fbbeb905 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -1,9 +1,11 @@ package com.prgrms.catchtable.shop.controller; import com.prgrms.catchtable.shop.dto.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.GetShopResponse; import com.prgrms.catchtable.shop.service.MemberShopService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -19,6 +21,10 @@ public GetAllShopResponse getAll(){ return memberShopService.getAll(); } + @GetMapping("/{shopId}") + public GetShopResponse getById(@PathVariable("shopId") Long id){ + return memberShopService.getById(id); + } } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index cc3644b0..c9d76c67 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -1,7 +1,11 @@ package com.prgrms.catchtable.shop.service; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.GetShopResponse; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; @@ -20,4 +24,11 @@ public GetAllShopResponse getAll() { List allShop = shopRepository.findAll(); return ShopMapper.toGetAllShopResponse(allShop); } + + @Transactional(readOnly = true) + public GetShopResponse getById(Long id){ + Shop findShop = shopRepository.findById(id) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); + return ShopMapper.toGetShopResponse(findShop); + } } From 73f7e531378475b55140f77c108073c1917b85ee Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:20:27 +0900 Subject: [PATCH 436/603] =?UTF-8?q?fix=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=98=ED=99=98=20=ED=83=80=EC=9E=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/controller/MemberShopController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index fbbeb905..89a427f9 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.shop.dto.GetShopResponse; import com.prgrms.catchtable.shop.service.MemberShopService; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,13 +18,13 @@ public class MemberShopController { private final MemberShopService memberShopService; @GetMapping - public GetAllShopResponse getAll(){ - return memberShopService.getAll(); + public ResponseEntity getAll(){ + return ResponseEntity.ok(memberShopService.getAll()); } @GetMapping("/{shopId}") - public GetShopResponse getById(@PathVariable("shopId") Long id){ - return memberShopService.getById(id); + public ResponseEntity getById(@PathVariable("shopId") Long id){ + return ResponseEntity.ok(memberShopService.getById(id)); } From 175d5c086d6b57e63629c7f8c11c0e88bcced70b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 17:26:41 +0900 Subject: [PATCH 437/603] =?UTF-8?q?chore=20:=20Query=20Dsl=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20&=20=EC=84=A4=EC=A0=95=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build.gradle b/build.gradle index 4860a110..835767d1 100644 --- a/build.gradle +++ b/build.gradle @@ -62,9 +62,30 @@ dependencies { implementation group: 'org.json', name: 'json', version: '20231013' + //Query Dsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } +//Query Dsl +def querydslDir = "src/main/generated" + +sourceSets { + main.java.srcDirs += [querydslDir] +} + +tasks.withType(JavaCompile) { + options.getGeneratedSourceOutputDirectory().set(file(querydslDir)) +} + +clean.doLast { + file(querydslDir).deleteDir() +} +//Query Dsl + tasks.named('test') { useJUnitPlatform() } From 5d1d275cbbb82383f67d3ff4d74f12be4c046c05 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 18:13:09 +0900 Subject: [PATCH 438/603] =?UTF-8?q?refactor=20:=20dto=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/controller/MemberShopController.java | 4 ++-- .../catchtable/shop/controller/OwnerShopController.java | 4 ++-- src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java | 4 ++++ .../catchtable/shop/dto/{ => request}/RegistShopRequest.java | 2 +- .../shop/dto/{ => response}/GetAllShopResponse.java | 2 +- .../catchtable/shop/dto/{ => response}/GetShopResponse.java | 2 +- .../shop/dto/{ => response}/RegistShopResponse.java | 2 +- .../com/prgrms/catchtable/shop/service/MemberShopService.java | 4 ++-- .../com/prgrms/catchtable/shop/service/OwnerShopService.java | 4 ++-- 9 files changed, 16 insertions(+), 12 deletions(-) rename src/main/java/com/prgrms/catchtable/shop/dto/{ => request}/RegistShopRequest.java (90%) rename src/main/java/com/prgrms/catchtable/shop/dto/{ => response}/GetAllShopResponse.java (68%) rename src/main/java/com/prgrms/catchtable/shop/dto/{ => response}/GetShopResponse.java (86%) rename src/main/java/com/prgrms/catchtable/shop/dto/{ => response}/RegistShopResponse.java (88%) diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index 89a427f9..ba86256e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.shop.controller; -import com.prgrms.catchtable.shop.dto.GetAllShopResponse; -import com.prgrms.catchtable.shop.dto.GetShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.service.MemberShopService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java index 52fd02d0..291e199b 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java @@ -2,8 +2,8 @@ import com.prgrms.catchtable.common.login.LogIn; import com.prgrms.catchtable.owner.domain.Owner; -import com.prgrms.catchtable.shop.dto.RegistShopRequest; -import com.prgrms.catchtable.shop.dto.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; import com.prgrms.catchtable.shop.service.OwnerShopService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index d77e2227..0ec5cda1 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -3,6 +3,10 @@ import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetShopResponse; +import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; import java.math.BigDecimal; import java.util.List; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java similarity index 90% rename from src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java rename to src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java index 6631c8e5..dc592e66 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopRequest.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.shop.dto; +package com.prgrms.catchtable.shop.dto.request; import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.constraints.Max; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java similarity index 68% rename from src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java rename to src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java index 806e607a..4303c5ac 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/GetAllShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.shop.dto; +package com.prgrms.catchtable.shop.dto.response; import java.util.List; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java similarity index 86% rename from src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java rename to src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java index 54661903..f6c3688a 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/GetShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.shop.dto; +package com.prgrms.catchtable.shop.dto.response; import java.math.BigDecimal; import java.time.LocalTime; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java similarity index 88% rename from src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java rename to src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java index f68c8f21..dd2a7455 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/RegistShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.shop.dto; +package com.prgrms.catchtable.shop.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; import java.time.LocalTime; diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index c9d76c67..5afe905f 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -4,8 +4,8 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.GetAllShopResponse; -import com.prgrms.catchtable.shop.dto.GetShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; diff --git a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index f42af3e1..e62d25b3 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -2,8 +2,8 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.RegistShopRequest; -import com.prgrms.catchtable.shop.dto.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; From ea00b505701a63adbfaa0b271d079f8c641660a3 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 18:39:31 +0900 Subject: [PATCH 439/603] =?UTF-8?q?chore=20:=20gitignore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(Q=ED=81=B4=EB=9E=98=EC=8A=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 182f11ab..02e02a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ out/ ### VS Code ### .vscode/ application.yaml -.DS_Store \ No newline at end of file +.DS_Store +src/main/generated/** \ No newline at end of file From 40e7ccd8d50430f7e4cfb7f87a0d966f7a0f7b29 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 20:08:35 +0900 Subject: [PATCH 440/603] =?UTF-8?q?feat=20:=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index e6e4fe70..69a96e14 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -68,7 +68,7 @@ public Waiting(int waitingNumber, int peopleCount, Member member, Shop shop) { } public void decreasePostponeRemainingCount() { - if (remainingPostponeCount <= 0) { + if (remainingPostponeCount == 0) { throw new BadRequestCustomException(POSTPONE_REMAINING_CNT_0); } remainingPostponeCount--; From 1d9ff2234e9d4a023781d90cc2b1d4787d0a9e16 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 20:27:44 +0900 Subject: [PATCH 441/603] =?UTF-8?q?feat=20:=20Shop=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/dto/request/ShopSearchCondition.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/request/ShopSearchCondition.java diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/request/ShopSearchCondition.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/ShopSearchCondition.java new file mode 100644 index 00000000..61554467 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/ShopSearchCondition.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.shop.dto.request; + +public record ShopSearchCondition( + String name, + String category, + String city +) { + +} From 7613634f3eb5d51cbd8079beac6c24e0dd4dfb73 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 9 Jan 2024 20:28:01 +0900 Subject: [PATCH 442/603] =?UTF-8?q?feat=20:=20Shop=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20&=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/MemberShopController.java | 7 +++ .../shop/repository/ShopRepository.java | 2 +- .../shop/repository/ShopRepositoryCustom.java | 11 ++++ .../shop/repository/ShopRepositoryImpl.java | 57 +++++++++++++++++++ .../shop/service/MemberShopService.java | 7 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index ba86256e..c66d96cd 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -1,11 +1,13 @@ package com.prgrms.catchtable.shop.controller; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.service.MemberShopService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -27,5 +29,10 @@ public ResponseEntity getById(@PathVariable("shopId") Long id){ return ResponseEntity.ok(memberShopService.getById(id)); } + @GetMapping("/search") + public ResponseEntity getBySearch(@ModelAttribute ShopSearchCondition condition){ + return ResponseEntity.ok(memberShopService.getBySearch(condition)); + } + } diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 2dc4ae92..1aa0efca 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -3,6 +3,6 @@ import com.prgrms.catchtable.shop.domain.Shop; import org.springframework.data.jpa.repository.JpaRepository; -public interface ShopRepository extends JpaRepository { +public interface ShopRepository extends JpaRepository, ShopRepositoryCustom{ } diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java new file mode 100644 index 00000000..59d67420 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.shop.repository; + +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; +import java.util.List; + +public interface ShopRepositoryCustom { + + List search(ShopSearchCondition condition); + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java new file mode 100644 index 00000000..3d55ac04 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java @@ -0,0 +1,57 @@ +package com.prgrms.catchtable.shop.repository; + +import static com.prgrms.catchtable.shop.domain.QShop.*; + +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import java.util.List; + +public class ShopRepositoryImpl implements ShopRepositoryCustom{ + + private final JPAQueryFactory queryFactory; + + public ShopRepositoryImpl(EntityManager em){ + queryFactory = new JPAQueryFactory(em); + } + + @Override + public List search(ShopSearchCondition condition) { + return queryFactory + .selectFrom(shop) + .where( + equalsName(condition.name()), + equalCategory(condition.category()), + equalCity(condition.city()) + ) + .orderBy( + //평점 내림차순 + ratingDesc() + ) + .fetch(); + } + + private BooleanExpression equalsName(String name){ + if(name.isEmpty()){ + return null; + } + + return shop.name.eq(name); + } + + private BooleanExpression equalCategory(String category){ + return shop.category.eq(Category.of(category)); + } + + private BooleanExpression equalCity(String city) { + return shop.address.city.eq(city); + } + + private OrderSpecifier ratingDesc() { + return shop.rating.desc(); + } +} diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 5afe905f..f551c239 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.dto.ShopMapper; @@ -31,4 +32,10 @@ public GetShopResponse getById(Long id){ .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); return ShopMapper.toGetShopResponse(findShop); } + + @Transactional(readOnly = true) + public GetAllShopResponse getBySearch(ShopSearchCondition condition){ + List searchShop = shopRepository.search(condition); + return ShopMapper.toGetAllShopResponse(searchShop); + } } From 57e95274aacc02df7d6645832f6f00d9e1e6b7df Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 22:25:20 +0900 Subject: [PATCH 443/603] =?UTF-8?q?feat=20:=20memberId=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20member=20=EA=B0=9D=EC=B2=B4=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=EB=A1=9C=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingController.java | 27 +++++------ .../waiting/service/MemberWaitingService.java | 12 ++--- .../MemberWaitingControllerTest.java | 46 +++++++++++++------ .../service/MemberWaitingServiceTest.java | 12 ++--- 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 7e757e41..003d6511 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.waiting.controller; +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; @@ -32,32 +34,31 @@ public ResponseEntity createWaiting(@PathVariable("shopId return ResponseEntity.ok(response); } - @PatchMapping("/{memberId}") + @PatchMapping public ResponseEntity postponeWaiting( - @PathVariable("memberId") Long memberId) { - MemberWaitingResponse response = memberWaitingService.postponeWaiting(memberId); + @LogIn Member member) { + MemberWaitingResponse response = memberWaitingService.postponeWaiting(member); return ResponseEntity.ok(response); } - @DeleteMapping("/{memberId}") + @DeleteMapping public ResponseEntity cancelWaiting( - @PathVariable("memberId") Long memberId) { - MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); + @LogIn Member member) { + MemberWaitingResponse response = memberWaitingService.cancelWaiting(member); return ResponseEntity.ok(response); } - @GetMapping("/{memberId}") + @GetMapping public ResponseEntity getWaiting( - @PathVariable("memberId") Long memberId) { - MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); + @LogIn Member member) { + MemberWaitingResponse response = memberWaitingService.getWaiting(member); return ResponseEntity.ok(response); } - @GetMapping("/all/{memberId}") + @GetMapping("/all") public ResponseEntity getMemberWaitingHistory( - @PathVariable("memberId") Long memberId) { - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( - memberId); + @LogIn Member member) { + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory(member); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index b740f60b..29f58426 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -66,8 +66,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Long memberId, } @Transactional - public MemberWaitingResponse postponeWaiting(Long memberId) { - Member member = getMemberEntity(memberId); + public MemberWaitingResponse postponeWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); @@ -80,8 +79,7 @@ public MemberWaitingResponse postponeWaiting(Long memberId) { } @Transactional - public MemberWaitingResponse cancelWaiting(Long memberId) { - Member member = getMemberEntity(memberId); + public MemberWaitingResponse cancelWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); @@ -92,8 +90,7 @@ public MemberWaitingResponse cancelWaiting(Long memberId) { } @Transactional(readOnly = true) - public MemberWaitingResponse getWaiting(Long memberId) { - Member member = getMemberEntity(memberId); + public MemberWaitingResponse getWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); @@ -103,8 +100,7 @@ public MemberWaitingResponse getWaiting(Long memberId) { } @Transactional(readOnly = true) - public MemberWaitingHistoryListResponse getMemberWaitingHistory(Long memberId) { - Member member = getMemberEntity(memberId); + public MemberWaitingHistoryListResponse getMemberWaitingHistory(Member member) { List waitings = waitingRepository.findWaitingWithMember(member); return toMemberWaitingListResponse(waitings); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index d1bf241b..380875af 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.waiting.controller; +import static com.prgrms.catchtable.common.Role.MEMBER; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; @@ -16,6 +17,7 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; @@ -35,6 +37,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.http.HttpHeaders; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; @@ -130,8 +133,9 @@ void createWaiting() throws Exception { @Test void postponeWaiting() throws Exception { //when, then - mockMvc.perform(patch("/waitings/{memberId}", member2.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(patch("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member2))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) @@ -144,8 +148,9 @@ void postponeWaiting() throws Exception { @DisplayName("맨 뒤의 멤버가 웨이팅 지연 API 호출 시 예외를 반환한다.") @Test void postponeWaiting_fails() throws Exception { - mockMvc.perform(patch("/waitings/{memberId}", member3.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(patch("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member3))) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 맨뒤라 웨이팅을 미룰 수 없습니다.")) .andDo(MockMvcResultHandlers.print()); @@ -158,8 +163,9 @@ void postponeWaiting_fails() throws Exception { void postponeWaiting_fails2() throws Exception { ReflectionTestUtils.setField(waiting2, "remainingPostponeCount", 0); waitingRepository.save(waiting2); - mockMvc.perform(patch("/waitings/{memberId}", member2.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(patch("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member2))) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 두 차례 대기를 미뤘습니다.")) .andDo(MockMvcResultHandlers.print()); @@ -169,8 +175,9 @@ void postponeWaiting_fails2() throws Exception { @Test void cancelWaiting() throws Exception { //when, then - mockMvc.perform(delete("/waitings/{memberId}", member1.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(delete("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member1))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) @@ -190,14 +197,15 @@ void cancelWaiting() throws Exception { @Test void getWaiting() throws Exception { //when, then - mockMvc.perform(get("/waitings/{memberId}", member3.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(get("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member2))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) - .andExpect(jsonPath("$.rank").value(3L)) - .andExpect(jsonPath("$.waitingNumber").value(waiting3.getWaitingNumber())) - .andExpect(jsonPath("$.peopleCount").value(waiting3.getPeopleCount())) + .andExpect(jsonPath("$.rank").value(2L)) + .andExpect(jsonPath("$.waitingNumber").value(waiting2.getWaitingNumber())) + .andExpect(jsonPath("$.peopleCount").value(waiting2.getPeopleCount())) .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) .andDo(MockMvcResultHandlers.print()); } @@ -209,8 +217,9 @@ void getMemberWaitingHistory() throws Exception { Waiting canceledWaiting = WaitingFixture.canceledWaiting(member1, shop, 23); Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 233); waitingRepository.saveAll(List.of(canceledWaiting, completedWaiting)); - mockMvc.perform(get("/waitings/all/{memberId}", member1.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(get("/waitings/all") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member1))) .andExpect(status().isOk()) .andExpect(jsonPath("$.memberWaitings", hasSize(3))) .andExpect(jsonPath("$.memberWaitings[0].waitingId").value(waiting1.getId())) @@ -222,4 +231,11 @@ void getMemberWaitingHistory() throws Exception { .andDo(MockMvcResultHandlers.print()) ; } + + private HttpHeaders getHttpHeaders(Member member) { + Token token = jwtTokenProvider.createToken(member.getEmail(), MEMBER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + return httpHeaders; + } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 01914252..027e80c4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -87,7 +87,6 @@ void postponeWaiting() { Member member = mock(Member.class); Waiting waiting = mock(Waiting.class); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); @@ -96,7 +95,7 @@ void postponeWaiting() { doNothing().when(waiting).decreasePostponeRemainingCount(); //when - MemberWaitingResponse response = memberWaitingService.postponeWaiting(1L); + MemberWaitingResponse response = memberWaitingService.postponeWaiting(member); //then assertAll( assertThat(response.peopleCount())::isNotNull, @@ -113,7 +112,6 @@ void cancelWaiting() { Member member = mock(Member.class); Waiting waiting = mock(Waiting.class); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); @@ -121,7 +119,7 @@ void cancelWaiting() { doNothing().when(waiting).changeStatusCanceled(); //when - MemberWaitingResponse response = memberWaitingService.cancelWaiting(1L); + MemberWaitingResponse response = memberWaitingService.cancelWaiting(member); //then assertAll( @@ -139,13 +137,12 @@ void getWaiting() { Member member = mock(Member.class); Waiting waiting = mock(Waiting.class); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); //when - MemberWaitingResponse response = memberWaitingService.getWaiting(1L); + MemberWaitingResponse response = memberWaitingService.getWaiting(member); //then assertAll( @@ -163,7 +160,6 @@ void getMemberAllWaiting() { Shop shop = mock(Shop.class); Waiting waiting = mock(Waiting.class); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.findWaitingWithMember(member)).willReturn( List.of(waiting)); given(waiting.getShop()).willReturn(shop); @@ -171,7 +167,7 @@ void getMemberAllWaiting() { //when MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( - 1L); + member); //then assertAll( From 40c7636a3c629c3c08809c7c3867a406a68a9313 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 22:49:24 +0900 Subject: [PATCH 444/603] =?UTF-8?q?feat=20:=20ownerId=20=EB=8C=80=EC=8B=A0?= =?UTF-8?q?=20owner=20=EA=B0=9D=EC=B2=B4=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=EB=A1=9C=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingController.java | 14 +++++++------ .../waiting/service/OwnerWaitingService.java | 8 ++------ .../OwnerWaitingControllerTest.java | 20 +++++++++++++------ .../service/OwnerWaitingServiceTest.java | 6 ++---- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index ee3fbfec..1c802f27 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.waiting.controller; +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.service.OwnerWaitingService; @@ -18,17 +20,17 @@ public class OwnerWaitingController { private final OwnerWaitingService ownerWaitingService; - @GetMapping("/{ownerId}") + @GetMapping public ResponseEntity getOwnerAllWaiting( - @PathVariable("ownerId") Long ownerId) { - OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(ownerId); + @LogIn Owner owner) { + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(owner); return ResponseEntity.ok(response); } - @PatchMapping("/{ownerId}") + @PatchMapping public ResponseEntity entryWaiting( - @PathVariable("ownerId") Long ownerId) { - OwnerWaitingResponse response = ownerWaitingService.entryWaiting(ownerId); + @LogIn Owner owner) { + OwnerWaitingResponse response = ownerWaitingService.entryWaiting(owner); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 39bfff51..c489bc1e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -28,9 +28,7 @@ public class OwnerWaitingService { private final OwnerRepository ownerRepository; @Transactional(readOnly = true) - public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { - Owner owner = ownerRepository.findById(ownerId) - .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); + public OwnerWaitingListResponse getOwnerAllWaiting(Owner owner) { List waitingIds = waitingLineRepository.getShopWaitingIdsInOrder( owner.getShop().getId()); List waitings = waitingRepository.findByIds(waitingIds); @@ -38,9 +36,7 @@ public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { } @Transactional - public OwnerWaitingResponse entryWaiting(Long ownerId) { - Owner owner = ownerRepository.findById(ownerId) - .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); + public OwnerWaitingResponse entryWaiting(Owner owner) { Long enteredWaitingId = waitingLineRepository.entry(owner.getShop().getId()); Waiting waiting = waitingRepository.findById(enteredWaitingId) .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 9823aeed..7d6e6f97 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.waiting.controller; +import static com.prgrms.catchtable.common.Role.MEMBER; +import static com.prgrms.catchtable.common.Role.OWNER; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -9,6 +11,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; @@ -48,7 +51,6 @@ class OwnerWaitingControllerTest extends BaseIntegrationTest { private StringRedisTemplate redisTemplate; private Shop shop; - private Owner owner; private Waiting waiting1, waiting2, waiting3; @@ -62,7 +64,7 @@ void setUp() { shop = ShopFixture.shopWith24(); shopRepository.save(shop); - owner = OwnerFixture.getOwner(shop); + Owner owner = OwnerFixture.getOwner(shop); ownerRepository.save(owner); waiting1 = Waiting.builder() @@ -89,6 +91,10 @@ void setUp() { waitingLineRepository.save(shop.getId(), waiting1.getId()); waitingLineRepository.save(shop.getId(), waiting2.getId()); waitingLineRepository.save(shop.getId(), waiting3.getId()); + + Token token = jwtTokenProvider.createToken(owner.getEmail(), OWNER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); } @AfterEach @@ -104,8 +110,9 @@ void clear() { @Test void getWaiting() throws Exception { //when, then - mockMvc.perform(get("/owner/waitings/{ownerId}", owner.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(get("/owner/waitings") + .contentType(APPLICATION_JSON) + .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopWaitings", hasSize(3))) .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(waiting1.getId())) @@ -125,8 +132,9 @@ void getWaiting() throws Exception { @Test void entryWaiting() throws Exception { //when, then - mockMvc.perform(patch("/owner/waitings/{ownerId}", owner.getId()) - .contentType(APPLICATION_JSON)) + mockMvc.perform(patch("/owner/waitings") + .contentType(APPLICATION_JSON) + .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$.waitingId").value(waiting1.getId())) .andExpect(jsonPath("$.waitingNumber").value(waiting1.getWaitingNumber())) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 4d7c59ef..1c0a5c0a 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -52,7 +52,6 @@ void getOwnerAllWaiting() { Waiting waiting1 = WaitingFixture.progressWaiting(member1, shop, 1); Waiting waiting2 = WaitingFixture.progressWaiting(member2, shop, 2); - given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( @@ -60,7 +59,7 @@ void getOwnerAllWaiting() { given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting1, waiting2)); //when - OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(owner); //then assertAll( @@ -85,12 +84,11 @@ void entryWaiting() { Shop shop = mock(Shop.class); Waiting waiting = WaitingFixture.progressWaiting(member, shop, 1); - given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(waitingLineRepository.entry(any(Long.class))).willReturn(1L); given(waitingRepository.findById(1L)).willReturn(Optional.of(waiting)); //when - OwnerWaitingResponse response = ownerWaitingService.entryWaiting(1L); + OwnerWaitingResponse response = ownerWaitingService.entryWaiting(owner); //then assertAll( () -> assertThat(response.waitingId()).isEqualTo(waiting.getId()), From bb4e15a088bd899c8f9981f401418c274bc2d25b Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 9 Jan 2024 23:13:32 +0900 Subject: [PATCH 445/603] =?UTF-8?q?feat=20:=20memberId=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20member=20=EC=82=AC=EC=9A=A9=20=EB=B0=8F=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=ED=95=84=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingController.java | 9 +- .../waiting/service/MemberWaitingService.java | 12 +-- .../waiting/service/OwnerWaitingService.java | 4 - .../MemberWaitingControllerDocsTest.java | 87 ------------------- .../MemberWaitingControllerTest.java | 9 +- .../service/MemberWaitingServiceTest.java | 7 +- 6 files changed, 13 insertions(+), 115 deletions(-) delete mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 003d6511..4f844d04 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -25,11 +25,11 @@ public class MemberWaitingController { private final MemberWaitingService memberWaitingService; - @PostMapping("/{shopId}/{memberId}") + @PostMapping("/{shopId}") public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, - @PathVariable("memberId") Long memberId, + @LogIn Member member, @Valid @RequestBody CreateWaitingRequest request) { - MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, member, request); return ResponseEntity.ok(response); } @@ -58,7 +58,8 @@ public ResponseEntity getWaiting( @GetMapping("/all") public ResponseEntity getMemberWaitingHistory( @LogIn Member member) { - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory(member); + MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( + member); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 29f58426..c7286637 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; -import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_MEMBER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; @@ -12,7 +11,6 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; @@ -38,14 +36,12 @@ public class MemberWaitingService { private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), LocalTime.of(23, 59, 59)); private final WaitingRepository waitingRepository; - private final MemberRepository memberRepository; private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; - public MemberWaitingResponse createWaiting(Long shopId, Long memberId, + public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { // 연관 엔티티 조회 - Member member = getMemberEntity(memberId); Shop shop = getShopEntity(shopId); // 기존 waiting이 있는지 검증 @@ -112,12 +108,6 @@ private void validateIfMemberWaitingExists(Member member) { } } - public Member getMemberEntity(Long memberId) { - return memberRepository.findById(memberId).orElseThrow( - () -> new NotFoundCustomException(NOT_EXIST_MEMBER) - ); - } - public Shop getShopEntity(Long shopId) { Shop shop = shopRepository.findById(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index c489bc1e..4c739adf 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -1,14 +1,11 @@ package com.prgrms.catchtable.waiting.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingResponse; -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; -import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; @@ -25,7 +22,6 @@ public class OwnerWaitingService { private final WaitingRepository waitingRepository; private final WaitingLineRepository waitingLineRepository; - private final OwnerRepository ownerRepository; @Transactional(readOnly = true) public OwnerWaitingListResponse getOwnerAllWaiting(Owner owner) { diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java deleted file mode 100644 index 6b7a0360..00000000 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.prgrms.catchtable.waiting.controller; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.prgrms.catchtable.common.restdocs.RestDocsSupport; -import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; -import com.prgrms.catchtable.waiting.service.MemberWaitingService; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; - -class MemberWaitingControllerDocsTest extends RestDocsSupport { - - private final MemberWaitingService memberWaitingService = mock(MemberWaitingService.class); - - @Override - protected Object initController() { - return new MemberWaitingController(memberWaitingService); - } - - @DisplayName("웨이팅 생성 API") - @Test - void createWaiting() throws Exception { - CreateWaitingRequest request = CreateWaitingRequest - .builder() - .peopleCount(2).build(); - MemberWaitingResponse response = MemberWaitingResponse.builder() - .waitingId(201L) - .shopId(1L) - .shopName("shop1") - .waitingNumber(324) - .rank(20L) - .peopleCount(2) - .remainingPostponeCount(2) - .status("진행 중") - .build(); - - given(memberWaitingService.createWaiting(1L, 1L, request)).willReturn(response); - - mockMvc.perform(post("/waitings/{shopId}/{memberId}", 1, 1) - .contentType(APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isOk()) - .andDo(MockMvcResultHandlers.print()) - .andDo(document("waiting-create", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - requestFields( - fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) - .description("인원수") - ), - responseFields( - fieldWithPath("waitingId").type(JsonFieldType.NUMBER) - .description("생성된 웨이팅 아이디"), - fieldWithPath("shopId").type(JsonFieldType.NUMBER) - .description("상점 아이디"), - fieldWithPath("shopName").type(JsonFieldType.STRING) - .description("상점 이름"), - fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) - .description("인원 수"), - fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) - .description("웨이팅 고유 번호"), - fieldWithPath("rank").type(JsonFieldType.NUMBER) - .description("웨이팅 순서"), - fieldWithPath("remainingPostponeCount").type(JsonFieldType.NUMBER) - .description("대기 지연 잔여 횟수"), - fieldWithPath("status").type(JsonFieldType.STRING) - .description("대기 상태") - ) - )); - - - } -} \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 380875af..ad85ee1e 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -115,9 +115,10 @@ void createWaiting() throws Exception { .peopleCount(2).build(); // when, then - mockMvc.perform(post("/waitings/{shopId}/{memberId}", shop.getId(), member4.getId()) + mockMvc.perform(post("/waitings/{shopId}", shop.getId()) .contentType(APPLICATION_JSON) - .content(asJsonString(request))) + .content(asJsonString(request)) + .headers(getHttpHeaders(member4))) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) @@ -164,8 +165,8 @@ void postponeWaiting_fails2() throws Exception { ReflectionTestUtils.setField(waiting2, "remainingPostponeCount", 0); waitingRepository.save(waiting2); mockMvc.perform(patch("/waitings") - .contentType(APPLICATION_JSON) - .headers(getHttpHeaders(member2))) + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member2))) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.message").value("이미 두 차례 대기를 미뤘습니다.")) .andDo(MockMvcResultHandlers.print()); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 027e80c4..93f1a1ed 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -11,7 +11,6 @@ import static org.mockito.Mockito.mock; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; @@ -37,8 +36,6 @@ class MemberWaitingServiceTest { private WaitingRepository waitingRepository; @Mock private ShopRepository shopRepository; - @Mock - private MemberRepository memberRepository; @Mock private WaitingLineRepository waitingLineRepository; @@ -60,17 +57,17 @@ void createWaiting() { .waitingNumber(1) .peopleCount(2) .build(); + doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); given(shop.getId()).willReturn(1L); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); given(waitingRepository.existsByMember(member)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); //when - MemberWaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(1L, member, request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), From 6c974b1b9ac1d8070e2c33cb4b699843443895ed Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 13:56:26 +0900 Subject: [PATCH 446/603] =?UTF-8?q?fix=20:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepositoryCustom.java | 2 +- .../prgrms/catchtable/shop/repository/ShopRepositoryImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java index 59d67420..0811174e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryCustom.java @@ -6,6 +6,6 @@ public interface ShopRepositoryCustom { - List search(ShopSearchCondition condition); + List findSearch(ShopSearchCondition condition); } diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java index 3d55ac04..bb48a8fe 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java @@ -20,7 +20,7 @@ public ShopRepositoryImpl(EntityManager em){ } @Override - public List search(ShopSearchCondition condition) { + public List findSearch(ShopSearchCondition condition) { return queryFactory .selectFrom(shop) .where( From 4f290507ea0776990f90bf605018340da962bb4f Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 13:58:08 +0900 Subject: [PATCH 447/603] =?UTF-8?q?fix=20:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/shop/service/MemberShopService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index f551c239..9b6ee979 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -35,7 +35,7 @@ public GetShopResponse getById(Long id){ @Transactional(readOnly = true) public GetAllShopResponse getBySearch(ShopSearchCondition condition){ - List searchShop = shopRepository.search(condition); + List searchShop = shopRepository.findSearch(condition); return ShopMapper.toGetAllShopResponse(searchShop); } } From 34571fe0a03bd64cce5832c4808425ebd058bf78 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 13:59:35 +0900 Subject: [PATCH 448/603] =?UTF-8?q?fix=20:=20dto=EC=9D=98=20rating=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/dto/request/RegistShopRequest.java | 5 ++++- .../catchtable/shop/dto/response/RegistShopResponse.java | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java index dc592e66..bffb4182 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java @@ -3,14 +3,17 @@ import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; +import java.math.BigDecimal; import java.time.LocalTime; +import lombok.Builder; +@Builder public record RegistShopRequest( String name, @Min(0) @Max(5) - int rating, + BigDecimal rating, String category, String city, String district, diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java index dd2a7455..1dde4ecf 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.shop.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; +import java.math.BigDecimal; import java.time.LocalTime; import lombok.Builder; @@ -8,7 +9,7 @@ public record RegistShopResponse( String name, - int rating, + BigDecimal rating, String category, String city, String district, From 6c09dfc3692979fc04ebcaa0a7d1b78ac2199386 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 14:01:13 +0900 Subject: [PATCH 449/603] =?UTF-8?q?fix=20:=20dto=EC=9D=98=20rating=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 0ec5cda1..24d39541 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -16,7 +16,7 @@ public static Shop toEntity(RegistShopRequest registShopRequest){ return Shop.builder() .name(registShopRequest.name()) - .rating(BigDecimal.valueOf(registShopRequest.rating())) + .rating(registShopRequest.rating()) .category(Category.of(registShopRequest.category())) .address(Address.builder() .city(registShopRequest.city()) @@ -31,7 +31,7 @@ public static Shop toEntity(RegistShopRequest registShopRequest){ public static RegistShopResponse toRegistShopResponse(Shop shop){ return RegistShopResponse.builder() .name(shop.getName()) - .rating(Integer.parseInt(String.valueOf(shop.getRating()))) + .rating(shop.getRating()) .category(shop.getCategory().getType()) .city(shop.getAddress().getCity()) .district(shop.getAddress().getDistrict()) From 18470b9794d7a196236eb5f8a178e89eab3f0a08 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 14:01:26 +0900 Subject: [PATCH 450/603] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EB=8D=94=EB=AF=B8=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/fixture/OwnerFixture.java | 11 +++++++++++ .../catchtable/shop/fixture/ShopFixture.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index d4fe383a..24cc0a71 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -13,6 +13,17 @@ public class OwnerFixture { + public static Owner getOwner(){ + return Owner.builder() + .name("ownerA") + .email("email1234@gmail.com") + .password("test1234") + .phoneNumber("010-3462-2480") + .gender(MALE) + .dateBirth(LocalDate.of(2000, 9, 13)) + .build(); + } + public static Owner getOwner(String email, String password) { Owner owner = Owner.builder() .name("ownerA") diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 615e126b..721ad049 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -3,6 +3,7 @@ import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; import java.math.BigDecimal; import java.time.LocalTime; @@ -31,4 +32,17 @@ public static Shop shopWith24() { .closingTime(LocalTime.of(23, 59, 59)) .build(); } + + public static RegistShopRequest getRequestDto(Shop shop){ + return RegistShopRequest.builder() + .name(shop.getName()) + .rating(shop.getRating()) + .category(shop.getCategory().getType()) + .city(shop.getAddress().getCity()) + .district(shop.getAddress().getDistrict()) + .capacity(shop.getCapacity()) + .openingTime(shop.getOpeningTime()) + .closingTime(shop.getClosingTime()) + .build(); + } } From e96a130f0fb815d2652dbd51cdc0692b6fa8a4c6 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 14:01:53 +0900 Subject: [PATCH 451/603] =?UTF-8?q?feat=20:=20Shop=20ReservationTime=20?= =?UTF-8?q?=EC=96=91=EB=B0=A9=ED=96=A5=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/ReservationTime.java | 1 + .../java/com/prgrms/catchtable/shop/domain/Shop.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 28d52594..a9867268 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -49,6 +49,7 @@ public ReservationTime(LocalDateTime time) { public void insertShop(Shop shop) { this.shop = shop; + shop.getReservationTimeList().add(this); } public void setOccupiedTrue() { diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index 36e74ef6..a3752115 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -7,17 +7,24 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.reservation.domain.ReservationTime; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; import java.math.BigDecimal; import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; @Getter @NoArgsConstructor(access = PROTECTED) @@ -51,6 +58,9 @@ public class Shop extends BaseEntity { @Column(name = "closing_time") private LocalTime closingTime; + @BatchSize(size = 30) + @OneToMany(mappedBy = "shop") + private List reservationTimeList = new ArrayList<>(); @Builder public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, From a45eb51c341ba6f9a756b5946efeb49e5bd249f0 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 14:04:41 +0900 Subject: [PATCH 452/603] =?UTF-8?q?fix=20:=20Shop=20=EB=8B=A8=EC=9D=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20ReservationTime=20fetchJoin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepository.java | 6 +++++- .../prgrms/catchtable/shop/service/MemberShopService.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 1aa0efca..322c928e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -1,8 +1,12 @@ package com.prgrms.catchtable.shop.repository; import com.prgrms.catchtable.shop.domain.Shop; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface ShopRepository extends JpaRepository, ShopRepositoryCustom{ - + @Query("select s from Shop s join fetch s.reservationTimeList where s.id = :id ") + Optional findByIdWithTime(@Param("id") Long id); } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 9b6ee979..464b3378 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -28,7 +28,7 @@ public GetAllShopResponse getAll() { @Transactional(readOnly = true) public GetShopResponse getById(Long id){ - Shop findShop = shopRepository.findById(id) + Shop findShop = shopRepository.findByIdWithTime(id) .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); return ShopMapper.toGetShopResponse(findShop); } From c5db156cb91b35011077f344c62ad9f1b7e6079f Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 14:09:08 +0900 Subject: [PATCH 453/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD=20=EB=B2=8C=ED=81=AC=20?= =?UTF-8?q?=EC=97=B0=EC=82=B0=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 6 ++++ .../repository/WaitingRepositoryTest.java | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index db1c814b..3093901e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -29,4 +30,9 @@ Optional findByMemberAndStatusWithShop(@Param("member") Member member, + "join fetch w.shop " + "join fetch w.member where w.member = :member") List findWaitingWithMember(@Param("member") Member member); + + @Modifying(clearAutomatically = true) + @Query("update Waiting w set w.status = :newStatus where w.status = :currentStatus") + void updateWaitingStatus(@Param("newStatus") WaitingStatus newStatus, + @Param("currentStatus") WaitingStatus currentStatus); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index da4f7f27..fc16fd2f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -1,7 +1,10 @@ package com.prgrms.catchtable.waiting.repository; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; @@ -15,6 +18,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -124,4 +128,31 @@ void findWaitingWithMember() { assertThat(memberAllWaitings).containsExactly(canceledWaiting, completedWaiting, progressWaiting); } + + @DisplayName("벌크 연산으로 진행 중인 대기 상태를 취소 상태로 업데이트 할 수 있다.") + @Test + void test() { + //given + Waiting progressWaiting1 = WaitingFixture.progressWaiting(member1, shop, 1); + Waiting progressWaiting2 = WaitingFixture.progressWaiting(member2, shop, 2); + Waiting progressWaiting3 = WaitingFixture.progressWaiting(member3, shop, 3); + Waiting completedWaiting = WaitingFixture.completedWaiting(member3, shop, 4); + + waitingRepository.saveAll( + List.of(progressWaiting1, progressWaiting2, progressWaiting3, completedWaiting)); + //when + waitingRepository.updateWaitingStatus(CANCELED,PROGRESS); + Waiting waiting1 = waitingRepository.findById(progressWaiting1.getId()).orElseThrow(); + Waiting waiting2 = waitingRepository.findById(progressWaiting2.getId()).orElseThrow(); + Waiting waiting3 = waitingRepository.findById(progressWaiting3.getId()).orElseThrow(); + Waiting waiting4 = waitingRepository.findById(completedWaiting.getId()).orElseThrow(); + + //then + assertAll( + () -> assertThat(waiting1.getStatus()).isEqualTo(CANCELED), + () -> assertThat(waiting2.getStatus()).isEqualTo(CANCELED), + () -> assertThat(waiting3.getStatus()).isEqualTo(CANCELED), + () -> assertThat(waiting4.getStatus()).isEqualTo(COMPLETED) + ); + } } \ No newline at end of file From a0e7de26482f58112f8d6f106a46d93cc7486ffb Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 14:19:27 +0900 Subject: [PATCH 454/603] feat : ShopService Test --- .../shop/service/ShopServiceTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java new file mode 100644 index 00000000..d90414d0 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -0,0 +1,91 @@ +package com.prgrms.catchtable.shop.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.ShopMapper; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class ShopServiceTest { + + @Mock + private ShopRepository shopRepository; + @InjectMocks + private MemberShopService memberShopService; + @InjectMocks + private OwnerShopService ownerShopService; + + @Test + @DisplayName("Owner가 Shop을 등록한다") + void registShopTest() { + //given + Owner owner = OwnerFixture.getOwner(); + + Shop shop = ShopFixture.shop(); + RegistShopRequest shopRequest = ShopFixture.getRequestDto(shop); + + //when + when(shopRepository.save(any(Shop.class))).thenReturn(shop); + RegistShopResponse registShopResponse = ownerShopService.registShop(shopRequest, owner); + + //then + assertThat(registShopResponse.name()).isEqualTo(shop.getName()); + assertThat(registShopResponse.city()).isEqualTo(shop.getAddress().getCity()); + assertThat(registShopResponse.rating()).isEqualTo(shop.getRating()); + assertThat(registShopResponse.openingTime()).isEqualTo(shop.getOpeningTime()); + } + + @Test + @DisplayName("Shop을 전체 조회할 수 있다.") + void getAllTest() { + //given + Shop shop = ShopFixture.shop(); + Shop shop2 = ShopFixture.shopWith24(); + List allShop = List.of(shop, shop2); + + //when + when(shopRepository.findAll()).thenReturn(allShop); + GetAllShopResponse all = memberShopService.getAll(); + + //then + assertThat(all.shopResponses().size()).isEqualTo(allShop.size()); + } + + @Test + @DisplayName("Shop을 단일 조회할 수 있다.") + void getByIdTest() { + //given + Shop shop = ShopFixture.shop(); + + //when + when(shopRepository.findByIdWithTime(1L)).thenReturn(Optional.of(shop)); + when(shopRepository.findByIdWithTime(2L)).thenReturn(Optional.empty()); + + //then + assertThat(memberShopService.getById(1L).name()).isEqualTo(shop.getName()); + assertThatThrownBy(()->memberShopService.getById(2L)).isInstanceOf(BadRequestCustomException.class); + } +} \ No newline at end of file From fe7fc783869b379448531c33a19ccd9f1b0e5110 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 15:05:33 +0900 Subject: [PATCH 455/603] =?UTF-8?q?feat=20:=20owner=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20=EC=95=8C=EB=A6=BC=20=ED=99=9C=EC=84=B1?= =?UTF-8?q?=ED=99=94=20=EC=97=AC=EB=B6=80=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/owner/domain/Owner.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index 8e748ae3..d5a06b1a 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -61,6 +61,9 @@ public class Owner extends BaseEntity implements UserDetails { @Column(name = "date_birth") private LocalDate dateBirth; + @Column(name = "notification_activated") + private boolean notification_activated; + @OneToOne(fetch = LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; @@ -75,6 +78,7 @@ public Owner(String name, String email, String password, String phoneNumber, Gen this.gender = gender; this.dateBirth = dateBirth; this.role = Role.OWNER; + this.notification_activated = true; } @Override From a98ec849aa66dbca6848da3f71801f62210b6b23 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 15:05:52 +0900 Subject: [PATCH 456/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=EB=B3=B4?= =?UTF-8?q?=EB=82=B4=EB=8A=94=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=84=88=EC=97=90=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/notification/NotificationEvent.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java index eba2c6e1..5ff260cf 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -2,9 +2,11 @@ import static org.springframework.transaction.event.TransactionPhase.AFTER_COMMIT; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.notification.dto.request.SendMessageToOwnerRequest; import com.prgrms.catchtable.notification.service.NotificationService; +import com.prgrms.catchtable.owner.domain.Owner; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -19,12 +21,18 @@ public class NotificationEvent { @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 public void sendMessage(SendMessageToMemberRequest request) { - notificationService.sendMessageAndSave(request.member(), request.content()); + Member member = request.member(); + if(member.isNotification_activated()){ + notificationService.sendMessageAndSave(member, request.content()); + } } @Async @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 public void sendMessage(SendMessageToOwnerRequest request) { - notificationService.sendMessageAndSave(request.owner(), request.content()); + Owner owner = request.owner(); + if(owner.isNotification_activated()){ + notificationService.sendMessageAndSave(request.owner(), request.content()); + } } } From 60b6bdb8d8c031da57d95f4dd1a9e3005d50df35 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 15:06:07 +0900 Subject: [PATCH 457/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index ee07abdc..18b42aab 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -4,6 +4,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; +import static com.prgrms.catchtable.common.notification.NotificationContent.*; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCancelReservationResponse; @@ -13,7 +14,9 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; @@ -29,6 +32,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,6 +44,7 @@ public class MemberReservationService { private final ReservationRepository reservationRepository; private final ReservationAsync reservationAsync; private final ReservationLockRepository reservationLockRepository; + private final ApplicationEventPublisher publisher; @Transactional public CreateReservationResponse preOccupyReservation(Member member, @@ -91,6 +96,13 @@ public CreateReservationResponse registerReservation(Member member, .member(member) .build(); Reservation savedReservation = reservationRepository.save(reservation); + + SendMessageToMemberRequest sendMessage = new SendMessageToMemberRequest( + member, + RESERVATION_COMPLETED + ); + + publisher.publishEvent(sendMessage); return toCreateReservationResponse(savedReservation); } From fe8a19b247dec295afaa563fcae32e7ea52a022b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 15:48:48 +0900 Subject: [PATCH 458/603] =?UTF-8?q?fix=20:=20Shop=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20null=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/repository/ShopRepositoryImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java index bb48a8fe..59dffeba 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java @@ -36,7 +36,7 @@ public List findSearch(ShopSearchCondition condition) { } private BooleanExpression equalsName(String name){ - if(name.isEmpty()){ + if(name == null){ return null; } @@ -44,10 +44,16 @@ private BooleanExpression equalsName(String name){ } private BooleanExpression equalCategory(String category){ + if (category == null){ + return null; + } return shop.category.eq(Category.of(category)); } private BooleanExpression equalCity(String city) { + if (city == null){ + return null; + } return shop.address.city.eq(city); } From cb8404891d53e0e81efe1408f51fb7219ae55e75 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 15:49:09 +0900 Subject: [PATCH 459/603] feat : ShopRepository Test --- .../shop/repository/ShopRepositoryTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java diff --git a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java new file mode 100644 index 00000000..4eee7b91 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java @@ -0,0 +1,69 @@ +package com.prgrms.catchtable.shop.repository; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; + +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = NONE) +class ShopRepositoryTest { + + @Autowired + private ShopRepository shopRepository; + + @Test + @DisplayName("이름 검색을 통해 Shop을 조회할 수 있다.") + void findNameSearchTest() { + //given + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), null, null); + + //when + List searchList = shopRepository.findSearch(condition); + + //then + assertThat(searchList.get(0)).isEqualTo(savedShop); + } + + @Test + @DisplayName("카테고리 검색을 통해 Shop을 조회할 수 있다.") + void findCategorySearchTest() { + //given + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), Category.WESTERN_FOOD.getType(), null); + + //when + List searchList = shopRepository.findSearch(condition); + + //then + assertThat(searchList.get(0)).isEqualTo(savedShop); + } + + @Test + @DisplayName("검색 조건 중 하나라도 값이 틀리면 조건이 성립하지 않는다.") + void findSearchTest() { + //given + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), Category.KOREAN_FOOD.getType(), savedShop.getAddress().getCity()); + + //when + List searchList = shopRepository.findSearch(condition); + + //then + assertThat(searchList.size()).isZero(); + } +} \ No newline at end of file From e32f2d7d079b539e5953052bcdd9abb65da9be0c Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 16:15:57 +0900 Subject: [PATCH 460/603] =?UTF-8?q?feat=20:=20OwnerShopController=20Test?= =?UTF-8?q?=20(Shop=20=EB=93=B1=EB=A1=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerShopControllerTest.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java new file mode 100644 index 00000000..fda0472e --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java @@ -0,0 +1,73 @@ +package com.prgrms.catchtable.shop.controller; + +import static org.junit.jupiter.api.Assertions.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.Role; +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; + +class OwnerShopControllerTest extends BaseIntegrationTest { + + @Autowired + private JwtTokenProvider jwtTokenProvider; + @Autowired + private OwnerRepository ownerRepository; + @Autowired + private RefreshTokenService refreshTokenService; + + private Owner owner; + private String email = "abc1234@gmail.com"; + private Token token; + + @BeforeEach + void init() { + //Owner 객체 저장 + owner = OwnerFixture.getOwner(email, "test"); + ownerRepository.save(owner); + + //토큰 발급 + token = jwtTokenProvider.createToken(email, Role.OWNER); + refreshTokenService.saveRefreshToken(token); + + //토큰 헤더 세팅 + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + } + + @Test + @DisplayName("Owner가 Shop을 등록한다.") + void registShopTest() throws Exception { + //given + Shop shop = ShopFixture.shop(); + RegistShopRequest shopRequest = ShopFixture.getRequestDto(shop); + + //then + mockMvc.perform(post("/owners/shops") + .contentType(MediaType.APPLICATION_JSON) + .headers(httpHeaders) + .content(asJsonString(shopRequest))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.name").value(shopRequest.name())) + .andExpect(jsonPath("$.rating").value(shopRequest.rating())) + .andExpect(jsonPath("$.category").value(shopRequest.category())) + .andExpect(jsonPath("$.city").value(shopRequest.city())) + .andExpect(jsonPath("$.district").value(shopRequest.district())) + .andExpect(jsonPath("$.capacity").value(shopRequest.capacity())); + } +} \ No newline at end of file From 59e286bebcfe616c7e210c15a04cf36febe0c95e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 16:25:43 +0900 Subject: [PATCH 461/603] =?UTF-8?q?fix=20:=20URL=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/controller/MemberShopController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index c66d96cd..8c8ae620 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -14,7 +14,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/shops/") +@RequestMapping("/shops") public class MemberShopController { private final MemberShopService memberShopService; From eadac54db34fe687da937a8e60937838073958dc Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:05:33 +0900 Subject: [PATCH 462/603] =?UTF-8?q?feat=20:=20=EB=B2=8C=ED=81=AC=20?= =?UTF-8?q?=EC=97=B0=EC=82=B0=20@=20Transactional=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/repository/WaitingRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 3093901e..e1d72c76 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -11,6 +11,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; public interface WaitingRepository extends JpaRepository { @@ -31,6 +32,7 @@ Optional findByMemberAndStatusWithShop(@Param("member") Member member, + "join fetch w.member where w.member = :member") List findWaitingWithMember(@Param("member") Member member); + @Transactional @Modifying(clearAutomatically = true) @Query("update Waiting w set w.status = :newStatus where w.status = :currentStatus") void updateWaitingStatus(@Param("newStatus") WaitingStatus newStatus, From a2079e0dfd2f4019638c0a3559a01eb3a522e7f2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:17:51 +0900 Subject: [PATCH 463/603] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/schedular/WaitingScheduler.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java new file mode 100644 index 00000000..ba4ccc51 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java @@ -0,0 +1,37 @@ +package com.prgrms.catchtable.waiting.schedular; + +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; + +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import java.util.Set; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@EnableScheduling +@RequiredArgsConstructor +public class WaitingScheduler { + + private final StringRedisTemplate redisTemplate; + + private final WaitingRepository waitingRepository; + + //매일 자정 레디스 데이터 비우기 + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") + public void clearRedis() { + Set keys = redisTemplate.keys("s*"); + redisTemplate.delete(keys); + } + + //매일 자정 대기 상태 바꾸기 + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") + public void changeProgressStatus() { + waitingRepository.updateWaitingStatus(CANCELED, PROGRESS); + } +} From 8a22068282990a31f45116d9b90c05204dc7c44d Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:18:24 +0900 Subject: [PATCH 464/603] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=9F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/WaitingRepositoryTest.java | 3 +- .../schedular/WaitingSchedulerTest.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index fc16fd2f..48567015 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -131,7 +131,7 @@ void findWaitingWithMember() { @DisplayName("벌크 연산으로 진행 중인 대기 상태를 취소 상태로 업데이트 할 수 있다.") @Test - void test() { + void updateWaitingStatus() { //given Waiting progressWaiting1 = WaitingFixture.progressWaiting(member1, shop, 1); Waiting progressWaiting2 = WaitingFixture.progressWaiting(member2, shop, 2); @@ -142,6 +142,7 @@ void test() { List.of(progressWaiting1, progressWaiting2, progressWaiting3, completedWaiting)); //when waitingRepository.updateWaitingStatus(CANCELED,PROGRESS); + System.out.println("progressWaiting3 = " + progressWaiting3.getStatus()); Waiting waiting1 = waitingRepository.findById(progressWaiting1.getId()).orElseThrow(); Waiting waiting2 = waitingRepository.findById(progressWaiting2.getId()).orElseThrow(); Waiting waiting3 = waitingRepository.findById(progressWaiting3.getId()).orElseThrow(); diff --git a/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java b/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java new file mode 100644 index 00000000..3782170a --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java @@ -0,0 +1,46 @@ +package com.prgrms.catchtable.waiting.schedular; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +@Disabled +class WaitingSchedulerTest { + + @Autowired + private WaitingLineRepository waitingLineRepository; + + @Autowired + private StringRedisTemplate redisTemplate; + + @AfterEach + void clear(){ + redisTemplate.delete("s1"); + } + + @DisplayName("특정 시간 주기로 redis 데이터를 비울 수 있다.") + @Test + void clearRedis() throws InterruptedException { + Long shopId = 1L; + + waitingLineRepository.save(shopId, 1L); + waitingLineRepository.save(shopId, 2L); + waitingLineRepository.save(shopId, 3L); + + assertThat(waitingLineRepository.getWaitingLineSize(shopId)).isEqualTo(3); + + Thread.sleep(60*1000); + assertThat(waitingLineRepository.getWaitingLineSize(shopId)).isZero(); + + } +} \ No newline at end of file From 7c6f5102cd2fde922ac8041832920535e1f727d4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 17:27:37 +0900 Subject: [PATCH 465/603] =?UTF-8?q?fix=20:=20Repository=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=BF=BC=EB=A6=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepository.java | 6 ++++-- .../prgrms/catchtable/shop/service/MemberShopService.java | 2 +- .../com/prgrms/catchtable/shop/service/ShopServiceTest.java | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 322c928e..939d3bb6 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -2,11 +2,13 @@ import com.prgrms.catchtable.shop.domain.Shop; import java.util.Optional; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; public interface ShopRepository extends JpaRepository, ShopRepositoryCustom{ - @Query("select s from Shop s join fetch s.reservationTimeList where s.id = :id ") - Optional findByIdWithTime(@Param("id") Long id); + + @EntityGraph(attributePaths = "reservationTimeList") + Optional findShopById(Long id); } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 464b3378..8bb4bbe2 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -28,7 +28,7 @@ public GetAllShopResponse getAll() { @Transactional(readOnly = true) public GetShopResponse getById(Long id){ - Shop findShop = shopRepository.findByIdWithTime(id) + Shop findShop = shopRepository.findShopById(id) .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); return ShopMapper.toGetShopResponse(findShop); } diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index d90414d0..024d9959 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -81,8 +81,8 @@ void getByIdTest() { Shop shop = ShopFixture.shop(); //when - when(shopRepository.findByIdWithTime(1L)).thenReturn(Optional.of(shop)); - when(shopRepository.findByIdWithTime(2L)).thenReturn(Optional.empty()); + when(shopRepository.findShopById(1L)).thenReturn(Optional.of(shop)); + when(shopRepository.findShopById(2L)).thenReturn(Optional.empty()); //then assertThat(memberShopService.getById(1L).name()).isEqualTo(shop.getName()); From 67ccba1b96bc447780d04c26766e20bc35801d52 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 17:48:41 +0900 Subject: [PATCH 466/603] =?UTF-8?q?feat=20:=20shop=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EC=A0=90=EC=A3=BC=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../owner/repository/OwnerRepository.java | 3 ++ .../owner/repository/OwnerRepositoryTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java diff --git a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java index 5e783c0e..26443879 100644 --- a/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/owner/repository/OwnerRepository.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.owner.repository; import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.shop.domain.Shop; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,4 +11,6 @@ public interface OwnerRepository extends JpaRepository { Optional findOwnerByEmail(String email); + Optional findOwnerByShop(Shop shop); + } diff --git a/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java new file mode 100644 index 00000000..fd62b110 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java @@ -0,0 +1,38 @@ +package com.prgrms.catchtable.owner.repository; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; + +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = NONE) +class OwnerRepositoryTest { + @Autowired + private OwnerRepository ownerRepository; + @Autowired + private ShopRepository shopRepository; + + @Test + @DisplayName("매장을 통해 점주를 찾을 수 있다") + void findByShop(){ + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + + Owner owner = OwnerFixture.getOwner(savedShop); + Owner savedOwner = ownerRepository.save(owner); + + Owner findOwner = ownerRepository.findOwnerByShop(savedShop).orElseThrow(); + + assertThat(findOwner).isEqualTo(savedOwner); + } +} \ No newline at end of file From edf5848d7afa16d40365e6473fadffc65c6b0243 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 17:49:30 +0900 Subject: [PATCH 467/603] =?UTF-8?q?feat=20:=20NotificationContent=20Functi?= =?UTF-8?q?on=ED=99=9C=EC=9A=A9=ED=95=B4=20=EC=95=8C=EB=A6=BC=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EB=A6=AC=ED=84=B4=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20(=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=B0=9B=EC=95=84=EC=84=9C=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EB=8C=80=20=EA=B4=80=EB=A0=A8=EB=90=9C=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=83=9D=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/NotificationContent.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java index 54b616eb..0f612ade 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java @@ -1,20 +1,23 @@ package com.prgrms.catchtable.common.notification; +import java.util.function.BiFunction; +import java.util.function.Function; import lombok.Getter; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @Getter public enum NotificationContent { - RESERVATION_COMPLETED("예약이 완료되었습니다"), - RESERVATION_ONE_HOUR_LEFT("예약 시간 1시간 전입니다."), - RESERVATION_TIME_TO_ENTER("예약시간이 되었습니다"), - WAITING_REGISTER_COMPLETED("웨이팅 등록이 완료되었습니다"), - WAITING_RANK_THIRD("웨이팅 순서가 3번째가 되었습니다"), - WAITING_TIME_TO_ENTER("웨이팅이 끝났습니다. 입장 부탁드립니다."), - WAITING_CANCELLED_AUTOMATICALLY("웨이팅이 자동으로 취소되었습니다."); + RESERVATION_COMPLETED(time -> time.concat(" 시간의 예약이 완료 되었습니다.")), + RESERVATION_CANCELLED(time -> time.concat(" 시간의 예약이 취소 되었습니다")), + RESERVATION_ONE_HOUR_LEFT(time -> time.concat(" 시간 예약까지 한시간 남았습니다")), + RESERVATION_TIME_OUT(time -> "예약 시간이 되었습니다. 입장해주세요."); - private final String message; + private final Function expression; + + public String apply(String time){ + return expression.apply(time); + } } From 32da933e664dc82d6a06eb9b6de9b6c94425e6ac Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 17:50:12 +0900 Subject: [PATCH 468/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20String=20=EC=9D=B8=EC=9E=90=20=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/SendMessageToMemberRequest.java | 2 +- .../dto/request/SendMessageToOwnerRequest.java | 2 +- .../notification/service/NotificationService.java | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java index 4e9fb6f7..71c977cd 100644 --- a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java @@ -6,6 +6,6 @@ @Builder public record SendMessageToMemberRequest(Member member, - NotificationContent content) { + String content) { } diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java index ae80ddef..9e0cefba 100644 --- a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java @@ -6,6 +6,6 @@ @Builder public record SendMessageToOwnerRequest(Owner owner, - NotificationContent content) { + String content) { } diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index 5e298cd1..f6601caa 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -38,11 +38,11 @@ public class NotificationService { private final OwnerRepository ownerRepository; // 추후 삭제 예정 private JSONObject jsonObject; - public void sendMessageAndSave(Member member, NotificationContent content) { + public void sendMessageAndSave(Member member, String content) { String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API String email = member.getEmail(); - String message = content.getMessage(); + String message = content; String slackId = getSlackIdByEmail(email); // 이메일을 통해 사용자의 슬랙 고유 ID 추출 requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 @@ -56,11 +56,11 @@ public void sendMessageAndSave(Member member, NotificationContent content) { } - public void sendMessageAndSave(Owner owner, NotificationContent content) { + public void sendMessageAndSave(Owner owner, String content) { String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API String email = owner.getEmail(); - String message = content.getMessage(); + String message = content; String slackId = getSlackIdByEmail(email); requestToSendMessage(slackId, message); From 07b872063cdffc48c453e5150bd97628264e0b18 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 17:50:34 +0900 Subject: [PATCH 469/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80(=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D,=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationService.java | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 18b42aab..4eb3dd53 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -2,9 +2,11 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_RESERVATION; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; -import static com.prgrms.catchtable.common.notification.NotificationContent.*; +import static com.prgrms.catchtable.common.notification.NotificationContent.RESERVATION_CANCELLED; +import static com.prgrms.catchtable.common.notification.NotificationContent.RESERVATION_COMPLETED; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import static com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper.toCancelReservationResponse; @@ -14,9 +16,11 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; -import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; +import com.prgrms.catchtable.notification.dto.request.SendMessageToOwnerRequest; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.mapper.ReservationMapper; @@ -44,6 +48,7 @@ public class MemberReservationService { private final ReservationRepository reservationRepository; private final ReservationAsync reservationAsync; private final ReservationLockRepository reservationLockRepository; + private final OwnerRepository ownerRepository; private final ApplicationEventPublisher publisher; @Transactional @@ -97,12 +102,22 @@ public CreateReservationResponse registerReservation(Member member, .build(); Reservation savedReservation = reservationRepository.save(reservation); - SendMessageToMemberRequest sendMessage = new SendMessageToMemberRequest( + Owner owner = ownerRepository.findOwnerByShop(reservationTime.getShop()) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); + + SendMessageToMemberRequest sendMessageToMember = new SendMessageToMemberRequest( member, - RESERVATION_COMPLETED - ); + RESERVATION_COMPLETED.apply(reservationTime.getTime().toString()) + ); // 회원에게 보낼 해당 시간대의 예약 완료 알림 생성 + + SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest( + owner, + RESERVATION_COMPLETED.apply(reservationTime.getTime().toString()) + ); // 점주에게 보낼 보낼 해당 시간대의 예약 완료 알림 생성 + + publisher.publishEvent(sendMessageToMember); // 회원에게 예약등록 알림 발송 + publisher.publishEvent(sendMessageToOwner); // 점주에게 예약등록 알림 발송 - publisher.publishEvent(sendMessage); return toCreateReservationResponse(savedReservation); } @@ -152,6 +167,14 @@ public CancelReservationResponse cancelReservation(Long reservationId) { reservationTime.setOccupiedFalse(); + Owner owner = ownerRepository.findOwnerByShop(reservationTime.getShop()) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); + + SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest(owner, + RESERVATION_CANCELLED.apply(reservationTime.getTime().toString())); // 해당 시간의 예약 취소 메세지 dto 생성 + + publisher.publishEvent(sendMessageToOwner); // 취소한 예약의 매장 점주에게 예약 취소 알림 발송 + return toCancelReservationResponse(reservation); } From 4f64b6adce7a574546a0bec057fa1fd08b545091 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 17:51:07 +0900 Subject: [PATCH 470/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/notification/NotificationContent.java | 3 +-- .../catchtable/common/notification/NotificationEvent.java | 4 ++-- .../notification/dto/request/SendMessageToMemberRequest.java | 1 - .../notification/dto/request/SendMessageToOwnerRequest.java | 1 - .../catchtable/notification/service/NotificationService.java | 1 - .../reservation/service/MemberReservationService.java | 3 ++- .../catchtable/owner/repository/OwnerRepositoryTest.java | 3 ++- .../controller/MemberReservationControllerTest.java | 1 - 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java index 0f612ade..6d63e0ec 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.common.notification; -import java.util.function.BiFunction; import java.util.function.Function; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -16,7 +15,7 @@ public enum NotificationContent { private final Function expression; - public String apply(String time){ + public String apply(String time) { return expression.apply(time); } diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java index 5ff260cf..e8254a04 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationEvent.java @@ -22,7 +22,7 @@ public class NotificationEvent { @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 public void sendMessage(SendMessageToMemberRequest request) { Member member = request.member(); - if(member.isNotification_activated()){ + if (member.isNotification_activated()) { notificationService.sendMessageAndSave(member, request.content()); } } @@ -31,7 +31,7 @@ public void sendMessage(SendMessageToMemberRequest request) { @TransactionalEventListener(phase = AFTER_COMMIT) // 호출한쪽의 트랜잭션이 커밋 된 후 이벤트 발생 public void sendMessage(SendMessageToOwnerRequest request) { Owner owner = request.owner(); - if(owner.isNotification_activated()){ + if (owner.isNotification_activated()) { notificationService.sendMessageAndSave(request.owner(), request.content()); } } diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java index 71c977cd..53fc5072 100644 --- a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToMemberRequest.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.notification.dto.request; -import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; import lombok.Builder; diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java index 9e0cefba..e6e0e42e 100644 --- a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageToOwnerRequest.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.notification.dto.request; -import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.owner.domain.Owner; import lombok.Builder; diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index f6601caa..2d5a8bb3 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -5,7 +5,6 @@ import static org.springframework.http.HttpMethod.POST; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.notification.domain.NotificationMember; diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 4eb3dd53..15cc3a37 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -171,7 +171,8 @@ public CancelReservationResponse cancelReservation(Long reservationId) { .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest(owner, - RESERVATION_CANCELLED.apply(reservationTime.getTime().toString())); // 해당 시간의 예약 취소 메세지 dto 생성 + RESERVATION_CANCELLED.apply( + reservationTime.getTime().toString())); // 해당 시간의 예약 취소 메세지 dto 생성 publisher.publishEvent(sendMessageToOwner); // 취소한 예약의 매장 점주에게 예약 취소 알림 발송 diff --git a/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java index fd62b110..d201f730 100644 --- a/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java @@ -17,6 +17,7 @@ @DataJpaTest @AutoConfigureTestDatabase(replace = NONE) class OwnerRepositoryTest { + @Autowired private OwnerRepository ownerRepository; @Autowired @@ -24,7 +25,7 @@ class OwnerRepositoryTest { @Test @DisplayName("매장을 통해 점주를 찾을 수 있다") - void findByShop(){ + void findByShop() { Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index e9f0e0a2..9e7916cb 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -54,7 +54,6 @@ void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - Member savedMember = memberRepository.save(member); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); From 1e57075c6f93aea8929f1f223e4397639cfea86e Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:56:44 +0900 Subject: [PATCH 471/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20API=20=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/{album => waiting}/waiting.adoc | 0 .../MemberWaitingControllerDocsTest.java | 104 ++++++++++++++++++ 2 files changed, 104 insertions(+) rename src/docs/asciidoc/api/{album => waiting}/waiting.adoc (100%) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java diff --git a/src/docs/asciidoc/api/album/waiting.adoc b/src/docs/asciidoc/api/waiting/waiting.adoc similarity index 100% rename from src/docs/asciidoc/api/album/waiting.adoc rename to src/docs/asciidoc/api/waiting/waiting.adoc diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java new file mode 100644 index 00000000..f2b1c441 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -0,0 +1,104 @@ +package com.prgrms.catchtable.waiting.controller; + +import static com.prgrms.catchtable.common.Role.MEMBER; +import static org.mockito.BDDMockito.given; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.restdocs.RestDocsSupport; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; +import com.prgrms.catchtable.waiting.service.MemberWaitingService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpHeaders; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.restdocs.payload.JsonFieldType; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +class MemberWaitingControllerDocsTest extends RestDocsSupport { + + @MockBean + private MemberWaitingService memberWaitingService; + @Autowired + private MemberRepository memberRepository; + + + + @DisplayName("웨이팅 생성 API") + @Test + void createWaiting() throws Exception { + CreateWaitingRequest request = CreateWaitingRequest + .builder() + .peopleCount(2).build(); + MemberWaitingResponse response = MemberWaitingResponse.builder() + .waitingId(201L) + .shopId(1L) + .shopName("shop1") + .waitingNumber(324) + .rank(20L) + .peopleCount(2) + .remainingPostponeCount(2) + .status("진행 중") + .build(); + Member member = MemberFixture.member("test@naver.com"); + memberRepository.save(member); + given(memberWaitingService.createWaiting(1L, member, request)).willReturn(response); + + mockMvc.perform(post("/waitings/{shopId}", 1) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(document("waiting-create", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestFields( + fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + .description("인원수") + ), + responseFields( + fieldWithPath("waitingId").type(JsonFieldType.NUMBER) + .description("생성된 웨이팅 아이디"), + fieldWithPath("shopId").type(JsonFieldType.NUMBER) + .description("상점 아이디"), + fieldWithPath("shopName").type(JsonFieldType.STRING) + .description("상점 이름"), + fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + .description("인원 수"), + fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("rank").type(JsonFieldType.NUMBER) + .description("웨이팅 순서"), + fieldWithPath("remainingPostponeCount").type(JsonFieldType.NUMBER) + .description("대기 지연 잔여 횟수"), + fieldWithPath("status").type(JsonFieldType.STRING) + .description("대기 상태") + ) + )); + + + } + + private HttpHeaders getHttpHeaders(Member member) { + Token token = jwtTokenProvider.createToken(member.getEmail(),MEMBER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + return httpHeaders; + } +} \ No newline at end of file From 7ce4b29a6e8de1f9a4403bc3f1ed67b24c5cc707 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:57:56 +0900 Subject: [PATCH 472/603] =?UTF-8?q?feat=20:=20Security=20Security=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20RestDocsSupport?= =?UTF-8?q?=20setUp=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/restdocs/RestDocsSupport.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index 381b6db1..a9ebeece 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,28 +1,53 @@ package com.prgrms.catchtable.common.restdocs; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; - import com.fasterxml.jackson.databind.ObjectMapper; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpHeaders; +import org.springframework.mock.web.MockFilterConfig; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +import org.springframework.security.config.BeanIds; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.filter.CharacterEncodingFilter; +import org.springframework.web.filter.DelegatingFilterProxy; @ExtendWith(RestDocumentationExtension.class) +@SpringBootTest public abstract class RestDocsSupport { protected MockMvc mockMvc; - protected ObjectMapper objectMapper = new ObjectMapper(); + @Autowired + protected ObjectMapper objectMapper; + protected HttpHeaders httpHeaders = new HttpHeaders(); + @Autowired + protected JwtTokenProvider jwtTokenProvider; @BeforeEach - void setUp(RestDocumentationContextProvider provider) { - this.mockMvc = MockMvcBuilders.standaloneSetup(initController()) - .apply(documentationConfiguration(provider)) + void setUp(final WebApplicationContext context, + final RestDocumentationContextProvider provider) throws ServletException { + DelegatingFilterProxy delegateProxyFilter = new DelegatingFilterProxy(); + delegateProxyFilter.init( + new MockFilterConfig(context.getServletContext(), BeanIds.SPRING_SECURITY_FILTER_CHAIN)); + + this.mockMvc = MockMvcBuilders.webAppContextSetup(context) + .apply( + MockMvcRestDocumentation.documentationConfiguration(provider)) // rest docs 설정 주입 + .alwaysDo(MockMvcResultHandlers.print()) + .addFilters( + new CharacterEncodingFilter("UTF-8", true), + delegateProxyFilter + ) .build(); } - - protected abstract Object initController(); } From 7975d322c246cf08f0447e1ce16f67fd1ccc3b4b Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 17:58:40 +0900 Subject: [PATCH 473/603] =?UTF-8?q?rename=20:=20adoc=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/index.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 160506fc..63a41be5 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -12,4 +12,4 @@ endif::[] [[CatchTable-API]] == Waiting API -include::api/album/waiting.adoc[] \ No newline at end of file +include::api/waiting/waiting.adoc[] \ No newline at end of file From 0accad0c2a9f541cdd403918307aaabbe422f7bb Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 18:01:13 +0900 Subject: [PATCH 474/603] feat : MemberShopController Test --- .../controller/MemberShopControllerTest.java | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java new file mode 100644 index 00000000..3baf4633 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -0,0 +1,125 @@ +package com.prgrms.catchtable.shop.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.Role; +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.service.RefreshTokenService; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +@Transactional +class MemberShopControllerTest extends BaseIntegrationTest { + + @Autowired + private JwtTokenProvider jwtTokenProvider; + @Autowired + private MemberRepository memberRepository; + @Autowired + private ShopRepository shopRepository; + @Autowired + private RefreshTokenService refreshTokenService; + + private Member member; + private Shop shop; + private String email = "abc1234@gmail.com"; + private Token token; + + @BeforeEach + void init() { + //Member 객체 저장 + member = MemberFixture.member(email); + memberRepository.save(member); + + //Shop 객체 저장 + shop = shopRepository.save(ShopFixture.shop()); + + //토큰 발급 + token = jwtTokenProvider.createToken(email, Role.MEMBER); + refreshTokenService.saveRefreshToken(token); + + //토큰 헤더 세팅 + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + } + + @Test + @DisplayName("Member가 Shop을 전체조회 한다.") + void getAllTest() throws Exception { + //then + mockMvc.perform(get("/shops") + .contentType(MediaType.APPLICATION_JSON) + .headers(httpHeaders)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) + .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) + .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) + .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) + .andExpect(jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) + .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); + } + + @Test + @DisplayName("Member가 Shop을 단일조회 한다.") + void getByIdTest() throws Exception { + //given + Shop shop1 = shopRepository.findAll().get(0); + + //then + mockMvc.perform(get("/shops/{shopId}", shop1.getId()) + .contentType(MediaType.APPLICATION_JSON) + .headers(httpHeaders)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.name").value(shop.getName())) + .andExpect(jsonPath("$.rating").value(shop.getRating())) + .andExpect(jsonPath("$.category").value(shop.getCategory().getType())) + .andExpect(jsonPath("$.city").value(shop.getAddress().getCity())) + .andExpect(jsonPath("$.district").value(shop.getAddress().getDistrict())) + .andExpect(jsonPath("$.capacity").value(shop.getCapacity())); + } + + @Test + @DisplayName("Member가 Shop을 필터 검색 조회 한다.") + void getBySearchTest() throws Exception { + //given + Shop shop1 = shopRepository.findAll().get(0); + ShopSearchCondition shopSearchCondition = new ShopSearchCondition(shop1.getName(), shop1.getCategory().getType(), shop1.getAddress().getCity()); + MultiValueMap params = new LinkedMultiValueMap<>(); + + //when + params.add("name", shopSearchCondition.name()); + params.add("category", shopSearchCondition.category()); + params.add("city", shopSearchCondition.city()); + + //then + mockMvc.perform(get("/shops/search") + .contentType(MediaType.APPLICATION_JSON) + .headers(httpHeaders) + .params(params)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) + .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) + .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) + .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) + .andExpect(jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) + .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); + + } +} \ No newline at end of file From b4e3fbb605b36dc7e840c12322d18d5c85a9a81d Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:04:39 +0900 Subject: [PATCH 475/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/controller/OwnerWaitingController.java | 1 - .../prgrms/catchtable/common/restdocs/RestDocsSupport.java | 4 ++-- .../waiting/controller/MemberWaitingControllerDocsTest.java | 4 +--- .../waiting/controller/OwnerWaitingControllerTest.java | 1 - .../catchtable/waiting/repository/WaitingRepositoryTest.java | 3 +-- .../catchtable/waiting/schedular/WaitingSchedulerTest.java | 4 ++-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index 1c802f27..24d90864 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -9,7 +9,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index a9ebeece..5ae7627c 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockFilterConfig; import org.springframework.restdocs.RestDocumentationContextProvider; @@ -38,7 +37,8 @@ void setUp(final WebApplicationContext context, final RestDocumentationContextProvider provider) throws ServletException { DelegatingFilterProxy delegateProxyFilter = new DelegatingFilterProxy(); delegateProxyFilter.init( - new MockFilterConfig(context.getServletContext(), BeanIds.SPRING_SECURITY_FILTER_CHAIN)); + new MockFilterConfig(context.getServletContext(), + BeanIds.SPRING_SECURITY_FILTER_CHAIN)); this.mockMvc = MockMvcBuilders.webAppContextSetup(context) .apply( diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index f2b1c441..06ddb955 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -26,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpHeaders; -import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.transaction.annotation.Transactional; @@ -39,7 +38,6 @@ class MemberWaitingControllerDocsTest extends RestDocsSupport { private MemberRepository memberRepository; - @DisplayName("웨이팅 생성 API") @Test void createWaiting() throws Exception { @@ -96,7 +94,7 @@ void createWaiting() throws Exception { } private HttpHeaders getHttpHeaders(Member member) { - Token token = jwtTokenProvider.createToken(member.getEmail(),MEMBER); + Token token = jwtTokenProvider.createToken(member.getEmail(), MEMBER); httpHeaders.add("AccessToken", token.getAccessToken()); httpHeaders.add("RefreshToken", token.getRefreshToken()); return httpHeaders; diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 7d6e6f97..dbb032a0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.waiting.controller; -import static com.prgrms.catchtable.common.Role.MEMBER; import static com.prgrms.catchtable.common.Role.OWNER; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.hasSize; diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 48567015..d9ad4898 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -18,7 +18,6 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -141,7 +140,7 @@ void updateWaitingStatus() { waitingRepository.saveAll( List.of(progressWaiting1, progressWaiting2, progressWaiting3, completedWaiting)); //when - waitingRepository.updateWaitingStatus(CANCELED,PROGRESS); + waitingRepository.updateWaitingStatus(CANCELED, PROGRESS); System.out.println("progressWaiting3 = " + progressWaiting3.getStatus()); Waiting waiting1 = waitingRepository.findById(progressWaiting1.getId()).orElseThrow(); Waiting waiting2 = waitingRepository.findById(progressWaiting2.getId()).orElseThrow(); diff --git a/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java b/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java index 3782170a..5a9c6c44 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/schedular/WaitingSchedulerTest.java @@ -24,7 +24,7 @@ class WaitingSchedulerTest { private StringRedisTemplate redisTemplate; @AfterEach - void clear(){ + void clear() { redisTemplate.delete("s1"); } @@ -39,7 +39,7 @@ void clearRedis() throws InterruptedException { assertThat(waitingLineRepository.getWaitingLineSize(shopId)).isEqualTo(3); - Thread.sleep(60*1000); + Thread.sleep(60 * 1000); assertThat(waitingLineRepository.getWaitingLineSize(shopId)).isZero(); } From d6a13821c0487f39306fd7cf3a6667824d0abaed Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 18:35:08 +0900 Subject: [PATCH 476/603] =?UTF-8?q?fix=20:=20ShopRepositoryTest=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepositoryTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java index 4eee7b91..5fe867ed 100644 --- a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java @@ -34,7 +34,7 @@ void findNameSearchTest() { List searchList = shopRepository.findSearch(condition); //then - assertThat(searchList.get(0)).isEqualTo(savedShop); + assertThat(searchList.get(0).getId()).isEqualTo(savedShop.getId()); } @Test @@ -49,7 +49,7 @@ void findCategorySearchTest() { List searchList = shopRepository.findSearch(condition); //then - assertThat(searchList.get(0)).isEqualTo(savedShop); + assertThat(searchList.get(0).getId()).isEqualTo(savedShop.getId()); } @Test From 0f8d07aa588ffc3c13824fe4d60b9d4de4fd3d9e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 18:35:53 +0900 Subject: [PATCH 477/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationService.java | 5 ++--- .../shop/controller/MemberShopController.java | 7 ++++--- .../shop/controller/OwnerShopController.java | 5 +++-- .../prgrms/catchtable/shop/domain/Category.java | 4 ++-- .../com/prgrms/catchtable/shop/domain/Shop.java | 2 -- .../prgrms/catchtable/shop/dto/ShopMapper.java | 9 ++++----- .../shop/repository/ShopRepository.java | 4 +--- .../shop/repository/ShopRepositoryImpl.java | 16 ++++++++-------- .../shop/service/MemberShopService.java | 8 ++++---- .../shop/service/OwnerShopService.java | 4 ++-- .../common/base/BaseIntegrationTest.java | 4 +--- .../owner/controller/OwnerControllerTest.java | 7 +++---- .../catchtable/owner/fixture/OwnerFixture.java | 2 +- .../MemberReservationControllerTest.java | 1 - .../service/MemberReservationServiceTest.java | 2 +- .../controller/MemberShopControllerTest.java | 13 ++++++++----- .../shop/controller/OwnerShopControllerTest.java | 1 - .../catchtable/shop/fixture/ShopFixture.java | 2 +- .../shop/repository/ShopRepositoryTest.java | 7 ++++--- .../catchtable/shop/service/ShopServiceTest.java | 8 ++------ 20 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index 5e298cd1..2364f869 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -29,13 +29,12 @@ @Slf4j public class NotificationService { - @Value("${slack.token}") - private String slackToken; - private final NotificationMemberRepository notificationMemberRepository; private final NotificationOwnerRepository notificationOwnerRepository; private final MemberRepository memberRepository; // 추후 삭제 예정 private final OwnerRepository ownerRepository; // 추후 삭제 예정 + @Value("${slack.token}") + private String slackToken; private JSONObject jsonObject; public void sendMessageAndSave(Member member, NotificationContent content) { diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index 8c8ae620..1aa98e69 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -20,17 +20,18 @@ public class MemberShopController { private final MemberShopService memberShopService; @GetMapping - public ResponseEntity getAll(){ + public ResponseEntity getAll() { return ResponseEntity.ok(memberShopService.getAll()); } @GetMapping("/{shopId}") - public ResponseEntity getById(@PathVariable("shopId") Long id){ + public ResponseEntity getById(@PathVariable("shopId") Long id) { return ResponseEntity.ok(memberShopService.getById(id)); } @GetMapping("/search") - public ResponseEntity getBySearch(@ModelAttribute ShopSearchCondition condition){ + public ResponseEntity getBySearch( + @ModelAttribute ShopSearchCondition condition) { return ResponseEntity.ok(memberShopService.getBySearch(condition)); } diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java index 291e199b..1405a731 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java @@ -22,8 +22,9 @@ public class OwnerShopController { private final OwnerShopService shopService; @PostMapping("/shops") - public ResponseEntity registShop(@Valid @RequestBody RegistShopRequest request, @LogIn - Owner owner){ + public ResponseEntity registShop( + @Valid @RequestBody RegistShopRequest request, @LogIn + Owner owner) { RegistShopResponse registShopResponse = shopService.registShop(request, owner); return ResponseEntity.status(HttpStatus.CREATED).body(registShopResponse); } diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java index c3e680a4..62e5382e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java @@ -16,14 +16,14 @@ public enum Category { private final String type; - public static Category of(String input){ + public static Category of(String input) { return Arrays.stream(values()) .filter(category -> category.isEqual(input)) .findAny() .orElseThrow(() -> new BadRequestCustomException(ErrorCode.INVALID_INPUT_TYPE)); } - private boolean isEqual(String input){ + private boolean isEqual(String input) { return type.equals(input); } } diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index a3752115..ce4e255b 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -7,7 +7,6 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.reservation.domain.ReservationTime; import jakarta.persistence.Column; import jakarta.persistence.Embedded; @@ -16,7 +15,6 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import java.math.BigDecimal; import java.time.LocalTime; import java.util.ArrayList; diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 24d39541..177a07c5 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -7,12 +7,11 @@ import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; -import java.math.BigDecimal; import java.util.List; public class ShopMapper { - public static Shop toEntity(RegistShopRequest registShopRequest){ + public static Shop toEntity(RegistShopRequest registShopRequest) { return Shop.builder() .name(registShopRequest.name()) @@ -28,7 +27,7 @@ public static Shop toEntity(RegistShopRequest registShopRequest){ .build(); } - public static RegistShopResponse toRegistShopResponse(Shop shop){ + public static RegistShopResponse toRegistShopResponse(Shop shop) { return RegistShopResponse.builder() .name(shop.getName()) .rating(shop.getRating()) @@ -41,13 +40,13 @@ public static RegistShopResponse toRegistShopResponse(Shop shop){ .build(); } - public static GetAllShopResponse toGetAllShopResponse(List shops){ + public static GetAllShopResponse toGetAllShopResponse(List shops) { return new GetAllShopResponse(shops.stream() .map(ShopMapper::toGetShopResponse) .toList()); } - public static GetShopResponse toGetShopResponse(Shop shop){ + public static GetShopResponse toGetShopResponse(Shop shop) { return GetShopResponse.builder() .id(shop.getId()) .name(shop.getName()) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 939d3bb6..f500ee5b 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -4,10 +4,8 @@ import java.util.Optional; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -public interface ShopRepository extends JpaRepository, ShopRepositoryCustom{ +public interface ShopRepository extends JpaRepository, ShopRepositoryCustom { @EntityGraph(attributePaths = "reservationTimeList") Optional findShopById(Long id); diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java index 59dffeba..794b8c3a 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.shop.repository; -import static com.prgrms.catchtable.shop.domain.QShop.*; +import static com.prgrms.catchtable.shop.domain.QShop.shop; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; @@ -11,11 +11,11 @@ import jakarta.persistence.EntityManager; import java.util.List; -public class ShopRepositoryImpl implements ShopRepositoryCustom{ +public class ShopRepositoryImpl implements ShopRepositoryCustom { private final JPAQueryFactory queryFactory; - public ShopRepositoryImpl(EntityManager em){ + public ShopRepositoryImpl(EntityManager em) { queryFactory = new JPAQueryFactory(em); } @@ -35,23 +35,23 @@ public List findSearch(ShopSearchCondition condition) { .fetch(); } - private BooleanExpression equalsName(String name){ - if(name == null){ + private BooleanExpression equalsName(String name) { + if (name == null) { return null; } return shop.name.eq(name); } - private BooleanExpression equalCategory(String category){ - if (category == null){ + private BooleanExpression equalCategory(String category) { + if (category == null) { return null; } return shop.category.eq(Category.of(category)); } private BooleanExpression equalCity(String city) { - if (city == null){ + if (city == null) { return null; } return shop.address.city.eq(city); diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 8bb4bbe2..cbdec14e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -1,13 +1,13 @@ package com.prgrms.catchtable.shop.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; -import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import lombok.RequiredArgsConstructor; @@ -27,14 +27,14 @@ public GetAllShopResponse getAll() { } @Transactional(readOnly = true) - public GetShopResponse getById(Long id){ + public GetShopResponse getById(Long id) { Shop findShop = shopRepository.findShopById(id) .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); return ShopMapper.toGetShopResponse(findShop); } @Transactional(readOnly = true) - public GetAllShopResponse getBySearch(ShopSearchCondition condition){ + public GetAllShopResponse getBySearch(ShopSearchCondition condition) { List searchShop = shopRepository.findSearch(condition); return ShopMapper.toGetAllShopResponse(searchShop); } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index e62d25b3..aa7d5da1 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -2,9 +2,9 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; -import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,7 +17,7 @@ public class OwnerShopService { private final ShopRepository shopRepository; @Transactional - public RegistShopResponse registShop(RegistShopRequest registShopRequest, Owner owner){ + public RegistShopResponse registShop(RegistShopRequest registShopRequest, Owner owner) { Shop registShop = shopRepository.save(ShopMapper.toEntity(registShopRequest)); owner.insertShop(registShop); diff --git a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java index 3841e406..87f2901d 100644 --- a/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/common/base/BaseIntegrationTest.java @@ -13,11 +13,9 @@ @AutoConfigureMockMvc public abstract class BaseIntegrationTest { + public static ObjectMapper objectMapper = new ObjectMapper(); @Autowired public JwtTokenProvider jwtTokenProvider; - - public static ObjectMapper objectMapper = new ObjectMapper(); - public HttpHeaders httpHeaders = new HttpHeaders(); @Autowired public MockMvc mockMvc; diff --git a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java index 21fbdc78..ba35bed4 100644 --- a/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/controller/OwnerControllerTest.java @@ -22,15 +22,14 @@ @Transactional class OwnerControllerTest extends BaseIntegrationTest { + private final String joinEmail = "qwer@56782naver.com"; + private final String notJoinEmail = "abc1234@gmail.com"; + private final String password = "qwer1234"; @Autowired private OwnerService ownerService; @Autowired private JwtTokenProvider jwtTokenProvider; - private final String joinEmail = "qwer@56782naver.com"; - private final String notJoinEmail = "abc1234@gmail.com"; - private final String password = "qwer1234"; - @BeforeEach public void init() { ownerService.joinOwner(OwnerFixture.getJoinOwnerRequest(joinEmail, password)); diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 24cc0a71..e129e28f 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -13,7 +13,7 @@ public class OwnerFixture { - public static Owner getOwner(){ + public static Owner getOwner() { return Owner.builder() .name("ownerA") .email("email1234@gmail.com") diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index e9f0e0a2..9e7916cb 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -54,7 +54,6 @@ void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); - Member savedMember = memberRepository.save(member); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index cf3ead87..6b17776d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -41,6 +41,7 @@ @ExtendWith(MockitoExtension.class) class MemberReservationServiceTest { + private final String email = "dlswns661035@gmail.com"; @Mock private ReservationRepository reservationRepository; @Mock @@ -51,7 +52,6 @@ class MemberReservationServiceTest { private ReservationTimeRepository reservationTimeRepository; @InjectMocks private MemberReservationService memberReservationService; - private final String email = "dlswns661035@gmail.com"; @Test @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java index 3baf4633..1b0bbd14 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -72,7 +72,8 @@ void getAllTest() throws Exception { .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) - .andExpect(jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) + .andExpect( + jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); } @@ -84,8 +85,8 @@ void getByIdTest() throws Exception { //then mockMvc.perform(get("/shops/{shopId}", shop1.getId()) - .contentType(MediaType.APPLICATION_JSON) - .headers(httpHeaders)) + .contentType(MediaType.APPLICATION_JSON) + .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value(shop.getName())) .andExpect(jsonPath("$.rating").value(shop.getRating())) @@ -100,7 +101,8 @@ void getByIdTest() throws Exception { void getBySearchTest() throws Exception { //given Shop shop1 = shopRepository.findAll().get(0); - ShopSearchCondition shopSearchCondition = new ShopSearchCondition(shop1.getName(), shop1.getCategory().getType(), shop1.getAddress().getCity()); + ShopSearchCondition shopSearchCondition = new ShopSearchCondition(shop1.getName(), + shop1.getCategory().getType(), shop1.getAddress().getCity()); MultiValueMap params = new LinkedMultiValueMap<>(); //when @@ -118,7 +120,8 @@ void getBySearchTest() throws Exception { .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) - .andExpect(jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) + .andExpect( + jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); } diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java index fda0472e..e7b4a992 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java @@ -1,6 +1,5 @@ package com.prgrms.catchtable.shop.controller; -import static org.junit.jupiter.api.Assertions.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 721ad049..0f24b2c5 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -33,7 +33,7 @@ public static Shop shopWith24() { .build(); } - public static RegistShopRequest getRequestDto(Shop shop){ + public static RegistShopRequest getRequestDto(Shop shop) { return RegistShopRequest.builder() .name(shop.getName()) .rating(shop.getRating()) diff --git a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java index 5fe867ed..940846ce 100644 --- a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.shop.repository; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.shop.domain.Category; @@ -43,7 +42,8 @@ void findCategorySearchTest() { //given Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); - ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), Category.WESTERN_FOOD.getType(), null); + ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), + Category.WESTERN_FOOD.getType(), null); //when List searchList = shopRepository.findSearch(condition); @@ -58,7 +58,8 @@ void findSearchTest() { //given Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); - ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), Category.KOREAN_FOOD.getType(), savedShop.getAddress().getCity()); + ShopSearchCondition condition = new ShopSearchCondition(savedShop.getName(), + Category.KOREAN_FOOD.getType(), savedShop.getAddress().getCity()); //when List searchList = shopRepository.findSearch(condition); diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index 024d9959..e2544be7 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -3,24 +3,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; -import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -86,6 +81,7 @@ void getByIdTest() { //then assertThat(memberShopService.getById(1L).name()).isEqualTo(shop.getName()); - assertThatThrownBy(()->memberShopService.getById(2L)).isInstanceOf(BadRequestCustomException.class); + assertThatThrownBy(() -> memberShopService.getById(2L)).isInstanceOf( + BadRequestCustomException.class); } } \ No newline at end of file From acb72b8f0cfb46703f62cbea80c4095f7747bf10 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 18:42:06 +0900 Subject: [PATCH 478/603] =?UTF-8?q?fix=20:=20=EA=B0=81=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A7=88=EB=8B=A4=20Repository=20deleteAll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/repository/ShopRepositoryTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java index 940846ce..179f0d2e 100644 --- a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java @@ -8,6 +8,7 @@ import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; import com.prgrms.catchtable.shop.fixture.ShopFixture; import java.util.List; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +22,11 @@ class ShopRepositoryTest { @Autowired private ShopRepository shopRepository; + @BeforeEach + void init() { + shopRepository.deleteAll(); + } + @Test @DisplayName("이름 검색을 통해 Shop을 조회할 수 있다.") void findNameSearchTest() { From 215a83aa329f27772c1cbcb631e04fb81f4f22ec Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:46:32 +0900 Subject: [PATCH 479/603] =?UTF-8?q?feat=20:=20RestDocsConfig=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/restdocs/RestDocsConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsConfig.java diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsConfig.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsConfig.java new file mode 100644 index 00000000..4d8bec07 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsConfig.java @@ -0,0 +1,20 @@ +package com.prgrms.catchtable.common.restdocs; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.restdocs.operation.preprocess.Preprocessors; + +@TestConfiguration +public class RestDocsConfig { + + @Bean + public RestDocumentationResultHandler write() { + return MockMvcRestDocumentation.document( + "{class-name}/{method-name}", + Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), + Preprocessors.preprocessResponse(Preprocessors.prettyPrint()) + ); + } +} \ No newline at end of file From 6037600cdec3023faaa134c0d7237e106292534e Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:47:57 +0900 Subject: [PATCH 480/603] =?UTF-8?q?feat=20:=20RestDocs=20Config=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?member=20header=20=EA=B3=B5=ED=86=B5=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/restdocs/RestDocsSupport.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index 5ae7627c..8b4ec69c 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,17 +1,23 @@ package com.prgrms.catchtable.common.restdocs; +import static com.prgrms.catchtable.common.Role.MEMBER; + import com.fasterxml.jackson.databind.ObjectMapper; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.domain.Member; import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockFilterConfig; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.security.config.BeanIds; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; @@ -21,12 +27,16 @@ import org.springframework.web.filter.DelegatingFilterProxy; @ExtendWith(RestDocumentationExtension.class) +@Import(RestDocsConfig.class) @SpringBootTest public abstract class RestDocsSupport { protected MockMvc mockMvc; @Autowired protected ObjectMapper objectMapper; + + @Autowired + protected RestDocumentationResultHandler restDocs; protected HttpHeaders httpHeaders = new HttpHeaders(); @Autowired @@ -43,6 +53,7 @@ void setUp(final WebApplicationContext context, this.mockMvc = MockMvcBuilders.webAppContextSetup(context) .apply( MockMvcRestDocumentation.documentationConfiguration(provider)) // rest docs 설정 주입 + .alwaysDo(restDocs) .alwaysDo(MockMvcResultHandlers.print()) .addFilters( new CharacterEncodingFilter("UTF-8", true), @@ -50,4 +61,11 @@ void setUp(final WebApplicationContext context, ) .build(); } + + public HttpHeaders getHttpHeaders(Member member) { + Token token = jwtTokenProvider.createToken(member.getEmail(), MEMBER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + return httpHeaders; + } } From 97d7fa9b4e3aedc2bea74dcb1279eec3c4aab12c Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:48:43 +0900 Subject: [PATCH 481/603] =?UTF-8?q?refactor=20:=20RestdocsConfig=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingControllerDocsTest.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index 06ddb955..ecd525ce 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -63,9 +63,7 @@ void createWaiting() throws Exception { .content(objectMapper.writeValueAsString(request)) .headers(getHttpHeaders(member))) .andExpect(status().isOk()) - .andDo(document("waiting-create", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), + .andDo(restDocs.document( requestFields( fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) .description("인원수") @@ -92,11 +90,4 @@ void createWaiting() throws Exception { } - - private HttpHeaders getHttpHeaders(Member member) { - Token token = jwtTokenProvider.createToken(member.getEmail(), MEMBER); - httpHeaders.add("AccessToken", token.getAccessToken()); - httpHeaders.add("RefreshToken", token.getRefreshToken()); - return httpHeaders; - } } \ No newline at end of file From 3c6f7ab92c7e607dd7a3423b42a500c1afa0c4ab Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:49:15 +0900 Subject: [PATCH 482/603] =?UTF-8?q?rename=20:=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EB=90=9C=20snippet=20=ED=8F=B4=EB=8D=94=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/waiting/waiting.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/docs/asciidoc/api/waiting/waiting.adoc b/src/docs/asciidoc/api/waiting/waiting.adoc index 7b3afde4..309f4425 100644 --- a/src/docs/asciidoc/api/waiting/waiting.adoc +++ b/src/docs/asciidoc/api/waiting/waiting.adoc @@ -3,10 +3,10 @@ ==== HTTP Request -include::{snippets}/waiting-create/http-request.adoc[] -include::{snippets}/waiting-create/request-fields.adoc[] +include::{snippets}/member-waiting-controller-docs-test/create-waiting/http-request.adoc[] +include::{snippets}/member-waiting-controller-docs-test/create-waiting/request-fields.adoc[] ==== HTTP Response -include::{snippets}/waiting-create/http-response.adoc[] -include::{snippets}/waiting-create/response-fields.adoc[] \ No newline at end of file +include::{snippets}/member-waiting-controller-docs-test/create-waiting/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/create-waiting/response-fields.adoc[] \ No newline at end of file From ec143df964d9153bf8256a39ea1b5c33af4c40f6 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 18:49:48 +0900 Subject: [PATCH 483/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingControllerDocsTest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index ecd525ce..c807c8b2 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -1,12 +1,7 @@ package com.prgrms.catchtable.waiting.controller; -import static com.prgrms.catchtable.common.Role.MEMBER; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -14,7 +9,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.restdocs.RestDocsSupport; -import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; @@ -25,7 +19,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpHeaders; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.transaction.annotation.Transactional; From 494bc3bb4ed1dfa1d8025432d959d7e19f239033 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 10 Jan 2024 19:19:18 +0900 Subject: [PATCH 484/603] =?UTF-8?q?fix=20:=20deleteAll=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/OwnerWaitingControllerTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 9823aeed..7c340db2 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -54,6 +54,9 @@ class OwnerWaitingControllerTest extends BaseIntegrationTest { @BeforeEach void setUp() { + memberRepository.deleteAll(); + shopRepository.deleteAll(); + ownerRepository.deleteAll(); Member member1 = MemberFixture.member("test1@naver.com"); Member member2 = MemberFixture.member("test2@naver.com"); Member member3 = MemberFixture.member("test3@naver.com"); From 6ced9aa62dba5ed161aa96ae0c56cb16b8f53aea Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 10 Jan 2024 19:21:49 +0900 Subject: [PATCH 485/603] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationService.java | 2 +- .../owner/repository/OwnerRepositoryTest.java | 3 ++- .../MemberReservationControllerTest.java | 15 +++++++++++++++ .../service/MemberReservationServiceTest.java | 18 +++++++++++++++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 15cc3a37..1ba62f3c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -62,7 +62,7 @@ public CreateReservationResponse preOccupyReservation(Member member, Thread.currentThread().interrupt(); } } - ReservationTime reservationTime = reservationTimeRepository.findById(reservationTimeId) + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop(reservationTimeId) .orElseThrow(() -> { reservationLockRepository.unlock(reservationTimeId); return new NotFoundCustomException(NOT_EXIST_TIME); diff --git a/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java index d201f730..6aae1a1f 100644 --- a/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/repository/OwnerRepositoryTest.java @@ -29,7 +29,8 @@ void findByShop() { Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); - Owner owner = OwnerFixture.getOwner(savedShop); + Owner owner = OwnerFixture.getOwner("injun", "injun2480"); + owner.insertShop(savedShop); Owner savedOwner = ownerRepository.save(owner); Owner findOwner = ownerRepository.findOwnerByShop(savedShop).orElseThrow(); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 9e7916cb..72a0d97d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -18,6 +18,9 @@ import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -28,6 +31,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; @@ -47,6 +51,8 @@ class MemberReservationControllerTest extends BaseIntegrationTest { private ReservationRepository reservationRepository; @Autowired private MemberRepository memberRepository; + @Autowired + private OwnerRepository ownerRepository; private Member member = MemberFixture.member("dlswns661035@gmail.com"); @BeforeEach @@ -54,6 +60,10 @@ void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); + Owner owner = OwnerFixture.getOwner("injun", "injun2480"); + owner.insertShop(savedShop); + ownerRepository.save(owner); + Member savedMember = memberRepository.save(member); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); @@ -65,6 +75,11 @@ void setUp() { httpHeaders.add("RefreshToken", token.getRefreshToken()); } + @AfterEach + void tearDown(){ + shopRepository.deleteAll(); + } + @Test @DisplayName("예약 선점 api 호출에 성공한다.") void preOccupyReservation() throws Exception { diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index cf3ead87..3eb25ac9 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -15,6 +15,9 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -36,6 +39,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.test.util.ReflectionTestUtils; @ExtendWith(MockitoExtension.class) @@ -49,6 +53,10 @@ class MemberReservationServiceTest { private ReservationAsync reservationAsync; @Mock private ReservationTimeRepository reservationTimeRepository; + @Mock + private OwnerRepository ownerRepository; + @Mock + private ApplicationEventPublisher publisher; @InjectMocks private MemberReservationService memberReservationService; private final String email = "dlswns661035@gmail.com"; @@ -63,7 +71,7 @@ void validateReservation() { CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); - when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn(Optional.of(reservationTime)); when(reservationLockRepository.lock(1L)).thenReturn(TRUE); when(reservationLockRepository.unlock(1L)).thenReturn(TRUE); doNothing().when(reservationAsync).setPreOcuppied(reservationTime); @@ -91,7 +99,7 @@ void alreadyPreOccupied() { CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); - when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn(Optional.of(reservationTime)); when(reservationLockRepository.lock(1L)).thenReturn(TRUE); //when @@ -106,6 +114,7 @@ void alreadyPreOccupied() { void registerReservation() { Member member = MemberFixture.member(email); ReservationTime reservationTime = ReservationFixture.getReservationTimePreOccupied(); + Owner owner = OwnerFixture.getOwner("dlswns661035@gmail.com", "injun2480"); CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); Reservation reservation = Reservation.builder() .status(COMPLETED) @@ -117,6 +126,8 @@ void registerReservation() { when(reservationTimeRepository.findByIdWithShop(any(Long.class))).thenReturn( Optional.of(reservationTime)); when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + when(ownerRepository.findOwnerByShop(any(Shop.class))).thenReturn(Optional.of(owner)); +// doNothing().when(publisher.publishEvent(any(Object.class))); CreateReservationResponse response = memberReservationService.registerReservation(member, request); @@ -265,10 +276,11 @@ void cancelReservation() { ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); Reservation reservation = ReservationFixture.getReservation(reservationTime); ReflectionTestUtils.setField(reservation, "id", 1L); + Owner owner = OwnerFixture.getOwner("dlswns661035@gmail.com", "injun2480"); when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( Optional.of(reservation)); - + when(ownerRepository.findOwnerByShop(any(Shop.class))).thenReturn(Optional.of(owner)); //when CancelReservationResponse response = memberReservationService.cancelReservation( reservation.getId()); From 734089be79f0eb1a09b4ea47c6b2187022dc79fb Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 20:19:53 +0900 Subject: [PATCH 486/603] =?UTF-8?q?refactor=20:=20WaitingMapper=20stream?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/dto/WaitingMapper.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 5620f06d..b241f5bb 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -11,8 +11,8 @@ import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; -import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicLong; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -55,11 +55,9 @@ public static MemberWaitingHistoryResponse toMemberWaitingHistoryResponse(Waitin public static MemberWaitingHistoryListResponse toMemberWaitingListResponse( List waitings) { - List list = new ArrayList<>(); - for (Waiting waiting : waitings) { - list.add(toMemberWaitingHistoryResponse(waiting)); - } - return new MemberWaitingHistoryListResponse(list); + return new MemberWaitingHistoryListResponse(waitings.stream() + .map(WaitingMapper::toMemberWaitingHistoryResponse) + .toList()); } public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank) { @@ -72,11 +70,11 @@ public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long } public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings) { - long rank = 1L; - List list = new ArrayList<>(); - for (Waiting waiting : waitings) { - list.add(toOwnerWaitingResponse(waiting, rank++)); - } - return new OwnerWaitingListResponse(list); + AtomicLong rank = new AtomicLong(1); + return new OwnerWaitingListResponse( + waitings.stream() + .map(waiting -> toOwnerWaitingResponse(waiting, rank.getAndIncrement())) + .toList() + ); } } From 07b08878acdf2e4f4f740fe04f70e9b3dfc9ecaa Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 10 Jan 2024 20:39:59 +0900 Subject: [PATCH 487/603] =?UTF-8?q?feat=20:=20repository=20test=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepositoryTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index d9ad4898..513a716b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -5,6 +5,7 @@ import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; @@ -23,13 +24,12 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.transaction.annotation.Transactional; - -@SpringBootTest -@Transactional +@DataJpaTest +@AutoConfigureTestDatabase(replace = NONE) class WaitingRepositoryTest { private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), From ac4c8cbc0f4bf3fef06deec99419d42d42ad43da Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 11 Jan 2024 14:26:08 +0900 Subject: [PATCH 488/603] =?UTF-8?q?feat=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20deleteAll=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepositoryTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 513a716b..be6e0c1d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -19,7 +19,6 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -56,13 +55,6 @@ void setUp() { shopRepository.save(shop); } - @AfterEach - void clear() { - memberRepository.deleteAll(); - waitingRepository.deleteAll(); - shopRepository.deleteAll(); - } - @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test void countByShopAndCreatedAtBetween() { From 2c3982e820a65ff61553a4f5174c82c249abbbdb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 14:36:16 +0900 Subject: [PATCH 489/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=20api=EC=97=90=20=EB=A9=A4=EB=B2=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/MemberReservationController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java index 3cbaa1a9..de49cee6 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/MemberReservationController.java @@ -52,8 +52,9 @@ public ResponseEntity modifyReservation( @DeleteMapping("/{reservationId}") public ResponseEntity cancelReservation( + @LogIn Member member, @PathVariable("reservationId") Long reservationId) { - return ResponseEntity.ok(memberReservationService.cancelReservation(reservationId)); + return ResponseEntity.ok(memberReservationService.cancelReservation(member, reservationId)); } @GetMapping From 161e00eb5e2455e3ed647754a132eb5c9be9def4 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 14:36:52 +0900 Subject: [PATCH 490/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=EB=A1=9C=20=EC=B6=94=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberReservationService.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index 1ba62f3c..c3d19e9a 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -16,6 +16,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.common.notification.NotificationContent; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.notification.dto.request.SendMessageToOwnerRequest; @@ -102,21 +103,7 @@ public CreateReservationResponse registerReservation(Member member, .build(); Reservation savedReservation = reservationRepository.save(reservation); - Owner owner = ownerRepository.findOwnerByShop(reservationTime.getShop()) - .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); - - SendMessageToMemberRequest sendMessageToMember = new SendMessageToMemberRequest( - member, - RESERVATION_COMPLETED.apply(reservationTime.getTime().toString()) - ); // 회원에게 보낼 해당 시간대의 예약 완료 알림 생성 - - SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest( - owner, - RESERVATION_COMPLETED.apply(reservationTime.getTime().toString()) - ); // 점주에게 보낼 보낼 해당 시간대의 예약 완료 알림 생성 - - publisher.publishEvent(sendMessageToMember); // 회원에게 예약등록 알림 발송 - publisher.publishEvent(sendMessageToOwner); // 점주에게 예약등록 알림 발송 + sendMessageToMemberAndOwner(member, reservationTime, RESERVATION_COMPLETED); //점주와 회원에게 알림 발송 return toCreateReservationResponse(savedReservation); } @@ -156,7 +143,7 @@ public ModifyReservationResponse modifyReservation(Long reservavtionId, } @Transactional - public CancelReservationResponse cancelReservation(Long reservationId) { + public CancelReservationResponse cancelReservation(Member member, Long reservationId) { Reservation reservation = reservationRepository.findByIdWithReservationTimeAndShop( reservationId) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_RESERVATION)); @@ -167,16 +154,27 @@ public CancelReservationResponse cancelReservation(Long reservationId) { reservationTime.setOccupiedFalse(); + sendMessageToMemberAndOwner(member, reservationTime, RESERVATION_CANCELLED); + + return toCancelReservationResponse(reservation); + } + + private void sendMessageToMemberAndOwner(Member member, ReservationTime reservationTime, NotificationContent content) { + Owner owner = ownerRepository.findOwnerByShop(reservationTime.getShop()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); + SendMessageToMemberRequest sendMessageToMember = new SendMessageToMemberRequest( + member, + content.apply(reservationTime.getTime().toString()) + ); // 회원에게 보낼 해당 시간대의 예약 완료 알림 생성 + SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest(owner, - RESERVATION_CANCELLED.apply( + content.apply( reservationTime.getTime().toString())); // 해당 시간의 예약 취소 메세지 dto 생성 + publisher.publishEvent(sendMessageToMember); publisher.publishEvent(sendMessageToOwner); // 취소한 예약의 매장 점주에게 예약 취소 알림 발송 - - return toCancelReservationResponse(reservation); } private void validateIsPreOccupied(ReservationTime reservationTime) { From 8efb45ff0e149471df3a1aa21c44b9e5dbc0c78d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 14:37:05 +0900 Subject: [PATCH 491/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationControllerTest.java | 1 + .../reservation/service/MemberReservationServiceTest.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 72a0d97d..2f5e9014 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -207,6 +207,7 @@ void cancelReservation() throws Exception { Reservation savedReservation = reservationRepository.save(reservation); mockMvc.perform(delete("/reservations/{reservationId}", savedReservation.getId()) + .headers(httpHeaders) .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.status").value(CANCELLED.toString())); diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 3eb25ac9..6128a207 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -272,6 +272,7 @@ void modifyReservationOccupied() { @DisplayName("예약을 취소할 수 있다") void cancelReservation() { //given + Member member = MemberFixture.member("dlswns661035@gmail.com"); ReservationTime reservationTime = ReservationFixture.getReservationTimeOccupied(); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); Reservation reservation = ReservationFixture.getReservation(reservationTime); @@ -283,6 +284,7 @@ void cancelReservation() { when(ownerRepository.findOwnerByShop(any(Shop.class))).thenReturn(Optional.of(owner)); //when CancelReservationResponse response = memberReservationService.cancelReservation( + member, reservation.getId()); //then @@ -297,11 +299,12 @@ void cancelReservation() { @Test @DisplayName("존재하지 않는 예약에 대한 삭제 요청 시 예외가 발생한다") void cancelReservationNotExist() { + Member member = MemberFixture.member("asd@gmail.com"); when(reservationRepository.findByIdWithReservationTimeAndShop(1L)).thenReturn( Optional.empty()); assertThrows(NotFoundCustomException.class, - () -> memberReservationService.cancelReservation(1L)); + () -> memberReservationService.cancelReservation(member, 1L)); } } \ No newline at end of file From 7a0abb161a3059ecfe7dd8a4336f20dc5f6903e2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 14:37:24 +0900 Subject: [PATCH 492/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/MemberReservationService.java | 9 ++++++--- .../controller/MemberReservationControllerTest.java | 2 +- .../service/MemberReservationServiceTest.java | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index c3d19e9a..ef39649b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -63,7 +63,8 @@ public CreateReservationResponse preOccupyReservation(Member member, Thread.currentThread().interrupt(); } } - ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop(reservationTimeId) + ReservationTime reservationTime = reservationTimeRepository.findByIdWithShop( + reservationTimeId) .orElseThrow(() -> { reservationLockRepository.unlock(reservationTimeId); return new NotFoundCustomException(NOT_EXIST_TIME); @@ -103,7 +104,8 @@ public CreateReservationResponse registerReservation(Member member, .build(); Reservation savedReservation = reservationRepository.save(reservation); - sendMessageToMemberAndOwner(member, reservationTime, RESERVATION_COMPLETED); //점주와 회원에게 알림 발송 + sendMessageToMemberAndOwner(member, reservationTime, + RESERVATION_COMPLETED); //점주와 회원에게 알림 발송 return toCreateReservationResponse(savedReservation); } @@ -159,7 +161,8 @@ public CancelReservationResponse cancelReservation(Member member, Long reservati return toCancelReservationResponse(reservation); } - private void sendMessageToMemberAndOwner(Member member, ReservationTime reservationTime, NotificationContent content) { + private void sendMessageToMemberAndOwner(Member member, ReservationTime reservationTime, + NotificationContent content) { Owner owner = ownerRepository.findOwnerByShop(reservationTime.getShop()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_OWNER)); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 2f5e9014..a4f288f2 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -76,7 +76,7 @@ void setUp() { } @AfterEach - void tearDown(){ + void tearDown() { shopRepository.deleteAll(); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 6128a207..438fe518 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -71,7 +71,8 @@ void validateReservation() { CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); - when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn( + Optional.of(reservationTime)); when(reservationLockRepository.lock(1L)).thenReturn(TRUE); when(reservationLockRepository.unlock(1L)).thenReturn(TRUE); doNothing().when(reservationAsync).setPreOcuppied(reservationTime); @@ -99,7 +100,8 @@ void alreadyPreOccupied() { CreateReservationRequest request = ReservationFixture.getCreateReservationRequestWithId( reservationTime.getId()); - when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn(Optional.of(reservationTime)); + when(reservationTimeRepository.findByIdWithShop(1L)).thenReturn( + Optional.of(reservationTime)); when(reservationLockRepository.lock(1L)).thenReturn(TRUE); //when From ae82272745f9219fcdc6c2fcde9c7350b3fecd98 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 14:39:47 +0900 Subject: [PATCH 493/603] =?UTF-8?q?enum=20=ED=91=9C=ED=98=84=EC=8B=9D=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/notification/NotificationContent.java | 2 +- .../reservation/service/MemberReservationService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java index 6d63e0ec..63c028b8 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/NotificationContent.java @@ -15,7 +15,7 @@ public enum NotificationContent { private final Function expression; - public String apply(String time) { + public String getMessage(String time) { return expression.apply(time); } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java index ef39649b..f27b601e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/MemberReservationService.java @@ -169,11 +169,11 @@ private void sendMessageToMemberAndOwner(Member member, ReservationTime reservat SendMessageToMemberRequest sendMessageToMember = new SendMessageToMemberRequest( member, - content.apply(reservationTime.getTime().toString()) + content.getMessage(reservationTime.getTime().toString()) ); // 회원에게 보낼 해당 시간대의 예약 완료 알림 생성 SendMessageToOwnerRequest sendMessageToOwner = new SendMessageToOwnerRequest(owner, - content.apply( + content.getMessage( reservationTime.getTime().toString())); // 해당 시간의 예약 취소 메세지 dto 생성 publisher.publishEvent(sendMessageToMember); From d2f9bcf8bb5ec4756011b2dedd903407a72bbbda Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 20:34:33 +0900 Subject: [PATCH 494/603] =?UTF-8?q?refactor=20:=20owner=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerReservationController.java | 9 ++++++--- .../reservation/service/OwnerReservationService.java | 4 ++-- .../controller/OwnerReservationControllerTest.java | 11 ++++++++++- .../service/OwnerReservationServiceTest.java | 6 ++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java index ff24e8bd..e97a8dcc 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.reservation.controller; +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; import com.prgrms.catchtable.reservation.service.OwnerReservationService; @@ -7,6 +9,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,7 +23,7 @@ public class OwnerReservationController { private final OwnerReservationService ownerReservationService; - @PostMapping("/{reservationId}") + @PatchMapping("/{reservationId}") public void modifyReservationStatus( @PathVariable("reservationId") Long reservationId, @RequestBody ModifyReservationStatusRequest request @@ -30,7 +33,7 @@ public void modifyReservationStatus( @GetMapping public ResponseEntity> getAllReservation( - @RequestBody Long ownerId) { - return ResponseEntity.ok(ownerReservationService.getAllReservation(ownerId)); + @LogIn Owner owner) { + return ResponseEntity.ok(ownerReservationService.getAllReservation(owner)); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 68398914..0ea1ade6 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -59,8 +59,8 @@ public void modifyReservationStatus( * @return */ @Transactional(readOnly = true) - public List getAllReservation(Long ownerId) { - Owner owner = ownerRepository.findById(ownerId).orElseThrow(); + public List getAllReservation(Owner owner) { + List reservations = reservationRepository.findAllWithReservationTimeAndShopByShopId( owner.getShop().getId()); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index cf6e7268..a02e9846 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -1,15 +1,19 @@ package com.prgrms.catchtable.reservation.controller; +import static com.prgrms.catchtable.common.Role.MEMBER; +import static com.prgrms.catchtable.common.Role.OWNER; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; @@ -65,6 +69,10 @@ void setUp() { Owner owner = OwnerFixture.getOwner("email", "password"); owner.insertShop(shop); ownerRepository.save(owner); + + Token token = jwtTokenProvider.createToken(owner.getEmail(), OWNER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); } @Test @@ -79,7 +87,7 @@ void modifyReservationStatus() throws Exception { //then assertThat(reservation.getReservationTime().isOccupied()).isTrue(); // 취소처리 전엔 예약시간 차있음 - mockMvc.perform(post("/owners/shop/{reservationId}", reservation.getId()) + mockMvc.perform(patch("/owners/shop/{reservationId}", reservation.getId()) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()); @@ -100,6 +108,7 @@ void getAllReservation() throws Exception { mockMvc.perform(get("/owners/shop") .contentType(APPLICATION_JSON) + .headers(httpHeaders) .content(asJsonString(owner.getId()))) .andExpect(status().isOk()) .andExpect( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java index 96c21097..3bd7784e 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/OwnerReservationServiceTest.java @@ -112,9 +112,8 @@ void getAllReservation() { Owner owner = OwnerFixture.getOwner("email", "password"); when(reservationRepository.findAllWithReservationTimeAndShopByShopId( any(Long.class))).thenReturn(reservations); - when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); List allReservation = ownerReservationService.getAllReservation( - 1L); + owner); assertAll( () -> assertThat(allReservation.get(0).date()).isEqualTo( @@ -131,10 +130,9 @@ void getAllReservationEmpty() { when(reservationRepository.findAllWithReservationTimeAndShopByShopId( any(Long.class))).thenReturn(List.of()); - when(ownerRepository.findById(any(Long.class))).thenReturn(Optional.of(owner)); List allReservation = ownerReservationService.getAllReservation( - 1L); + owner); assertThat(allReservation).isEmpty(); } From f87e9f5584d1b5a6d20d4b83a35c26a090c49bc6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 20:34:58 +0900 Subject: [PATCH 495/603] =?UTF-8?q?feat=20:=20=EC=A0=90=EC=A3=BC=20?= =?UTF-8?q?=ED=97=A4=EB=8D=94=20=EC=83=9D=EC=84=B1=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/restdocs/RestDocsSupport.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index 8b4ec69c..035f8dbd 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,11 +1,13 @@ package com.prgrms.catchtable.common.restdocs; import static com.prgrms.catchtable.common.Role.MEMBER; +import static com.prgrms.catchtable.common.Role.OWNER; import com.fasterxml.jackson.databind.ObjectMapper; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.owner.domain.Owner; import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,4 +70,11 @@ public HttpHeaders getHttpHeaders(Member member) { httpHeaders.add("RefreshToken", token.getRefreshToken()); return httpHeaders; } + + public HttpHeaders getHttpHeaders(Owner owner) { + Token token = jwtTokenProvider.createToken(owner.getEmail(), OWNER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + return httpHeaders; + } } From 7372ec6b4dcad5c47785e6a6973f852b31511e71 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 20:35:21 +0900 Subject: [PATCH 496/603] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20api=20=EB=8B=A8=EC=9C=84=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberReservationControllerDocsTest.java | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java new file mode 100644 index 00000000..7194edd9 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java @@ -0,0 +1,253 @@ +package com.prgrms.catchtable.reservation.controller; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static org.mockito.Mockito.when; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; +import static org.springframework.restdocs.payload.JsonFieldType.STRING; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.restdocs.RestDocsSupport; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CancelReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.GetAllReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ModifyReservationResponse; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.service.MemberReservationService; +import java.time.LocalDateTime; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class MemberReservationControllerDocsTest extends RestDocsSupport { + @MockBean + private MemberReservationService memberReservationService; + + @Autowired + private MemberRepository memberRepository; + + @BeforeEach + void setUp(){ + Member member = MemberFixture.member("dlswns6asd61035@gmail.com"); + Member savedMember = memberRepository.save(member); + } + + + + @Test + @DisplayName("예약 선점 api") + void preOccupy() throws Exception { + Member member = memberRepository.findAll().get(0); + + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); + CreateReservationResponse response = CreateReservationResponse.builder() + .shopName("shopA") + .memberName(member.getName()) + .date(LocalDateTime.of(2024, 1, 1, 19, 30)) + .peopleCount(request.peopleCount()) + .build(); + + when(memberReservationService.preOccupyReservation(member, request)).thenReturn(response); + + mockMvc.perform(post("/reservations") + .headers(getHttpHeaders(member)) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestFields( + fieldWithPath("reservationTimeId").type(NUMBER) + .description("예약시간 id"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ), + responseFields( + fieldWithPath("shopName").type(STRING) + .description("매장명"), + fieldWithPath("memberName").type(STRING) + .description("예약자 이름"), + fieldWithPath("date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ) + ) + ); + } + + @Test + @DisplayName("예약 등록 api") + void register() throws Exception { + Member member = memberRepository.findAll().get(0); + + CreateReservationRequest request = ReservationFixture.getCreateReservationRequest(); + CreateReservationResponse response = CreateReservationResponse.builder() + .shopName("shopA") + .memberName(member.getName()) + .date(LocalDateTime.of(2024, 1, 1, 19, 30)) + .peopleCount(request.peopleCount()) + .build(); + + when(memberReservationService.registerReservation(member, request)).thenReturn(response); + + mockMvc.perform(post("/reservations/success") + .headers(getHttpHeaders(member)) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestFields( + fieldWithPath("reservationTimeId").type(NUMBER) + .description("예약시간 id"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ), + responseFields( + fieldWithPath("shopName").type(STRING) + .description("매장명"), + fieldWithPath("memberName").type(STRING) + .description("예약자 이름"), + fieldWithPath("date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ) + ) + ); + } + + @Test + @DisplayName("예약 전체 조회 api") + void getAll() throws Exception { + Member member = memberRepository.findAll().get(0); + GetAllReservationResponse reservation1 = GetAllReservationResponse.builder() + .reservationId(1L) + .date(LocalDateTime.of(2024, 1, 1, 19, 30)) + .shopName("shopA") + .peopleCount(5) + .status(COMPLETED) + .build(); + GetAllReservationResponse reservation2 = GetAllReservationResponse.builder() + .reservationId(2L) + .date(LocalDateTime.of(2024, 1, 5, 20, 30)) + .shopName("shopB") + .peopleCount(3) + .status(CANCELLED) + .build(); + + List response = List.of(reservation1, reservation2); + + when(memberReservationService.getAllReservation(member)).thenReturn(response); + + mockMvc.perform(get("/reservations") + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("[0].reservationId").type(NUMBER) + .description("예약 id"), + fieldWithPath("[0].date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("[0].shopName").type(STRING) + .description("매장명"), + fieldWithPath("[0].peopleCount").type(NUMBER) + .description("예약 인원 수"), + fieldWithPath("[0].status").type(STRING) + .description("예약 상태"), + fieldWithPath("[1].reservationId").type(NUMBER) + .description("예약 id"), + fieldWithPath("[1].date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("[1].shopName").type(STRING) + .description("매장명"), + fieldWithPath("[1].peopleCount").type(NUMBER) + .description("예약 인원 수"), + fieldWithPath("[1].status").type(STRING) + .description("예약 상태") + ) + )); + } + + @Test + @DisplayName("예약 수정 api") + void modify() throws Exception { + Member member = memberRepository.findAll().get(0); + + ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest(1L); + + ModifyReservationResponse response = ModifyReservationResponse.builder() + .shopName("shopA") + .memberName(member.getName()) + .date(LocalDateTime.of(2024, 1, 1, 19, 30)) + .peopleCount(5) + .build(); + + when(memberReservationService.modifyReservation(1L, request)).thenReturn(response); + + mockMvc.perform(patch("/reservations/{reservationId}", 1) + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member)) + .content(objectMapper.writeValueAsString(request))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestFields( + fieldWithPath("reservationTimeId").type(NUMBER) + .description("수정하려는 예약시간 id"), + fieldWithPath("peopleCount").type(NUMBER) + .description("수정하려는 인원 수") + ), + responseFields( + fieldWithPath("shopName").type(STRING) + .description("매장명"), + fieldWithPath("memberName").type(STRING) + .description("예약자명"), + fieldWithPath("date").type(STRING) + .description("수정된 예약 날짜 및 시간"), + fieldWithPath("peopleCount").type(NUMBER) + .description("수정된 예약 인원 수") + ) + )); + } + + @Test + @DisplayName("예약 취소 api") + void cancel() throws Exception { + Member member = memberRepository.findAll().get(0); + + CancelReservationResponse response = CancelReservationResponse.builder() + .status(CANCELLED) + .build(); + + when(memberReservationService.cancelReservation(member, 1L)).thenReturn(response); + + mockMvc.perform(delete("/reservations/{reservationId}", 1L) + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("status").type(STRING) + .description("예약 상태") + ) + )); + } + +} From 0ffa0dccb3e683473115504585a566fc8d5478f0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 20:35:49 +0900 Subject: [PATCH 497/603] =?UTF-8?q?feat=20:=20=EC=A0=90=EC=A3=BC=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20api=20=EB=8B=A8=EC=9C=84=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerReservationControllerDocsTest.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java new file mode 100644 index 00000000..06aaee1e --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java @@ -0,0 +1,113 @@ +package com.prgrms.catchtable.reservation.controller; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static org.mockito.Mockito.doNothing; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; +import static org.springframework.restdocs.payload.JsonFieldType.STRING; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.restdocs.RestDocsSupport; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.dto.request.ModifyReservationStatusRequest; +import com.prgrms.catchtable.reservation.dto.response.OwnerGetAllReservationResponse; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; +import com.prgrms.catchtable.reservation.service.OwnerReservationService; +import java.time.LocalDateTime; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class OwnerReservationControllerDocsTest extends RestDocsSupport { + @MockBean + private OwnerReservationService ownerReservationService; + @Autowired + private OwnerRepository ownerRepository; + + @BeforeEach + void setUp(){ + Owner owner = OwnerFixture.getOwner("dlswns", "dlswns24802840"); + ownerRepository.save(owner); + } + + @Test + @DisplayName("예약 노쇼, 취소 처리 api") + void noshowAndCancel() throws Exception { + Owner owner = ownerRepository.findAll().get(0); + + ModifyReservationStatusRequest request = ReservationFixture.getModifyReservationStatusRequest( + CANCELLED); + doNothing().when(ownerReservationService).modifyReservationStatus(1L, request); + + mockMvc.perform(patch("/owners/shop/{reservationId}", 1) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + .headers(getHttpHeaders(owner))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestFields( + fieldWithPath("status").type(STRING) + .description("수정하려는 예약 상태") + ) + )); + } + + @Test + @DisplayName("가게의 예약 전체 조회 api") + void getAllReservation() throws Exception { + Owner owner = ownerRepository.findAll().get(0); + OwnerGetAllReservationResponse reservation1 = OwnerGetAllReservationResponse.builder() + .reservationId(1L) + .date(LocalDateTime.of(2024, 3, 4, 12, 30)) + .peopleCount(4) + .status(COMPLETED) + .build(); + OwnerGetAllReservationResponse reservation2 = OwnerGetAllReservationResponse.builder() + .reservationId(2L) + .date(LocalDateTime.of(2024, 3, 25, 17, 30)) + .peopleCount(2) + .status(CANCELLED) + .build(); + List response = List.of(reservation1, reservation2); + + Mockito.when(ownerReservationService.getAllReservation(owner)).thenReturn(response); + + mockMvc.perform(get("/owners/shop") + .headers(getHttpHeaders(owner))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("[0].reservationId").type(NUMBER) + .description("예약 id"), + fieldWithPath("[0].date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("[0].peopleCount").type(NUMBER) + .description("예약 인원 수"), + fieldWithPath("[0].status").type(STRING) + .description("예약 상태"), + fieldWithPath("[1].reservationId").type(NUMBER) + .description("예약 id"), + fieldWithPath("[1].date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("[1].peopleCount").type(NUMBER) + .description("예약 인원 수"), + fieldWithPath("[1].status").type(STRING) + .description("예약 상태") + ) + )); + } +} From ad78b60c2134e1e4db3e7b796b8d631bab38dbb6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 11 Jan 2024 20:36:08 +0900 Subject: [PATCH 498/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerReservationController.java | 1 - .../MemberReservationControllerDocsTest.java | 56 +++++++++---------- .../OwnerReservationControllerDocsTest.java | 11 ++-- .../OwnerReservationControllerTest.java | 2 - 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java index e97a8dcc..4105bfa0 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java @@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java index 7194edd9..d30ec08b 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerDocsTest.java @@ -38,6 +38,7 @@ @Transactional public class MemberReservationControllerDocsTest extends RestDocsSupport { + @MockBean private MemberReservationService memberReservationService; @@ -45,13 +46,12 @@ public class MemberReservationControllerDocsTest extends RestDocsSupport { private MemberRepository memberRepository; @BeforeEach - void setUp(){ + void setUp() { Member member = MemberFixture.member("dlswns6asd61035@gmail.com"); Member savedMember = memberRepository.save(member); } - @Test @DisplayName("예약 선점 api") void preOccupy() throws Exception { @@ -68,28 +68,28 @@ void preOccupy() throws Exception { when(memberReservationService.preOccupyReservation(member, request)).thenReturn(response); mockMvc.perform(post("/reservations") - .headers(getHttpHeaders(member)) - .contentType(APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) + .headers(getHttpHeaders(member)) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) .andDo(restDocs.document( - requestFields( - fieldWithPath("reservationTimeId").type(NUMBER) - .description("예약시간 id"), - fieldWithPath("peopleCount").type(NUMBER) - .description("예약 인원") - ), - responseFields( - fieldWithPath("shopName").type(STRING) - .description("매장명"), - fieldWithPath("memberName").type(STRING) - .description("예약자 이름"), - fieldWithPath("date").type(STRING) - .description("예약 날짜 및 시간"), - fieldWithPath("peopleCount").type(NUMBER) - .description("예약 인원") + requestFields( + fieldWithPath("reservationTimeId").type(NUMBER) + .description("예약시간 id"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ), + responseFields( + fieldWithPath("shopName").type(STRING) + .description("매장명"), + fieldWithPath("memberName").type(STRING) + .description("예약자 이름"), + fieldWithPath("date").type(STRING) + .description("예약 날짜 및 시간"), + fieldWithPath("peopleCount").type(NUMBER) + .description("예약 인원") + ) ) - ) ); } @@ -158,7 +158,7 @@ void getAll() throws Exception { when(memberReservationService.getAllReservation(member)).thenReturn(response); mockMvc.perform(get("/reservations") - .headers(getHttpHeaders(member))) + .headers(getHttpHeaders(member))) .andExpect(status().isOk()) .andDo(restDocs.document( responseFields( @@ -171,7 +171,7 @@ void getAll() throws Exception { fieldWithPath("[0].peopleCount").type(NUMBER) .description("예약 인원 수"), fieldWithPath("[0].status").type(STRING) - .description("예약 상태"), + .description("예약 상태"), fieldWithPath("[1].reservationId").type(NUMBER) .description("예약 id"), fieldWithPath("[1].date").type(STRING) @@ -203,9 +203,9 @@ void modify() throws Exception { when(memberReservationService.modifyReservation(1L, request)).thenReturn(response); mockMvc.perform(patch("/reservations/{reservationId}", 1) - .contentType(APPLICATION_JSON) - .headers(getHttpHeaders(member)) - .content(objectMapper.writeValueAsString(request))) + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member)) + .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) .andDo(restDocs.document( requestFields( @@ -239,8 +239,8 @@ void cancel() throws Exception { when(memberReservationService.cancelReservation(member, 1L)).thenReturn(response); mockMvc.perform(delete("/reservations/{reservationId}", 1L) - .contentType(APPLICATION_JSON) - .headers(getHttpHeaders(member))) + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) .andExpect(status().isOk()) .andDo(restDocs.document( responseFields( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java index 06aaee1e..40e6e434 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java @@ -33,13 +33,14 @@ @Transactional public class OwnerReservationControllerDocsTest extends RestDocsSupport { + @MockBean private OwnerReservationService ownerReservationService; @Autowired private OwnerRepository ownerRepository; @BeforeEach - void setUp(){ + void setUp() { Owner owner = OwnerFixture.getOwner("dlswns", "dlswns24802840"); ownerRepository.save(owner); } @@ -54,9 +55,9 @@ void noshowAndCancel() throws Exception { doNothing().when(ownerReservationService).modifyReservationStatus(1L, request); mockMvc.perform(patch("/owners/shop/{reservationId}", 1) - .contentType(APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - .headers(getHttpHeaders(owner))) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) .andDo(restDocs.document( requestFields( @@ -87,7 +88,7 @@ void getAllReservation() throws Exception { Mockito.when(ownerReservationService.getAllReservation(owner)).thenReturn(response); mockMvc.perform(get("/owners/shop") - .headers(getHttpHeaders(owner))) + .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) .andDo(restDocs.document( responseFields( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index a02e9846..fbeb90f0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -1,13 +1,11 @@ package com.prgrms.catchtable.reservation.controller; -import static com.prgrms.catchtable.common.Role.MEMBER; import static com.prgrms.catchtable.common.Role.OWNER; import static com.prgrms.catchtable.reservation.domain.ReservationStatus.CANCELLED; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; From ae2e68e019fe48dad3baeff5722fca475adea68c Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 10:40:39 +0900 Subject: [PATCH 499/603] =?UTF-8?q?feat=20:=20DTO=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 1 + .../catchtable/waiting/dto/response/OwnerWaitingResponse.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index b241f5bb..5729a611 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -66,6 +66,7 @@ public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long .waitingNumber(waiting.getWaitingNumber()) .rank(rank) .peopleCount(waiting.getPeopleCount()) + .status(waiting.getStatus().getDescription()) .build(); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java index e3c04197..559f04cd 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -7,7 +7,8 @@ public record OwnerWaitingResponse( Long waitingId, int waitingNumber, Long rank, - int peopleCount + int peopleCount, + String status ) { } From 7c2ad50eb4f8c06545cbcbf1e251d7bfbec5e8ae Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 10:41:42 +0900 Subject: [PATCH 500/603] =?UTF-8?q?feat=20:=20header=20util=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/restdocs/RestDocsSupport.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index 8b4ec69c..8dfb5bef 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,11 +1,14 @@ package com.prgrms.catchtable.common.restdocs; +import static com.prgrms.catchtable.common.Role.*; import static com.prgrms.catchtable.common.Role.MEMBER; import com.fasterxml.jackson.databind.ObjectMapper; +import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.owner.domain.Owner; import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,4 +71,11 @@ public HttpHeaders getHttpHeaders(Member member) { httpHeaders.add("RefreshToken", token.getRefreshToken()); return httpHeaders; } + + public HttpHeaders getHttpHeaders(Owner owner) { + Token token = jwtTokenProvider.createToken(owner.getEmail(), OWNER); + httpHeaders.add("AccessToken", token.getAccessToken()); + httpHeaders.add("RefreshToken", token.getRefreshToken()); + return httpHeaders; + } } From fe01d7816cd8dca1d4aa4773567ccb873831b89d Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 11:53:39 +0900 Subject: [PATCH 501/603] =?UTF-8?q?feat=20:=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 1 - .../waiting/dto/response/MemberWaitingHistoryResponse.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 5729a611..ad69f7c4 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -48,7 +48,6 @@ public static MemberWaitingHistoryResponse toMemberWaitingHistoryResponse(Waitin .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) .peopleCount(waiting.getPeopleCount()) - .waitingNumber(waiting.getWaitingNumber()) .status(waiting.getStatus().getDescription()) .build(); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java index bdcd9872..c48e2109 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryResponse.java @@ -8,7 +8,6 @@ public record MemberWaitingHistoryResponse( Long shopId, String shopName, int peopleCount, - int waitingNumber, String status ) { From da5af41d7d3b0da88176c11514dae574df4d4fde Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 12:06:11 +0900 Subject: [PATCH 502/603] =?UTF-8?q?fix=20:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/shop/service/MemberShopService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index cbdec14e..8f90d48c 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; @@ -29,7 +30,7 @@ public GetAllShopResponse getAll() { @Transactional(readOnly = true) public GetShopResponse getById(Long id) { Shop findShop = shopRepository.findShopById(id) - .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_SHOP)); + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_SHOP)); return ShopMapper.toGetShopResponse(findShop); } From ab0f08d369e4fb57941e9ba37595b20746982c41 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 12:06:43 +0900 Subject: [PATCH 503/603] =?UTF-8?q?refactor=20:=20ErrorCode=20static=20?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/shop/domain/Category.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java index 62e5382e..c8b95463 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.shop.domain; +import static com.prgrms.catchtable.common.exception.ErrorCode.*; + import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import java.util.Arrays; @@ -20,7 +22,7 @@ public static Category of(String input) { return Arrays.stream(values()) .filter(category -> category.isEqual(input)) .findAny() - .orElseThrow(() -> new BadRequestCustomException(ErrorCode.INVALID_INPUT_TYPE)); + .orElseThrow(() -> new BadRequestCustomException(INVALID_INPUT_TYPE)); } private boolean isEqual(String input) { From af6f9645f6097f3111b3597ebbc5e5ede1a4a0f5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 12:07:51 +0900 Subject: [PATCH 504/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=20=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/service/MemberWaitingServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 93f1a1ed..6e7162c7 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -169,8 +169,8 @@ void getMemberAllWaiting() { //then assertAll( assertThat(response.memberWaitings().get(0).peopleCount())::isNotNull, - assertThat(response.memberWaitings().get(0).waitingNumber())::isNotNull, - assertThat(response.memberWaitings().get(0).status())::isNotNull + assertThat(response.memberWaitings().get(0).status())::isNotNull, + assertThat(response.memberWaitings().get(0).shopName())::isNotNull ); } } \ No newline at end of file From cff88a63133be36db65f933d142d8725222f975b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 12:07:51 +0900 Subject: [PATCH 505/603] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EB=8C=80=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/MemberShopControllerTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java index 1b0bbd14..0f89a4d6 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -88,12 +88,12 @@ void getByIdTest() throws Exception { .contentType(MediaType.APPLICATION_JSON) .headers(httpHeaders)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.name").value(shop.getName())) - .andExpect(jsonPath("$.rating").value(shop.getRating())) - .andExpect(jsonPath("$.category").value(shop.getCategory().getType())) - .andExpect(jsonPath("$.city").value(shop.getAddress().getCity())) - .andExpect(jsonPath("$.district").value(shop.getAddress().getDistrict())) - .andExpect(jsonPath("$.capacity").value(shop.getCapacity())); + .andExpect(jsonPath("$.name").value(shop1.getName())) + .andExpect(jsonPath("$.rating").value(shop1.getRating())) + .andExpect(jsonPath("$.category").value(shop1.getCategory().getType())) + .andExpect(jsonPath("$.city").value(shop1.getAddress().getCity())) + .andExpect(jsonPath("$.district").value(shop1.getAddress().getDistrict())) + .andExpect(jsonPath("$.capacity").value(shop1.getCapacity())); } @Test From 3dc8883f33272722ae916fea2c404dbf3b6eb2e6 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 12:09:22 +0900 Subject: [PATCH 506/603] =?UTF-8?q?feat=20:=20DTO=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20Builder=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/dto/response/MemberWaitingHistoryListResponse.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java index 5cbd4b01..1e2fac61 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingHistoryListResponse.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.waiting.dto.response; import java.util.List; +import lombok.Builder; +@Builder public record MemberWaitingHistoryListResponse( List memberWaitings ) { From d32785b489287d4658f2918d81cf836b6664dd53 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 12:19:16 +0900 Subject: [PATCH 507/603] =?UTF-8?q?style=20:=20=EB=84=A4=EC=9D=B4=EB=B0=8D?= =?UTF-8?q?=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/domain/ReservationTime.java | 1 - .../shop/controller/OwnerShopController.java | 12 ++++----- .../catchtable/shop/dto/ShopMapper.java | 26 +++++++++---------- ...pRequest.java => RegisterShopRequest.java} | 9 ++++--- ...esponse.java => RegisterShopResponse.java} | 8 ++++-- .../shop/service/OwnerShopService.java | 12 ++++----- .../controller/OwnerShopControllerTest.java | 4 +-- .../catchtable/shop/fixture/ShopFixture.java | 6 ++--- .../shop/service/ShopServiceTest.java | 8 +++--- 9 files changed, 46 insertions(+), 40 deletions(-) rename src/main/java/com/prgrms/catchtable/shop/dto/request/{RegistShopRequest.java => RegisterShopRequest.java} (71%) rename src/main/java/com/prgrms/catchtable/shop/dto/response/{RegistShopResponse.java => RegisterShopResponse.java} (67%) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index a9867268..28d52594 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -49,7 +49,6 @@ public ReservationTime(LocalDateTime time) { public void insertShop(Shop shop) { this.shop = shop; - shop.getReservationTimeList().add(this); } public void setOccupiedTrue() { diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java index 1405a731..5b13feda 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/OwnerShopController.java @@ -2,8 +2,8 @@ import com.prgrms.catchtable.common.login.LogIn; import com.prgrms.catchtable.owner.domain.Owner; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; -import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; +import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import com.prgrms.catchtable.shop.service.OwnerShopService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -22,11 +22,11 @@ public class OwnerShopController { private final OwnerShopService shopService; @PostMapping("/shops") - public ResponseEntity registShop( - @Valid @RequestBody RegistShopRequest request, @LogIn + public ResponseEntity registerShop( + @Valid @RequestBody RegisterShopRequest request, @LogIn Owner owner) { - RegistShopResponse registShopResponse = shopService.registShop(request, owner); - return ResponseEntity.status(HttpStatus.CREATED).body(registShopResponse); + RegisterShopResponse registerShopResponse = shopService.registerShop(request, owner); + return ResponseEntity.status(HttpStatus.CREATED).body(registerShopResponse); } } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 177a07c5..815125d1 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -3,32 +3,32 @@ import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; -import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import java.util.List; public class ShopMapper { - public static Shop toEntity(RegistShopRequest registShopRequest) { + public static Shop toEntity(RegisterShopRequest registerShopRequest) { return Shop.builder() - .name(registShopRequest.name()) - .rating(registShopRequest.rating()) - .category(Category.of(registShopRequest.category())) + .name(registerShopRequest.name()) + .rating(registerShopRequest.rating()) + .category(Category.of(registerShopRequest.category())) .address(Address.builder() - .city(registShopRequest.city()) - .district(registShopRequest.district()) + .city(registerShopRequest.city()) + .district(registerShopRequest.district()) .build()) - .capacity(registShopRequest.capacity()) - .openingTime(registShopRequest.openingTime()) - .closingTime(registShopRequest.closingTime()) + .capacity(registerShopRequest.capacity()) + .openingTime(registerShopRequest.openingTime()) + .closingTime(registerShopRequest.closingTime()) .build(); } - public static RegistShopResponse toRegistShopResponse(Shop shop) { - return RegistShopResponse.builder() + public static RegisterShopResponse toRegisterShopResponse(Shop shop) { + return RegisterShopResponse.builder() .name(shop.getName()) .rating(shop.getRating()) .category(shop.getCategory().getType()) diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java similarity index 71% rename from src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java rename to src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java index bffb4182..4de9dc32 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegistShopRequest.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java @@ -4,11 +4,13 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; import lombok.Builder; @Builder -public record RegistShopRequest( +public record RegisterShopRequest( String name, @Min(0) @@ -21,8 +23,9 @@ public record RegistShopRequest( @JsonFormat(pattern = "kk:mm:ss") LocalTime openingTime, @JsonFormat(pattern = "kk:mm:ss") - LocalTime closingTime - + LocalTime closingTime, + List resservationTimeList, + List menuRequestList ) { } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegisterShopResponse.java similarity index 67% rename from src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java rename to src/main/java/com/prgrms/catchtable/shop/dto/response/RegisterShopResponse.java index 1dde4ecf..2583785f 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/response/RegistShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/RegisterShopResponse.java @@ -3,11 +3,13 @@ import com.fasterxml.jackson.annotation.JsonFormat; import java.math.BigDecimal; import java.time.LocalTime; +import java.util.List; import lombok.Builder; @Builder -public record RegistShopResponse( +public record RegisterShopResponse( + Long id, String name, BigDecimal rating, String category, @@ -17,7 +19,9 @@ public record RegistShopResponse( @JsonFormat(pattern = "kk:mm:ss") LocalTime openingTime, @JsonFormat(pattern = "kk:mm:ss") - LocalTime closingTime + LocalTime closingTime, + List reservationTimeResponseList, + List menuResponseList ) { } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index aa7d5da1..a6eb1e5b 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -3,8 +3,8 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.ShopMapper; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; -import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; +import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,12 +17,12 @@ public class OwnerShopService { private final ShopRepository shopRepository; @Transactional - public RegistShopResponse registShop(RegistShopRequest registShopRequest, Owner owner) { + public RegisterShopResponse registerShop(RegisterShopRequest registerShopRequest, Owner owner) { - Shop registShop = shopRepository.save(ShopMapper.toEntity(registShopRequest)); - owner.insertShop(registShop); + Shop registerShop = shopRepository.save(ShopMapper.toEntity(registerShopRequest)); + owner.insertShop(registerShop); - return ShopMapper.toRegistShopResponse(registShop); + return ShopMapper.toRegisterShopResponse(registerShop); } diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java index e7b4a992..6ad9d6ee 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/OwnerShopControllerTest.java @@ -13,7 +13,7 @@ import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.fixture.ShopFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -54,7 +54,7 @@ void init() { void registShopTest() throws Exception { //given Shop shop = ShopFixture.shop(); - RegistShopRequest shopRequest = ShopFixture.getRequestDto(shop); + RegisterShopRequest shopRequest = ShopFixture.getRequestDto(shop); //then mockMvc.perform(post("/owners/shops") diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index 0f24b2c5..e04399e4 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -3,7 +3,7 @@ import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import java.math.BigDecimal; import java.time.LocalTime; @@ -33,8 +33,8 @@ public static Shop shopWith24() { .build(); } - public static RegistShopRequest getRequestDto(Shop shop) { - return RegistShopRequest.builder() + public static RegisterShopRequest getRequestDto(Shop shop) { + return RegisterShopRequest.builder() .name(shop.getName()) .rating(shop.getRating()) .category(shop.getCategory().getType()) diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index e2544be7..ecdf29cb 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -9,9 +9,9 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.dto.request.RegistShopRequest; +import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; -import com.prgrms.catchtable.shop.dto.response.RegistShopResponse; +import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; @@ -40,11 +40,11 @@ void registShopTest() { Owner owner = OwnerFixture.getOwner(); Shop shop = ShopFixture.shop(); - RegistShopRequest shopRequest = ShopFixture.getRequestDto(shop); + RegisterShopRequest shopRequest = ShopFixture.getRequestDto(shop); //when when(shopRepository.save(any(Shop.class))).thenReturn(shop); - RegistShopResponse registShopResponse = ownerShopService.registShop(shopRequest, owner); + RegisterShopResponse registShopResponse = ownerShopService.registerShop(shopRequest, owner); //then assertThat(registShopResponse.name()).isEqualTo(shop.getName()); From 9ae1167151b46a01c5e196b497fc35f0b650725b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 12:23:31 +0900 Subject: [PATCH 508/603] =?UTF-8?q?fix=20:=20=EC=96=91=EB=B0=A9=ED=96=A5?= =?UTF-8?q?=20=EA=B4=80=EA=B3=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/shop/domain/Shop.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index ce4e255b..9bf9bbbe 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -56,10 +56,6 @@ public class Shop extends BaseEntity { @Column(name = "closing_time") private LocalTime closingTime; - @BatchSize(size = 30) - @OneToMany(mappedBy = "shop") - private List reservationTimeList = new ArrayList<>(); - @Builder public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, LocalTime openingTime, LocalTime closingTime) { From 5ea4e6bb9dbb35bd9b38bdeba187a3e52bbb9ec9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 12:34:50 +0900 Subject: [PATCH 509/603] =?UTF-8?q?style=20:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC,=20=EC=84=9C=EB=B9=84=EC=8A=A4=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/OwnerWaitingController.java | 4 ++-- .../catchtable/waiting/service/OwnerWaitingService.java | 2 +- .../catchtable/waiting/service/OwnerWaitingServiceTest.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index 24d90864..99a3b56b 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -20,9 +20,9 @@ public class OwnerWaitingController { private final OwnerWaitingService ownerWaitingService; @GetMapping - public ResponseEntity getOwnerAllWaiting( + public ResponseEntity getShopAllWaiting( @LogIn Owner owner) { - OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(owner); + OwnerWaitingListResponse response = ownerWaitingService.getShopAllWaiting(owner); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 4c739adf..8e9734e7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -24,7 +24,7 @@ public class OwnerWaitingService { private final WaitingLineRepository waitingLineRepository; @Transactional(readOnly = true) - public OwnerWaitingListResponse getOwnerAllWaiting(Owner owner) { + public OwnerWaitingListResponse getShopAllWaiting(Owner owner) { List waitingIds = waitingLineRepository.getShopWaitingIdsInOrder( owner.getShop().getId()); List waitings = waitingRepository.findByIds(waitingIds); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 1c0a5c0a..0bcb523e 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -40,9 +40,9 @@ class OwnerWaitingServiceTest { @InjectMocks private OwnerWaitingService ownerWaitingService; - @DisplayName("owner의 waiting 목록을 모두 가져온다.") + @DisplayName("가게의 waiting 목록을 모두 가져온다.") @Test - void getOwnerAllWaiting() { + void getShopAllWaiting() { //given List waitingIds = List.of(1L, 2L); Member member1 = mock(Member.class); @@ -59,7 +59,7 @@ void getOwnerAllWaiting() { given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting1, waiting2)); //when - OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(owner); + OwnerWaitingListResponse response = ownerWaitingService.getShopAllWaiting(owner); //then assertAll( From ffbd10b0ffa57726f1b0bf6966915273a5d94230 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 13:01:07 +0900 Subject: [PATCH 510/603] =?UTF-8?q?feat=20:=20fixture=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/fixture/WaitingFixture.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index e686972c..448da31f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -3,6 +3,8 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; public class WaitingFixture { @@ -26,4 +28,17 @@ public static Waiting canceledWaiting(Member member, Shop shop, int waitingNumbe waiting.changeStatusCanceled(); return waiting; } + + public static MemberWaitingResponse memberWaitingResponse(int remainingPostponeCount, WaitingStatus status){ + return MemberWaitingResponse.builder() + .waitingId(1L) + .shopId(1L) + .shopName("shop1") + .waitingNumber(324) + .rank(20L) + .peopleCount(remainingPostponeCount) + .remainingPostponeCount(2) + .status(status.getDescription()) + .build(); + } } \ No newline at end of file From 2f33cb0407189bf0ad1b497e5a2db466fdde0824 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 13:02:44 +0900 Subject: [PATCH 511/603] =?UTF-8?q?feat=20:=20waiting=20member=20API=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingControllerDocsTest.java | 208 ++++++++++++++++-- .../service/MemberWaitingServiceTest.java | 3 +- 2 files changed, 186 insertions(+), 25 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index c807c8b2..1daf5d80 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -1,25 +1,36 @@ package com.prgrms.catchtable.waiting.controller; +import static com.prgrms.catchtable.member.MemberFixture.member; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; +import static org.springframework.restdocs.payload.JsonFieldType.STRING; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.restdocs.RestDocsSupport; -import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import com.prgrms.catchtable.waiting.service.MemberWaitingService; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.transaction.annotation.Transactional; @Transactional @@ -29,7 +40,13 @@ class MemberWaitingControllerDocsTest extends RestDocsSupport { private MemberWaitingService memberWaitingService; @Autowired private MemberRepository memberRepository; + private Member member; + @BeforeEach + void setUp() { + member = member("test@naver.com"); + memberRepository.save(member); + } @DisplayName("웨이팅 생성 API") @Test @@ -37,18 +54,7 @@ void createWaiting() throws Exception { CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); - MemberWaitingResponse response = MemberWaitingResponse.builder() - .waitingId(201L) - .shopId(1L) - .shopName("shop1") - .waitingNumber(324) - .rank(20L) - .peopleCount(2) - .remainingPostponeCount(2) - .status("진행 중") - .build(); - Member member = MemberFixture.member("test@naver.com"); - memberRepository.save(member); + MemberWaitingResponse response = WaitingFixture.memberWaitingResponse(2, PROGRESS); given(memberWaitingService.createWaiting(1L, member, request)).willReturn(response); mockMvc.perform(post("/waitings/{shopId}", 1) @@ -58,29 +64,185 @@ void createWaiting() throws Exception { .andExpect(status().isOk()) .andDo(restDocs.document( requestFields( - fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + fieldWithPath("peopleCount").type(NUMBER) .description("인원수") ), responseFields( - fieldWithPath("waitingId").type(JsonFieldType.NUMBER) + fieldWithPath("waitingId").type(NUMBER) .description("생성된 웨이팅 아이디"), - fieldWithPath("shopId").type(JsonFieldType.NUMBER) + fieldWithPath("shopId").type(NUMBER) .description("상점 아이디"), - fieldWithPath("shopName").type(JsonFieldType.STRING) + fieldWithPath("shopName").type(STRING) .description("상점 이름"), - fieldWithPath("peopleCount").type(JsonFieldType.NUMBER) + fieldWithPath("peopleCount").type(NUMBER) .description("인원 수"), - fieldWithPath("waitingNumber").type(JsonFieldType.NUMBER) + fieldWithPath("waitingNumber").type(NUMBER) .description("웨이팅 고유 번호"), - fieldWithPath("rank").type(JsonFieldType.NUMBER) + fieldWithPath("rank").type(NUMBER) .description("웨이팅 순서"), - fieldWithPath("remainingPostponeCount").type(JsonFieldType.NUMBER) + fieldWithPath("remainingPostponeCount").type(NUMBER) .description("대기 지연 잔여 횟수"), - fieldWithPath("status").type(JsonFieldType.STRING) + fieldWithPath("status").type(STRING) .description("대기 상태") ) )); + } + @DisplayName("웨이팅 지연 API") + @Test + void postponeWaiting() throws Exception { + //given + MemberWaitingResponse response = WaitingFixture.memberWaitingResponse(2, PROGRESS); + given(memberWaitingService.postponeWaiting(member)).willReturn(response); + //when, then + mockMvc.perform(patch("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("waitingId").type(NUMBER) + .description("생성된 웨이팅 아이디"), + fieldWithPath("shopId").type(NUMBER) + .description("상점 아이디"), + fieldWithPath("shopName").type(STRING) + .description("상점 이름"), + fieldWithPath("peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("remainingPostponeCount").type(NUMBER) + .description("대기 지연 잔여 횟수"), + fieldWithPath("status").type(STRING) + .description("대기 상태") + ) + )); + } + + @DisplayName("웨이팅 취소 API") + @Test + void cancelWaiting() throws Exception { + //given + MemberWaitingResponse response = WaitingFixture.memberWaitingResponse(1, + CANCELED); + given(memberWaitingService.cancelWaiting(member)).willReturn(response); + //when, then + mockMvc.perform(delete("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("waitingId").type(NUMBER) + .description("생성된 웨이팅 아이디"), + fieldWithPath("shopId").type(NUMBER) + .description("상점 아이디"), + fieldWithPath("shopName").type(STRING) + .description("상점 이름"), + fieldWithPath("peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("remainingPostponeCount").type(NUMBER) + .description("대기 지연 잔여 횟수"), + fieldWithPath("status").type(STRING) + .description("대기 상태") + ) + )); } + + @DisplayName("회원 진행 중인 웨이팅 조회 API") + @Test + void getWaiting() throws Exception { + //given + MemberWaitingResponse response = + WaitingFixture.memberWaitingResponse(2, + PROGRESS); + given(memberWaitingService.getWaiting(member)).willReturn(response); + //when, then + mockMvc.perform(get("/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("waitingId").type(NUMBER) + .description("생성된 웨이팅 아이디"), + fieldWithPath("shopId").type(NUMBER) + .description("상점 아이디"), + fieldWithPath("shopName").type(STRING) + .description("상점 이름"), + fieldWithPath("peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("remainingPostponeCount").type(NUMBER) + .description("대기 지연 잔여 횟수"), + fieldWithPath("status").type(STRING) + .description("대기 상태") + ) + )); + } + + @DisplayName("회원의 웨이팅 이력 조회") + @Test + void getMemberWaitingHistory() throws Exception { + //given + MemberWaitingHistoryResponse response1 = MemberWaitingHistoryResponse.builder() + .waitingId(1L) + .shopId(77L) + .shopName("shop1") + .status("취소") + .peopleCount(2) + .build(); + MemberWaitingHistoryResponse response2 = MemberWaitingHistoryResponse.builder() + .waitingId(22L) + .shopId(77L) + .shopName("shop1") + .status("진행중") + .peopleCount(2) + .build(); + MemberWaitingHistoryListResponse responses = MemberWaitingHistoryListResponse.builder() + .memberWaitings(List.of(response1, response2)) + .build(); + given(memberWaitingService.getMemberWaitingHistory(member)).willReturn(responses); + //when, then + mockMvc.perform(get("/waitings/all") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(member))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("memberWaitings[0].waitingId").type(NUMBER) + .description("회원 웨이팅 아이디"), + fieldWithPath("memberWaitings[0].shopId").type(NUMBER) + .description("가게 아이디"), + fieldWithPath("memberWaitings[0].shopName").type(STRING) + .description("가게 이름"), + fieldWithPath("memberWaitings[0].peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("memberWaitings[0].status").type(STRING) + .description("대기 상태"), + fieldWithPath("memberWaitings[1].waitingId").type(NUMBER) + .description("회원 웨이팅 아이디"), + fieldWithPath("memberWaitings[1].shopId").type(NUMBER) + .description("가게 아이디"), + fieldWithPath("memberWaitings[1].shopName").type(STRING) + .description("가게 이름"), + fieldWithPath("memberWaitings[1].peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("memberWaitings[1].status").type(STRING) + .description("대기 상태") + ) + )); + } + + } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 6e7162c7..79d44bfb 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -169,8 +169,7 @@ void getMemberAllWaiting() { //then assertAll( assertThat(response.memberWaitings().get(0).peopleCount())::isNotNull, - assertThat(response.memberWaitings().get(0).status())::isNotNull, - assertThat(response.memberWaitings().get(0).shopName())::isNotNull + assertThat(response.memberWaitings().get(0).status())::isNotNull ); } } \ No newline at end of file From cc1023bab671151680ac6f0504522dd65f99c863 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 13:03:11 +0900 Subject: [PATCH 512/603] =?UTF-8?q?feat=20:=20waiting=20owner=20API=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerWaitingControllerDocsTest.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java new file mode 100644 index 00000000..7c083eb4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java @@ -0,0 +1,133 @@ +package com.prgrms.catchtable.waiting.controller; + +import static org.mockito.BDDMockito.given; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; +import static org.springframework.restdocs.payload.JsonFieldType.STRING; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.restdocs.RestDocsSupport; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; +import com.prgrms.catchtable.waiting.service.OwnerWaitingService; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +class OwnerWaitingControllerDocsTest extends RestDocsSupport { + + @MockBean + private OwnerWaitingService ownerWaitingService; + + @Autowired + private OwnerRepository ownerRepository; + + private Owner owner; + + @BeforeEach + void setUp() { + owner = OwnerFixture.getOwner("hyun@gmail.com", "hyun1234"); + ownerRepository.save(owner); + } + + @DisplayName("웨이팅 입장 API") + @Test + void entryWaiting() throws Exception { + //given + OwnerWaitingResponse response = OwnerWaitingResponse.builder() + .waitingId(1L) + .waitingNumber(20) + .rank(1L) + .peopleCount(2) + .status("진행 중") + .build(); + given(ownerWaitingService.entryWaiting(owner)).willReturn(response); + //when, then + mockMvc.perform(patch("/owner/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(owner))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("waitingId").type(NUMBER) + .description("회원 웨이팅 아이디"), + fieldWithPath("waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("status").type(STRING) + .description("대기 상태") + ) + )); + + } + + @DisplayName("owner 가게의 웨이팅 목록 조회") + @Test + void getShopAllWaiting() throws Exception { + //given + OwnerWaitingResponse response1 = OwnerWaitingResponse.builder() + .waitingId(1L) + .waitingNumber(20) + .rank(1L) + .peopleCount(2) + .status("진행 중") + .build(); + OwnerWaitingResponse response2 = OwnerWaitingResponse.builder() + .waitingId(2L) + .waitingNumber(21) + .rank(2L) + .peopleCount(2) + .status("진행 중") + .build(); + OwnerWaitingListResponse responses = OwnerWaitingListResponse.builder() + .shopWaitings(List.of(response1, response2)) + .build(); + + given(ownerWaitingService.getShopAllWaiting(owner)).willReturn(responses); + + //when, then + mockMvc.perform(get("/owner/waitings") + .contentType(APPLICATION_JSON) + .headers(getHttpHeaders(owner))) + .andExpect(status().isOk()) + .andDo(restDocs.document( + responseFields( + fieldWithPath("shopWaitings[0].waitingId").type(NUMBER) + .description("회원 웨이팅 아이디"), + fieldWithPath("shopWaitings[0].waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("shopWaitings[0].rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("shopWaitings[0].peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("shopWaitings[0].status").type(STRING) + .description("대기 상태"), + fieldWithPath("shopWaitings[1].waitingId").type(NUMBER) + .description("회원 웨이팅 아이디"), + fieldWithPath("shopWaitings[1].waitingNumber").type(NUMBER) + .description("웨이팅 고유 번호"), + fieldWithPath("shopWaitings[1].rank").type(NUMBER) + .description("웨이팅 순서"), + fieldWithPath("shopWaitings[1].peopleCount").type(NUMBER) + .description("인원 수"), + fieldWithPath("shopWaitings[1].status").type(STRING) + .description("대기 상태") + ) + )); + } +} From 48450e8dd8038c2aba3123c4663852efedcfadea Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 13:04:20 +0900 Subject: [PATCH 513/603] =?UTF-8?q?feat=20:=20waiting.adoc=20=EC=8A=A4?= =?UTF-8?q?=EB=8B=88=ED=8E=AB=20=ED=95=A9=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/waiting/waiting.adoc | 60 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/docs/asciidoc/api/waiting/waiting.adoc b/src/docs/asciidoc/api/waiting/waiting.adoc index 309f4425..641c9595 100644 --- a/src/docs/asciidoc/api/waiting/waiting.adoc +++ b/src/docs/asciidoc/api/waiting/waiting.adoc @@ -1,5 +1,5 @@ [[waiting-create]] -=== 웨이팅 등록 +=== 웨이팅 등록 API ==== HTTP Request @@ -9,4 +9,60 @@ include::{snippets}/member-waiting-controller-docs-test/create-waiting/request-f ==== HTTP Response include::{snippets}/member-waiting-controller-docs-test/create-waiting/http-response.adoc[] -include::{snippets}/member-waiting-controller-docs-test/create-waiting/response-fields.adoc[] \ No newline at end of file +include::{snippets}/member-waiting-controller-docs-test/create-waiting/response-fields.adoc[] + +=== 웨이팅 지연 API + +==== HTTP Request + +include::{snippets}/member-waiting-controller-docs-test/postpone-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-waiting-controller-docs-test/postpone-waiting/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/postpone-waiting/response-fields.adoc[] + +=== 웨이팅 취소 API + +==== HTTP Request + +include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/response-fields.adoc[] + +=== 회원 진행 중인 웨이팅 조회 API + +==== HTTP Request + +include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/get-waiting/response-fields.adoc[] + + +=== 웨이팅 입장 API + +==== HTTP Request + +include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/http-response.adoc[] +include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/response-fields.adoc[] + +=== 가게 웨이팅 이력 조회 API + +==== HTTP Request + +include::{snippets}/owner-waiting-controller-docs-test/get-shop-all-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/owner-waiting-controller-docs-test/get-shop-all-waiting/http-response.adoc[] +include::{snippets}/owner-waiting-controller-docs-test/get-shop-all-waiting/response-fields.adoc[] \ No newline at end of file From 555df75659c6223f00ecf726dd8fdf31c9d6ff79 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 13:05:02 +0900 Subject: [PATCH 514/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingControllerDocsTest.java | 2 +- .../com/prgrms/catchtable/waiting/fixture/WaitingFixture.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index 1daf5d80..8d5bf5da 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -162,7 +162,7 @@ void getWaiting() throws Exception { //given MemberWaitingResponse response = WaitingFixture.memberWaitingResponse(2, - PROGRESS); + PROGRESS); given(memberWaitingService.getWaiting(member)).willReturn(response); //when, then mockMvc.perform(get("/waitings") diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index 448da31f..effae299 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -29,7 +29,8 @@ public static Waiting canceledWaiting(Member member, Shop shop, int waitingNumbe return waiting; } - public static MemberWaitingResponse memberWaitingResponse(int remainingPostponeCount, WaitingStatus status){ + public static MemberWaitingResponse memberWaitingResponse(int remainingPostponeCount, + WaitingStatus status) { return MemberWaitingResponse.builder() .waitingId(1L) .shopId(1L) From 6d7f8a68eb71b82f5d1e21dee2c1f5e1195e98ef Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 14:49:16 +0900 Subject: [PATCH 515/603] =?UTF-8?q?feat=20:=20=EA=B0=80=EA=B2=8C=EC=99=80?= =?UTF-8?q?=20=EB=A9=94=EB=89=B4=20=EC=96=91=EB=B0=A9=ED=96=A5=20=EA=B4=80?= =?UTF-8?q?=EA=B3=84,=20=EA=B0=80=EA=B2=8C=EC=99=80=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=20=EC=8B=9C=EA=B0=84=20=EB=8B=A8=EB=B0=A9=ED=96=A5=20=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/shop/domain/Menu.java | 4 ++++ .../java/com/prgrms/catchtable/shop/domain/Shop.java | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java b/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java index 549e78da..9f446468 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Menu.java @@ -47,4 +47,8 @@ public Menu(String name, int price, String description) { this.price = price; this.description = description; } + + public void insertShop(Shop shop) { + this.shop = shop; + } } diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index 9bf9bbbe..c4f9e30e 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.shop.domain; import static com.prgrms.catchtable.common.exception.ErrorCode.SHOP_NOT_RUNNING; +import static jakarta.persistence.CascadeType.*; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; @@ -8,6 +9,7 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -56,9 +58,13 @@ public class Shop extends BaseEntity { @Column(name = "closing_time") private LocalTime closingTime; + @BatchSize(size = 30) + @OneToMany(mappedBy = "shop", cascade = ALL, orphanRemoval = true) + List menuList = new ArrayList<>(); + @Builder public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, - LocalTime openingTime, LocalTime closingTime) { + LocalTime openingTime, LocalTime closingTime, List menuList) { this.name = name; this.rating = rating; this.category = category; @@ -66,6 +72,10 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.capacity = capacity; this.openingTime = openingTime; this.closingTime = closingTime; + this.menuList = menuList; + for (Menu menu : menuList) { + menu.insertShop(this); + } } public void validateIfShopOpened(LocalTime localTime) { From a31053a6660615c512ab9f5eb5de6832d2aabab8 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 15:27:27 +0900 Subject: [PATCH 516/603] =?UTF-8?q?feat=20:=20=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/domain/Shop.java | 4 +- .../catchtable/shop/dto/ShopMapper.java | 38 ++++++++++++++++++- .../shop/dto/request/RegisterMenuRequest.java | 9 +++++ .../shop/dto/request/RegisterShopRequest.java | 7 ++-- .../shop/dto/response/MenuResponse.java | 13 +++++++ .../dto/response/ReservationTimeResponse.java | 15 ++++++++ .../shop/service/OwnerShopService.java | 17 ++++++++- 7 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterMenuRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/response/MenuResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index c4f9e30e..21b315ca 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -73,9 +73,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.openingTime = openingTime; this.closingTime = closingTime; this.menuList = menuList; - for (Menu menu : menuList) { - menu.insertShop(this); - } + menuList.forEach(menu -> menu.insertShop(this)); } public void validateIfShopOpened(LocalTime localTime) { diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 815125d1..650ca1c9 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -1,17 +1,29 @@ package com.prgrms.catchtable.shop.dto; +import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Menu; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; +import com.prgrms.catchtable.shop.dto.response.MenuResponse; import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; +import com.prgrms.catchtable.shop.dto.response.ReservationTimeResponse; import java.util.List; public class ShopMapper { public static Shop toEntity(RegisterShopRequest registerShopRequest) { + List menuList = registerShopRequest.menuRequestList() + .stream() + .map(menu -> Menu.builder() + .name(menu.name()) + .price(menu.price()) + .description(menu.description()) + .build()) + .toList(); return Shop.builder() .name(registerShopRequest.name()) @@ -24,11 +36,33 @@ public static Shop toEntity(RegisterShopRequest registerShopRequest) { .capacity(registerShopRequest.capacity()) .openingTime(registerShopRequest.openingTime()) .closingTime(registerShopRequest.closingTime()) + .menuList(menuList) .build(); } - public static RegisterShopResponse toRegisterShopResponse(Shop shop) { + public static RegisterShopResponse toRegisterShopResponse(Shop shop, + List reservationTimeList) { + + List timeResponses = reservationTimeList.stream() + .map(time -> ReservationTimeResponse.builder() + .id(time.getId()) + .reservationTime(time.getTime()) + .build()) + .toList(); + + List menuResponses = shop.getMenuList() + .stream() + .map(menu -> MenuResponse.builder() + .id(menu.getId()) + .name(menu.getName()) + .price(menu.getPrice()) + .description(menu.getDescription()) + .build() + ) + .toList(); + return RegisterShopResponse.builder() + .id(shop.getId()) .name(shop.getName()) .rating(shop.getRating()) .category(shop.getCategory().getType()) @@ -37,6 +71,8 @@ public static RegisterShopResponse toRegisterShopResponse(Shop shop) { .capacity(shop.getCapacity()) .openingTime(shop.getOpeningTime()) .closingTime(shop.getClosingTime()) + .reservationTimeResponseList(timeResponses) + .menuResponseList(menuResponses) .build(); } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterMenuRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterMenuRequest.java new file mode 100644 index 00000000..07d4f341 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterMenuRequest.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.shop.dto.request; + +public record RegisterMenuRequest( + String name, + int price, + String description +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java index 4de9dc32..59fd8371 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/request/RegisterShopRequest.java @@ -20,11 +20,12 @@ public record RegisterShopRequest( String city, String district, int capacity, - @JsonFormat(pattern = "kk:mm:ss") + @JsonFormat(pattern = "HH:mm") LocalTime openingTime, - @JsonFormat(pattern = "kk:mm:ss") + @JsonFormat(pattern = "HH:mm") LocalTime closingTime, - List resservationTimeList, + @JsonFormat(pattern = "yyyy-MM-dd HH:mm") + List reservationTimeRequestList, List menuRequestList ) { diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/MenuResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/MenuResponse.java new file mode 100644 index 00000000..7ab445fa --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/MenuResponse.java @@ -0,0 +1,13 @@ +package com.prgrms.catchtable.shop.dto.response; + +import lombok.Builder; + +@Builder +public record MenuResponse( + Long id, + String name, + int price, + String description +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java new file mode 100644 index 00000000..f9f6240d --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java @@ -0,0 +1,15 @@ +package com.prgrms.catchtable.shop.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record ReservationTimeResponse( + Long id, + @JsonFormat(pattern = "yyyy-MM-dd HH:mm") + + LocalDateTime reservationTime +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index a6eb1e5b..3aa0b785 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -1,11 +1,14 @@ package com.prgrms.catchtable.shop.service; import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +18,7 @@ public class OwnerShopService { private final ShopRepository shopRepository; + private final ReservationTimeRepository reservationTimeRepository; @Transactional public RegisterShopResponse registerShop(RegisterShopRequest registerShopRequest, Owner owner) { @@ -22,8 +26,19 @@ public RegisterShopResponse registerShop(RegisterShopRequest registerShopRequest Shop registerShop = shopRepository.save(ShopMapper.toEntity(registerShopRequest)); owner.insertShop(registerShop); - return ShopMapper.toRegisterShopResponse(registerShop); + List reservationTimeList = registerShopRequest.reservationTimeRequestList() + .stream() + .map(time -> ReservationTime.builder() + .time(time) + .build()) + .toList(); + for (ReservationTime reservationTime : reservationTimeList) { + reservationTime.insertShop(registerShop); + reservationTimeRepository.save(reservationTime); + } + + return ShopMapper.toRegisterShopResponse(registerShop, reservationTimeList); } } From a953ba0b32eb684e121af3545b8b4986df6aa0a1 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 16:33:19 +0900 Subject: [PATCH 517/603] =?UTF-8?q?feat=20:=20=EA=B0=80=EA=B2=8C=20update?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/service/OwnerShopService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java index 3aa0b785..fb328d65 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/OwnerShopService.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.shop.service; import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; @@ -18,14 +19,19 @@ public class OwnerShopService { private final ShopRepository shopRepository; + private final OwnerRepository ownerRepository; private final ReservationTimeRepository reservationTimeRepository; @Transactional public RegisterShopResponse registerShop(RegisterShopRequest registerShopRequest, Owner owner) { + //가게 저장 Shop registerShop = shopRepository.save(ShopMapper.toEntity(registerShopRequest)); + //점주와 가게 관계 매핑 owner.insertShop(registerShop); + ownerRepository.save(owner); + //예약 시간 엔티티 생성 List reservationTimeList = registerShopRequest.reservationTimeRequestList() .stream() .map(time -> ReservationTime.builder() @@ -33,6 +39,7 @@ public RegisterShopResponse registerShop(RegisterShopRequest registerShopRequest .build()) .toList(); + //예약 시간과 가게 관계 매핑 for (ReservationTime reservationTime : reservationTimeList) { reservationTime.insertShop(registerShop); reservationTimeRepository.save(reservationTime); From 26a4c6b3c70909781eb5ab47e71f00b495b485bb Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 16:41:27 +0900 Subject: [PATCH 518/603] =?UTF-8?q?feat=20:=20=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/MemberShopController.java | 6 +++--- .../prgrms/catchtable/shop/dto/ShopMapper.java | 16 +++++++++++++--- .../shop/dto/response/GetAllShopResponse.java | 12 ++++++++++-- .../shop/dto/response/GetAllShopResponses.java | 9 +++++++++ .../shop/service/MemberShopService.java | 11 +++++------ .../catchtable/shop/service/ShopServiceTest.java | 4 ++-- 6 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponses.java diff --git a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java index 1aa98e69..a26d8358 100644 --- a/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java +++ b/src/main/java/com/prgrms/catchtable/shop/controller/MemberShopController.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.shop.controller; import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; -import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponses; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.service.MemberShopService; import lombok.RequiredArgsConstructor; @@ -20,7 +20,7 @@ public class MemberShopController { private final MemberShopService memberShopService; @GetMapping - public ResponseEntity getAll() { + public ResponseEntity getAll() { return ResponseEntity.ok(memberShopService.getAll()); } @@ -30,7 +30,7 @@ public ResponseEntity getById(@PathVariable("shopId") Long id) } @GetMapping("/search") - public ResponseEntity getBySearch( + public ResponseEntity getBySearch( @ModelAttribute ShopSearchCondition condition) { return ResponseEntity.ok(memberShopService.getBySearch(condition)); } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 650ca1c9..beaa973d 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponses; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.dto.response.MenuResponse; import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; @@ -76,12 +77,21 @@ public static RegisterShopResponse toRegisterShopResponse(Shop shop, .build(); } - public static GetAllShopResponse toGetAllShopResponse(List shops) { - return new GetAllShopResponse(shops.stream() - .map(ShopMapper::toGetShopResponse) + public static GetAllShopResponses toGetAllShopResponses(List shops) { + return new GetAllShopResponses(shops.stream() + .map(ShopMapper::toGetAllShopResponse) .toList()); } + private static GetAllShopResponse toGetAllShopResponse(Shop shop) { + return GetAllShopResponse.builder() + .id(shop.getId()) + .name(shop.getName()) + .openingTime(shop.getOpeningTime()) + .closingTime(shop.getClosingTime()) + .build(); + } + public static GetShopResponse toGetShopResponse(Shop shop) { return GetShopResponse.builder() .id(shop.getId()) diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java index 4303c5ac..8e6944d0 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponse.java @@ -1,9 +1,17 @@ package com.prgrms.catchtable.shop.dto.response; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; +import java.time.LocalTime; +import lombok.Builder; +@Builder public record GetAllShopResponse( - List shopResponses + Long id, + String name, + @JsonFormat(pattern = "HH:mm") + LocalTime openingTime, + @JsonFormat(pattern = "HH:mm") + LocalTime closingTime ) { } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponses.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponses.java new file mode 100644 index 00000000..bd07b2c8 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetAllShopResponses.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.shop.dto.response; + +import java.util.List; + +public record GetAllShopResponses( + List shopResponses +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 8f90d48c..9c53df73 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -2,12 +2,11 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; -import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponses; import com.prgrms.catchtable.shop.dto.response.GetShopResponse; import com.prgrms.catchtable.shop.repository.ShopRepository; import java.util.List; @@ -22,9 +21,9 @@ public class MemberShopService { private final ShopRepository shopRepository; @Transactional(readOnly = true) - public GetAllShopResponse getAll() { + public GetAllShopResponses getAll() { List allShop = shopRepository.findAll(); - return ShopMapper.toGetAllShopResponse(allShop); + return ShopMapper.toGetAllShopResponses(allShop); } @Transactional(readOnly = true) @@ -35,8 +34,8 @@ public GetShopResponse getById(Long id) { } @Transactional(readOnly = true) - public GetAllShopResponse getBySearch(ShopSearchCondition condition) { + public GetAllShopResponses getBySearch(ShopSearchCondition condition) { List searchShop = shopRepository.findSearch(condition); - return ShopMapper.toGetAllShopResponse(searchShop); + return ShopMapper.toGetAllShopResponses(searchShop); } } diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index ecdf29cb..07a0dfbd 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -10,7 +10,7 @@ import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; -import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse; +import com.prgrms.catchtable.shop.dto.response.GetAllShopResponses; import com.prgrms.catchtable.shop.dto.response.RegisterShopResponse; import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -63,7 +63,7 @@ void getAllTest() { //when when(shopRepository.findAll()).thenReturn(allShop); - GetAllShopResponse all = memberShopService.getAll(); + GetAllShopResponses all = memberShopService.getAll(); //then assertThat(all.shopResponses().size()).isEqualTo(allShop.size()); From fde2c15e7dd6a97e840c2cb15cbd9e0fe631d5e8 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 16:52:37 +0900 Subject: [PATCH 519/603] =?UTF-8?q?feat=20:=20=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EB=8B=A8=EA=B1=B4=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationTimeRepository.java | 4 ++++ .../catchtable/shop/dto/ShopMapper.java | 21 ++++++++++++++++++- .../shop/dto/response/GetShopResponse.java | 6 ++++-- .../dto/response/ReservationTimeResponse.java | 1 - .../shop/repository/ShopRepository.java | 2 +- .../shop/service/MemberShopService.java | 10 ++++++++- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java index 5d8f1b80..b28b03e4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.reservation.repository; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -15,4 +16,7 @@ public interface ReservationTimeRepository extends JpaRepository findByIdAndShopId(@Param("reservationTimeId") Long reservationTimeId, @Param("shopId") Long shopId); + + @Query("select rt from ReservationTime rt where rt.shop.id = :shopId") + List findByShopId(@Param("shopId") Long shopId); } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index beaa973d..c1b711d7 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -92,7 +92,24 @@ private static GetAllShopResponse toGetAllShopResponse(Shop shop) { .build(); } - public static GetShopResponse toGetShopResponse(Shop shop) { + public static GetShopResponse toGetShopResponse(Shop shop, List reservationTimeList) { + + List menuResponses = shop.getMenuList().stream() + .map(menu -> MenuResponse.builder() + .id(menu.getId()) + .name(menu.getName()) + .price(menu.getPrice()) + .description(menu.getDescription()) + .build()) + .toList(); + + List timeResponses = reservationTimeList.stream() + .map(time -> ReservationTimeResponse.builder() + .id(time.getId()) + .reservationTime(time.getTime()) + .build()) + .toList(); + return GetShopResponse.builder() .id(shop.getId()) .name(shop.getName()) @@ -103,6 +120,8 @@ public static GetShopResponse toGetShopResponse(Shop shop) { .capacity(shop.getCapacity()) .openingTime(shop.getOpeningTime()) .closingTime(shop.getClosingTime()) + .reservationTimeResponseList(timeResponses) + .menuResponseList(menuResponses) .build(); } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java index f6c3688a..0d48715d 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/GetShopResponse.java @@ -2,6 +2,7 @@ import java.math.BigDecimal; import java.time.LocalTime; +import java.util.List; import lombok.Builder; @Builder @@ -15,8 +16,9 @@ public record GetShopResponse( String district, int capacity, LocalTime openingTime, - LocalTime closingTime - + LocalTime closingTime, + List reservationTimeResponseList, + List menuResponseList ) { } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java b/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java index f9f6240d..318f8c65 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/response/ReservationTimeResponse.java @@ -8,7 +8,6 @@ public record ReservationTimeResponse( Long id, @JsonFormat(pattern = "yyyy-MM-dd HH:mm") - LocalDateTime reservationTime ) { diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index f500ee5b..860f893f 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -7,6 +7,6 @@ public interface ShopRepository extends JpaRepository, ShopRepositoryCustom { - @EntityGraph(attributePaths = "reservationTimeList") + @EntityGraph(attributePaths = {"menuList"}) Optional findShopById(Long id); } diff --git a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java index 9c53df73..58e12163 100644 --- a/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java +++ b/src/main/java/com/prgrms/catchtable/shop/service/MemberShopService.java @@ -3,6 +3,8 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.ShopMapper; import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition; @@ -19,6 +21,7 @@ public class MemberShopService { private final ShopRepository shopRepository; + private final ReservationTimeRepository reservationTimeRepository; @Transactional(readOnly = true) public GetAllShopResponses getAll() { @@ -28,9 +31,14 @@ public GetAllShopResponses getAll() { @Transactional(readOnly = true) public GetShopResponse getById(Long id) { + //예약시간 조회 + List reservationTime = reservationTimeRepository.findByShopId(id); + + //가게와 메뉴 조회 Shop findShop = shopRepository.findShopById(id) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_SHOP)); - return ShopMapper.toGetShopResponse(findShop); + + return ShopMapper.toGetShopResponse(findShop, reservationTime); } @Transactional(readOnly = true) From f77bfdb0c8c64162ae12e9752081bb3c28d349a1 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 16:57:57 +0900 Subject: [PATCH 520/603] =?UTF-8?q?fix=20:=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 2ce8c72f..a8ecb5e7 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -35,7 +35,7 @@ public enum ErrorCode { ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), INVALID_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), - INVALID_INPUT_TYPE("성별 타입을 양식대로 입력해주세요"); + INVALID_INPUT_TYPE("입력 값을 양식대로 입력해주세요"); private final String message; } \ No newline at end of file From 2edc4837adcb9d9bab458554a5fff0b2d6a5e747 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 16:58:33 +0900 Subject: [PATCH 521/603] =?UTF-8?q?fix=20:=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EC=8B=9C,=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=8F=99=EC=9D=BC=EC=84=B1=EC=9D=B4=20=EC=95=84=EB=8B=8C=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/repository/ShopRepositoryImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java index 794b8c3a..380ab3c8 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepositoryImpl.java @@ -24,7 +24,7 @@ public List findSearch(ShopSearchCondition condition) { return queryFactory .selectFrom(shop) .where( - equalsName(condition.name()), + containsName(condition.name()), equalCategory(condition.category()), equalCity(condition.city()) ) @@ -35,12 +35,12 @@ public List findSearch(ShopSearchCondition condition) { .fetch(); } - private BooleanExpression equalsName(String name) { + private BooleanExpression containsName(String name) { if (name == null) { return null; } - return shop.name.eq(name); + return shop.name.contains(name); } private BooleanExpression equalCategory(String category) { From 73e322d5fdb6c972ccc2417223d02f348bf165c4 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 17:01:57 +0900 Subject: [PATCH 522/603] fix : conflict resolve --- .../controller/MemberReservationControllerTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 9e7916cb..602c429a 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -18,6 +18,9 @@ import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -47,6 +50,8 @@ class MemberReservationControllerTest extends BaseIntegrationTest { private ReservationRepository reservationRepository; @Autowired private MemberRepository memberRepository; + @Autowired + private OwnerRepository ownerRepository; private Member member = MemberFixture.member("dlswns661035@gmail.com"); @BeforeEach @@ -54,6 +59,10 @@ void setUp() { Shop shop = ShopData.getShop(); Shop savedShop = shopRepository.save(shop); + Owner owner = OwnerFixture.getOwner("injun", "injun2480"); + owner.insertShop(savedShop); + ownerRepository.save(owner); + Member savedMember = memberRepository.save(member); ReservationTime reservationTime = ReservationFixture.getReservationTimeNotPreOccupied(); From eb44b18578d5a2d30ea4211179f036a5464b3fc0 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 19:38:10 +0900 Subject: [PATCH 523/603] =?UTF-8?q?fix=20:=20Shop=20&=20Menu=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=20=EA=B4=80=EA=B3=84=20=EC=84=B8=ED=8C=85=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/shop/domain/Shop.java | 9 ++++++--- .../java/com/prgrms/catchtable/shop/dto/ShopMapper.java | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index 21b315ca..cf641445 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -64,7 +64,7 @@ public class Shop extends BaseEntity { @Builder public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, - LocalTime openingTime, LocalTime closingTime, List menuList) { + LocalTime openingTime, LocalTime closingTime) { this.name = name; this.rating = rating; this.category = category; @@ -72,8 +72,11 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.capacity = capacity; this.openingTime = openingTime; this.closingTime = closingTime; - this.menuList = menuList; - menuList.forEach(menu -> menu.insertShop(this)); + } + + public void updateMenuList(List menuList){ + this.menuList.addAll(menuList); + this.menuList.forEach(menu -> menu.insertShop(this)); } public void validateIfShopOpened(LocalTime localTime) { diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index c1b711d7..29662a10 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -26,7 +26,7 @@ public static Shop toEntity(RegisterShopRequest registerShopRequest) { .build()) .toList(); - return Shop.builder() + Shop registerShop = Shop.builder() .name(registerShopRequest.name()) .rating(registerShopRequest.rating()) .category(Category.of(registerShopRequest.category())) @@ -37,8 +37,9 @@ public static Shop toEntity(RegisterShopRequest registerShopRequest) { .capacity(registerShopRequest.capacity()) .openingTime(registerShopRequest.openingTime()) .closingTime(registerShopRequest.closingTime()) - .menuList(menuList) .build(); + registerShop.updateMenuList(menuList); + return registerShop; } public static RegisterShopResponse toRegisterShopResponse(Shop shop, From 7155a3fa0e7d1d034da4a5a5a18895c95f303d72 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 19:49:43 +0900 Subject: [PATCH 524/603] =?UTF-8?q?fix=20:=20=ED=95=84=EB=93=9C=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EA=B2=8C=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/fixture/ShopFixture.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java index e04399e4..6a1dd1e1 100644 --- a/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java +++ b/src/test/java/com/prgrms/catchtable/shop/fixture/ShopFixture.java @@ -3,9 +3,12 @@ import com.prgrms.catchtable.shop.domain.Address; import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.dto.request.RegisterMenuRequest; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; public class ShopFixture { @@ -34,6 +37,16 @@ public static Shop shopWith24() { } public static RegisterShopRequest getRequestDto(Shop shop) { + List reservationTimeList = List.of( + LocalDateTime.of(2024, 2, 2, 12, 0), + LocalDateTime.of(2024, 2, 2, 18, 0), + LocalDateTime.of(2024, 2, 2, 19, 0)); + + List menuRequestList = List.of( + new RegisterMenuRequest("돈까스", 11000, "경양식 돈까스"), + new RegisterMenuRequest("냉모밀&알밥세트", 13000, "세트 묶음") + ); + return RegisterShopRequest.builder() .name(shop.getName()) .rating(shop.getRating()) @@ -43,6 +56,8 @@ public static RegisterShopRequest getRequestDto(Shop shop) { .capacity(shop.getCapacity()) .openingTime(shop.getOpeningTime()) .closingTime(shop.getClosingTime()) + .reservationTimeRequestList(reservationTimeList) + .menuRequestList(menuRequestList) .build(); } } From 7af9bc5ee4cd340c0d37c44911bfb09d30942f5d Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 19:53:19 +0900 Subject: [PATCH 525/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=EC=97=B4?= =?UTF-8?q?=20repository=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/BasicWaitingLineRepository.java | 12 ++++++++++++ .../waitingline/RedisWaitingLineRepository.java | 9 +++++++++ .../waitingline/WaitingLineRepository.java | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index c4acade0..ec1eb9d9 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -72,6 +72,18 @@ public Long findRank(Long shopId, Long waitingId) { return -1L; } + public Long findRankThirdValue(Long shopId) { + Queue waitingLine = waitingLines.get(shopId); + int index = 0; + for (Long element : waitingLine) { + if (index == 2) { + return element; + } + index++; + } + return null; + } + public Long getWaitingLineSize(Long shopId) { //postpone에서 사용 Queue waitingLine = waitingLines.get(shopId); return (long) (waitingLine != null ? waitingLine.size() : 0); diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 59df16d6..4c2527f1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -123,6 +123,15 @@ public Long findRank(Long shopId, Long waitingId) { return getWaitingLineSize(shopId) - index; } + public Long findRankThirdValue(Long shopId) { + String waitingId = redisTemplate.opsForList().index("s" + shopId, -3); + if (waitingId == null) { + return null; + } + return Long.valueOf(waitingId); + } + + public Long getWaitingLineSize(Long shopId) { return redisTemplate.opsForList().size("s" + shopId); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index fe95d74e..890d35e6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -14,6 +14,8 @@ public interface WaitingLineRepository { Long findRank(Long shopId, Long waitingId); + Long findRankThirdValue(Long shopId); + Long getWaitingLineSize(Long shopId); List getShopWaitingIdsInOrder(Long shopId); From d212ae4556cdf32233eebc40268952264260a073 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 19:56:00 +0900 Subject: [PATCH 526/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=EC=97=B4?= =?UTF-8?q?=20repository=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RedisWaitingLineRepositoryTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 1c7761e0..2532916d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -145,4 +145,31 @@ void getWaitingLineSize() { //then assertThat(waitingLineSize).isZero(); } + + @DisplayName("웨이팅 3번째 waitingId 반환") + @Test + void findRankSecondValue() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + Long waitingId = repository.findRankThirdValue(shopId); + //then + assertThat(waitingId).isEqualTo(3L); + } + + @DisplayName("웨이팅 3번째 waitingId 없으면 null 반환") + @Test + void findRankThirdValueNull() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + //when + Long waitingId = repository.findRankThirdValue(shopId); + //then + assertThat(waitingId).isNull(); + } } \ No newline at end of file From fa46040a61954fb25ac150b29d368f24df5177ca Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 19:56:41 +0900 Subject: [PATCH 527/603] =?UTF-8?q?fix=20:=20ShopServiceTest=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/service/ShopServiceTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index 07a0dfbd..8f272c2a 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -6,8 +6,11 @@ import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.dto.request.RegisterShopRequest; import com.prgrms.catchtable.shop.dto.response.GetAllShopResponses; @@ -28,6 +31,10 @@ class ShopServiceTest { @Mock private ShopRepository shopRepository; + @Mock + private ReservationTimeRepository reservationTimeRepository; + @Mock + private OwnerRepository ownerRepository; @InjectMocks private MemberShopService memberShopService; @InjectMocks @@ -82,6 +89,6 @@ void getByIdTest() { //then assertThat(memberShopService.getById(1L).name()).isEqualTo(shop.getName()); assertThatThrownBy(() -> memberShopService.getById(2L)).isInstanceOf( - BadRequestCustomException.class); + NotFoundCustomException.class); } } \ No newline at end of file From 9a2218e27ca5ed5ed18bb3d40b8ec568674596e7 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Fri, 12 Jan 2024 20:15:09 +0900 Subject: [PATCH 528/603] =?UTF-8?q?fix=20:=20MemberShopControllerTest=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=82=AC=ED=95=AD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberShopControllerTest.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java index 0f89a4d6..de99255e 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -69,12 +69,8 @@ void getAllTest() throws Exception { .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) - .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) - .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) - .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) - .andExpect( - jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) - .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); + .andExpect(jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) + .andExpect(jsonPath("$.shopResponses.[0].closingTime").value(shop.getClosingTime().toString())); } @Test @@ -117,12 +113,7 @@ void getBySearchTest() throws Exception { .params(params)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) - .andExpect(jsonPath("$.shopResponses.[0].rating").value(shop.getRating())) - .andExpect(jsonPath("$.shopResponses.[0].category").value(shop.getCategory().getType())) - .andExpect(jsonPath("$.shopResponses.[0].city").value(shop.getAddress().getCity())) - .andExpect( - jsonPath("$.shopResponses.[0].district").value(shop.getAddress().getDistrict())) - .andExpect(jsonPath("$.shopResponses.[0].capacity").value(shop.getCapacity())); - + .andExpect(jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) + .andExpect(jsonPath("$.shopResponses.[0].closingTime").value(shop.getClosingTime().toString())); } } \ No newline at end of file From 23d08f1364347aa2d98aa708885d9119dcdbd43f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 12 Jan 2024 20:24:41 +0900 Subject: [PATCH 529/603] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=EC=97=90=20=ED=95=B4=EB=8B=B9=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EC=95=BD=20=EC=A0=84=EB=B6=80=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepository.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index cf51a4c9..2e3a63a5 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -2,6 +2,7 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -28,4 +29,15 @@ Optional findByIdWithReservationTimeAndShop( + "join fetch rt.shop s " + "where s.id = :shopId") List findAllWithReservationTimeAndShopByShopId(@Param("shopId") Long shopId); + + @Query("select r from Reservation r " + + "join fetch r.member m " + + "join fetch r.reservationTime rt " + + "where rt.time >= :startOfDay " + + "and rt.time < :endOfDay " // endOfDay는 다음날 00시00분이므로 그 시간보다 미만 조건 + + "and r.status = 'COMPLETED'") + List findAllTodayReservation( + @Param("startOfDay") LocalDateTime startOfDay, + @Param("endOfDay") LocalDateTime endOfDay + ); } From ce8f6f21344432aba07ae792eea43ddf364da76d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 12 Jan 2024 20:24:56 +0900 Subject: [PATCH 530/603] =?UTF-8?q?feat=20:=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=EC=97=90=20=ED=95=B4=EB=8B=B9=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EC=95=BD=20=EC=A0=84=EB=B6=80=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepositoryTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 317502c3..3538f567 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -14,7 +14,9 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.time.LocalDateTime; import java.util.List; +import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -119,4 +121,42 @@ void getAllReservationByShopId() { ); } + @Test + @DisplayName("오늘 날짜인 예약들만 가져올 수 있다.") + void findAllTodayReservation(){ + Member member = MemberFixture.member("dls@gmail.com"); + Member savedMember = memberRepository.save(member); + Shop shop = ShopFixture.shop(); + Shop savedShop = shopRepository.save(shop); + + LocalDateTime startOfDay = LocalDateTime.of(2024,1,2,0,0); + LocalDateTime endOfDay = LocalDateTime.of(2024,1,3,0,0); + + ReservationTime time1 = ReservationTime.builder() + .time(LocalDateTime.of(2024,1,2,19,30)) + .build(); + ReservationTime time2 = ReservationTime.builder() + .time(LocalDateTime.of(2024,1,3,15,30)) + .build(); + + time1.insertShop(savedShop); //예약시간 - 매장 매핑 + time2.insertShop(savedShop); + reservationTimeRepository.saveAll(List.of(time1, time2)); + + Reservation reservation1 = ReservationFixture.getReservation(time1, savedMember); // 예약시간 - 예약 - 회원 매핑 + Reservation reservation2 = ReservationFixture.getReservation(time2, savedMember); + + Reservation savedReservation1 = reservationRepository.save(reservation1); + Reservation savedReservation2 = reservationRepository.save(reservation2); + + List reservations = reservationRepository.findAllTodayReservation( + startOfDay, + endOfDay + ); //1월 2일의 예약만 조회 -> reservation1만 조회될 것 + + assertThat(reservations).contains(savedReservation1); // 시간 범위 안에 있으므로 가져와야됨 + assertThat(reservations).doesNotContain(savedReservation2); // 범위 밖이니 가져오면 안됨 + + } + } \ No newline at end of file From d19ae9f3b9c2eb1dc4287085ef8277a8d5f46f1c Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 12 Jan 2024 20:25:14 +0900 Subject: [PATCH 531/603] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=9F=AC=20=ED=99=9C=EC=84=B1=ED=99=94=20configuration=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/scheduler/SchedulerConfig.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/scheduler/SchedulerConfig.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/scheduler/SchedulerConfig.java b/src/main/java/com/prgrms/catchtable/reservation/scheduler/SchedulerConfig.java new file mode 100644 index 00000000..b2a002bf --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/scheduler/SchedulerConfig.java @@ -0,0 +1,10 @@ +package com.prgrms.catchtable.reservation.scheduler; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; + +@Configuration +@EnableScheduling +public class SchedulerConfig { + +} From 888d9fe6e70cd7f374db3afeddb8cb001a5fa902 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 12 Jan 2024 20:25:31 +0900 Subject: [PATCH 532/603] =?UTF-8?q?feat=20:=20=EC=8B=9C=EA=B0=84=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EC=B6=B0=20=EC=95=8C=EB=A6=BC=20=EB=B3=B4=EB=82=B4?= =?UTF-8?q?=EB=8A=94=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=9F=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationNotificationScheduler.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java b/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java new file mode 100644 index 00000000..a1ead2b4 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java @@ -0,0 +1,70 @@ +package com.prgrms.catchtable.reservation.scheduler; + +import static com.prgrms.catchtable.common.notification.NotificationContent.RESERVATION_ONE_HOUR_LEFT; +import static com.prgrms.catchtable.common.notification.NotificationContent.RESERVATION_TIME_OUT; +import static java.time.temporal.ChronoUnit.MINUTES; + +import com.prgrms.catchtable.common.notification.NotificationContent; +import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class ReservationNotificationScheduler { + private final ReservationRepository reservationRepository; + private final ApplicationEventPublisher publisher; + + private List reservations = new ArrayList<>(); + + @Scheduled(cron = "0 0 0 * * *") // 매일 자정에 당일의 예약 다 가져옴 + public void getAllTodayReservation(){ + + LocalDate today = LocalDate.now(); + + LocalDateTime startOfDay = today.atStartOfDay(); // 하루의 시작 (오늘의 00시 00분) + LocalDateTime endOfDay = today.plusDays(1).atStartOfDay(); // 하루의 끝 (내일의 00시 00분) + + reservations = reservationRepository.findAllTodayReservation(startOfDay, endOfDay); + reservations.forEach(reservation -> reservation.getReservationTime().getTime().truncatedTo(MINUTES)); //예약시간의 '초' 다 버림 + } + + @Scheduled(cron = "0 * * * * *") // 1분마다 예약 시간 체크 (1시간 전인 지, 입장시간 됐는 지) + public void sendReservationMessage(){ + + LocalDateTime now = LocalDateTime.now(); + LocalDateTime nowTime = now.truncatedTo(MINUTES); // '분'까지만 가져옴 (초 버림) + + for (Reservation r : reservations) { // 당일의 예약 리스트를 돌며 시간 만족하는 예약은 알림 발송 + + LocalDateTime reservationTime = r.getReservationTime().getTime(); + + if (nowTime.isEqual(reservationTime)) { // 예약시간이 한시간 이하로 남았다면 + sendMessage(r, reservationTime, RESERVATION_ONE_HOUR_LEFT); // 한시간 남았다고 알림 발송 + continue; + } + + if(nowTime.isEqual(reservationTime)){ // 현재시간이 예약시간이 됐다면 + sendMessage(r, reservationTime, RESERVATION_TIME_OUT); + reservations.remove(r); //예약 입장 알림 보낸 예약은 순회 리스트에서 삭제 + } + } + } + + private void sendMessage(Reservation r, LocalDateTime reservationTime, NotificationContent content) { + SendMessageToMemberRequest request = new SendMessageToMemberRequest( + r.getMember(), + content.getMessage(reservationTime.toString()) + ); + publisher.publishEvent(request); + } +} From 06e0f3a720d89df4fc871fe56fd3b2792796065b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Fri, 12 Jan 2024 20:27:37 +0900 Subject: [PATCH 533/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationNotificationScheduler.java | 20 ++++++++++--------- .../repository/ReservationRepositoryTest.java | 14 ++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java b/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java index a1ead2b4..41465d4e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java +++ b/src/main/java/com/prgrms/catchtable/reservation/scheduler/ReservationNotificationScheduler.java @@ -10,7 +10,6 @@ import com.prgrms.catchtable.reservation.repository.ReservationRepository; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; @@ -21,13 +20,14 @@ @Component @RequiredArgsConstructor public class ReservationNotificationScheduler { + private final ReservationRepository reservationRepository; private final ApplicationEventPublisher publisher; private List reservations = new ArrayList<>(); @Scheduled(cron = "0 0 0 * * *") // 매일 자정에 당일의 예약 다 가져옴 - public void getAllTodayReservation(){ + public void getAllTodayReservation() { LocalDate today = LocalDate.now(); @@ -35,11 +35,12 @@ public void getAllTodayReservation(){ LocalDateTime endOfDay = today.plusDays(1).atStartOfDay(); // 하루의 끝 (내일의 00시 00분) reservations = reservationRepository.findAllTodayReservation(startOfDay, endOfDay); - reservations.forEach(reservation -> reservation.getReservationTime().getTime().truncatedTo(MINUTES)); //예약시간의 '초' 다 버림 + reservations.forEach(reservation -> reservation.getReservationTime().getTime() + .truncatedTo(MINUTES)); //예약시간의 '초' 다 버림 } - @Scheduled(cron = "0 * * * * *") // 1분마다 예약 시간 체크 (1시간 전인 지, 입장시간 됐는 지) - public void sendReservationMessage(){ + @Scheduled(cron = "0 * * * * *") // 1분마다 예약 시간 체크 후 알림 발송 (1시간 전인 지, 입장시간 됐는 지) + public void sendReservationMessage() { LocalDateTime now = LocalDateTime.now(); LocalDateTime nowTime = now.truncatedTo(MINUTES); // '분'까지만 가져옴 (초 버림) @@ -48,19 +49,20 @@ public void sendReservationMessage(){ LocalDateTime reservationTime = r.getReservationTime().getTime(); - if (nowTime.isEqual(reservationTime)) { // 예약시간이 한시간 이하로 남았다면 + if (nowTime.isEqual(reservationTime.minusHours(1))) { // 예약시간이 한시간 남았다면 sendMessage(r, reservationTime, RESERVATION_ONE_HOUR_LEFT); // 한시간 남았다고 알림 발송 continue; } - if(nowTime.isEqual(reservationTime)){ // 현재시간이 예약시간이 됐다면 - sendMessage(r, reservationTime, RESERVATION_TIME_OUT); + if (nowTime.isEqual(reservationTime)) { // 현재시간이 예약시간이 됐다면 + sendMessage(r, reservationTime, RESERVATION_TIME_OUT); // 예약 시간 됐다고 알림 발송 reservations.remove(r); //예약 입장 알림 보낸 예약은 순회 리스트에서 삭제 } } } - private void sendMessage(Reservation r, LocalDateTime reservationTime, NotificationContent content) { + private void sendMessage(Reservation r, LocalDateTime reservationTime, + NotificationContent content) { SendMessageToMemberRequest request = new SendMessageToMemberRequest( r.getMember(), content.getMessage(reservationTime.toString()) diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 3538f567..42bcbb34 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -16,7 +16,6 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import java.time.LocalDateTime; import java.util.List; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -123,27 +122,28 @@ void getAllReservationByShopId() { @Test @DisplayName("오늘 날짜인 예약들만 가져올 수 있다.") - void findAllTodayReservation(){ + void findAllTodayReservation() { Member member = MemberFixture.member("dls@gmail.com"); Member savedMember = memberRepository.save(member); Shop shop = ShopFixture.shop(); Shop savedShop = shopRepository.save(shop); - LocalDateTime startOfDay = LocalDateTime.of(2024,1,2,0,0); - LocalDateTime endOfDay = LocalDateTime.of(2024,1,3,0,0); + LocalDateTime startOfDay = LocalDateTime.of(2024, 1, 2, 0, 0); + LocalDateTime endOfDay = LocalDateTime.of(2024, 1, 3, 0, 0); ReservationTime time1 = ReservationTime.builder() - .time(LocalDateTime.of(2024,1,2,19,30)) + .time(LocalDateTime.of(2024, 1, 2, 19, 30)) .build(); ReservationTime time2 = ReservationTime.builder() - .time(LocalDateTime.of(2024,1,3,15,30)) + .time(LocalDateTime.of(2024, 1, 3, 15, 30)) .build(); time1.insertShop(savedShop); //예약시간 - 매장 매핑 time2.insertShop(savedShop); reservationTimeRepository.saveAll(List.of(time1, time2)); - Reservation reservation1 = ReservationFixture.getReservation(time1, savedMember); // 예약시간 - 예약 - 회원 매핑 + Reservation reservation1 = ReservationFixture.getReservation(time1, + savedMember); // 예약시간 - 예약 - 회원 매핑 Reservation reservation2 = ReservationFixture.getReservation(time2, savedMember); Reservation savedReservation1 = reservationRepository.save(reservation1); From 906616303122743e3e8b8a557995c1fbc5aa47e7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 20:28:06 +0900 Subject: [PATCH 534/603] =?UTF-8?q?style=20:=20=EB=8C=80=EA=B8=B0=EC=97=B4?= =?UTF-8?q?=20=ED=95=A8=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/BasicWaitingLineRepository.java | 2 +- .../waitingline/RedisWaitingLineRepository.java | 2 +- .../repository/waitingline/WaitingLineRepository.java | 2 +- .../waitingline/RedisWaitingLineRepositoryTest.java | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index ec1eb9d9..ea69e7a7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -72,7 +72,7 @@ public Long findRank(Long shopId, Long waitingId) { return -1L; } - public Long findRankThirdValue(Long shopId) { + public Long findThirdRankValue(Long shopId) { Queue waitingLine = waitingLines.get(shopId); int index = 0; for (Long element : waitingLine) { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 4c2527f1..f7070f92 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -123,7 +123,7 @@ public Long findRank(Long shopId, Long waitingId) { return getWaitingLineSize(shopId) - index; } - public Long findRankThirdValue(Long shopId) { + public Long findThirdRankValue(Long shopId) { String waitingId = redisTemplate.opsForList().index("s" + shopId, -3); if (waitingId == null) { return null; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 890d35e6..6b9632b5 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -14,7 +14,7 @@ public interface WaitingLineRepository { Long findRank(Long shopId, Long waitingId); - Long findRankThirdValue(Long shopId); + Long findThirdRankValue(Long shopId); Long getWaitingLineSize(Long shopId); diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 2532916d..422fd17a 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -148,27 +148,27 @@ void getWaitingLineSize() { @DisplayName("웨이팅 3번째 waitingId 반환") @Test - void findRankSecondValue() { + void findThirdRankValue() { //given Long shopId = 1L; repository.save(shopId, 1L); repository.save(shopId, 2L); repository.save(shopId, 3L); //when - Long waitingId = repository.findRankThirdValue(shopId); + Long waitingId = repository.findThirdRankValue(shopId); //then assertThat(waitingId).isEqualTo(3L); } @DisplayName("웨이팅 3번째 waitingId 없으면 null 반환") @Test - void findRankThirdValueNull() { + void findThirdRankValueNull() { //given Long shopId = 1L; repository.save(shopId, 1L); repository.save(shopId, 2L); //when - Long waitingId = repository.findRankThirdValue(shopId); + Long waitingId = repository.findThirdRankValue(shopId); //then assertThat(waitingId).isNull(); } From 7ae5ae5c987278dc66812625a78f7ff7b82d4896 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 21:33:59 +0900 Subject: [PATCH 535/603] =?UTF-8?q?feat=20:=20waitingRepository=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/repository/WaitingRepository.java | 6 +++++- .../waiting/repository/WaitingRepositoryTest.java | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index e1d72c76..ee359f9a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -27,10 +27,14 @@ Optional findByMemberAndStatusWithShop(@Param("member") Member member, @Query("select w from Waiting w where w.id in :ids") List findByIds(@Param("ids") List ids); + @Query("select w from Waiting w " + + "join fetch w.member where w.id = :waitingId") + Waiting findWaitingWithMember(@Param("waitingId") Long waitingId); + @Query("select w from Waiting w " + "join fetch w.shop " + "join fetch w.member where w.member = :member") - List findWaitingWithMember(@Param("member") Member member); + List findWaitingWithMemberAndShop(@Param("member") Member member); @Transactional @Modifying(clearAutomatically = true) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index be6e0c1d..fa32f3c1 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -106,7 +106,7 @@ void findByMemberAndStatusWithShop() { @DisplayName("특정 멤버의 웨이팅 목록을 조회할 수 있다.") @Test - void findWaitingWithMember() { + void findWaitingWithShopAndMember() { //given Waiting canceledWaiting = WaitingFixture.canceledWaiting(member1, shop, 1); Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 2); @@ -114,7 +114,7 @@ void findWaitingWithMember() { waitingRepository.saveAll(List.of(canceledWaiting, completedWaiting, progressWaiting)); //when - List memberAllWaitings = waitingRepository.findWaitingWithMember(member1); + List memberAllWaitings = waitingRepository.findWaitingWithMemberAndShop(member1); //then assertThat(memberAllWaitings).containsExactly(canceledWaiting, completedWaiting, progressWaiting); From 3b17cabd7a863510e1bc87cff81173f2c5edf7f6 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 21:34:11 +0900 Subject: [PATCH 536/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 46 +++++++++++++++++-- .../waiting/service/OwnerWaitingService.java | 6 ++- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index c7286637..10f7d1fb 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -11,9 +11,11 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; @@ -24,6 +26,7 @@ import java.time.LocalTime; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,6 +41,7 @@ public class MemberWaitingService { private final WaitingRepository waitingRepository; private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; + private final ApplicationEventPublisher publisher; public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { @@ -57,6 +61,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, waitingLineRepository.save(shopId, waiting.getId()); Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); + sendMessageToMember(member, PROGRESS, rank); return toMemberWaitingResponse(savedWaiting, rank); } @@ -64,24 +69,31 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, @Transactional public MemberWaitingResponse postponeWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); - Shop shop = waiting.getShop(); + Long previousRank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); waiting.decreasePostponeRemainingCount(); waitingLineRepository.postpone(shop.getId(), waiting.getId()); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - + if (previousRank < 3) { + sendMessageToThirdRankMember(shop.getId()); + } return toMemberWaitingResponse(waiting, rank); } @Transactional public MemberWaitingResponse cancelWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); - Shop shop = waiting.getShop(); + Long previousRank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + waitingLineRepository.cancel(shop.getId(), waiting.getId()); waiting.changeStatusCanceled(); + sendMessageToMember(member, PROGRESS, -1L); + if (previousRank < 3) { + sendMessageToThirdRankMember(shop.getId()); + } return toMemberWaitingResponse(waiting, -1L); } @@ -97,10 +109,36 @@ public MemberWaitingResponse getWaiting(Member member) { @Transactional(readOnly = true) public MemberWaitingHistoryListResponse getMemberWaitingHistory(Member member) { - List waitings = waitingRepository.findWaitingWithMember(member); + List waitings = waitingRepository.findWaitingWithMemberAndShop(member); return toMemberWaitingListResponse(waitings); } + public void sendMessageToThirdRankMember(Long shopId) { + Long thirdRankWaitingId = waitingLineRepository.findThirdRankValue(shopId); + if (thirdRankWaitingId != null) { + Member thirdRankMember = waitingRepository.findWaitingWithMember(thirdRankWaitingId) + .getMember(); + SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() + .member(thirdRankMember) + .content("3번째 순서로 곧 입장하실 차례입니다.") + .build(); + publisher.publishEvent(request); + } + } + + public void sendMessageToMember(Member member, WaitingStatus status, Long rank) { + String content; + if (status == PROGRESS) { + content = String.format("웨이팅이 등록되었습니다. %d번째 순서입니다.", rank); + } else { + content = "웨이팅이 취소되었습니다."; + } + SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() + .member(member) + .content(content) + .build(); + publisher.publishEvent(request); + } private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMember(member)) { diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 8e9734e7..ef0354df 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; @@ -22,6 +23,7 @@ public class OwnerWaitingService { private final WaitingRepository waitingRepository; private final WaitingLineRepository waitingLineRepository; + private final MemberWaitingService memberWaitingService; @Transactional(readOnly = true) public OwnerWaitingListResponse getShopAllWaiting(Owner owner) { @@ -33,10 +35,12 @@ public OwnerWaitingListResponse getShopAllWaiting(Owner owner) { @Transactional public OwnerWaitingResponse entryWaiting(Owner owner) { - Long enteredWaitingId = waitingLineRepository.entry(owner.getShop().getId()); + Long shopId = owner.getShop().getId(); + Long enteredWaitingId = waitingLineRepository.entry(shopId); Waiting waiting = waitingRepository.findById(enteredWaitingId) .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); waiting.changeStatusCompleted(); + memberWaitingService.sendMessageToThirdRankMember(shopId); return toOwnerWaitingResponse(waiting, 0L); } } From b3b4f559b6f5b29344398b7d154ecf35d053b14a Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 21:34:46 +0900 Subject: [PATCH 537/603] =?UTF-8?q?feat=20:=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingServiceTest.java | 7 ++++++- .../waiting/service/OwnerWaitingServiceTest.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 79d44bfb..719056e8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -28,6 +28,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.context.ApplicationEventPublisher; @ExtendWith(MockitoExtension.class) class MemberWaitingServiceTest { @@ -37,6 +38,9 @@ class MemberWaitingServiceTest { @Mock private ShopRepository shopRepository; + @Mock + private ApplicationEventPublisher publisher; + @Mock private WaitingLineRepository waitingLineRepository; @InjectMocks @@ -113,6 +117,7 @@ void cancelWaiting() { Optional.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(CANCELED); + given(waitingRepository.findWaitingWithMember(anyLong())).willReturn(waiting); doNothing().when(waiting).changeStatusCanceled(); //when @@ -157,7 +162,7 @@ void getMemberAllWaiting() { Shop shop = mock(Shop.class); Waiting waiting = mock(Waiting.class); - given(waitingRepository.findWaitingWithMember(member)).willReturn( + given(waitingRepository.findWaitingWithMemberAndShop(member)).willReturn( List.of(waiting)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(CANCELED); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 0bcb523e..d06b277c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -31,6 +31,9 @@ class OwnerWaitingServiceTest { @Mock private OwnerRepository ownerRepository; + @Mock + private MemberWaitingService memberWaitingService; + @Mock private WaitingRepository waitingRepository; From fbd6be91306a14f16dddfaaa39b61950101b996b Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 21:35:44 +0900 Subject: [PATCH 538/603] =?UTF-8?q?refactor=20:=20=EB=8C=80=EA=B8=B0?= =?UTF-8?q?=EC=97=B4=20=EC=B6=9C=EB=A0=A5=20=ED=95=A8=EC=88=98=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/RedisWaitingLineRepository.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index f7070f92..5b648d63 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -131,7 +131,6 @@ public Long findThirdRankValue(Long shopId) { return Long.valueOf(waitingId); } - public Long getWaitingLineSize(Long shopId) { return redisTemplate.opsForList().size("s" + shopId); } @@ -153,10 +152,6 @@ private void validateIfPostponeAvailable(Long shopId, Long waitingId) { public void printWaitingLine(Long shopId) { List waitingLine = redisTemplate.opsForList().range("s" + shopId, 0, -1); - if (waitingLine != null) { - log.info("Queue: {}", waitingLine); - } else { - log.warn("Queue is empty or not found for Shop ID: {}", shopId); - } + log.info("Queue: {}", waitingLine); } } From 698070201deb493f704cf2b06e64e99d5690da4e Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 21:36:28 +0900 Subject: [PATCH 539/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/service/OwnerWaitingService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index ef0354df..4807ae6c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -7,7 +7,6 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; From 478fb47dc71572424d83449e74773eb909693efe Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 12 Jan 2024 22:04:47 +0900 Subject: [PATCH 540/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/WaitingNotificationContent.java | 15 +++++++++++++++ .../waiting/service/MemberWaitingService.java | 13 ++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java diff --git a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java new file mode 100644 index 00000000..31d275cc --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java @@ -0,0 +1,15 @@ +package com.prgrms.catchtable.common.notification; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum WaitingNotificationContent { + REGISTERED("웨이팅이 등록되었습니다."), + CANCELED("웨이팅이 취소되었습니다."), + + THIRD_RANK("3번째 순서로 곧 입장하실 차례입니다."); + + private final String message; +} \ No newline at end of file diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 10f7d1fb..66b6074f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -3,6 +3,9 @@ import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.CANCELED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.REGISTERED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.THIRD_RANK; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; @@ -120,22 +123,22 @@ public void sendMessageToThirdRankMember(Long shopId) { .getMember(); SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() .member(thirdRankMember) - .content("3번째 순서로 곧 입장하실 차례입니다.") + .content(THIRD_RANK.getMessage()) .build(); publisher.publishEvent(request); } } public void sendMessageToMember(Member member, WaitingStatus status, Long rank) { - String content; + StringBuilder content = new StringBuilder(); if (status == PROGRESS) { - content = String.format("웨이팅이 등록되었습니다. %d번째 순서입니다.", rank); + content.append(String.format(REGISTERED.getMessage(), rank)); } else { - content = "웨이팅이 취소되었습니다."; + content.append(CANCELED.getMessage()); } SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() .member(member) - .content(content) + .content(content.toString()) .build(); publisher.publishEvent(request); } From 45e750139eeb9b46e7467f3a83f8333c8b01e57d Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:17:18 +0900 Subject: [PATCH 541/603] =?UTF-8?q?feat=20:=20redis=20repository=20postpon?= =?UTF-8?q?e=20=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RedisWaitingLineRepository.java | 39 ++++--------------- .../RedisWaitingLineRepositoryTest.java | 8 ++-- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 5b648d63..1fda48b5 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -56,45 +56,19 @@ public List getShopWaitingIdsInOrder(Long shopId) { public Long entry(Long shopId) { Long waitingId = getShopWaitingIdsInOrder(shopId).get(0); - redisTemplate.execute(new SessionCallback<>() { - @Override - public Object execute(RedisOperations operations) - throws DataAccessException { - try { - operations.multi(); - redisTemplate.opsForList().rightPop("s" + shopId); - return operations.exec(); - } catch (Exception e) { - operations.discard(); - } - return operations.exec(); - } - }); + redisTemplate.opsForList().rightPop("s" + shopId); return waitingId; } public void cancel(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); - redisTemplate.execute(new SessionCallback<>() { - @Override - public Object execute(RedisOperations operations) - throws DataAccessException { - try { - operations.multi(); - redisTemplate.opsForList().remove("s" + shopId, 1, waitingId.toString()); - return operations.exec(); - } catch (Exception e) { - operations.discard(); - } - return operations.exec(); - } - }); + redisTemplate.opsForList().remove("s" + shopId, 1, waitingId.toString()); } public void postpone(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); validateIfPostponeAvailable(shopId, waitingId); - + String key = "s"+shopId; if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { throw new BadRequestCustomException(ALREADY_END_LINE); } @@ -104,13 +78,14 @@ public Object execute(RedisOperations operations) throws DataAccessException { try { operations.multi(); - redisTemplate.opsForList().rightPop("s" + shopId); - redisTemplate.opsForList().leftPush("s" + shopId, waitingId.toString()); + + redisTemplate.opsForList().remove(key, 1, waitingId.toString()); + redisTemplate.opsForList().leftPush(key, waitingId.toString()); return operations.exec(); } catch (Exception e) { operations.discard(); } - return operations.exec(); + return null; } }); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 422fd17a..d55c37a9 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -74,13 +74,13 @@ void postpone() { repository.save(shopId, 3L); //when - repository.postpone(1L, 1L); + repository.postpone(1L, 2L); //then assertThat(repository.findRank(1L, 1L)) - .isEqualTo(3); - assertThat(repository.findRank(1L, 2L)) .isEqualTo(1); + assertThat(repository.findRank(1L, 2L)) + .isEqualTo(3); assertThat(repository.findRank(1L, 3L)) .isEqualTo(2); @@ -172,4 +172,6 @@ void findThirdRankValueNull() { //then assertThat(waitingId).isNull(); } + + } \ No newline at end of file From cb2758cd40f8f498070d882a1ab8dc7c9fe14d73 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:20:14 +0900 Subject: [PATCH 542/603] =?UTF-8?q?feat=20:=20=EC=9E=85=EC=9E=A5=20?= =?UTF-8?q?=EB=AF=B8=EB=A6=AC=20=EC=95=8C=EB=A6=BC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 66b6074f..4c796650 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -6,6 +6,7 @@ import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.CANCELED; import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.REGISTERED; import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.THIRD_RANK; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; @@ -14,6 +15,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -45,7 +47,7 @@ public class MemberWaitingService { private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; private final ApplicationEventPublisher publisher; - + @Transactional public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { // 연관 엔티티 조회 @@ -78,7 +80,7 @@ public MemberWaitingResponse postponeWaiting(Member member) { waiting.decreasePostponeRemainingCount(); waitingLineRepository.postpone(shop.getId(), waiting.getId()); Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - if (previousRank < 3) { + if (previousRank <= 3) { sendMessageToThirdRankMember(shop.getId()); } return toMemberWaitingResponse(waiting, rank); @@ -93,8 +95,8 @@ public MemberWaitingResponse cancelWaiting(Member member) { waitingLineRepository.cancel(shop.getId(), waiting.getId()); waiting.changeStatusCanceled(); - sendMessageToMember(member, PROGRESS, -1L); - if (previousRank < 3) { + sendMessageToMember(member, WaitingStatus.CANCELED, -1L); + if (previousRank <= 3) { sendMessageToThirdRankMember(shop.getId()); } return toMemberWaitingResponse(waiting, -1L); From 2f075445c9e80e34765c569aa5bea723b50205a4 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:41:35 +0900 Subject: [PATCH 543/603] =?UTF-8?q?feat=20:=20waiting=20request=20fixture?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/fixture/WaitingFixture.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index effae299..f4a45e5a 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -4,6 +4,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; public class WaitingFixture { @@ -29,6 +30,12 @@ public static Waiting canceledWaiting(Member member, Shop shop, int waitingNumbe return waiting; } + public static CreateWaitingRequest createWaitingRequest(){ + return CreateWaitingRequest + .builder() + .peopleCount(2).build(); + } + public static MemberWaitingResponse memberWaitingResponse(int remainingPostponeCount, WaitingStatus status) { return MemberWaitingResponse.builder() From 53b6ceaf2d429a8a22dd371b5ffaf050da2c60d7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:42:44 +0900 Subject: [PATCH 544/603] =?UTF-8?q?style=20:=20enum=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/common/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 2ce8c72f..1b6621a8 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -21,7 +21,7 @@ public enum ErrorCode { SLACK_ID_IS_WRONG("요청한 슬랙 Id를 찾을 수 없거나 잘못 되었습니다"), CAN_NOT_COMPLETE_WAITING("입장 처리가 불가한 대기 상태입니다."), - EXISTING_MEMBER_WAITING("이미 회원이 웨이팅 중인 가게가 존재합니다."), + ALREADY_PROGRESS_WAITING_EXISTS("이미 회원이 웨이팅 중인 가게가 존재합니다."), ALREADY_END_LINE("이미 맨뒤라 웨이팅을 미룰 수 없습니다."), NOT_EXIST_PROGRESS_WAITING("진행 중인 웨이팅이 존재하지 않습니다."), From 213b196eb333e2b38bab3d82958a986371d17100 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:43:54 +0900 Subject: [PATCH 545/603] =?UTF-8?q?feat=20:=20repository=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/repository/WaitingRepository.java | 2 +- .../catchtable/waiting/service/MemberWaitingService.java | 8 +++----- .../waiting/service/MemberWaitingServiceTest.java | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index ee359f9a..e7c3a6d6 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -15,7 +15,7 @@ public interface WaitingRepository extends JpaRepository { - boolean existsByMember(Member member); + boolean existsByMemberAndStatus(Member member, WaitingStatus status); Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 4c796650..f4fb13e9 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -1,12 +1,11 @@ package com.prgrms.catchtable.waiting.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.EXISTING_MEMBER_WAITING; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PROGRESS_WAITING_EXISTS; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.CANCELED; import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.REGISTERED; import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.THIRD_RANK; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; @@ -15,7 +14,6 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -146,8 +144,8 @@ public void sendMessageToMember(Member member, WaitingStatus status, Long rank) } private void validateIfMemberWaitingExists(Member member) { - if (waitingRepository.existsByMember(member)) { - throw new BadRequestCustomException(EXISTING_MEMBER_WAITING); + if (waitingRepository.existsByMemberAndStatus(member, PROGRESS)) { + throw new BadRequestCustomException(ALREADY_PROGRESS_WAITING_EXISTS); } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 719056e8..6099417c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -66,7 +66,7 @@ void createWaiting() { given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); given(shop.getId()).willReturn(1L); - given(waitingRepository.existsByMember(member)).willReturn(false); + given(waitingRepository.existsByMemberAndStatus(member,PROGRESS)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); From eea20bfb1e289945eee38f70bbfde68d29885727 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:44:31 +0900 Subject: [PATCH 546/603] =?UTF-8?q?feat=20:=20controller=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=ED=94=BD=EC=8A=A4=EC=B2=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingControllerTest.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index ad85ee1e..c06772c3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.waiting.controller; import static com.prgrms.catchtable.common.Role.MEMBER; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PROGRESS_WAITING_EXISTS; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; @@ -108,11 +110,10 @@ void clear() { @Test void createWaiting() throws Exception { //given + CreateWaitingRequest request = WaitingFixture.createWaitingRequest(); Member member4 = MemberFixture.member("test4@naver.com"); memberRepository.save(member4); - CreateWaitingRequest request = CreateWaitingRequest - .builder() - .peopleCount(2).build(); + // when, then mockMvc.perform(post("/waitings/{shopId}", shop.getId()) @@ -130,6 +131,48 @@ void createWaiting() throws Exception { } + @DisplayName("회원이 이미 취소된 웨이팅이 있어도, 해당 회원은 웨이팅을 생성할 수 없다.") + @Test + void createWaitingSuccess() throws Exception { + //given + CreateWaitingRequest request = WaitingFixture.createWaitingRequest(); + + waiting1.changeStatusCanceled(); + waitingRepository.save(waiting1); + + // when, then + mockMvc.perform(post("/waitings/{shopId}", shop.getId()) + .contentType(APPLICATION_JSON) + .content(asJsonString(request)) + .headers(getHttpHeaders(member1))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopId").value(shop.getId())) + .andExpect(jsonPath("$.shopName").value(shop.getName())) + .andExpect(jsonPath("$.rank").value(4)) + .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) + .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) + .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) + .andDo(MockMvcResultHandlers.print()); + + } + + @DisplayName("회원이 이미 진행 중인 웨이팅이 있을 경우, 해당 회원은 웨이팅을 생성할 수 없다.") + @Test + void createWaitingFails() throws Exception { + //given + CreateWaitingRequest request = WaitingFixture.createWaitingRequest(); + + // when, then + mockMvc.perform(post("/waitings/{shopId}", shop.getId()) + .contentType(APPLICATION_JSON) + .content(asJsonString(request)) + .headers(getHttpHeaders(member1))) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.message").value(ALREADY_PROGRESS_WAITING_EXISTS.getMessage())) + .andDo(MockMvcResultHandlers.print()); + + } + @DisplayName("웨이팅 지연 API를 호출할 수 있다.") @Test void postponeWaiting() throws Exception { From 4b017fc6e053ddcbc3bfd8bd9c7fedc8b54492f7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:47:44 +0900 Subject: [PATCH 547/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/RedisWaitingLineRepository.java | 2 +- .../prgrms/catchtable/waiting/service/MemberWaitingService.java | 1 + .../waiting/controller/MemberWaitingControllerTest.java | 2 -- .../com/prgrms/catchtable/waiting/fixture/WaitingFixture.java | 2 +- .../catchtable/waiting/service/MemberWaitingServiceTest.java | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 1fda48b5..24b7c099 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -68,7 +68,7 @@ public void cancel(Long shopId, Long waitingId) { public void postpone(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); validateIfPostponeAvailable(shopId, waitingId); - String key = "s"+shopId; + String key = "s" + shopId; if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { throw new BadRequestCustomException(ALREADY_END_LINE); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index f4fb13e9..8479df49 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -45,6 +45,7 @@ public class MemberWaitingService { private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; private final ApplicationEventPublisher publisher; + @Transactional public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index c06772c3..03577355 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.waiting.controller; import static com.prgrms.catchtable.common.Role.MEMBER; -import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_OCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PROGRESS_WAITING_EXISTS; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; @@ -114,7 +113,6 @@ void createWaiting() throws Exception { Member member4 = MemberFixture.member("test4@naver.com"); memberRepository.save(member4); - // when, then mockMvc.perform(post("/waitings/{shopId}", shop.getId()) .contentType(APPLICATION_JSON) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index f4a45e5a..ea0ce4e7 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -30,7 +30,7 @@ public static Waiting canceledWaiting(Member member, Shop shop, int waitingNumbe return waiting; } - public static CreateWaitingRequest createWaitingRequest(){ + public static CreateWaitingRequest createWaitingRequest() { return CreateWaitingRequest .builder() .peopleCount(2).build(); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 6099417c..bfc9a0c4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -66,7 +66,7 @@ void createWaiting() { given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); given(shop.getId()).willReturn(1L); - given(waitingRepository.existsByMemberAndStatus(member,PROGRESS)).willReturn(false); + given(waitingRepository.existsByMemberAndStatus(member, PROGRESS)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); From 1fb6fb5c4f6cbcbe8e0ce22c6ab64dfd630cbd29 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 17:51:13 +0900 Subject: [PATCH 548/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20stubbing=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/service/MemberWaitingServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index bfc9a0c4..f301995a 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -90,6 +90,7 @@ void postponeWaiting() { given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); + given(waitingRepository.findWaitingWithMember(anyLong())).willReturn(waiting); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); From cba57477b458fefb51ba81a5a41c8a2138768336 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 13 Jan 2024 18:02:50 +0900 Subject: [PATCH 549/603] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/notification/WaitingNotificationContent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java index 31d275cc..83fc872f 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java @@ -6,7 +6,7 @@ @RequiredArgsConstructor @Getter public enum WaitingNotificationContent { - REGISTERED("웨이팅이 등록되었습니다."), + REGISTERED("웨이팅이 등록되었습니다.\n내 순서 : %d번째"), CANCELED("웨이팅이 취소되었습니다."), THIRD_RANK("3번째 순서로 곧 입장하실 차례입니다."); From 8fb8e5566d843424241fed332480335875340794 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sat, 13 Jan 2024 22:36:07 +0900 Subject: [PATCH 550/603] =?UTF-8?q?chore=20:=20security=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 835767d1..5a2c52d8 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' -// implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' From 85a30d24585a1246c57a2dc16a75a99212a8f7fc Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sat, 13 Jan 2024 22:36:28 +0900 Subject: [PATCH 551/603] =?UTF-8?q?feat=20:=20Member=20&=20Owner=20?= =?UTF-8?q?=ED=99=94=EC=9D=B4=ED=8A=B8=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/security/config/SecurityConfig.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index e4c67aa6..19be4554 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -25,6 +25,9 @@ public class SecurityConfig { private final ExceptionHandlerFilter exceptionHandlerFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter; + private final String[] memberWhiteList = {"/reservations/**", "/watings/**", "/testMember/**"}; + private final String[] ownerWhiteList = {"/owners/shops/**", "/owners/waitings"}; + @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); @@ -39,8 +42,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti SessionCreationPolicy.STATELESS)) .formLogin(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorization -> authorization - .requestMatchers(new AntPathRequestMatcher("/testMember/**")).hasRole("MEMBER") - .requestMatchers(new AntPathRequestMatcher("/**")).permitAll() + .requestMatchers(memberWhiteList).hasRole("MEMBER") + .requestMatchers(ownerWhiteList).hasRole("OWNER") ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)) .exceptionHandling(exhandle -> exhandle From 1d449f19dbe7ff5292b729b5cb83d6bb6da9aeec Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sat, 13 Jan 2024 23:19:20 +0900 Subject: [PATCH 552/603] =?UTF-8?q?feat=20:=20test=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20controller=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/config/SecurityConfig.java | 2 +- .../security/controller/TestController.java | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/security/controller/TestController.java diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 19be4554..53c16772 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -25,7 +25,7 @@ public class SecurityConfig { private final ExceptionHandlerFilter exceptionHandlerFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter; - private final String[] memberWhiteList = {"/reservations/**", "/watings/**", "/testMember/**"}; + private final String[] memberWhiteList = {"/reservations/**", "/watings/**"}; private final String[] ownerWhiteList = {"/owners/shops/**", "/owners/waitings"}; @Bean diff --git a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java b/src/main/java/com/prgrms/catchtable/security/controller/TestController.java deleted file mode 100644 index 56f32d9a..00000000 --- a/src/main/java/com/prgrms/catchtable/security/controller/TestController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.prgrms.catchtable.security.controller; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@Slf4j -@RestController -public class TestController { - - @GetMapping("/testMember") - public ResponseEntity testMember() { - log.info("testMember"); - return ResponseEntity.ok("testMember OK"); - } -} From fc0593732079f003ae256437833ddf213a6865e5 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sat, 13 Jan 2024 23:38:11 +0900 Subject: [PATCH 553/603] =?UTF-8?q?fix=20:=20security=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=20=EC=9D=B8=EA=B0=80=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B3=B4?= =?UTF-8?q?=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/JwtAuthenticationTest.java | 119 +++++++++++------- 1 file changed, 77 insertions(+), 42 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 84403d07..2af6afa9 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -1,94 +1,129 @@ package com.prgrms.catchtable.security.controller; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.Role; -import com.prgrms.catchtable.jwt.filter.JwtAuthenticationFilter; +import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; -import com.prgrms.catchtable.security.filter.ExceptionHandlerFilter; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.fixture.ReservationFixture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.context.WebApplicationContext; -@SpringBootTest @Transactional -@AutoConfigureMockMvc -@WebAppConfiguration -class JwtAuthenticationTest { - - @Autowired - private WebApplicationContext webApplicationContext; - @Autowired - private ExceptionHandlerFilter exceptionHandlerFilter; - @Autowired - private JwtAuthenticationFilter jwtAuthenticationFilter; +class JwtAuthenticationTest extends BaseIntegrationTest { @Autowired private MemberRepository memberRepository; @Autowired + private OwnerRepository ownerRepository; + @Autowired private RefreshTokenService refreshTokenService; @Autowired private JwtTokenProvider jwtTokenProvider; - private MockMvc mockMvc; private Member loginMember; - private String email = "abc1234@gmail.com"; - private Token token; + private Owner loginOwner; + private String memberEmail = "abc1234@gmail.com"; + private String ownerEmail = "qwer5678@naver.com"; + private Token memberToken; + private Token ownerToken; + private CreateReservationRequest createReservationRequest = ReservationFixture.getCreateReservationRequest(); + @BeforeEach public void init() { //Member 객체 저장 - loginMember = MemberFixture.member(email); + loginMember = MemberFixture.member(memberEmail); memberRepository.save(loginMember); - //토큰 발급 - token = jwtTokenProvider.createToken(email, Role.MEMBER); - refreshTokenService.saveRefreshToken(token); + //Owner 객체 저장 + loginOwner = OwnerFixture.getOwner(); + ownerRepository.save(loginOwner); + + //Member 토큰 발급 + memberToken = jwtTokenProvider.createToken(memberEmail, Role.MEMBER); + refreshTokenService.saveRefreshToken(memberToken); - //필터 추가 - mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) - .addFilters(exceptionHandlerFilter, jwtAuthenticationFilter) - .build(); + //Owner 토큰 발급 + ownerToken = jwtTokenProvider.createToken(ownerEmail, Role.OWNER); + refreshTokenService.saveRefreshToken(ownerToken); } @Test - @DisplayName("Member의 AceessToken이 유효하다면, Member 권한을 갖는다.") + @DisplayName("Member의 AceessToken이 유효하다면, MemberWhiteList 접근이 가능하다.") void testMemberAccessToken() throws Exception { - mockMvc.perform(get("/testMember") - .header("AccessToken", token.getAccessToken()) - .header("RefreshToken", token.getRefreshToken())) + httpHeaders.add("AccessToken", memberToken.getAccessToken()); + httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); + + //Reservation 도메인 + mockMvc.perform(post("/reservations") + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(createReservationRequest))) .andExpect(status().isOk()); } @Test - @DisplayName("Member의 AccessToken이 유효하지 않고, RefreshToken이 유효하다면, Member 권한을 갖는다.") + @DisplayName("Member의 AccessToken이 유효하지 않아도 RefreshToken이 유효하다면, MemberWhiteList 접근이 가능하다.") void testMemberRefreshToken() throws Exception { - mockMvc.perform(get("/testMember") - .header("AccessToken", token.getAccessToken() + "abc") - .header("RefreshToken", token.getRefreshToken())) + httpHeaders.add("AccessToken", memberToken.getAccessToken() + "abc"); + httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); + + mockMvc.perform(post("/reservations") + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(createReservationRequest))) .andExpect(status().isOk()); } @Test - @DisplayName("Member의 AccessToken과 RefreshToken이 모두 유효하지 않다면, 400 Error를 반환한다.") + @DisplayName("Member의 AccessToken과 RefreshToken이 모두 유효하지 않다면, MemberWhiteList의 접근하지 못한다.") void testInvalidToken() throws Exception { - mockMvc.perform(get("/testMember") - .header("AccessToken", token.getAccessToken() + "abc") - .header("RefreshToken", token.getRefreshToken() + "abc")) + httpHeaders.add("AccessToken", memberToken.getAccessToken() + "abc"); + httpHeaders.add("RefreshToken", memberToken.getRefreshToken() + "abc"); + + mockMvc.perform(get("/reservations") + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(createReservationRequest))) .andExpect(status().isBadRequest()); } + + @Test + @DisplayName("Header의 토큰이 담겨있지 않은 상태로 WhiteList의 접근 시 401 에러를 반환한다. (인증 테스트)") + void testNotContainsToken() throws Exception { + mockMvc.perform(get("/reservations") + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(createReservationRequest))) + .andExpect(status().isUnauthorized()); + } + + @Test + @DisplayName("Member가 OwnerWhiteList의 접근 시 403 에러를 반환한다. (인가 테스트)") + void testAuthorization() throws Exception { + httpHeaders.add("AccessToken", memberToken.getAccessToken()); + httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); + + mockMvc.perform(get("/owners/shop") + .headers(httpHeaders) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(createReservationRequest))) + .andExpect(status().isForbidden()); + } } \ No newline at end of file From 748230f3d9b10e3ae7b5b1911fdd653632ee8251 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sat, 13 Jan 2024 23:53:59 +0900 Subject: [PATCH 554/603] =?UTF-8?q?feat=20:=20WhiteList=20=EC=99=B8=20URL?= =?UTF-8?q?=20=EC=A0=91=EA=B7=BC=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/security/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 53c16772..7191dd49 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -44,6 +44,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .authorizeHttpRequests(authorization -> authorization .requestMatchers(memberWhiteList).hasRole("MEMBER") .requestMatchers(ownerWhiteList).hasRole("OWNER") + .requestMatchers(new AntPathRequestMatcher("/**")).permitAll() ) .oauth2Login(oauth2Login -> oauth2Login.successHandler(successHandler)) .exceptionHandling(exhandle -> exhandle From 56003e2a43645b078e74330dc0ace3946dac9172 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 14 Jan 2024 00:06:06 +0900 Subject: [PATCH 555/603] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=8B=9C=EC=9E=91=20=EC=A0=84,=20DB=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/controller/MemberShopControllerTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java index de99255e..e60e2bb0 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -44,6 +44,9 @@ class MemberShopControllerTest extends BaseIntegrationTest { @BeforeEach void init() { + memberRepository.deleteAll(); + shopRepository.deleteAll(); + //Member 객체 저장 member = MemberFixture.member(email); memberRepository.save(member); From ec508cb396e1cab1b5e48d7ba8445958a6df969f Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 14 Jan 2024 16:11:28 +0900 Subject: [PATCH 556/603] =?UTF-8?q?feat=20:=20waiting.adoc=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20=EB=AA=85=EC=84=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/waiting/waiting.adoc | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/docs/asciidoc/api/waiting/waiting.adoc b/src/docs/asciidoc/api/waiting/waiting.adoc index 641c9595..4f5a51b3 100644 --- a/src/docs/asciidoc/api/waiting/waiting.adoc +++ b/src/docs/asciidoc/api/waiting/waiting.adoc @@ -11,6 +11,28 @@ include::{snippets}/member-waiting-controller-docs-test/create-waiting/request-f include::{snippets}/member-waiting-controller-docs-test/create-waiting/http-response.adoc[] include::{snippets}/member-waiting-controller-docs-test/create-waiting/response-fields.adoc[] +=== 회원 진행 중인 웨이팅 조회 API + +==== HTTP Request + +include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/get-waiting/response-fields.adoc[] + +=== 회원 웨이팅 이력 조회 API + +==== HTTP Request + +include::{snippets}/member-waiting-controller-docs-test/get-member-waiting-history/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-waiting-controller-docs-test/get-member-waiting-history/http-response.adoc[] +include::{snippets}/member-waiting-controller-docs-test/get-member-waiting-history/response-fields.adoc[] + === 웨이팅 지연 API ==== HTTP Request @@ -33,17 +55,6 @@ include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-requ include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-response.adoc[] include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/response-fields.adoc[] -=== 회원 진행 중인 웨이팅 조회 API - -==== HTTP Request - -include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-request.adoc[] - -==== HTTP Response - -include::{snippets}/member-waiting-controller-docs-test/get-waiting/http-response.adoc[] -include::{snippets}/member-waiting-controller-docs-test/get-waiting/response-fields.adoc[] - === 웨이팅 입장 API @@ -56,7 +67,7 @@ include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/http-reques include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/http-response.adoc[] include::{snippets}/owner-waiting-controller-docs-test/entry-waiting/response-fields.adoc[] -=== 가게 웨이팅 이력 조회 API +=== 가게 웨이팅 조회 API ==== HTTP Request From edc020e1bb640f0bf8f9948c5fe7744f8cb4d7e9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 14 Jan 2024 16:36:05 +0900 Subject: [PATCH 557/603] =?UTF-8?q?refactor=20:=20ownerWaiting=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingControllerDocsTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java index 7c083eb4..b75cd9dc 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.waiting.controller; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; @@ -14,6 +15,7 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.service.OwnerWaitingService; @@ -49,9 +51,9 @@ void entryWaiting() throws Exception { OwnerWaitingResponse response = OwnerWaitingResponse.builder() .waitingId(1L) .waitingNumber(20) - .rank(1L) + .rank(0L) .peopleCount(2) - .status("진행 중") + .status(COMPLETED.getDescription()) .build(); given(ownerWaitingService.entryWaiting(owner)).willReturn(response); //when, then @@ -85,14 +87,14 @@ void getShopAllWaiting() throws Exception { .waitingNumber(20) .rank(1L) .peopleCount(2) - .status("진행 중") + .status(PROGRESS.getDescription()) .build(); OwnerWaitingResponse response2 = OwnerWaitingResponse.builder() .waitingId(2L) .waitingNumber(21) .rank(2L) .peopleCount(2) - .status("진행 중") + .status(PROGRESS.getDescription()) .build(); OwnerWaitingListResponse responses = OwnerWaitingListResponse.builder() .shopWaitings(List.of(response1, response2)) From af1e06dfbdfd6e73f51fe4ca6464b3eef36522b7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 14 Jan 2024 16:39:44 +0900 Subject: [PATCH 558/603] =?UTF-8?q?refactor=20:=20waitingStatus=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/WaitingStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java index 3d71c58f..f1c335f2 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/WaitingStatus.java @@ -7,7 +7,7 @@ @RequiredArgsConstructor public enum WaitingStatus { PROGRESS("진행 중"), - COMPLETED("입장"), + COMPLETED("입장 완료"), CANCELED("취소"), NO_SHOW("노쇼"); From e2dcf0ed2ceb0d6bd3e5afaf5ab651d8221c27a9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 14 Jan 2024 17:03:53 +0900 Subject: [PATCH 559/603] =?UTF-8?q?refactor=20:=20uri=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20=EB=B0=8F=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 6 +++--- .../waiting/controller/OwnerWaitingController.java | 2 +- .../catchtable/waiting/service/MemberWaitingService.java | 2 +- .../waiting/controller/MemberWaitingControllerDocsTest.java | 4 ++-- .../waiting/controller/MemberWaitingControllerTest.java | 4 ++-- .../waiting/controller/OwnerWaitingControllerDocsTest.java | 4 ++-- .../waiting/controller/OwnerWaitingControllerTest.java | 4 ++-- .../waiting/service/MemberWaitingServiceTest.java | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 4f844d04..e447fda9 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -55,10 +55,10 @@ public ResponseEntity getWaiting( return ResponseEntity.ok(response); } - @GetMapping("/all") - public ResponseEntity getMemberWaitingHistory( + @GetMapping("/history") + public ResponseEntity getWaitingHistory( @LogIn Member member) { - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( + MemberWaitingHistoryListResponse response = memberWaitingService.getWaitingHistory( member); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index 99a3b56b..218ab13d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor -@RequestMapping("owner/waitings") +@RequestMapping("owners/waitings") @RestController public class OwnerWaitingController { diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 8479df49..69d5bd3a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -112,7 +112,7 @@ public MemberWaitingResponse getWaiting(Member member) { } @Transactional(readOnly = true) - public MemberWaitingHistoryListResponse getMemberWaitingHistory(Member member) { + public MemberWaitingHistoryListResponse getWaitingHistory(Member member) { List waitings = waitingRepository.findWaitingWithMemberAndShop(member); return toMemberWaitingListResponse(waitings); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index 8d5bf5da..f40e1e01 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -212,9 +212,9 @@ void getMemberWaitingHistory() throws Exception { MemberWaitingHistoryListResponse responses = MemberWaitingHistoryListResponse.builder() .memberWaitings(List.of(response1, response2)) .build(); - given(memberWaitingService.getMemberWaitingHistory(member)).willReturn(responses); + given(memberWaitingService.getWaitingHistory(member)).willReturn(responses); //when, then - mockMvc.perform(get("/waitings/all") + mockMvc.perform(get("/waitings/history") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(member))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 03577355..602c9d4d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -235,7 +235,7 @@ void cancelWaiting() throws Exception { () -> waitingLineRepository.findRank(shop.getId(), waiting1.getId())); } - @DisplayName("웨이팅 조회 API를 호출할 수 있다.") + @DisplayName("진행 중인 웨이팅 조회 API를 호출할 수 있다.") @Test void getWaiting() throws Exception { //when, then @@ -259,7 +259,7 @@ void getMemberWaitingHistory() throws Exception { Waiting canceledWaiting = WaitingFixture.canceledWaiting(member1, shop, 23); Waiting completedWaiting = WaitingFixture.completedWaiting(member1, shop, 233); waitingRepository.saveAll(List.of(canceledWaiting, completedWaiting)); - mockMvc.perform(get("/waitings/all") + mockMvc.perform(get("/waitings/history") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(member1))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java index b75cd9dc..5e88f086 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java @@ -57,7 +57,7 @@ void entryWaiting() throws Exception { .build(); given(ownerWaitingService.entryWaiting(owner)).willReturn(response); //when, then - mockMvc.perform(patch("/owner/waitings") + mockMvc.perform(patch("/owners/waitings") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) @@ -103,7 +103,7 @@ void getShopAllWaiting() throws Exception { given(ownerWaitingService.getShopAllWaiting(owner)).willReturn(responses); //when, then - mockMvc.perform(get("/owner/waitings") + mockMvc.perform(get("/owners/waitings") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index dbb032a0..e582ad61 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -109,7 +109,7 @@ void clear() { @Test void getWaiting() throws Exception { //when, then - mockMvc.perform(get("/owner/waitings") + mockMvc.perform(get("/owners/waitings") .contentType(APPLICATION_JSON) .headers(httpHeaders)) .andExpect(status().isOk()) @@ -131,7 +131,7 @@ void getWaiting() throws Exception { @Test void entryWaiting() throws Exception { //when, then - mockMvc.perform(patch("/owner/waitings") + mockMvc.perform(patch("/owners/waitings") .contentType(APPLICATION_JSON) .headers(httpHeaders)) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index f301995a..2cce6d12 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -169,7 +169,7 @@ void getMemberAllWaiting() { given(waiting.getStatus()).willReturn(CANCELED); //when - MemberWaitingHistoryListResponse response = memberWaitingService.getMemberWaitingHistory( + MemberWaitingHistoryListResponse response = memberWaitingService.getWaitingHistory( member); //then From 0e3a13077d2cec943f92e893fb2e6d8c7a3c634c Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 14 Jan 2024 17:44:07 +0900 Subject: [PATCH 560/603] =?UTF-8?q?fix=20:=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/security/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java index 7191dd49..e03e2dce 100644 --- a/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java +++ b/src/main/java/com/prgrms/catchtable/security/config/SecurityConfig.java @@ -25,7 +25,7 @@ public class SecurityConfig { private final ExceptionHandlerFilter exceptionHandlerFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter; - private final String[] memberWhiteList = {"/reservations/**", "/watings/**"}; + private final String[] memberWhiteList = {"/reservations/**", "/waitings/**"}; private final String[] ownerWhiteList = {"/owners/shops/**", "/owners/waitings"}; @Bean From 417333da5537fd25972d7a52061367ea961709b5 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 14 Jan 2024 18:15:53 +0900 Subject: [PATCH 561/603] =?UTF-8?q?refactor=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=A0=84=20=EC=9E=91=EC=97=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/JwtAuthenticationTest.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 2af6afa9..66c63404 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -6,7 +6,9 @@ import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; +import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; @@ -32,7 +34,7 @@ class JwtAuthenticationTest extends BaseIntegrationTest { @Autowired private OwnerRepository ownerRepository; @Autowired - private RefreshTokenService refreshTokenService; + private RefreshTokenRepository refreshTokenRepository; @Autowired private JwtTokenProvider jwtTokenProvider; @@ -47,6 +49,10 @@ class JwtAuthenticationTest extends BaseIntegrationTest { @BeforeEach public void init() { + memberRepository.deleteAll(); + ownerRepository.deleteAll(); + refreshTokenRepository.deleteAll(); + //Member 객체 저장 loginMember = MemberFixture.member(memberEmail); memberRepository.save(loginMember); @@ -57,11 +63,19 @@ public void init() { //Member 토큰 발급 memberToken = jwtTokenProvider.createToken(memberEmail, Role.MEMBER); - refreshTokenService.saveRefreshToken(memberToken); + refreshTokenRepository.save(RefreshToken.builder() + .token(memberToken.getRefreshToken()) + .email(memberEmail) + .role(Role.MEMBER) + .build()); //Owner 토큰 발급 ownerToken = jwtTokenProvider.createToken(ownerEmail, Role.OWNER); - refreshTokenService.saveRefreshToken(ownerToken); + refreshTokenRepository.save(RefreshToken.builder() + .token(ownerToken.getRefreshToken()) + .email(ownerEmail) + .role(Role.OWNER) + .build()); } @Test From 73cb1e9f15fe513afa4aca8169bb7ff4e93514a7 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 14 Jan 2024 18:17:17 +0900 Subject: [PATCH 562/603] refactor : MediaType static import --- .../security/controller/JwtAuthenticationTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 66c63404..48e52133 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.security.controller; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -87,7 +88,7 @@ void testMemberAccessToken() throws Exception { //Reservation 도메인 mockMvc.perform(post("/reservations") .headers(httpHeaders) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .content(asJsonString(createReservationRequest))) .andExpect(status().isOk()); } @@ -100,7 +101,7 @@ void testMemberRefreshToken() throws Exception { mockMvc.perform(post("/reservations") .headers(httpHeaders) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .content(asJsonString(createReservationRequest))) .andExpect(status().isOk()); } @@ -113,7 +114,7 @@ void testInvalidToken() throws Exception { mockMvc.perform(get("/reservations") .headers(httpHeaders) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .content(asJsonString(createReservationRequest))) .andExpect(status().isBadRequest()); } @@ -123,7 +124,7 @@ void testInvalidToken() throws Exception { void testNotContainsToken() throws Exception { mockMvc.perform(get("/reservations") .headers(httpHeaders) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .content(asJsonString(createReservationRequest))) .andExpect(status().isUnauthorized()); } @@ -136,7 +137,7 @@ void testAuthorization() throws Exception { mockMvc.perform(get("/owners/shop") .headers(httpHeaders) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .content(asJsonString(createReservationRequest))) .andExpect(status().isForbidden()); } From 03f8b972353380e4b942a9e21da8f37ef49b5404 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Sun, 14 Jan 2024 18:19:24 +0900 Subject: [PATCH 563/603] =?UTF-8?q?fix=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=8B=9C,=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/MemberReservationControllerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index a4f288f2..4d46c7f0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -188,6 +188,7 @@ void modifyReservation() throws Exception { request.reservationTimeId(), reservation.getShop().getId()).orElseThrow(); // 수정하려는 예약시간 mockMvc.perform(patch("/reservations/{reservaionId}", savedReservation.getId()) + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()) From f1def1d4651ba9db52a43734976a75cb729522d7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sun, 14 Jan 2024 20:55:33 +0900 Subject: [PATCH 564/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=95=8C=EB=9E=8C=20=EB=A9=94=EC=84=B8=EC=A7=80=20enum=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/WaitingNotificationContent.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java index 83fc872f..62ba900f 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java @@ -6,10 +6,13 @@ @RequiredArgsConstructor @Getter public enum WaitingNotificationContent { - REGISTERED("웨이팅이 등록되었습니다.\n내 순서 : %d번째"), - CANCELED("웨이팅이 취소되었습니다."), - - THIRD_RANK("3번째 순서로 곧 입장하실 차례입니다."); + MEMBER_CREATED("웨이팅이 등록되었습니다.\n내 순서 : %d번째"), + MEMBER_CANCELED("웨이팅이 취소되었습니다."), + MEMBER_ENTRY("웨이팅 입장할 차례입니다."), + MEMBER_POSTPONED("웨이팅 순서를 %d번으로 미뤘습니다."), + THIRD_RANK("3번째 순서로 곧 입장하실 차례입니다."), + OWNER_CREATED("%d번째 웨이팅이 등록되었습니다."), + OWNER_CANCELED("%d번째 웨이팅이 취소되었습니다."); private final String message; -} \ No newline at end of file +} From 2e8207f9d9bc852fbe166036f40a10a8aecf5ce9 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 15 Jan 2024 00:05:23 +0900 Subject: [PATCH 565/603] =?UTF-8?q?fix=20:=20URL=20Path=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/OwnerReservationController.java | 2 +- .../catchtable/waiting/controller/OwnerWaitingController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java index 4105bfa0..38ffc549 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/OwnerReservationController.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/owners/shop") +@RequestMapping("/owners/shops") @RequiredArgsConstructor public class OwnerReservationController { diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java index 99a3b56b..218ab13d 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor -@RequestMapping("owner/waitings") +@RequestMapping("owners/waitings") @RestController public class OwnerWaitingController { From f39b12c0b0e95b466b50f593d85b3e9a758de8db Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 15 Jan 2024 00:05:38 +0900 Subject: [PATCH 566/603] =?UTF-8?q?fix=20:=20URL=20Path=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20test=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerReservationControllerDocsTest.java | 4 ++-- .../controller/OwnerReservationControllerTest.java | 5 +++-- .../waiting/controller/OwnerWaitingControllerDocsTest.java | 4 ++-- .../waiting/controller/OwnerWaitingControllerTest.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java index 40e6e434..e952f311 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerDocsTest.java @@ -54,7 +54,7 @@ void noshowAndCancel() throws Exception { CANCELLED); doNothing().when(ownerReservationService).modifyReservationStatus(1L, request); - mockMvc.perform(patch("/owners/shop/{reservationId}", 1) + mockMvc.perform(patch("/owners/shops/{reservationId}", 1) .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(request)) .headers(getHttpHeaders(owner))) @@ -87,7 +87,7 @@ void getAllReservation() throws Exception { Mockito.when(ownerReservationService.getAllReservation(owner)).thenReturn(response); - mockMvc.perform(get("/owners/shop") + mockMvc.perform(get("/owners/shops") .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) .andDo(restDocs.document( diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index fbeb90f0..01e4629c 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -85,7 +85,8 @@ void modifyReservationStatus() throws Exception { //then assertThat(reservation.getReservationTime().isOccupied()).isTrue(); // 취소처리 전엔 예약시간 차있음 - mockMvc.perform(patch("/owners/shop/{reservationId}", reservation.getId()) + mockMvc.perform(patch("/owners/shops/{reservationId}", reservation.getId()) + .headers(httpHeaders) .contentType(APPLICATION_JSON) .content(asJsonString(request))) .andExpect(status().isOk()); @@ -104,7 +105,7 @@ void getAllReservation() throws Exception { Reservation reservation1 = reservations.get(0); Reservation reservation2 = reservations.get(1); - mockMvc.perform(get("/owners/shop") + mockMvc.perform(get("/owners/shops") .contentType(APPLICATION_JSON) .headers(httpHeaders) .content(asJsonString(owner.getId()))) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java index 7c083eb4..c8e5b327 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java @@ -55,7 +55,7 @@ void entryWaiting() throws Exception { .build(); given(ownerWaitingService.entryWaiting(owner)).willReturn(response); //when, then - mockMvc.perform(patch("/owner/waitings") + mockMvc.perform(patch("/owners/waitings") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) @@ -101,7 +101,7 @@ void getShopAllWaiting() throws Exception { given(ownerWaitingService.getShopAllWaiting(owner)).willReturn(responses); //when, then - mockMvc.perform(get("/owner/waitings") + mockMvc.perform(get("/owners/waitings") .contentType(APPLICATION_JSON) .headers(getHttpHeaders(owner))) .andExpect(status().isOk()) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 9d981c0b..144b6375 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -112,7 +112,7 @@ void clear() { @Test void getWaiting() throws Exception { //when, then - mockMvc.perform(get("/owner/waitings") + mockMvc.perform(get("/owners/waitings") .contentType(APPLICATION_JSON) .headers(httpHeaders)) .andExpect(status().isOk()) @@ -134,7 +134,7 @@ void getWaiting() throws Exception { @Test void entryWaiting() throws Exception { //when, then - mockMvc.perform(patch("/owner/waitings") + mockMvc.perform(patch("/owners/waitings") .contentType(APPLICATION_JSON) .headers(httpHeaders)) .andExpect(status().isOk()) From d3ffb89587929a538fde4601add1f8570b4f9f1e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 15 Jan 2024 00:31:38 +0900 Subject: [PATCH 567/603] =?UTF-8?q?fix=20:=20JwtAuthenticationTest=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/JwtAuthenticationTest.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 48e52133..4d9488ae 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -59,7 +59,7 @@ public void init() { memberRepository.save(loginMember); //Owner 객체 저장 - loginOwner = OwnerFixture.getOwner(); + loginOwner = OwnerFixture.getOwner(ownerEmail, "1234"); ownerRepository.save(loginOwner); //Member 토큰 발급 @@ -86,10 +86,9 @@ void testMemberAccessToken() throws Exception { httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); //Reservation 도메인 - mockMvc.perform(post("/reservations") + mockMvc.perform(get("/reservations") .headers(httpHeaders) - .contentType(APPLICATION_JSON) - .content(asJsonString(createReservationRequest))) + .contentType(APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -99,10 +98,9 @@ void testMemberRefreshToken() throws Exception { httpHeaders.add("AccessToken", memberToken.getAccessToken() + "abc"); httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); - mockMvc.perform(post("/reservations") + mockMvc.perform(get("/reservations") .headers(httpHeaders) - .contentType(APPLICATION_JSON) - .content(asJsonString(createReservationRequest))) + .contentType(APPLICATION_JSON)) .andExpect(status().isOk()); } @@ -130,15 +128,14 @@ void testNotContainsToken() throws Exception { } @Test - @DisplayName("Member가 OwnerWhiteList의 접근 시 403 에러를 반환한다. (인가 테스트)") + @DisplayName("Owner가 MemberWhiteList의 접근 시 403 에러를 반환한다. (인가 테스트)") void testAuthorization() throws Exception { - httpHeaders.add("AccessToken", memberToken.getAccessToken()); - httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); + httpHeaders.add("AccessToken", ownerToken.getAccessToken()); + httpHeaders.add("RefreshToken", ownerToken.getRefreshToken()); - mockMvc.perform(get("/owners/shop") + mockMvc.perform(get("/reservations") .headers(httpHeaders) - .contentType(APPLICATION_JSON) - .content(asJsonString(createReservationRequest))) + .contentType(APPLICATION_JSON)) .andExpect(status().isForbidden()); } } \ No newline at end of file From 99688d9278dab880682aad738650621300c860f3 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Mon, 15 Jan 2024 00:36:53 +0900 Subject: [PATCH 568/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/shop/domain/Category.java | 3 +-- .../prgrms/catchtable/shop/domain/Shop.java | 20 +++++-------------- .../catchtable/shop/dto/ShopMapper.java | 3 ++- .../common/restdocs/RestDocsSupport.java | 2 -- .../controller/JwtAuthenticationTest.java | 5 +---- .../controller/MemberShopControllerTest.java | 12 +++++++---- .../shop/service/ShopServiceTest.java | 1 - 7 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java index c8b95463..c467de6d 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Category.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Category.java @@ -1,8 +1,7 @@ package com.prgrms.catchtable.shop.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.INVALID_INPUT_TYPE; -import com.prgrms.catchtable.common.exception.ErrorCode; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import java.util.Arrays; import lombok.Getter; diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index cf641445..0b0114b3 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -1,15 +1,13 @@ package com.prgrms.catchtable.shop.domain; import static com.prgrms.catchtable.common.exception.ErrorCode.SHOP_NOT_RUNNING; -import static jakarta.persistence.CascadeType.*; +import static jakarta.persistence.CascadeType.ALL; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -31,37 +29,29 @@ @Entity public class Shop extends BaseEntity { + @BatchSize(size = 30) + @OneToMany(mappedBy = "shop", cascade = ALL, orphanRemoval = true) + List menuList = new ArrayList<>(); @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "shop_id") private Long id; - @Column(name = "shop_name") private String name; - @Column(name = "rating") private BigDecimal rating; - @Column(name = "category") @Enumerated(STRING) private Category category; - @Embedded private Address address; - @Column(name = "capacity") private int capacity; - @Column(name = "opening_time") private LocalTime openingTime; - @Column(name = "closing_time") private LocalTime closingTime; - @BatchSize(size = 30) - @OneToMany(mappedBy = "shop", cascade = ALL, orphanRemoval = true) - List menuList = new ArrayList<>(); - @Builder public Shop(String name, BigDecimal rating, Category category, Address address, int capacity, LocalTime openingTime, LocalTime closingTime) { @@ -74,7 +64,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.closingTime = closingTime; } - public void updateMenuList(List menuList){ + public void updateMenuList(List menuList) { this.menuList.addAll(menuList); this.menuList.forEach(menu -> menu.insertShop(this)); } diff --git a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java index 29662a10..5b11579a 100644 --- a/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java +++ b/src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java @@ -93,7 +93,8 @@ private static GetAllShopResponse toGetAllShopResponse(Shop shop) { .build(); } - public static GetShopResponse toGetShopResponse(Shop shop, List reservationTimeList) { + public static GetShopResponse toGetShopResponse(Shop shop, + List reservationTimeList) { List menuResponses = shop.getMenuList().stream() .map(menu -> MenuResponse.builder() diff --git a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java index e6411a7d..035f8dbd 100644 --- a/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java +++ b/src/test/java/com/prgrms/catchtable/common/restdocs/RestDocsSupport.java @@ -1,11 +1,9 @@ package com.prgrms.catchtable.common.restdocs; -import static com.prgrms.catchtable.common.Role.*; import static com.prgrms.catchtable.common.Role.MEMBER; import static com.prgrms.catchtable.common.Role.OWNER; import com.fasterxml.jackson.databind.ObjectMapper; -import com.prgrms.catchtable.common.Role; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.domain.Member; diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 4d9488ae..7e0f4472 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -1,8 +1,7 @@ package com.prgrms.catchtable.security.controller; -import static org.springframework.http.MediaType.*; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.Role; @@ -10,7 +9,6 @@ import com.prgrms.catchtable.jwt.domain.RefreshToken; import com.prgrms.catchtable.jwt.provider.JwtTokenProvider; import com.prgrms.catchtable.jwt.repository.RefreshTokenRepository; -import com.prgrms.catchtable.jwt.service.RefreshTokenService; import com.prgrms.catchtable.jwt.token.Token; import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; @@ -24,7 +22,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; @Transactional diff --git a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java index e60e2bb0..ed362f46 100644 --- a/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/controller/MemberShopControllerTest.java @@ -72,8 +72,10 @@ void getAllTest() throws Exception { .headers(httpHeaders)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) - .andExpect(jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) - .andExpect(jsonPath("$.shopResponses.[0].closingTime").value(shop.getClosingTime().toString())); + .andExpect( + jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) + .andExpect(jsonPath("$.shopResponses.[0].closingTime").value( + shop.getClosingTime().toString())); } @Test @@ -116,7 +118,9 @@ void getBySearchTest() throws Exception { .params(params)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopResponses.[0].name").value(shop.getName())) - .andExpect(jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) - .andExpect(jsonPath("$.shopResponses.[0].closingTime").value(shop.getClosingTime().toString())); + .andExpect( + jsonPath("$.shopResponses.[0].openingTime").value(shop.getOpeningTime().toString())) + .andExpect(jsonPath("$.shopResponses.[0].closingTime").value( + shop.getClosingTime().toString())); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java index 8f272c2a..94aa425b 100644 --- a/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/service/ShopServiceTest.java @@ -5,7 +5,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; From 4d60d7c3a46baa5319dd53a39cc7c8f80a4e5ab0 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 16:28:18 +0900 Subject: [PATCH 569/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EB=A9=94=EC=84=B8=EC=A7=80=20enum=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/notification/WaitingNotificationContent.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java index 62ba900f..b7327d48 100644 --- a/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/notification/WaitingNotificationContent.java @@ -8,11 +8,13 @@ public enum WaitingNotificationContent { MEMBER_CREATED("웨이팅이 등록되었습니다.\n내 순서 : %d번째"), MEMBER_CANCELED("웨이팅이 취소되었습니다."), + MEMBER_COMPLETED("가게에 입장 처리되었습니다."), MEMBER_ENTRY("웨이팅 입장할 차례입니다."), MEMBER_POSTPONED("웨이팅 순서를 %d번으로 미뤘습니다."), THIRD_RANK("3번째 순서로 곧 입장하실 차례입니다."), + FIRST_RANK("입장할 순서예요! 지금 매장으로 와주세요."), OWNER_CREATED("%d번째 웨이팅이 등록되었습니다."), OWNER_CANCELED("%d번째 웨이팅이 취소되었습니다."); - private final String message; + private final String content; } From 19f7c343d796b8389ef2d2ed83fcc1248be6e0e2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 16:35:11 +0900 Subject: [PATCH 570/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=EC=97=B4?= =?UTF-8?q?=20findRankValue()=20=EC=B6=94=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/BasicWaitingLineRepository.java | 4 ++-- .../repository/waitingline/RedisWaitingLineRepository.java | 4 ++-- .../waiting/repository/waitingline/WaitingLineRepository.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index ea69e7a7..e1be238a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -72,11 +72,11 @@ public Long findRank(Long shopId, Long waitingId) { return -1L; } - public Long findThirdRankValue(Long shopId) { + public Long findRankValue(Long shopId,int rank) { Queue waitingLine = waitingLines.get(shopId); int index = 0; for (Long element : waitingLine) { - if (index == 2) { + if (index == rank-1) { return element; } index++; diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 24b7c099..bbcf4ad1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -98,8 +98,8 @@ public Long findRank(Long shopId, Long waitingId) { return getWaitingLineSize(shopId) - index; } - public Long findThirdRankValue(Long shopId) { - String waitingId = redisTemplate.opsForList().index("s" + shopId, -3); + public Long findRankValue(Long shopId, int rank) { + String waitingId = redisTemplate.opsForList().index("s" + shopId, -rank); if (waitingId == null) { return null; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 6b9632b5..8368c079 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -14,7 +14,7 @@ public interface WaitingLineRepository { Long findRank(Long shopId, Long waitingId); - Long findThirdRankValue(Long shopId); + Long findRankValue(Long shopId, int rank); Long getWaitingLineSize(Long shopId); From 7aefce3fa6fe5cb5157fd16941f207e881e79ca4 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 16:43:27 +0900 Subject: [PATCH 571/603] =?UTF-8?q?feat=20:=20=EB=8C=80=EA=B8=B0=EC=97=B4?= =?UTF-8?q?=20=ED=95=A8=EC=88=98=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicWaitingLineRepositoryTest.java | 27 +++++++++++++++++++ .../RedisWaitingLineRepositoryTest.java | 24 ++++++++++++----- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 89f925fb..66129ee2 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -130,4 +130,31 @@ void getShopWaitingIdOrder() { assertThat(waitingIds.get(2)).isEqualTo(3L); } + @DisplayName("웨이팅 3번째 waitingId 반환한다.") + @Test + void findThirdRankValue() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + Long waitingId = repository.findRankValue(shopId, 3); + //then + assertThat(waitingId).isEqualTo(3L); + } + + @DisplayName("웨이팅 3번째 waitingId 없으면 null을 반환한다.") + @Test + void findThirdRankValueNull() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + //when + Long waitingId = repository.findRankValue(shopId, 3); + //then + assertThat(waitingId).isNull(); + } + } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index d55c37a9..1cabf45f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -146,7 +146,21 @@ void getWaitingLineSize() { assertThat(waitingLineSize).isZero(); } - @DisplayName("웨이팅 3번째 waitingId 반환") + @DisplayName("웨이팅 1번째 waitingId 반환한다.") + @Test + void findThirdFirstValue() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + Long waitingId = repository.findRankValue(shopId, 1); + //then + assertThat(waitingId).isEqualTo(1L); + } + + @DisplayName("웨이팅 3번째 waitingId 반환한다.") @Test void findThirdRankValue() { //given @@ -155,12 +169,12 @@ void findThirdRankValue() { repository.save(shopId, 2L); repository.save(shopId, 3L); //when - Long waitingId = repository.findThirdRankValue(shopId); + Long waitingId = repository.findRankValue(shopId, 3); //then assertThat(waitingId).isEqualTo(3L); } - @DisplayName("웨이팅 3번째 waitingId 없으면 null 반환") + @DisplayName("웨이팅 3번째 waitingId 없으면 null을 반환한다.") @Test void findThirdRankValueNull() { //given @@ -168,10 +182,8 @@ void findThirdRankValueNull() { repository.save(shopId, 1L); repository.save(shopId, 2L); //when - Long waitingId = repository.findThirdRankValue(shopId); + Long waitingId = repository.findRankValue(shopId, 3); //then assertThat(waitingId).isNull(); } - - } \ No newline at end of file From 4a6b9e787a75e3deaa806943bda2d279e80adc3e Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 16:55:34 +0900 Subject: [PATCH 572/603] =?UTF-8?q?feat=20:=20=20waitingNotification=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=B1=85=EC=9E=84=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/WaitingNotification.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java new file mode 100644 index 00000000..6369e83f --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java @@ -0,0 +1,81 @@ +package com.prgrms.catchtable.waiting.service; + +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.FIRST_RANK; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.MEMBER_CANCELED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.MEMBER_COMPLETED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.MEMBER_CREATED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.MEMBER_POSTPONED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.OWNER_CANCELED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.OWNER_CREATED; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.THIRD_RANK; + +import com.prgrms.catchtable.common.notification.WaitingNotificationContent; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; +import com.prgrms.catchtable.notification.dto.request.SendMessageToOwnerRequest; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class WaitingNotification { + private final ApplicationEventPublisher publisher; + private final WaitingLineRepository waitingLineRepository; + private final WaitingRepository waitingRepository; + + public void sendMessageAsCreated(Member member, Owner owner, Long rank) { + sendMessageToMember(member, String.format(MEMBER_CREATED.getContent(), rank)); + sendMessageToOwner(owner, String.format(OWNER_CREATED.getContent(), rank)); + } + + public void sendMessageAsPostponed(Member member, Long rank) { + sendMessageToMember(member, String.format(MEMBER_POSTPONED.getContent(), rank)); + } + + public void sendMessageAsCompleted(Member member) { + sendMessageToMember(member, MEMBER_COMPLETED.getContent()); + } + + public void sendMessageAsCanceled(Member member, Owner owner, Long rank) { + sendMessageToMember(member,MEMBER_CANCELED.getContent()); + sendMessageToOwner(owner, String.format(OWNER_CANCELED.getContent(), rank)); + } + + public void sendEntryMessageToOthers(Long shopId, Long removedMemberRank) { + if (removedMemberRank <= 3) { // 대기열에서 rank 3이하 회원이 사라지면 + sendEntryMessageToOthers(shopId, 3, THIRD_RANK); // 세 번째 회원에게 알림 + } + if (removedMemberRank == 1) { //대기열에서 rank 1 회원이 사라지면 + sendEntryMessageToOthers(shopId, 1, FIRST_RANK); // 첫 번째 회원에게 알림 + } + } + + private void sendEntryMessageToOthers(Long shopId, int rank, + WaitingNotificationContent content) { + Long waitingId = waitingLineRepository.findRankValue(shopId, rank); // rank로 waitingId 찾기 + if (waitingId != null) { + Member member = waitingRepository.findWaitingWithMember(waitingId).getMember(); + sendMessageToMember(member, content.getContent()); + } + } + + private void sendMessageToMember(Member member, String content) { + SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() + .member(member) + .content(content) + .build(); + publisher.publishEvent(request); + } + + private void sendMessageToOwner(Owner owner, String content) { + SendMessageToOwnerRequest request = SendMessageToOwnerRequest.builder() + .owner(owner) + .content(content) + .build(); + publisher.publishEvent(request); + } +} From 68a322dcee4cb7cfcfb114969dbe376101a8e220 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 16:55:50 +0900 Subject: [PATCH 573/603] =?UTF-8?q?feat=20:=20=EB=88=84=EB=9D=BD=EB=90=9C?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 87 +++++++------------ .../waiting/service/OwnerWaitingService.java | 16 +++- 2 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 69d5bd3a..578e719f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -1,11 +1,9 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PROGRESS_WAITING_EXISTS; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_PROGRESS_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_SHOP; -import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.CANCELED; -import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.REGISTERED; -import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.THIRD_RANK; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toMemberWaitingResponse; @@ -14,11 +12,11 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.notification.dto.request.SendMessageToMemberRequest; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingHistoryListResponse; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; @@ -29,7 +27,6 @@ import java.time.LocalTime; import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -44,28 +41,27 @@ public class MemberWaitingService { private final WaitingRepository waitingRepository; private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; - private final ApplicationEventPublisher publisher; + private final OwnerRepository ownerRepository; + private final WaitingNotification notification; @Transactional public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { - // 연관 엔티티 조회 - Shop shop = getShopEntity(shopId); + Shop shop = getShopEntity(shopId); // 연관 엔티티 조회 + Owner owner = getOwnerEntity(shop); - // 기존 waiting이 있는지 검증 - validateIfMemberWaitingExists(member); + validateIfMemberWaitingExists(member); // 기존 진행 중인 waiting이 있는지 검증 - // 대기 번호 생성 int waitingNumber = (waitingRepository.countByShopAndCreatedAtBetween(shop, - START_DATE_TIME, END_DATE_TIME)).intValue() + 1; + START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // 대기 번호 생성 - // waiting 저장 - Waiting waiting = toWaiting(request, waitingNumber, member, shop); + Waiting waiting = toWaiting(request, waitingNumber, member, shop); //waiting 생성 후 저장 Waiting savedWaiting = waitingRepository.save(waiting); - waitingLineRepository.save(shopId, waiting.getId()); + waitingLineRepository.save(shopId, waiting.getId()); // 대기열 저장 + Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); - sendMessageToMember(member, PROGRESS, rank); + notification.sendMessageAsCreated(member, owner,rank); return toMemberWaitingResponse(savedWaiting, rank); } @@ -73,15 +69,16 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, @Transactional public MemberWaitingResponse postponeWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); - Shop shop = waiting.getShop(); - Long previousRank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); + Long shopId = waiting.getShop().getId(); + Long previousRank = waitingLineRepository.findRank(shopId, waiting.getId()); // 미루기 전 rank 저장 waiting.decreasePostponeRemainingCount(); - waitingLineRepository.postpone(shop.getId(), waiting.getId()); - Long rank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); - if (previousRank <= 3) { - sendMessageToThirdRankMember(shop.getId()); - } + waitingLineRepository.postpone(shopId, waiting.getId()); + Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); // 미룬 후 rank 저장 + + notification.sendEntryMessageToOthers(shopId, previousRank); + notification.sendMessageAsPostponed(member,previousRank); + return toMemberWaitingResponse(waiting, rank); } @@ -89,15 +86,16 @@ public MemberWaitingResponse postponeWaiting(Member member) { public MemberWaitingResponse cancelWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); Shop shop = waiting.getShop(); + Owner owner = getOwnerEntity(shop); + Long previousRank = waitingLineRepository.findRank(shop.getId(), waiting.getId()); waitingLineRepository.cancel(shop.getId(), waiting.getId()); waiting.changeStatusCanceled(); - sendMessageToMember(member, WaitingStatus.CANCELED, -1L); - if (previousRank <= 3) { - sendMessageToThirdRankMember(shop.getId()); - } + notification.sendEntryMessageToOthers(shop.getId(), previousRank); + notification.sendMessageAsCanceled(member, owner, previousRank); + return toMemberWaitingResponse(waiting, -1L); } @@ -117,33 +115,6 @@ public MemberWaitingHistoryListResponse getWaitingHistory(Member member) { return toMemberWaitingListResponse(waitings); } - public void sendMessageToThirdRankMember(Long shopId) { - Long thirdRankWaitingId = waitingLineRepository.findThirdRankValue(shopId); - if (thirdRankWaitingId != null) { - Member thirdRankMember = waitingRepository.findWaitingWithMember(thirdRankWaitingId) - .getMember(); - SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() - .member(thirdRankMember) - .content(THIRD_RANK.getMessage()) - .build(); - publisher.publishEvent(request); - } - } - - public void sendMessageToMember(Member member, WaitingStatus status, Long rank) { - StringBuilder content = new StringBuilder(); - if (status == PROGRESS) { - content.append(String.format(REGISTERED.getMessage(), rank)); - } else { - content.append(CANCELED.getMessage()); - } - SendMessageToMemberRequest request = SendMessageToMemberRequest.builder() - .member(member) - .content(content.toString()) - .build(); - publisher.publishEvent(request); - } - private void validateIfMemberWaitingExists(Member member) { if (waitingRepository.existsByMemberAndStatus(member, PROGRESS)) { throw new BadRequestCustomException(ALREADY_PROGRESS_WAITING_EXISTS); @@ -158,6 +129,12 @@ public Shop getShopEntity(Long shopId) { return shop; } + public Owner getOwnerEntity(Shop shop) { + return ownerRepository.findOwnerByShop(shop).orElseThrow( + () -> new NotFoundCustomException(NOT_EXIST_OWNER) + ); + } + public Waiting getWaitingEntityInProgress(Member member) { return waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_PROGRESS_WAITING)); diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 4807ae6c..4e32aa02 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; +import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.*; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingResponse; @@ -22,7 +23,7 @@ public class OwnerWaitingService { private final WaitingRepository waitingRepository; private final WaitingLineRepository waitingLineRepository; - private final MemberWaitingService memberWaitingService; + private final WaitingNotification waitingNotification; @Transactional(readOnly = true) public OwnerWaitingListResponse getShopAllWaiting(Owner owner) { @@ -36,10 +37,17 @@ public OwnerWaitingListResponse getShopAllWaiting(Owner owner) { public OwnerWaitingResponse entryWaiting(Owner owner) { Long shopId = owner.getShop().getId(); Long enteredWaitingId = waitingLineRepository.entry(shopId); - Waiting waiting = waitingRepository.findById(enteredWaitingId) - .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); + Waiting waiting = getWaitingEntity(enteredWaitingId); waiting.changeStatusCompleted(); - memberWaitingService.sendMessageToThirdRankMember(shopId); + + waitingNotification.sendMessageAsCompleted(waiting.getMember()); + waitingNotification.sendEntryMessageToOthers(shopId,1L); + return toOwnerWaitingResponse(waiting, 0L); } + + private Waiting getWaitingEntity(Long waitingId){ + return waitingRepository.findById(waitingId) + .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); + } } From e530e2173abd455e739dc62d8f0bf821e1f73879 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 17:26:49 +0900 Subject: [PATCH 574/603] =?UTF-8?q?feat=20:=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=A1=9C=EC=A7=81=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberWaitingServiceTest.java | 19 +++++++++++-------- .../service/OwnerWaitingServiceTest.java | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 2cce6d12..4204ef0d 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -11,6 +11,8 @@ import static org.mockito.Mockito.mock; import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; @@ -33,14 +35,15 @@ @ExtendWith(MockitoExtension.class) class MemberWaitingServiceTest { + @Mock + WaitingNotification waitingNotification; + + @Mock + private OwnerRepository ownerRepository; @Mock private WaitingRepository waitingRepository; @Mock private ShopRepository shopRepository; - - @Mock - private ApplicationEventPublisher publisher; - @Mock private WaitingLineRepository waitingLineRepository; @InjectMocks @@ -55,17 +58,17 @@ void createWaiting() { .build(); Shop shop = mock(Shop.class); Member member = mock(Member.class); + Owner owner = mock(Owner.class); Waiting waiting = Waiting.builder() .member(member) .shop(shop) .waitingNumber(1) .peopleCount(2) .build(); - + given(ownerRepository.findOwnerByShop(shop)).willReturn(Optional.of(owner)); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); given(shop.getId()).willReturn(1L); - given(waitingRepository.existsByMemberAndStatus(member, PROGRESS)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); @@ -90,7 +93,6 @@ void postponeWaiting() { given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); - given(waitingRepository.findWaitingWithMember(anyLong())).willReturn(waiting); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); given(waitingLineRepository.findRank(anyLong(), anyLong())).willReturn(3L); @@ -113,12 +115,13 @@ void cancelWaiting() { Shop shop = mock(Shop.class); Member member = mock(Member.class); Waiting waiting = mock(Waiting.class); + Owner owner = mock(Owner.class); given(waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS)).willReturn( Optional.of(waiting)); + given(ownerRepository.findOwnerByShop(shop)).willReturn(Optional.of(owner)); given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(CANCELED); - given(waitingRepository.findWaitingWithMember(anyLong())).willReturn(waiting); doNothing().when(waiting).changeStatusCanceled(); //when diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index d06b277c..df7bc3e8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -32,7 +32,7 @@ class OwnerWaitingServiceTest { private OwnerRepository ownerRepository; @Mock - private MemberWaitingService memberWaitingService; + private WaitingNotification waitingNotification; @Mock private WaitingRepository waitingRepository; From 55caa7a9ef76ea373c47581ba57a9b547ab45c1d Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 17:30:06 +0900 Subject: [PATCH 575/603] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=9B=A8=EC=9D=B4=ED=8C=85=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EC=A0=9C=EC=96=B4=EC=9E=90=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/service/MemberWaitingService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 578e719f..cd6a5d70 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -59,8 +59,8 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, Waiting savedWaiting = waitingRepository.save(waiting); waitingLineRepository.save(shopId, waiting.getId()); // 대기열 저장 - Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); + notification.sendMessageAsCreated(member, owner,rank); return toMemberWaitingResponse(savedWaiting, rank); @@ -121,7 +121,7 @@ private void validateIfMemberWaitingExists(Member member) { } } - public Shop getShopEntity(Long shopId) { + private Shop getShopEntity(Long shopId) { Shop shop = shopRepository.findById(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) ); @@ -129,13 +129,13 @@ public Shop getShopEntity(Long shopId) { return shop; } - public Owner getOwnerEntity(Shop shop) { + private Owner getOwnerEntity(Shop shop) { return ownerRepository.findOwnerByShop(shop).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_OWNER) ); } - public Waiting getWaitingEntityInProgress(Member member) { + private Waiting getWaitingEntityInProgress(Member member) { return waitingRepository.findByMemberAndStatusWithShop(member, PROGRESS) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_PROGRESS_WAITING)); } From 75bbea320aa82f9784e2e1ffe2c2b16bace4deb7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 17:41:15 +0900 Subject: [PATCH 576/603] =?UTF-8?q?feat=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingControllerTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 602c9d4d..f26cc92f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -22,6 +22,9 @@ import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -48,20 +51,20 @@ class MemberWaitingControllerTest extends BaseIntegrationTest { @Autowired private MemberRepository memberRepository; @Autowired + private OwnerRepository ownerRepository; + @Autowired private WaitingRepository waitingRepository; - @Autowired private WaitingLineRepository waitingLineRepository; @Autowired private ShopRepository shopRepository; + @Autowired + private StringRedisTemplate redisTemplate; private Member member1, member2, member3; private Shop shop; private Waiting waiting1, waiting2, waiting3; private List waitings; - @Autowired - private StringRedisTemplate redisTemplate; - @BeforeEach void setUp() { member1 = MemberFixture.member("test1@naver.com"); @@ -71,6 +74,11 @@ void setUp() { shop = ShopFixture.shopWith24(); shopRepository.save(shop); + + Owner owner = OwnerFixture.getOwner("owner@naver.com", "owner"); + owner.insertShop(shop); + ownerRepository.save(owner); + waiting1 = Waiting.builder() .member(member1) .shop(shop) @@ -270,8 +278,7 @@ void getMemberWaitingHistory() throws Exception { .andExpect(jsonPath("$.memberWaitings[1].status").value(CANCELED.getDescription())) .andExpect(jsonPath("$.memberWaitings[2].waitingId").value(completedWaiting.getId())) .andExpect(jsonPath("$.memberWaitings[2].status").value(COMPLETED.getDescription())) - .andDo(MockMvcResultHandlers.print()) - ; + .andDo(MockMvcResultHandlers.print()); } private HttpHeaders getHttpHeaders(Member member) { From 60bab57685d4ea2709dd65137576a05a5427682e Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 19:16:30 +0900 Subject: [PATCH 577/603] =?UTF-8?q?feat=20:=20redis=20=EB=8C=80=EA=B8=B0?= =?UTF-8?q?=EC=97=B4=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicWaitingLineRepository.java | 6 ++- .../RedisWaitingLineRepository.java | 54 ++++--------------- .../waitingline/WaitingLineRepository.java | 4 +- 3 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index e1be238a..5c98007e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -20,9 +20,10 @@ public class BasicWaitingLineRepository implements WaitingLineRepository { public final Map> waitingLines = new ConcurrentHashMap<>(); - public void save(Long shopId, Long waitingId) { + public Long save(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.computeIfAbsent(shopId, k -> new LinkedList<>()); waitingLine.add(waitingId); + return findRank(shopId, waitingId); } public Long entry(Long shopId) { @@ -46,7 +47,7 @@ public void cancel(Long shopId, Long waitingId) { } } - public void postpone(Long shopId, Long waitingId) { + public Long postpone(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); validateIfWaitingExists(waitingLine, waitingId); validateIfPostponeAvailable(shopId, waitingId); @@ -57,6 +58,7 @@ public void postpone(Long shopId, Long waitingId) { break; } } + return findRank(shopId, waitingId); } public Long findRank(Long shopId, Long waitingId) { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index bbcf4ad1..96c0f7a3 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -12,9 +12,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Primary; -import org.springframework.dao.DataAccessException; -import org.springframework.data.redis.core.RedisOperations; -import org.springframework.data.redis.core.SessionCallback; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; @@ -26,21 +23,9 @@ public class RedisWaitingLineRepository implements WaitingLineRepository { private final StringRedisTemplate redisTemplate; - public void save(Long shopId, Long waitingId) { - redisTemplate.execute(new SessionCallback<>() { - @Override - public Object execute(RedisOperations operations) - throws DataAccessException { - try { - operations.multi(); - redisTemplate.opsForList().leftPush("s" + shopId, waitingId.toString()); - return operations.exec(); - } catch (Exception e) { - operations.discard(); - } - return operations.exec(); - } - }); + public Long save(Long shopId, Long waitingId) { + redisTemplate.opsForList().leftPush("s" + shopId, waitingId.toString()); + return findRank(shopId, waitingId); } public List getShopWaitingIdsInOrder(Long shopId) { @@ -61,33 +46,18 @@ public Long entry(Long shopId) { } public void cancel(Long shopId, Long waitingId) { - validateIfWaitingExists(shopId, waitingId); + validateIfWaitingExists(shopId, waitingId); //삭제할 웨이팅 존재하는지 확인 redisTemplate.opsForList().remove("s" + shopId, 1, waitingId.toString()); } - public void postpone(Long shopId, Long waitingId) { + public Long postpone(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); validateIfPostponeAvailable(shopId, waitingId); + String key = "s" + shopId; - if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { - throw new BadRequestCustomException(ALREADY_END_LINE); - } - redisTemplate.execute(new SessionCallback<>() { - @Override - public Object execute(RedisOperations operations) - throws DataAccessException { - try { - operations.multi(); - - redisTemplate.opsForList().remove(key, 1, waitingId.toString()); - redisTemplate.opsForList().leftPush(key, waitingId.toString()); - return operations.exec(); - } catch (Exception e) { - operations.discard(); - } - return null; - } - }); + redisTemplate.opsForList().remove(key, 1, waitingId.toString()); + redisTemplate.opsForList().leftPush(key, waitingId.toString()); + return findRank(shopId, waitingId); } public Long findRank(Long shopId, Long waitingId) { @@ -110,7 +80,7 @@ public Long getWaitingLineSize(Long shopId) { return redisTemplate.opsForList().size("s" + shopId); } - public void validateIfWaitingExists(Long shopId, Long waitingId) { + private void validateIfWaitingExists(Long shopId, Long waitingId) { Long index = redisTemplate.opsForList().indexOf("s" + shopId, waitingId.toString()); if (index == null) { throw new NotFoundCustomException(WAITING_DOES_NOT_EXIST); @@ -119,9 +89,7 @@ public void validateIfWaitingExists(Long shopId, Long waitingId) { private void validateIfPostponeAvailable(Long shopId, Long waitingId) { if (Objects.equals(findRank(shopId, waitingId), getWaitingLineSize(shopId))) { - { - throw new BadRequestCustomException(ALREADY_END_LINE); - } + throw new BadRequestCustomException(ALREADY_END_LINE); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index 8368c079..0df6b05a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -4,13 +4,13 @@ public interface WaitingLineRepository { - void save(Long shopId, Long waitingId); + Long save(Long shopId, Long waitingId); Long entry(Long shopId); void cancel(Long shopId, Long waitingId); - void postpone(Long shopId, Long waitingId); + Long postpone(Long shopId, Long waitingId); Long findRank(Long shopId, Long waitingId); From 1d4f6a09b743fc38741dcc4706ff891e43221bcc Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 19:17:02 +0900 Subject: [PATCH 578/603] =?UTF-8?q?refactor=20:=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20redis=20=EB=8C=80=EA=B8=B0=EC=97=B4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/service/MemberWaitingService.java | 6 ++---- .../waiting/service/MemberWaitingServiceTest.java | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index cd6a5d70..39f3dd05 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -58,8 +58,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, Waiting waiting = toWaiting(request, waitingNumber, member, shop); //waiting 생성 후 저장 Waiting savedWaiting = waitingRepository.save(waiting); - waitingLineRepository.save(shopId, waiting.getId()); // 대기열 저장 - Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); + Long rank = waitingLineRepository.save(shopId, waiting.getId());// 대기열 저장 notification.sendMessageAsCreated(member, owner,rank); @@ -73,8 +72,7 @@ public MemberWaitingResponse postponeWaiting(Member member) { Long previousRank = waitingLineRepository.findRank(shopId, waiting.getId()); // 미루기 전 rank 저장 waiting.decreasePostponeRemainingCount(); - waitingLineRepository.postpone(shopId, waiting.getId()); - Long rank = waitingLineRepository.findRank(shopId, waiting.getId()); // 미룬 후 rank 저장 + Long rank = waitingLineRepository.postpone(shopId, waiting.getId());// 미룬 후 rank 저장 notification.sendEntryMessageToOthers(shopId, previousRank); notification.sendMessageAsPostponed(member,previousRank); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 4204ef0d..2f44eb12 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -71,7 +71,7 @@ void createWaiting() { given(shop.getId()).willReturn(1L); given(waitingRepository.existsByMemberAndStatus(member, PROGRESS)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); - given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); + given(waitingLineRepository.save(shop.getId(), waiting.getId())).willReturn(1L); //when MemberWaitingResponse response = memberWaitingService.createWaiting(1L, member, request); From f93d7f826cbe48e64e6101f2b727339357e550f3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 19:19:32 +0900 Subject: [PATCH 579/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/BasicWaitingLineRepository.java | 4 ++-- .../catchtable/waiting/service/MemberWaitingService.java | 7 ++++--- .../catchtable/waiting/service/OwnerWaitingService.java | 5 ++--- .../catchtable/waiting/service/WaitingNotification.java | 3 ++- .../waiting/controller/OwnerWaitingControllerDocsTest.java | 4 ++-- .../waiting/service/MemberWaitingServiceTest.java | 1 - 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 5c98007e..2c865928 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -74,11 +74,11 @@ public Long findRank(Long shopId, Long waitingId) { return -1L; } - public Long findRankValue(Long shopId,int rank) { + public Long findRankValue(Long shopId, int rank) { Queue waitingLine = waitingLines.get(shopId); int index = 0; for (Long element : waitingLine) { - if (index == rank-1) { + if (index == rank - 1) { return element; } index++; diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 39f3dd05..9ccc15b7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -60,7 +60,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, Long rank = waitingLineRepository.save(shopId, waiting.getId());// 대기열 저장 - notification.sendMessageAsCreated(member, owner,rank); + notification.sendMessageAsCreated(member, owner, rank); return toMemberWaitingResponse(savedWaiting, rank); } @@ -69,13 +69,14 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, public MemberWaitingResponse postponeWaiting(Member member) { Waiting waiting = getWaitingEntityInProgress(member); Long shopId = waiting.getShop().getId(); - Long previousRank = waitingLineRepository.findRank(shopId, waiting.getId()); // 미루기 전 rank 저장 + Long previousRank = waitingLineRepository.findRank(shopId, + waiting.getId()); // 미루기 전 rank 저장 waiting.decreasePostponeRemainingCount(); Long rank = waitingLineRepository.postpone(shopId, waiting.getId());// 미룬 후 rank 저장 notification.sendEntryMessageToOthers(shopId, previousRank); - notification.sendMessageAsPostponed(member,previousRank); + notification.sendMessageAsPostponed(member, previousRank); return toMemberWaitingResponse(waiting, rank); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 4e32aa02..1f550556 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -1,7 +1,6 @@ package com.prgrms.catchtable.waiting.service; import static com.prgrms.catchtable.common.exception.ErrorCode.WAITING_DOES_NOT_EXIST; -import static com.prgrms.catchtable.common.notification.WaitingNotificationContent.*; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingResponse; @@ -41,12 +40,12 @@ public OwnerWaitingResponse entryWaiting(Owner owner) { waiting.changeStatusCompleted(); waitingNotification.sendMessageAsCompleted(waiting.getMember()); - waitingNotification.sendEntryMessageToOthers(shopId,1L); + waitingNotification.sendEntryMessageToOthers(shopId, 1L); return toOwnerWaitingResponse(waiting, 0L); } - private Waiting getWaitingEntity(Long waitingId){ + private Waiting getWaitingEntity(Long waitingId) { return waitingRepository.findById(waitingId) .orElseThrow(() -> new NotFoundCustomException(WAITING_DOES_NOT_EXIST)); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java index 6369e83f..4c654c1f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/WaitingNotification.java @@ -23,6 +23,7 @@ @Component @RequiredArgsConstructor public class WaitingNotification { + private final ApplicationEventPublisher publisher; private final WaitingLineRepository waitingLineRepository; private final WaitingRepository waitingRepository; @@ -41,7 +42,7 @@ public void sendMessageAsCompleted(Member member) { } public void sendMessageAsCanceled(Member member, Owner owner, Long rank) { - sendMessageToMember(member,MEMBER_CANCELED.getContent()); + sendMessageToMember(member, MEMBER_CANCELED.getContent()); sendMessageToOwner(owner, String.format(OWNER_CANCELED.getContent(), rank)); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java index 5e88f086..7721303f 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerDocsTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.waiting.controller; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static org.mockito.BDDMockito.given; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.payload.JsonFieldType.NUMBER; @@ -15,7 +16,6 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; import com.prgrms.catchtable.waiting.service.OwnerWaitingService; diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 2f44eb12..35523c60 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -30,7 +30,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.ApplicationEventPublisher; @ExtendWith(MockitoExtension.class) class MemberWaitingServiceTest { From bddc416a5c714ca3a6b9919365635b1bca5145fe Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 15 Jan 2024 20:23:44 +0900 Subject: [PATCH 580/603] =?UTF-8?q?fix=20:=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/service/MemberWaitingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 9ccc15b7..2f902aec 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -76,7 +76,7 @@ public MemberWaitingResponse postponeWaiting(Member member) { Long rank = waitingLineRepository.postpone(shopId, waiting.getId());// 미룬 후 rank 저장 notification.sendEntryMessageToOthers(shopId, previousRank); - notification.sendMessageAsPostponed(member, previousRank); + notification.sendMessageAsPostponed(member, rank); return toMemberWaitingResponse(waiting, rank); } From e2c35892a56e7b37f229174e7df4a2ceb4301555 Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 16 Jan 2024 18:44:39 +0900 Subject: [PATCH 581/603] =?UTF-8?q?fix=20:=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/controller/JwtAuthenticationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index 7e0f4472..c5bc175e 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -77,7 +77,7 @@ public void init() { } @Test - @DisplayName("Member의 AceessToken이 유효하다면, MemberWhiteList 접근이 가능하다.") + @DisplayName("Member의 AcceessToken이 유효하다면, MemberWhiteList 접근이 가능하다.") void testMemberAccessToken() throws Exception { httpHeaders.add("AccessToken", memberToken.getAccessToken()); httpHeaders.add("RefreshToken", memberToken.getRefreshToken()); From 9dfae2a62a8fe6569265d66f3e8e373e6e064c7b Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Tue, 16 Jan 2024 18:45:29 +0900 Subject: [PATCH 582/603] =?UTF-8?q?refactor=20:=20final=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/security/controller/JwtAuthenticationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java index c5bc175e..165e10e8 100644 --- a/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java +++ b/src/test/java/com/prgrms/catchtable/security/controller/JwtAuthenticationTest.java @@ -38,8 +38,8 @@ class JwtAuthenticationTest extends BaseIntegrationTest { private Member loginMember; private Owner loginOwner; - private String memberEmail = "abc1234@gmail.com"; - private String ownerEmail = "qwer5678@naver.com"; + private final String memberEmail = "abc1234@gmail.com"; + private final String ownerEmail = "qwer5678@naver.com"; private Token memberToken; private Token ownerToken; private CreateReservationRequest createReservationRequest = ReservationFixture.getCreateReservationRequest(); From c17dcc352055cfbc4d594275345d16b5ca5602f8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:25:44 +0900 Subject: [PATCH 583/603] =?UTF-8?q?feat=20:=20shop=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=8C=80=EA=B8=B0=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B5=AC=ED=95=98=EB=8A=94=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/shop/domain/Shop.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index cf641445..e2066bf7 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -1,15 +1,13 @@ package com.prgrms.catchtable.shop.domain; import static com.prgrms.catchtable.common.exception.ErrorCode.SHOP_NOT_RUNNING; -import static jakarta.persistence.CascadeType.*; +import static jakarta.persistence.CascadeType.ALL; import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -52,6 +50,9 @@ public class Shop extends BaseEntity { @Column(name = "capacity") private int capacity; + @Column(name = "waiting_count") + private int waitingCount; + @Column(name = "opening_time") private LocalTime openingTime; @@ -70,11 +71,16 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.category = category; this.address = address; this.capacity = capacity; + this.waitingCount = 0; this.openingTime = openingTime; this.closingTime = closingTime; } - public void updateMenuList(List menuList){ + public int findWaitingNumber(){ + return ++waitingCount; + } + + public void updateMenuList(List menuList) { this.menuList.addAll(menuList); this.menuList.forEach(menu -> menu.insertShop(this)); } From 682c921d40f9d798b0d663d7b703dcef6decdb37 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:28:05 +0900 Subject: [PATCH 584/603] =?UTF-8?q?feat=20:=20repository=20waitingCount=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 860f893f..8009a13c 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -4,9 +4,17 @@ import java.util.Optional; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.transaction.annotation.Transactional; public interface ShopRepository extends JpaRepository, ShopRepositoryCustom { @EntityGraph(attributePaths = {"menuList"}) Optional findShopById(Long id); + + @Transactional + @Modifying(clearAutomatically = true) + @Query("update Shop s set s.waitingCount = 0") + void initWaitingCount(); } From 64ba3dd5f309a6b59e6800f1bfd25560da346dd5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:29:06 +0900 Subject: [PATCH 585/603] =?UTF-8?q?feat=20:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/repository/ShopRepositoryTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java index 179f0d2e..30ebfcb3 100644 --- a/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/shop/repository/ShopRepositoryTest.java @@ -1,6 +1,7 @@ package com.prgrms.catchtable.shop.repository; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE; import com.prgrms.catchtable.shop.domain.Category; @@ -73,4 +74,26 @@ void findSearchTest() { //then assertThat(searchList.size()).isZero(); } + + @Test + @DisplayName("벌크 연산으로 가게 웨이팅 수를 0으로 만들 수 있다.") + void updateWaitingStatus() { + //given + Shop shop1 = ShopFixture.shop(); + shop1.findWaitingNumber(); // waitingCount 증가 + Shop shop2 = ShopFixture.shop(); + shop2.findWaitingNumber(); + shopRepository.saveAll(List.of(shop1, shop2)); + + //when + shopRepository.initWaitingCount(); + Shop savedShop1 = shopRepository.findById(shop1.getId()).orElseThrow(); + Shop savedShop2 = shopRepository.findById(shop2.getId()).orElseThrow(); + + //then + assertAll( + () -> assertThat(savedShop1.getWaitingCount()).isZero(), + () -> assertThat(savedShop2.getWaitingCount()).isZero() + ); + } } \ No newline at end of file From 6904b2f91232ac13adc9bcafc29cca4be60fb0be Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:30:14 +0900 Subject: [PATCH 586/603] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84?= =?UTF-8?q?=EB=9F=AC=20=ED=99=9C=EC=9A=A9=ED=95=B4=20=EB=A7=A4=EC=9D=BC=20?= =?UTF-8?q?=EC=B4=9D=20=EB=8C=80=EA=B8=B0=EC=88=98=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/schedular/WaitingScheduler.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java index ba4ccc51..e72424e9 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java +++ b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; +import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import java.util.Set; import lombok.RequiredArgsConstructor; @@ -21,17 +22,24 @@ public class WaitingScheduler { private final StringRedisTemplate redisTemplate; private final WaitingRepository waitingRepository; + private final ShopRepository shopRepository; - //매일 자정 레디스 데이터 비우기 + // 매일 자정 레디스 데이터 비우기 @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") public void clearRedis() { Set keys = redisTemplate.keys("s*"); redisTemplate.delete(keys); } - //매일 자정 대기 상태 바꾸기 + // 매일 자정 대기 상태 바꾸기 @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") - public void changeProgressStatus() { + public void updateProgressStatus() { waitingRepository.updateWaitingStatus(CANCELED, PROGRESS); } + + // 매일 자정 대기 수 초기화 + @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") + public void initWaitingCount(){ + shopRepository.initWaitingCount(); + } } From b9cb35e60953bfbf89c0cffdb126fb45bee5ae32 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:32:49 +0900 Subject: [PATCH 587/603] =?UTF-8?q?refactor=20:=20=EB=8C=80=EA=B8=B0=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=B0=9C=EA=B8=89=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 2f902aec..d8ac66a4 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -22,8 +22,6 @@ import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; import lombok.RequiredArgsConstructor; @@ -33,11 +31,6 @@ @RequiredArgsConstructor @Service public class MemberWaitingService { - - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(0, 0, 0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(23, 59, 59)); private final WaitingRepository waitingRepository; private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; @@ -52,9 +45,7 @@ public MemberWaitingResponse createWaiting(Long shopId, Member member, validateIfMemberWaitingExists(member); // 기존 진행 중인 waiting이 있는지 검증 - int waitingNumber = (waitingRepository.countByShopAndCreatedAtBetween(shop, - START_DATE_TIME, END_DATE_TIME)).intValue() + 1; // 대기 번호 생성 - + int waitingNumber = shop.findWaitingNumber();// 대기 번호 생성 Waiting waiting = toWaiting(request, waitingNumber, member, shop); //waiting 생성 후 저장 Waiting savedWaiting = waitingRepository.save(waiting); From 50c2b9bd9fd143e5578f1835485af8c1478421c0 Mon Sep 17 00:00:00 2001 From: hs12 Date: Tue, 16 Jan 2024 23:33:19 +0900 Subject: [PATCH 588/603] =?UTF-8?q?refactor=20:=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index f26cc92f..40bfc6b8 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -73,6 +73,7 @@ void setUp() { memberRepository.saveAll(List.of(member1, member2, member3)); shop = ShopFixture.shopWith24(); + ReflectionTestUtils.setField(shop,"waitingCount",3); shopRepository.save(shop); Owner owner = OwnerFixture.getOwner("owner@naver.com", "owner"); @@ -145,7 +146,6 @@ void createWaitingSuccess() throws Exception { waiting1.changeStatusCanceled(); waitingRepository.save(waiting1); - // when, then mockMvc.perform(post("/waitings/{shopId}", shop.getId()) .contentType(APPLICATION_JSON) @@ -155,7 +155,7 @@ void createWaitingSuccess() throws Exception { .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) .andExpect(jsonPath("$.rank").value(4)) - .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) + .andExpect(jsonPath("$.waitingNumber").value(waitings.size()+1)) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) .andDo(MockMvcResultHandlers.print()); From d04a32d9688b3da49ea5d500fd0573c112836cdc Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 03:12:14 +0900 Subject: [PATCH 589/603] =?UTF-8?q?feat=20:=20shop=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=A1=B0=ED=9A=8C=20=EB=B9=84=EA=B4=80=EC=A0=81=20?= =?UTF-8?q?=EB=9D=BD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/shop/repository/ShopRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java index 8009a13c..fc22af52 100644 --- a/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java +++ b/src/main/java/com/prgrms/catchtable/shop/repository/ShopRepository.java @@ -1,11 +1,14 @@ package com.prgrms.catchtable.shop.repository; import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.LockModeType; import java.util.Optional; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; public interface ShopRepository extends JpaRepository, ShopRepositoryCustom { @@ -13,6 +16,10 @@ public interface ShopRepository extends JpaRepository, ShopRepositor @EntityGraph(attributePaths = {"menuList"}) Optional findShopById(Long id); + @Lock(LockModeType.PESSIMISTIC_WRITE) + @Query("select s from Shop s where s.id = :id") + Optional findByIdWithPessimisticLock(@Param("id") Long id); + @Transactional @Modifying(clearAutomatically = true) @Query("update Shop s set s.waitingCount = 0") From 2e1a418ab850bfd3c8ed7d879f3d84524507135f Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 03:16:30 +0900 Subject: [PATCH 590/603] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20repository=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 2 -- .../repository/WaitingRepositoryTest.java | 28 ------------------- 2 files changed, 30 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index e7c3a6d6..040561bf 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -17,8 +17,6 @@ public interface WaitingRepository extends JpaRepository { boolean existsByMemberAndStatus(Member member, WaitingStatus status); - Long countByShopAndCreatedAtBetween(Shop shop, LocalDateTime start, LocalDateTime end); - @Query("select w from Waiting w join fetch w.shop " + "where w.member = :member and w.status = :status") Optional findByMemberAndStatusWithShop(@Param("member") Member member, diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index fa32f3c1..4c34a9be 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -15,9 +15,6 @@ import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.fixture.WaitingFixture; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -25,16 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.util.ReflectionTestUtils; @DataJpaTest @AutoConfigureTestDatabase(replace = NONE) class WaitingRepositoryTest { - private final LocalDateTime START_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(0, 0, 0)); - private final LocalDateTime END_DATE_TIME = LocalDateTime.of(LocalDate.now(), - LocalTime.of(23, 59, 59)); @Autowired private WaitingRepository waitingRepository; @Autowired @@ -55,26 +47,6 @@ void setUp() { shopRepository.save(shop); } - @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") - @Test - void countByShopAndCreatedAtBetween() { - //given - Waiting yesterdayWaiting = WaitingFixture.progressWaiting(member1, shop, 1); - Waiting completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); - Waiting normalWaiting = WaitingFixture.progressWaiting(member3, shop, 3); - waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); - - ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", - LocalDateTime.now().minusDays(1)); - waitingRepository.save(yesterdayWaiting); - - //when - Long count = waitingRepository.countByShopAndCreatedAtBetween(shop, START_DATE_TIME, - END_DATE_TIME); - //then - assertThat(count).isEqualTo(2L); //waiting2, waiting3 - } - @DisplayName("멤버의 아이디 리스트로 waiting 목록을 조회 가능하다.") @Test void findByIdsWithMember() { From 8c3fd8cfae19a4c2e61b2eb1f441f14a8b6f11d8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 03:19:37 +0900 Subject: [PATCH 591/603] =?UTF-8?q?feat=20:=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=ED=95=A8=EC=88=98=20=EB=B9=84=EA=B4=80?= =?UTF-8?q?=EC=A0=81=20=EB=9D=BD=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index d8ac66a4..c256fc6e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -31,6 +31,7 @@ @RequiredArgsConstructor @Service public class MemberWaitingService { + private final WaitingRepository waitingRepository; private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; @@ -40,11 +41,11 @@ public class MemberWaitingService { @Transactional public MemberWaitingResponse createWaiting(Long shopId, Member member, CreateWaitingRequest request) { - Shop shop = getShopEntity(shopId); // 연관 엔티티 조회 - Owner owner = getOwnerEntity(shop); - validateIfMemberWaitingExists(member); // 기존 진행 중인 waiting이 있는지 검증 + Shop shop = getShopEntityWithPessimisticLock(shopId); // 연관 엔티티 조회 + Owner owner = getOwnerEntity(shop); + int waitingNumber = shop.findWaitingNumber();// 대기 번호 생성 Waiting waiting = toWaiting(request, waitingNumber, member, shop); //waiting 생성 후 저장 Waiting savedWaiting = waitingRepository.save(waiting); @@ -111,8 +112,8 @@ private void validateIfMemberWaitingExists(Member member) { } } - private Shop getShopEntity(Long shopId) { - Shop shop = shopRepository.findById(shopId).orElseThrow( + private Shop getShopEntityWithPessimisticLock(Long shopId) { + Shop shop = shopRepository.findByIdWithPessimisticLock(shopId).orElseThrow( () -> new NotFoundCustomException(NOT_EXIST_SHOP) ); shop.validateIfShopOpened(LocalTime.now()); From 192ef8a076ab45b03d47bb45f8661d6894d81958 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 03:19:59 +0900 Subject: [PATCH 592/603] =?UTF-8?q?feat=20:=20=EC=9B=A8=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=20=EC=83=9D=EC=84=B1=20=EB=8F=99=EC=8B=9C?= =?UTF-8?q?=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingServiceIntegrationTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java new file mode 100644 index 00000000..69589698 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java @@ -0,0 +1,79 @@ +package com.prgrms.catchtable.waiting.service; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class MemberWaitingServiceIntegrationTest { + + @Autowired + private ShopRepository shopRepository; + @Autowired + private OwnerRepository ownerRepository; + @Autowired + private MemberRepository memberRepository; + @Autowired + private MemberWaitingService memberWaitingService; + + private Shop shop; + private CreateWaitingRequest request; + + @BeforeEach + void setUp() { + request = WaitingFixture.createWaitingRequest(); + + shop = ShopFixture.shopWith24(); + shopRepository.save(shop); + + Owner owner = OwnerFixture.getOwner(shop); + ownerRepository.save(owner); + } + + @DisplayName("동시에 50개 요청이 들어와도 각각 다른 대기번호를 부여한다.") + @Test + void createWaitingNumberConcurrency() throws InterruptedException { + int threadCount = 50; + ExecutorService executorService = Executors.newFixedThreadPool(32); + CountDownLatch latch = new CountDownLatch( + threadCount); // 다른 thread에서 수행 중인 작업이 완료될 때까지 대기할 수 있도록 돕는 클래스 + + for (int i = 0; i < threadCount; i++) { + Member member = MemberFixture.member(String.format("hyun%d@gmail.com", i)); // validateMemberWaitingExists 오류 안 나도록 (한 기기 당 한 회원 웨이팅 생성) + memberRepository.save(member); + executorService.submit(() -> { + try { + memberWaitingService.createWaiting(shop.getId(), member, request); + } catch (Exception e) { + e.printStackTrace(); + } finally { + latch.countDown(); + } + }); + } + + latch.await(); //다른 스레드에서 수행중인 작업이 완료될 때까지 대기 + + int waitingCount = shopRepository.findById(1L).orElseThrow().getWaitingCount(); + + assertEquals(50, waitingCount); + } +} \ No newline at end of file From 9fd8bafa36281651be290d34f8de1996498d4b72 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 10:22:55 +0900 Subject: [PATCH 593/603] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/shop/domain/Shop.java | 2 +- .../catchtable/waiting/repository/WaitingRepository.java | 2 -- .../prgrms/catchtable/waiting/schedular/WaitingScheduler.java | 2 +- .../waiting/controller/MemberWaitingControllerTest.java | 4 ++-- .../waiting/service/MemberWaitingServiceIntegrationTest.java | 3 ++- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index e2066bf7..daff15c9 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -76,7 +76,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, this.closingTime = closingTime; } - public int findWaitingNumber(){ + public int findWaitingNumber() { return ++waitingCount; } diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 040561bf..5644b922 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -1,10 +1,8 @@ package com.prgrms.catchtable.waiting.repository; import com.prgrms.catchtable.member.domain.Member; -import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java index e72424e9..2988a0df 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java +++ b/src/main/java/com/prgrms/catchtable/waiting/schedular/WaitingScheduler.java @@ -39,7 +39,7 @@ public void updateProgressStatus() { // 매일 자정 대기 수 초기화 @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") - public void initWaitingCount(){ + public void initWaitingCount() { shopRepository.initWaitingCount(); } } diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 40bfc6b8..3ad68969 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -73,7 +73,7 @@ void setUp() { memberRepository.saveAll(List.of(member1, member2, member3)); shop = ShopFixture.shopWith24(); - ReflectionTestUtils.setField(shop,"waitingCount",3); + ReflectionTestUtils.setField(shop, "waitingCount", 3); shopRepository.save(shop); Owner owner = OwnerFixture.getOwner("owner@naver.com", "owner"); @@ -155,7 +155,7 @@ void createWaitingSuccess() throws Exception { .andExpect(jsonPath("$.shopId").value(shop.getId())) .andExpect(jsonPath("$.shopName").value(shop.getName())) .andExpect(jsonPath("$.rank").value(4)) - .andExpect(jsonPath("$.waitingNumber").value(waitings.size()+1)) + .andExpect(jsonPath("$.waitingNumber").value(waitings.size() + 1)) .andExpect(jsonPath("$.peopleCount").value(request.peopleCount())) .andExpect(jsonPath("$.status").value(PROGRESS.getDescription())) .andDo(MockMvcResultHandlers.print()); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java index 69589698..919015a6 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java @@ -57,7 +57,8 @@ void createWaitingNumberConcurrency() throws InterruptedException { threadCount); // 다른 thread에서 수행 중인 작업이 완료될 때까지 대기할 수 있도록 돕는 클래스 for (int i = 0; i < threadCount; i++) { - Member member = MemberFixture.member(String.format("hyun%d@gmail.com", i)); // validateMemberWaitingExists 오류 안 나도록 (한 기기 당 한 회원 웨이팅 생성) + Member member = MemberFixture.member(String.format("hyun%d@gmail.com", + i)); // validateMemberWaitingExists 오류 안 나도록 (한 기기 당 한 회원 웨이팅 생성) memberRepository.save(member); executorService.submit(() -> { try { From b849637d5f617fa45b0e532feacf4782d2c68dcc Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 10:46:35 +0900 Subject: [PATCH 594/603] =?UTF-8?q?feat=20:=20Owner=20logout=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/service/RefreshTokenService.java | 5 +++++ .../catchtable/owner/controller/OwnerController.java | 8 ++++++++ .../com/prgrms/catchtable/owner/service/OwnerService.java | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index d505ed88..212a8460 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -40,4 +40,9 @@ public RefreshToken getRefreshTokenByToken(String refreshToken) { return refreshTokenRepository.findRefreshTokenByToken(refreshToken) .orElseThrow(() -> new NotFoundCustomException(NOT_FOUND_REFRESH_TOKEN)); } + + @Transactional + public void deleteRefreshToken(String email){ + refreshTokenRepository.deleteRefreshTokenByEmail(email); + } } diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java index a8e781df..5cafb006 100644 --- a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.owner.controller; +import com.prgrms.catchtable.common.login.LogIn; import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; @@ -36,4 +38,10 @@ public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOw return ResponseEntity.ok(responseToken); } + @PostMapping("/logout") + public ResponseEntity logout(@LogIn Owner owner){ + ownerService.logout(owner.getEmail()); + return ResponseEntity.ok("logout"); + } + } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index 3998044c..425dd3b9 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -65,6 +65,11 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { return createTotalToken(loginOwner.getEmail()); } + @Transactional + public void logout(String email){ + refreshTokenService.deleteRefreshToken(email); + } + private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) { if (!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())) { throw new BadRequestCustomException(INVALID_EMAIL_OR_PASSWORD); From 75a13624b067d1519bc7ff4731088990afbbdbbf Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 10:58:42 +0900 Subject: [PATCH 595/603] =?UTF-8?q?feat=20:=20Owner=20logout=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/service/OwnerServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 0758a08b..35ed75c3 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -4,6 +4,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.Role; @@ -91,6 +93,17 @@ void loginSuccess() { assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(token); } + @Test + @DisplayName("로그아웃이 성공하면, RefreshToken을 삭제한다.") + void logoutSuccess() { + //when + ownerService.logout(email); + + //then + verify(refreshTokenService, times(1)).deleteRefreshToken(any()); + + } + @Test @DisplayName("해당 이메일의 유저가 존재하지 않으면 로그인을 실패한다") void loginFailureId() { From 7cd8d329a25c424ae377ae402390b143a2c4136e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 20:19:16 +0900 Subject: [PATCH 596/603] =?UTF-8?q?feat=20:=20Member=20login=20&=20logout?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 36 +++++++++++++++++++ .../member/service/MemberService.java | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/member/controller/MemberController.java diff --git a/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java new file mode 100644 index 00000000..06230af7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java @@ -0,0 +1,36 @@ +package com.prgrms.catchtable.member.controller; + +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.service.MemberService; +import java.net.URI; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberController { + + private final MemberService memberService; + + @GetMapping("/login/kakao") + public ResponseEntity loginRedirect(){ + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setLocation(URI.create("/oauth2/authorization/kakao")); + return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY); + } + + @PostMapping("/logout") + public ResponseEntity logout(@LogIn Member member){ + memberService.logout(member.getEmail()); + return ResponseEntity.ok("logout"); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 638c897c..9af6d339 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -34,6 +34,11 @@ public Token oauthLogin(OAuthAttribute attributes) { return createTotalToken(email); } + @Transactional + public void logout(String email){ + refreshTokenService.deleteRefreshToken(email); + } + private Token createTotalToken(String email) { Token totalToken = jwtTokenProvider.createToken(email, Role.MEMBER); refreshTokenService.saveRefreshToken(totalToken); From e8a25f9b6b1ba809fd002fe9da82823da5916da2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Wed, 17 Jan 2024 21:23:05 +0900 Subject: [PATCH 597/603] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20ci=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemberWaitingServiceIntegrationTest.java | 29 ++++++++++++------- .../service/MemberWaitingServiceTest.java | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java index 919015a6..728553d4 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceIntegrationTest.java @@ -16,13 +16,17 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.StringRedisTemplate; @SpringBootTest +@Disabled class MemberWaitingServiceIntegrationTest { @Autowired @@ -34,6 +38,9 @@ class MemberWaitingServiceIntegrationTest { @Autowired private MemberWaitingService memberWaitingService; + @Autowired + private StringRedisTemplate redisTemplate; + private Shop shop; private CreateWaitingRequest request; @@ -48,23 +55,26 @@ void setUp() { ownerRepository.save(owner); } - @DisplayName("동시에 50개 요청이 들어와도 각각 다른 대기번호를 부여한다.") + @AfterEach + void clear() { + redisTemplate.delete("s" + shop.getId()); + } + + @DisplayName("동시에 30개 요청이 들어와도 각각 다른 대기번호를 부여한다.") @Test void createWaitingNumberConcurrency() throws InterruptedException { - int threadCount = 50; - ExecutorService executorService = Executors.newFixedThreadPool(32); + int threadCount = 30; + ExecutorService executorService = Executors.newFixedThreadPool(30); CountDownLatch latch = new CountDownLatch( threadCount); // 다른 thread에서 수행 중인 작업이 완료될 때까지 대기할 수 있도록 돕는 클래스 - for (int i = 0; i < threadCount; i++) { Member member = MemberFixture.member(String.format("hyun%d@gmail.com", i)); // validateMemberWaitingExists 오류 안 나도록 (한 기기 당 한 회원 웨이팅 생성) memberRepository.save(member); + executorService.submit(() -> { try { memberWaitingService.createWaiting(shop.getId(), member, request); - } catch (Exception e) { - e.printStackTrace(); } finally { latch.countDown(); } @@ -72,9 +82,8 @@ void createWaitingNumberConcurrency() throws InterruptedException { } latch.await(); //다른 스레드에서 수행중인 작업이 완료될 때까지 대기 - - int waitingCount = shopRepository.findById(1L).orElseThrow().getWaitingCount(); - - assertEquals(50, waitingCount); + int waitingCount = shopRepository.findAll().get(0) + .getWaitingCount(); + assertEquals(threadCount, waitingCount); } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 35523c60..d143bfb3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -66,7 +66,7 @@ void createWaiting() { .build(); given(ownerRepository.findOwnerByShop(shop)).willReturn(Optional.of(owner)); doNothing().when(shop).validateIfShopOpened(any(LocalTime.class)); - given(shopRepository.findById(1L)).willReturn(Optional.of(shop)); + given(shopRepository.findByIdWithPessimisticLock(1L)).willReturn(Optional.of(shop)); given(shop.getId()).willReturn(1L); given(waitingRepository.existsByMemberAndStatus(member, PROGRESS)).willReturn(false); given(waitingRepository.save(any(Waiting.class))).willReturn(waiting); From 09efc17141401f656795fb0c55523fe85a71ca41 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 17 Jan 2024 23:40:54 +0900 Subject: [PATCH 598/603] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=ED=9A=8C=EC=9B=90=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EA=B9=8C=EC=A7=80=20=ED=8E=98=EC=B9=98=EC=A1=B0?= =?UTF-8?q?=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/repository/ReservationRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java index 2e3a63a5..b56f631c 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -18,6 +18,7 @@ public interface ReservationRepository extends JpaRepository List findAllWithReservationTimeAndShopByMemberId(@Param("member") Member member); @Query("select r from Reservation r " + + "join fetch r.member m " + "join fetch r.reservationTime rt " + "join fetch rt.shop " + "where r.id = :reservationId") From 4482c6845b08a83a0a96ebdb7db8210b1b281d31 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 17 Jan 2024 23:41:06 +0900 Subject: [PATCH 599/603] =?UTF-8?q?feat=20:=20mapper=EC=97=90=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EC=9D=B4=EB=A6=84=20=ED=95=84=EB=93=9C=20=EB=84=A3?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/dto/mapper/ReservationMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java index bd4dd02c..e9c7c9f6 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/mapper/ReservationMapper.java @@ -16,7 +16,7 @@ public class ReservationMapper { public static CreateReservationResponse toCreateReservationResponse(Reservation reservation) { return CreateReservationResponse.builder() .shopName(reservation.getShop().getName()) - .memberName("memberA") + .memberName(reservation.getMember().getName()) .date(reservation.getReservationTime().getTime()) .peopleCount(reservation.getPeopleCount()) .build(); @@ -35,7 +35,7 @@ public static GetAllReservationResponse toGetAllReservationRepsonse(Reservation public static ModifyReservationResponse toModifyReservationResponse(Reservation reservation) { return ModifyReservationResponse.builder() .shopName(reservation.getShop().getName()) - .memberName("memberA") + .memberName(reservation.getMember().getName()) .date(reservation.getReservationTime().getTime()) .peopleCount(reservation.getPeopleCount()) .build(); From 1f048325540f465a2ae37e54e02d6d974f833d2f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 17 Jan 2024 23:53:09 +0900 Subject: [PATCH 600/603] =?UTF-8?q?fix=20:=20mapper,=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A0=84=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberReservationControllerTest.java | 6 ++++-- .../controller/OwnerReservationControllerTest.java | 10 +++++++++- .../reservation/fixture/ReservationFixture.java | 12 ++++++++++++ .../repository/ReservationRepositoryTest.java | 5 ++++- .../service/MemberReservationServiceTest.java | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 4d46c7f0..88ea0402 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -170,8 +170,9 @@ void registerReservationWithException() throws Exception { @DisplayName("예약 수정 api 호출에 성공한다.") void modifyReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); + Member member1 = memberRepository.findAll().get(0); reservationTime.setOccupiedTrue(); - Reservation reservation = ReservationFixture.getReservation(reservationTime); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, member1); Reservation savedReservation = reservationRepository.save(reservation); /** * 수정하려는 예약시간 예제 데이터 생성 @@ -204,7 +205,8 @@ void modifyReservation() throws Exception { @DisplayName("예약 삭제 api 호출에 성공한다") void cancelReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); - Reservation reservation = ReservationFixture.getReservation(reservationTime); + Member member1 = memberRepository.findAll().get(0); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, member1); Reservation savedReservation = reservationRepository.save(reservation); mockMvc.perform(delete("/reservations/{reservationId}", savedReservation.getId()) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index 01e4629c..20efc437 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -12,6 +12,9 @@ import com.prgrms.catchtable.common.base.BaseIntegrationTest; import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.fixture.OwnerFixture; import com.prgrms.catchtable.owner.repository.OwnerRepository; @@ -44,6 +47,8 @@ class OwnerReservationControllerTest extends BaseIntegrationTest { private ShopRepository shopRepository; @Autowired private ReservationRepository reservationRepository; + @Autowired + private MemberRepository memberRepository; @BeforeEach void setUp() { @@ -53,8 +58,11 @@ void setUp() { ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); savedReservationTime.setOccupiedTrue(); log.info("예약 시간 차지 여부 : {}", savedReservationTime.isOccupied()); + + Member member = MemberFixture.member("qwe@naver.com"); + Member savedMember = memberRepository.save(member); Reservation reservation = reservationRepository.save( - ReservationFixture.getReservation(savedReservationTime)); + ReservationFixture.getReservationWithMember(savedReservationTime,savedMember)); ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); reservationTime2.insertShop(shop); diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index af468e84..d7c49f9d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -3,6 +3,7 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationStatus; @@ -108,4 +109,15 @@ public static Reservation getReservation(ReservationTime reservationTime, Member .build(); } + public static Reservation getReservationWithMember(ReservationTime reservationTime, Member member) { + if (!reservationTime.isOccupied()) { + reservationTime.setOccupiedTrue(); + } + return Reservation.builder() + .status(COMPLETED) + .peopleCount(4) + .reservationTime(reservationTime) + .member(member) + .build(); + } } diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 42bcbb34..2e56cbf0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -70,7 +70,10 @@ void findByIdWithReservationTimeAndShop() { reservationTime.insertShop(savedShop); ReservationTime savedReservationTime = reservationTimeRepository.save(reservationTime); - Reservation reservation = ReservationFixture.getReservation(savedReservationTime); + Member member = MemberFixture.member("dlswns661035@gmail.com"); + Member savedMember = memberRepository.save(member); + + Reservation reservation = ReservationFixture.getReservationWithMember(savedReservationTime, savedMember); Reservation savedReservation = reservationRepository.save(reservation); Reservation findReservation = reservationRepository.findByIdWithReservationTimeAndShop( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 165a56b7..6fd4b429 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -204,7 +204,7 @@ void modifyReservation() { ReservationTime modifyTime = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(modifyTime, "id", 2L); //수정하려는 예약시간 객체 -> Id : 2 - Reservation reservation = ReservationFixture.getReservation(reservationTime); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, MemberFixture.member("dlsw@gamil.com")); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( 2L); From 77636fcc9854ea0e5084d03cdae7fb1c5d901a34 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 17 Jan 2024 23:54:05 +0900 Subject: [PATCH 601/603] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/waiting/waiting.adoc | 1 - .../prgrms/catchtable/jwt/service/RefreshTokenService.java | 2 +- .../catchtable/member/controller/MemberController.java | 4 ++-- .../com/prgrms/catchtable/member/service/MemberService.java | 2 +- .../prgrms/catchtable/owner/controller/OwnerController.java | 2 +- .../com/prgrms/catchtable/owner/service/OwnerService.java | 2 +- src/main/java/com/prgrms/catchtable/shop/domain/Shop.java | 2 +- .../controller/MemberReservationControllerTest.java | 6 ++++-- .../controller/OwnerReservationControllerTest.java | 2 +- .../catchtable/reservation/fixture/ReservationFixture.java | 4 ++-- .../reservation/repository/ReservationRepositoryTest.java | 3 ++- .../reservation/service/MemberReservationServiceTest.java | 3 ++- 12 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/docs/asciidoc/api/waiting/waiting.adoc b/src/docs/asciidoc/api/waiting/waiting.adoc index 4f5a51b3..96fc4403 100644 --- a/src/docs/asciidoc/api/waiting/waiting.adoc +++ b/src/docs/asciidoc/api/waiting/waiting.adoc @@ -55,7 +55,6 @@ include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-requ include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/http-response.adoc[] include::{snippets}/member-waiting-controller-docs-test/cancel-waiting/response-fields.adoc[] - === 웨이팅 입장 API ==== HTTP Request diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index 212a8460..684c4c8e 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -42,7 +42,7 @@ public RefreshToken getRefreshTokenByToken(String refreshToken) { } @Transactional - public void deleteRefreshToken(String email){ + public void deleteRefreshToken(String email) { refreshTokenRepository.deleteRefreshTokenByEmail(email); } } diff --git a/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java index 06230af7..49913c27 100644 --- a/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java +++ b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java @@ -21,14 +21,14 @@ public class MemberController { private final MemberService memberService; @GetMapping("/login/kakao") - public ResponseEntity loginRedirect(){ + public ResponseEntity loginRedirect() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(URI.create("/oauth2/authorization/kakao")); return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY); } @PostMapping("/logout") - public ResponseEntity logout(@LogIn Member member){ + public ResponseEntity logout(@LogIn Member member) { memberService.logout(member.getEmail()); return ResponseEntity.ok("logout"); } diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 9af6d339..02df275e 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -35,7 +35,7 @@ public Token oauthLogin(OAuthAttribute attributes) { } @Transactional - public void logout(String email){ + public void logout(String email) { refreshTokenService.deleteRefreshToken(email); } diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java index 5cafb006..8642995d 100644 --- a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -39,7 +39,7 @@ public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOw } @PostMapping("/logout") - public ResponseEntity logout(@LogIn Owner owner){ + public ResponseEntity logout(@LogIn Owner owner) { ownerService.logout(owner.getEmail()); return ResponseEntity.ok("logout"); } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index 425dd3b9..b506d02b 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -66,7 +66,7 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { } @Transactional - public void logout(String email){ + public void logout(String email) { refreshTokenService.deleteRefreshToken(email); } diff --git a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java index 19686be4..45edf862 100644 --- a/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java +++ b/src/main/java/com/prgrms/catchtable/shop/domain/Shop.java @@ -70,7 +70,7 @@ public Shop(String name, BigDecimal rating, Category category, Address address, public int findWaitingNumber() { return ++waitingCount; } - + public void updateMenuList(List menuList) { this.menuList.addAll(menuList); this.menuList.forEach(menu -> menu.insertShop(this)); diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java index 88ea0402..bc4f7134 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/MemberReservationControllerTest.java @@ -172,7 +172,8 @@ void modifyReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); Member member1 = memberRepository.findAll().get(0); reservationTime.setOccupiedTrue(); - Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, member1); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, + member1); Reservation savedReservation = reservationRepository.save(reservation); /** * 수정하려는 예약시간 예제 데이터 생성 @@ -206,7 +207,8 @@ void modifyReservation() throws Exception { void cancelReservation() throws Exception { ReservationTime reservationTime = reservationTimeRepository.findAll().get(0); Member member1 = memberRepository.findAll().get(0); - Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, member1); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, + member1); Reservation savedReservation = reservationRepository.save(reservation); mockMvc.perform(delete("/reservations/{reservationId}", savedReservation.getId()) diff --git a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java index 20efc437..443b66ed 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/controller/OwnerReservationControllerTest.java @@ -62,7 +62,7 @@ void setUp() { Member member = MemberFixture.member("qwe@naver.com"); Member savedMember = memberRepository.save(member); Reservation reservation = reservationRepository.save( - ReservationFixture.getReservationWithMember(savedReservationTime,savedMember)); + ReservationFixture.getReservationWithMember(savedReservationTime, savedMember)); ReservationTime reservationTime2 = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); reservationTime2.insertShop(shop); diff --git a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java index d7c49f9d..fa83e2e0 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java +++ b/src/test/java/com/prgrms/catchtable/reservation/fixture/ReservationFixture.java @@ -3,7 +3,6 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.MemberFixture; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationStatus; @@ -109,7 +108,8 @@ public static Reservation getReservation(ReservationTime reservationTime, Member .build(); } - public static Reservation getReservationWithMember(ReservationTime reservationTime, Member member) { + public static Reservation getReservationWithMember(ReservationTime reservationTime, + Member member) { if (!reservationTime.isOccupied()) { reservationTime.setOccupiedTrue(); } diff --git a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java index 2e56cbf0..d3809539 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/repository/ReservationRepositoryTest.java @@ -73,7 +73,8 @@ void findByIdWithReservationTimeAndShop() { Member member = MemberFixture.member("dlswns661035@gmail.com"); Member savedMember = memberRepository.save(member); - Reservation reservation = ReservationFixture.getReservationWithMember(savedReservationTime, savedMember); + Reservation reservation = ReservationFixture.getReservationWithMember(savedReservationTime, + savedMember); Reservation savedReservation = reservationRepository.save(reservation); Reservation findReservation = reservationRepository.findByIdWithReservationTimeAndShop( diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java index 6fd4b429..77921a37 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/MemberReservationServiceTest.java @@ -204,7 +204,8 @@ void modifyReservation() { ReservationTime modifyTime = ReservationFixture.getAnotherReservationTimeNotPreOccupied(); ReflectionTestUtils.setField(modifyTime, "id", 2L); //수정하려는 예약시간 객체 -> Id : 2 - Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, MemberFixture.member("dlsw@gamil.com")); + Reservation reservation = ReservationFixture.getReservationWithMember(reservationTime, + MemberFixture.member("dlsw@gamil.com")); ModifyReservationRequest request = ReservationFixture.getModifyReservationRequest( 2L); From 1b277247a305e378f1ec031e5c6669e3d8988614 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 18 Jan 2024 18:03:09 +0900 Subject: [PATCH 602/603] =?UTF-8?q?chore=20:=20reservation.adoc=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asciidoc/api/reservation/reservation.adoc | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/docs/asciidoc/api/reservation/reservation.adoc diff --git a/src/docs/asciidoc/api/reservation/reservation.adoc b/src/docs/asciidoc/api/reservation/reservation.adoc new file mode 100644 index 00000000..01310899 --- /dev/null +++ b/src/docs/asciidoc/api/reservation/reservation.adoc @@ -0,0 +1,80 @@ +[[reservation-create]] +=== 예약 선점 API + +==== HTTP Request + +include::{snippets}/member-reservation-controller-docs-test/pre-occupy/http-request.adoc[] +include::{snippets}/member-reservation-controller-docs-test/pre-occupy/request-fields.adoc[] + +==== HTTP Response + +include::{snippets}/member-reservation-controller-docs-test/pre-occupy/http-response.adoc[] +include::{snippets}/member-reservation-controller-docs-test/pre-occupy/response-fields.adoc[] + +=== 가게 예약 API + +==== HTTP Request + +include::{snippets}/member-reservation-controller-docs-test/register/http-request.adoc[] +include::{snippets}/member-reservation-controller-docs-test/register/request-fields.adoc[] + +==== HTTP Response + +include::{snippets}/member-reservation-controller-docs-test/register/http-response.adoc[] +include::{snippets}/member-reservation-controller-docs-test/register/response-fields.adoc[] + +=== 예약 전체 조회 API + +==== HTTP Request + +include::{snippets}/member-reservation-controller-docs-test/get-all/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-reservation-controller-docs-test/get-all/http-response.adoc[] +include::{snippets}/member-reservation-controller-docs-test/get-all/response-fields.adoc[] + +=== 예약 수정 API + +==== HTTP Request + +include::{snippets}/member-reservation-controller-docs-test/modify/http-request.adoc[] +include::{snippets}/member-reservation-controller-docs-test/modify/request-fields.adoc[] + +==== HTTP Response + +include::{snippets}/member-reservation-controller-docs-test/modify/http-response.adoc[] +include::{snippets}/member-reservation-controller-docs-test/modify/response-fields.adoc[] + +=== 예약 삭제 API + +==== HTTP Request + +include::{snippets}/member-reservation-controller-docs-test/cancel/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/member-reservation-controller-docs-test/cancel/http-response.adoc[] +include::{snippets}/member-reservation-controller-docs-test/cancel/response-fields.adoc[] + +=== 예약 노쇼, 취소 처리 API + +==== HTTP Request + +include::{snippets}/owner-reservation-controller-docs-test/noshow-and-cancel/http-request.adoc[] +include::{snippets}/owner-reservation-controller-docs-test/noshow-and-cancel/request-fields.adoc[] + +==== HTTP Response + +include::{snippets}/owner-reservation-controller-docs-test/noshow-and-cancel/http-response.adoc[] + +=== 예약 정보 전체 조회 API + +==== HTTP Request + +include::{snippets}/owner-reservation-controller-docs-test/get-all-reservation/http-request.adoc[] + +==== HTTP Response + +include::{snippets}/owner-reservation-controller-docs-test/get-all-reservation/http-response.adoc[] +include::{snippets}/owner-reservation-controller-docs-test/get-all-reservation/response-fields.adoc[] \ No newline at end of file From 41fe6e268de0398c6780eb569978cca360368799 Mon Sep 17 00:00:00 2001 From: hs12 Date: Thu, 18 Jan 2024 18:04:16 +0900 Subject: [PATCH 603/603] =?UTF-8?q?chore=20:=20index.adoc=20=EC=8A=A4?= =?UTF-8?q?=EB=8B=88=ED=8E=AB=20=ED=95=A9=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/index.adoc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 63a41be5..2f7042bc 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -12,4 +12,8 @@ endif::[] [[CatchTable-API]] == Waiting API -include::api/waiting/waiting.adoc[] \ No newline at end of file +include::api/waiting/waiting.adoc[] + +== Reservation API + +include::api/reservation/reservation.adoc[] \ No newline at end of file