From 8f89fd3f0bc975d8317b73deee158986b649b45f Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 13:48:31 +0900 Subject: [PATCH 01/55] =?UTF-8?q?feat:=20Reservation=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EA=B8=B0=EB=B3=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=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 --- build.gradle | 1 + .../controller/ReservationController.java | 12 ++++++++ .../reservation/domain/Reservation.java | 28 +++++++++++++++++++ .../domain/ReservationRepository.java | 9 ++++++ .../service/ReservationService.java | 4 +++ .../service/impl/ReservationServiceImpl.java | 13 +++++++++ 6 files changed, 67 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java diff --git a/build.gradle b/build.gradle index 043ddad..dc4cf69 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java new file mode 100644 index 0000000..0bc16c1 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.reservation.controller; + +import com.hanaro.hanafun.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class ReservationController { + private final ReservationService reservationService; + +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java b/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java new file mode 100644 index 0000000..ab055e2 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java @@ -0,0 +1,28 @@ +package com.hanaro.hanafun.reservation.domain; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "Reservation") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +public class Reservation { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long reservationId; + + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne + @JoinColumn(name = "lessondate_id", nullable = false) + private LessonDate lessonDate; + + private int applicant; + + private boolean isDeleted; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java new file mode 100644 index 0000000..f5cc7a8 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -0,0 +1,9 @@ +package com.hanaro.hanafun.reservation.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ReservationRepository extends JpaRepository { + +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java new file mode 100644 index 0000000..f63ac41 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -0,0 +1,4 @@ +package com.hanaro.hanafun.reservation.service; + +public interface ReservationService { +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java new file mode 100644 index 0000000..a5b0a7b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -0,0 +1,13 @@ +package com.hanaro.hanafun.reservation.service.impl; + +import com.hanaro.hanafun.reservation.domain.ReservationRepository; +import com.hanaro.hanafun.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReservationServiceImpl implements ReservationService { + private final ReservationRepository reservationRepository; + +} From a7b15f560d1b0e9e96c5b49254b5673f401fe207 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 25 Jun 2024 14:14:46 +0900 Subject: [PATCH 02/55] feat: user, host, and account domain are implemented --- .../account/controller/AccountController.java | 7 +++ .../hanafun/account/domain/AccountEntity.java | 53 +++++++++++++++++++ .../account/domain/AccountRepository.java | 6 +++ .../account/service/AccountService.java | 4 ++ .../service/impl/AccountServiceImpl.java | 7 +++ .../host/controller/HostController.java | 7 +++ .../hanafun/host/domain/HostEntity.java | 43 +++++++++++++++ .../hanafun/host/domain/HostRepository.java | 6 +++ .../hanafun/host/service/HostService.java | 4 ++ .../host/service/impl/HostServiceImpl.java | 7 +++ .../user/controller/UserController.java | 7 +++ .../hanafun/user/domain/UserEntity.java | 48 +++++++++++++++++ .../hanafun/user/domain/UserRepository.java | 8 +++ .../hanafun/user/service/UserService.java | 5 ++ .../user/service/impl/UserServiceImpl.java | 7 +++ 15 files changed, 219 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/account/controller/AccountController.java create mode 100644 src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/account/service/AccountService.java create mode 100644 src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java create mode 100644 src/main/java/com/hanaro/hanafun/host/controller/HostController.java create mode 100644 src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/host/service/HostService.java create mode 100644 src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java create mode 100644 src/main/java/com/hanaro/hanafun/user/controller/UserController.java create mode 100644 src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/user/service/UserService.java create mode 100644 src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java new file mode 100644 index 0000000..c41a6fb --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.account.controller; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { +} diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java new file mode 100644 index 0000000..2c60860 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -0,0 +1,53 @@ +package com.hanaro.hanafun.account.domain; + +import com.hanaro.hanafun.user.domain.UserEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; + +import java.time.LocalDate; + +@Entity +@Table(name = "Account") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@DynamicUpdate +public class AccountEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "account_id") + private Long accountId; + + @JoinColumn(name = "user_id") + @ManyToOne(optional = false) + private UserEntity userEntity; + + @Column(name = "account_number", length = 20, nullable = false) + private String accountNumber; + + @Column(name = "account_name", length = 30) + private String accountName; + + @Column(name = "password", length = 20, nullable = false) + private String password; + + @Column(name = "balance", nullable = false) + private Integer balance; + + @Column(name = "qr", length = 255, nullable = false) + private String qr; + + @Column(name = "is_deleted", nullable = false) + private Boolean isDeleted; + + @Column(name = "created_date", nullable = false) + private LocalDate createdDate; + + @Column(name = "updated_date", nullable = false) + private LocalDate updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java new file mode 100644 index 0000000..08203ad --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java @@ -0,0 +1,6 @@ +package com.hanaro.hanafun.account.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AccountRepository extends JpaRepository { +} diff --git a/src/main/java/com/hanaro/hanafun/account/service/AccountService.java b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java new file mode 100644 index 0000000..b5ec1a0 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java @@ -0,0 +1,4 @@ +package com.hanaro.hanafun.account.service; + +public interface AccountService { +} diff --git a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java new file mode 100644 index 0000000..72410be --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.account.service.impl; + +import org.springframework.stereotype.Service; + +@Service +public class AccountServiceImpl { +} diff --git a/src/main/java/com/hanaro/hanafun/host/controller/HostController.java b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java new file mode 100644 index 0000000..77140f4 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.host.controller; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HostController { +} diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java new file mode 100644 index 0000000..03b6607 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java @@ -0,0 +1,43 @@ +package com.hanaro.hanafun.host.domain; + +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.user.domain.UserEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; + +import java.time.LocalDate; + +@Entity +@Table(name = "Host") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@DynamicUpdate +public class HostEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "host_id") + private Long hostId; + + @JoinColumn(name = "user_id") + @OneToOne(optional = false) + private UserEntity userEntity; + + @Column(name = "introduction", length = 255, nullable = false) + private String introduction; + + @Column(name = "account_id") + @OneToOne(optional = false) + private AccountEntity accountEntity; + + @Column(name = "created_date", nullable = false) + private LocalDate createdDate; + + @Column(name = "updated_date", nullable = false) + private LocalDate updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java new file mode 100644 index 0000000..8626212 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java @@ -0,0 +1,6 @@ +package com.hanaro.hanafun.host.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface HostRepository extends JpaRepository { +} diff --git a/src/main/java/com/hanaro/hanafun/host/service/HostService.java b/src/main/java/com/hanaro/hanafun/host/service/HostService.java new file mode 100644 index 0000000..328a297 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/service/HostService.java @@ -0,0 +1,4 @@ +package com.hanaro.hanafun.host.service; + +public interface HostService { +} diff --git a/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java new file mode 100644 index 0000000..6b83048 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.host.service.impl; + +import org.springframework.stereotype.Service; + +@Service +public class HostServiceImpl { +} diff --git a/src/main/java/com/hanaro/hanafun/user/controller/UserController.java b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java new file mode 100644 index 0000000..d4fccf9 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.user.controller; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class UserController { +} diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java new file mode 100644 index 0000000..b9b474e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java @@ -0,0 +1,48 @@ +package com.hanaro.hanafun.user.domain; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicUpdate; + +import java.time.LocalDate; + +@Entity +@Table(name="User") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@DynamicUpdate +public class UserEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user_id") + private Long userId; + + @Column(name="user_name", length = 255, nullable = false) + private String userName; + + @Column(name="password", length = 20, nullable = false) + private String password; + + @Column(name = "point", nullable = false) + private Integer point; + + @Column(name = "email", length = 255, nullable = false) + private String email; + + @Column(name = "is_host", nullable = false) + private Boolean isHost; + + @Column(name = "is_deleted", nullable = false) + private Boolean isDeleted; + + @Column(name = "created_date", nullable = false) + private LocalDate createdDate; + + @Column(name = "updated_date", nullable = false) + private LocalDate updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java new file mode 100644 index 0000000..9d4bb4b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.user.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { +} diff --git a/src/main/java/com/hanaro/hanafun/user/service/UserService.java b/src/main/java/com/hanaro/hanafun/user/service/UserService.java new file mode 100644 index 0000000..aba0981 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/service/UserService.java @@ -0,0 +1,5 @@ +package com.hanaro.hanafun.user.service; + +public interface UserService { + +} diff --git a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..b8cff0b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.user.service.impl; + +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl { +} From 8727b8e940e3018109e8487690f6f8a93369e1f5 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 14:40:16 +0900 Subject: [PATCH 03/55] =?UTF-8?q?feat:=20Lesson,=20LessonDate,=20Category?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EA=B8=B0=EB=B3=B8=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hanafun/category/domain/Category.java | 26 ++++++++ .../category/domain/CategoryRepository.java | 9 +++ .../hanaro/hanafun/lesson/domain/Lesson.java | 63 +++++++++++++++++++ .../lesson/domain/LessonRepository.java | 7 +++ .../hanafun/lessondate/domain/LessonDate.java | 44 +++++++++++++ .../domain/LessonDateRepository.java | 9 +++ .../reservation/domain/Reservation.java | 15 +++++ 7 files changed, 173 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/category/domain/Category.java create mode 100644 src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java diff --git a/src/main/java/com/hanaro/hanafun/category/domain/Category.java b/src/main/java/com/hanaro/hanafun/category/domain/Category.java new file mode 100644 index 0000000..3f4b9e1 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/domain/Category.java @@ -0,0 +1,26 @@ +package com.hanaro.hanafun.category.domain; + +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "Category") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Builder +@AllArgsConstructor +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long categoryId; + + @Column(nullable = false) + private String categoryName; + + @Column(nullable = false) + private LocalDateTime createdDate; + + private LocalDateTime updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java b/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java new file mode 100644 index 0000000..c5d92f2 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java @@ -0,0 +1,9 @@ +package com.hanaro.hanafun.category.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CategoryRepository extends JpaRepository { + +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java b/src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java new file mode 100644 index 0000000..a3cc583 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java @@ -0,0 +1,63 @@ +package com.hanaro.hanafun.lesson.domain; + +import com.hanaro.hanafun.category.domain.Category; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "Lesson") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +@DynamicInsert +public class Lesson { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long lessonId; + + @ManyToOne + @JoinColumn(name = "host_id", nullable = false) + private Host host; + + @OneToOne + @JoinColumn(name = "category_id", nullable = false) + private Category category; + + @Column(nullable = false, length = 30) + private String title; + + @Column(nullable = false) + private String location; + + @Column(nullable = false) + private int price; + + @Column(nullable = false) + private int capacity; + + @Column(nullable = false) + private String image; + + @Column(nullable = false) + private String description; + + private String materials; + + @ColumnDefault("0") + @Column(nullable = false) + private int applicantSum; + + @ColumnDefault("0") + @Column(nullable = false) + private boolean isDeleted; + + @Column(nullable = false) + private LocalDateTime createdDate; + + private LocalDateTime updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java new file mode 100644 index 0000000..4611782 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.lesson.domain; + +import org.springframework.stereotype.Repository; + +@Repository +public interface LessonRepository { +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java new file mode 100644 index 0000000..efa74d0 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java @@ -0,0 +1,44 @@ +package com.hanaro.hanafun.lessondate.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Entity +@Table(name = "LessonDate") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +@DynamicInsert +public class LessonDate { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long lessondateId; + + @ManyToOne + @JoinColumn(name = "lesson_id", nullable = false) + private Lesson lesson; + + @Column(nullable = false) + private LocalDate date; + + @Column(nullable = false) + private LocalDateTime startTime; + + @Column(nullable = false) + private LocalDateTime endTime; + + @ColumnDefault("0") + @Column(nullable = false) + private int applicant; + + @Column(nullable = false) + private LocalDateTime createdDate; + + private LocalDateTime updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java new file mode 100644 index 0000000..37eaa53 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java @@ -0,0 +1,9 @@ +package com.hanaro.hanafun.lessondate.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface LessonDateRepository extends JpaRepository { + +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java b/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java index ab055e2..90f4190 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java @@ -1,7 +1,12 @@ package com.hanaro.hanafun.reservation.domain; +import com.hanaro.hanafun.lessondate.domain.LessonDate; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; + +import java.time.LocalDateTime; @Entity @Table(name = "Reservation") @@ -9,6 +14,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder @AllArgsConstructor +@DynamicInsert public class Reservation { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -22,7 +28,16 @@ public class Reservation { @JoinColumn(name = "lessondate_id", nullable = false) private LessonDate lessonDate; + @ColumnDefault("0") + @Column(nullable = false) private int applicant; + @ColumnDefault("0") + @Column(nullable = false) private boolean isDeleted; + + @Column(nullable = false) + private LocalDateTime createdDate; + + private LocalDateTime updatedDate; } From edf3b8532ce2e3b61ff67f0ab794d2d1599a581c Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 14:46:14 +0900 Subject: [PATCH 04/55] =?UTF-8?q?fix:=20LessonDate=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EA=B8=B0=EB=B3=B8=20=ED=81=B4=EB=9E=98=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 --- .../java/com/hanaro/hanafun/lessondate/domain/LessonDate.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java index efa74d0..80bfe6e 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.lessondate.domain; +import com.hanaro.hanafun.lesson.domain.Lesson; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; From 6af4d14b4f8f55da1555f302aed4b59c6089c87e Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 15:01:19 +0900 Subject: [PATCH 05/55] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/{Category.java => CategoryEntity.java} | 2 +- .../hanafun/category/domain/CategoryRepository.java | 2 +- .../lesson/domain/{Lesson.java => LessonEntity.java} | 9 +++++---- .../domain/{LessonDate.java => LessonDateEntity.java} | 6 +++--- .../hanafun/lessondate/domain/LessonDateRepository.java | 2 +- .../domain/{Reservation.java => ReservationEntity.java} | 9 +++++---- .../reservation/domain/ReservationRepository.java | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) rename src/main/java/com/hanaro/hanafun/category/domain/{Category.java => CategoryEntity.java} (94%) rename src/main/java/com/hanaro/hanafun/lesson/domain/{Lesson.java => LessonEntity.java} (85%) rename src/main/java/com/hanaro/hanafun/lessondate/domain/{LessonDate.java => LessonDateEntity.java} (88%) rename src/main/java/com/hanaro/hanafun/reservation/domain/{Reservation.java => ReservationEntity.java} (79%) diff --git a/src/main/java/com/hanaro/hanafun/category/domain/Category.java b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java similarity index 94% rename from src/main/java/com/hanaro/hanafun/category/domain/Category.java rename to src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java index 3f4b9e1..ff9b837 100644 --- a/src/main/java/com/hanaro/hanafun/category/domain/Category.java +++ b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java @@ -11,7 +11,7 @@ @Getter @Builder @AllArgsConstructor -public class Category { +public class CategoryEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long categoryId; diff --git a/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java b/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java index c5d92f2..999bf70 100644 --- a/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java +++ b/src/main/java/com/hanaro/hanafun/category/domain/CategoryRepository.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface CategoryRepository extends JpaRepository { +public interface CategoryRepository extends JpaRepository { } diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java similarity index 85% rename from src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java rename to src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java index a3cc583..a3b80e4 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/Lesson.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java @@ -1,6 +1,7 @@ package com.hanaro.hanafun.lesson.domain; -import com.hanaro.hanafun.category.domain.Category; +import com.hanaro.hanafun.category.domain.CategoryEntity; +import com.hanaro.hanafun.host.domain.HostEntity; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; @@ -15,18 +16,18 @@ @Builder @AllArgsConstructor @DynamicInsert -public class Lesson { +public class LessonEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lessonId; @ManyToOne @JoinColumn(name = "host_id", nullable = false) - private Host host; + private HostEntity hostEntity; @OneToOne @JoinColumn(name = "category_id", nullable = false) - private Category category; + private CategoryEntity categoryEntity; @Column(nullable = false, length = 30) private String title; diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java similarity index 88% rename from src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java rename to src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java index 80bfe6e..89bcb73 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDate.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java @@ -1,6 +1,6 @@ package com.hanaro.hanafun.lessondate.domain; -import com.hanaro.hanafun.lesson.domain.Lesson; +import com.hanaro.hanafun.lesson.domain.LessonEntity; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; @@ -16,14 +16,14 @@ @Builder @AllArgsConstructor @DynamicInsert -public class LessonDate { +public class LessonDateEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lessondateId; @ManyToOne @JoinColumn(name = "lesson_id", nullable = false) - private Lesson lesson; + private LessonEntity lessonEntity; @Column(nullable = false) private LocalDate date; diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java index 37eaa53..ed7856c 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface LessonDateRepository extends JpaRepository { +public interface LessonDateRepository extends JpaRepository { } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java similarity index 79% rename from src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java rename to src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java index 90f4190..9dd8911 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/Reservation.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java @@ -1,6 +1,7 @@ package com.hanaro.hanafun.reservation.domain; -import com.hanaro.hanafun.lessondate.domain.LessonDate; +import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; +import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; @@ -15,18 +16,18 @@ @Builder @AllArgsConstructor @DynamicInsert -public class Reservation { +public class ReservationEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long reservationId; @ManyToOne @JoinColumn(name = "user_id", nullable = false) - private User user; + private UserEntity userEntity; @ManyToOne @JoinColumn(name = "lessondate_id", nullable = false) - private LessonDate lessonDate; + private LessonDateEntity lessonDateEntity; @ColumnDefault("0") @Column(nullable = false) diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java index f5cc7a8..bab6c83 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface ReservationRepository extends JpaRepository { +public interface ReservationRepository extends JpaRepository { } From 034fc441164aa286900fc881d41d04614a536915 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 25 Jun 2024 15:36:38 +0900 Subject: [PATCH 06/55] feat: user, host, and account domain are implemented --- .../hanaro/hanafun/account/domain/AccountEntity.java | 8 ++++---- .../com/hanaro/hanafun/host/domain/HostEntity.java | 10 +++++----- .../com/hanaro/hanafun/user/domain/UserEntity.java | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 2c60860..9cf0da6 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicUpdate; -import java.time.LocalDate; +import java.time.LocalDateTime; @Entity @Table(name = "Account") @@ -23,8 +23,8 @@ public class AccountEntity { @Column(name = "account_id") private Long accountId; - @JoinColumn(name = "user_id") @ManyToOne(optional = false) + @JoinColumn(name = "user_id", nullable = false) private UserEntity userEntity; @Column(name = "account_number", length = 20, nullable = false) @@ -46,8 +46,8 @@ public class AccountEntity { private Boolean isDeleted; @Column(name = "created_date", nullable = false) - private LocalDate createdDate; + private LocalDateTime createdDate; @Column(name = "updated_date", nullable = false) - private LocalDate updatedDate; + private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java index 03b6607..52d5078 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java @@ -9,7 +9,7 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicUpdate; -import java.time.LocalDate; +import java.time.LocalDateTime; @Entity @Table(name = "Host") @@ -24,20 +24,20 @@ public class HostEntity { @Column(name = "host_id") private Long hostId; - @JoinColumn(name = "user_id") @OneToOne(optional = false) + @JoinColumn(name = "user_id", nullable = false) private UserEntity userEntity; @Column(name = "introduction", length = 255, nullable = false) private String introduction; - @Column(name = "account_id") @OneToOne(optional = false) + @JoinColumn(name = "account_id", nullable = false) private AccountEntity accountEntity; @Column(name = "created_date", nullable = false) - private LocalDate createdDate; + private LocalDateTime createdDate; @Column(name = "updated_date", nullable = false) - private LocalDate updatedDate; + private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java index b9b474e..e293020 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java @@ -8,6 +8,7 @@ import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDate; +import java.time.LocalDateTime; @Entity @Table(name="User") @@ -41,8 +42,8 @@ public class UserEntity { private Boolean isDeleted; @Column(name = "created_date", nullable = false) - private LocalDate createdDate; + private LocalDateTime createdDate; @Column(name = "updated_date", nullable = false) - private LocalDate updatedDate; + private LocalDateTime updatedDate; } From 84b3cb66452ffede31e567eeae40d6a90098b51b Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 15:42:05 +0900 Subject: [PATCH 07/55] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5(=EC=98=88=EC=95=BD=EB=82=B4=EC=97=AD)=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 --- .../controller/ReservationController.java | 8 ++++ .../domain/ReservationRepository.java | 5 ++- .../reservation/dto/request/MyPageReqDto.java | 8 ++++ .../dto/response/MyPageResDto.java | 13 ++++++ .../dto/response/ReservationList.java | 18 ++++++++ .../service/ReservationService.java | 4 ++ .../service/impl/ReservationServiceImpl.java | 44 +++++++++++++++++++ 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/request/MyPageReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/MyPageResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 0bc16c1..414119d 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -1,7 +1,11 @@ package com.hanaro.hanafun.reservation.controller; +import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; import com.hanaro.hanafun.reservation.service.ReservationService; 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 @@ -9,4 +13,8 @@ public class ReservationController { private final ReservationService reservationService; + @GetMapping("/reservation/my") + public MyPageResDto myPage(@RequestBody MyPageReqDto myPageReqDto) { + return reservationService.myPage(myPageReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java index bab6c83..cb6dce7 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -1,9 +1,12 @@ package com.hanaro.hanafun.reservation.domain; +import com.hanaro.hanafun.user.domain.UserEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface ReservationRepository extends JpaRepository { - + List findReservationEntitiesByUserEntity(UserEntity userEntity); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyPageReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyPageReqDto.java new file mode 100644 index 0000000..2f41757 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyPageReqDto.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.reservation.dto.request; + +import lombok.Getter; + +@Getter +public class MyPageReqDto { + private Long userId; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyPageResDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyPageResDto.java new file mode 100644 index 0000000..a4f7848 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyPageResDto.java @@ -0,0 +1,13 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class MyPageResDto { + private int point; + private List lessons; +} \ No newline at end of file diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java new file mode 100644 index 0000000..583ff14 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java @@ -0,0 +1,18 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@Builder +public class ReservationList { + private Long reservationId; + private Long lessondateId; + private Long lessonId; + private String image; + private String title; + private String location; + private LocalDate date; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index f63ac41..23599a1 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -1,4 +1,8 @@ package com.hanaro.hanafun.reservation.service; +import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; + public interface ReservationService { + MyPageResDto myPage(MyPageReqDto myPageReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index a5b0a7b..b585f6c 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -1,13 +1,57 @@ package com.hanaro.hanafun.reservation.service.impl; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; +import com.hanaro.hanafun.reservation.domain.ReservationEntity; import com.hanaro.hanafun.reservation.domain.ReservationRepository; +import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.ReservationList; import com.hanaro.hanafun.reservation.service.ReservationService; +import com.hanaro.hanafun.user.domain.UserEntity; +import com.hanaro.hanafun.user.domain.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class ReservationServiceImpl implements ReservationService { private final ReservationRepository reservationRepository; + private final UserRepository userRepository; + + // 마이페이지 데이터 출력 + @Transactional + @Override + public MyPageResDto myPage(MyPageReqDto myPageReqDto) { + UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); + List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); + + List lessons = reservations.stream() + .map(reservation -> { + LessonDateEntity lessonDate = reservation.getLessonDateEntity(); + LessonEntity lessonEntity = lessonDate.getLessonEntity(); + + ReservationList lesson = ReservationList.builder() + .reservationId(reservation.getReservationId()) + .lessondateId(lessonDate.getLessondateId()) + .lessonId(lessonEntity.getLessonId()) + .image(lessonEntity.getImage()) + .title(lessonEntity.getTitle()) + .location(lessonEntity.getTitle()) + .date(lessonDate.getDate()) + .build(); + return lesson; + }) + .collect(Collectors.toList()); + + MyPageResDto myPageResDto = MyPageResDto.builder() + .point(user.getPoint()) + .lessons(lessons).build(); + return myPageResDto; + } } From fc1edb829423a7134ab8b64df836bbcc02888122 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 15:49:24 +0900 Subject: [PATCH 08/55] =?UTF-8?q?fix:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80-=20=EC=98=88=EC=95=BD=20=EB=82=B4=EC=97=AD?= =?UTF-8?q?=20=EC=98=A4=EB=8A=98=20=EC=9D=B4=ED=9B=84=EB=A7=8C=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/impl/ReservationServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index b585f6c..83875c1 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.List; import java.util.stream.Collectors; @@ -30,7 +31,10 @@ public MyPageResDto myPage(MyPageReqDto myPageReqDto) { UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); + LocalDate today = LocalDate.now(); // 오늘이후 날짜의 예약만 출력 + List lessons = reservations.stream() + .filter(reservation -> !reservation.getLessonDateEntity().getDate().isBefore(today)) .map(reservation -> { LessonDateEntity lessonDate = reservation.getLessonDateEntity(); LessonEntity lessonEntity = lessonDate.getLessonEntity(); @@ -41,7 +45,7 @@ public MyPageResDto myPage(MyPageReqDto myPageReqDto) { .lessonId(lessonEntity.getLessonId()) .image(lessonEntity.getImage()) .title(lessonEntity.getTitle()) - .location(lessonEntity.getTitle()) + .location(lessonEntity.getLocation()) .date(lessonDate.getDate()) .build(); return lesson; From baa899806f2063dfac568bcf5ddbb7a48581cb94 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 17:00:25 +0900 Subject: [PATCH 09/55] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A0=84=EC=B2=B4=20=EC=B6=9C=EB=A0=A5=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 --- .../controller/CategoryController.java | 21 +++++++++++ .../category/dto/response/CategoryResDto.java | 11 ++++++ .../category/service/CategoryService.java | 9 +++++ .../service/impl/CategoryServiceImpl.java | 36 +++++++++++++++++++ .../controller/ReservationController.java | 3 +- 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java create mode 100644 src/main/java/com/hanaro/hanafun/category/dto/response/CategoryResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/category/service/CategoryService.java create mode 100644 src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java new file mode 100644 index 0000000..4f8616e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java @@ -0,0 +1,21 @@ +package com.hanaro.hanafun.category.controller; + +import com.hanaro.hanafun.category.dto.response.CategoryResDto; +import com.hanaro.hanafun.category.service.CategoryService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +public class CategoryController { + private final CategoryService categoryService; + + @GetMapping("/category") + public List categoryList() { + return categoryService.categoryList(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/category/dto/response/CategoryResDto.java b/src/main/java/com/hanaro/hanafun/category/dto/response/CategoryResDto.java new file mode 100644 index 0000000..e2b86b8 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/dto/response/CategoryResDto.java @@ -0,0 +1,11 @@ +package com.hanaro.hanafun.category.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CategoryResDto { + private Long categoryId; + private String categoryName; +} diff --git a/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java new file mode 100644 index 0000000..d2d1e9d --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java @@ -0,0 +1,9 @@ +package com.hanaro.hanafun.category.service; + +import com.hanaro.hanafun.category.dto.response.CategoryResDto; + +import java.util.List; + +public interface CategoryService { + List categoryList(); +} diff --git a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java new file mode 100644 index 0000000..82cc291 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java @@ -0,0 +1,36 @@ +package com.hanaro.hanafun.category.service.impl; + +import com.hanaro.hanafun.category.domain.CategoryEntity; +import com.hanaro.hanafun.category.domain.CategoryRepository; +import com.hanaro.hanafun.category.dto.response.CategoryResDto; +import com.hanaro.hanafun.category.service.CategoryService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CategoryServiceImpl implements CategoryService { + private final CategoryRepository categoryRepository; + + // 카테고리 전체 출력 + @Transactional + @Override + public List categoryList() { + List categoryResDtoList = new ArrayList<>(); + List categoryEntities = categoryRepository.findAll(); + + for(int i = 0; i < categoryEntities.size(); i++) { + CategoryResDto categoryResDto = CategoryResDto.builder() + .categoryId(categoryEntities.get(i).getCategoryId()) + .categoryName(categoryEntities.get(i).getCategoryName()) + .build(); + categoryResDtoList.add(categoryResDto); + } + return categoryResDtoList; + } +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 414119d..c210bef 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -5,6 +5,7 @@ import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -13,7 +14,7 @@ public class ReservationController { private final ReservationService reservationService; - @GetMapping("/reservation/my") + @PostMapping("/reservation/my") public MyPageResDto myPage(@RequestBody MyPageReqDto myPageReqDto) { return reservationService.myPage(myPageReqDto); } From d5bfc7f4e4e93bcac407537918ba8e5a5b708d89 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 17:38:35 +0900 Subject: [PATCH 10/55] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=EB=AA=85=20=EC=86=8C=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hanaro/hanafun/account/domain/AccountEntity.java | 7 ++----- .../com/hanaro/hanafun/category/domain/CategoryEntity.java | 2 +- .../java/com/hanaro/hanafun/host/domain/HostEntity.java | 7 ++----- .../com/hanaro/hanafun/lesson/domain/LessonEntity.java | 2 +- .../hanaro/hanafun/lessondate/domain/LessonDateEntity.java | 2 +- .../hanafun/reservation/domain/ReservationEntity.java | 2 +- .../java/com/hanaro/hanafun/user/domain/UserEntity.java | 7 ++----- 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 9cf0da6..0b6ebb1 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -2,10 +2,7 @@ import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDateTime; @@ -15,7 +12,7 @@ @Data @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @DynamicUpdate public class AccountEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java index ff9b837..d0944a4 100644 --- a/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java +++ b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java @@ -6,7 +6,7 @@ import java.time.LocalDateTime; @Entity -@Table(name = "Category") +@Table(name = "category") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Builder diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java index 52d5078..a956171 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java @@ -3,10 +3,7 @@ import com.hanaro.hanafun.account.domain.AccountEntity; import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDateTime; @@ -16,7 +13,7 @@ @Data @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @DynamicUpdate public class HostEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java index a3b80e4..79538d6 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; @Entity -@Table(name = "Lesson") +@Table(name = "lesson") @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java index 89bcb73..6c471e3 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; @Entity -@Table(name = "LessonDate") +@Table(name = "lessondate") @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java index 9dd8911..92716b9 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; @Entity -@Table(name = "Reservation") +@Table(name = "reservation") @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java index e293020..0b038d0 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java @@ -1,10 +1,7 @@ package com.hanaro.hanafun.user.domain; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDate; @@ -15,7 +12,7 @@ @Data @Builder @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @DynamicUpdate public class UserEntity { @Id From 0fbb44249deae44878011dba32249b10ba9438ff Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 25 Jun 2024 17:44:13 +0900 Subject: [PATCH 11/55] =?UTF-8?q?fix:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A0=84=EC=B2=B4=20=EC=B6=9C=EB=A0=A5=20stream=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=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 --- .../service/impl/CategoryServiceImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java index 82cc291..5b1ff7a 100644 --- a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java @@ -21,16 +21,18 @@ public class CategoryServiceImpl implements CategoryService { @Transactional @Override public List categoryList() { - List categoryResDtoList = new ArrayList<>(); List categoryEntities = categoryRepository.findAll(); - for(int i = 0; i < categoryEntities.size(); i++) { - CategoryResDto categoryResDto = CategoryResDto.builder() - .categoryId(categoryEntities.get(i).getCategoryId()) - .categoryName(categoryEntities.get(i).getCategoryName()) - .build(); - categoryResDtoList.add(categoryResDto); - } + List categoryResDtoList = categoryEntities.stream() + .map(categoryEntity -> { + CategoryResDto categoryResDto = CategoryResDto.builder() + .categoryId(categoryEntity.getCategoryId()) + .categoryName(categoryEntity.getCategoryName()) + .build(); + return categoryResDto; + }) + .collect(Collectors.toList()); + return categoryResDtoList; } } From 7cd31efe1ad100dacbfeddab4d49fd27458074b1 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 09:14:14 +0900 Subject: [PATCH 12/55] feat: common files are implemented --- .../account/controller/AccountController.java | 19 ++++++++++ .../hanafun/account/domain/AccountEntity.java | 34 +++++------------ .../service/impl/AccountServiceImpl.java | 10 +++++ .../GlobalExceptionHandler.java | 8 ++-- .../hanafun/common/domain/BaseEntity.java | 23 +++++++++++ .../hanafun/common/dto/ApiResponse.java | 8 ++-- .../common/exception/BasicErrorStatus.java | 13 +++---- .../hanafun/host/domain/HostEntity.java | 28 ++++---------- .../user/controller/UserController.java | 19 ++++++++++ .../hanafun/user/domain/UserEntity.java | 31 ++++----------- .../hanafun/user/domain/UserRepository.java | 3 ++ .../hanaro/hanafun/user/dto/IsHostResDto.java | 14 +++++++ .../hanaro/hanafun/user/dto/LoginReqDto.java | 14 +++++++ .../hanaro/hanafun/user/dto/LoginResDto.java | 15 ++++++++ .../hanaro/hanafun/user/dto/PointResDto.java | 14 +++++++ .../user/exception/UserNotFoundException.java | 5 +++ .../hanafun/user/service/UserService.java | 10 +++++ .../user/service/impl/UserServiceImpl.java | 38 ++++++++++++++++++- 18 files changed, 224 insertions(+), 82 deletions(-) rename src/main/java/com/hanaro/hanafun/common/{exception => aop}/GlobalExceptionHandler.java (59%) create mode 100644 src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/user/dto/IsHostResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/user/dto/LoginReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/user/dto/LoginResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/user/dto/PointResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java diff --git a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java index c41a6fb..e310ef6 100644 --- a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java +++ b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java @@ -1,7 +1,26 @@ package com.hanaro.hanafun.account.controller; +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.service.impl.AccountServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.swing.text.html.Option; +import java.util.Optional; + @RestController +@RequestMapping("/account") +@RequiredArgsConstructor public class AccountController { + private final AccountServiceImpl accountService; + private final AccountRepository accountRepository; + @GetMapping("/test") + public ResponseEntity> test(){ + Optional test = accountRepository.findById(1L); + return ResponseEntity.ok(test); + } } diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 9cf0da6..1fcf926 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -1,23 +1,15 @@ package com.hanaro.hanafun.account.domain; +import com.hanaro.hanafun.common.domain.BaseEntity; import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.DynamicUpdate; - -import java.time.LocalDateTime; +import lombok.*; @Entity -@Table(name = "Account") -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@DynamicUpdate -public class AccountEntity { +@Table(name = "account") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class AccountEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "account_id") @@ -30,24 +22,18 @@ public class AccountEntity { @Column(name = "account_number", length = 20, nullable = false) private String accountNumber; - @Column(name = "account_name", length = 30) + @Column(name = "account_name", length = 50) private String accountName; - @Column(name = "password", length = 20, nullable = false) - private String password; + @Column(name = "password", nullable = false) + private Integer password; @Column(name = "balance", nullable = false) private Integer balance; - @Column(name = "qr", length = 255, nullable = false) + @Column(name = "qr") private String qr; @Column(name = "is_deleted", nullable = false) private Boolean isDeleted; - - @Column(name = "created_date", nullable = false) - private LocalDateTime createdDate; - - @Column(name = "updated_date", nullable = false) - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java index 72410be..d81fe23 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java @@ -1,7 +1,17 @@ package com.hanaro.hanafun.account.service.impl; +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.domain.AccountRepository; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service +@RequiredArgsConstructor public class AccountServiceImpl { + private final AccountRepository accountRepository; + private Optional test(){ + return accountRepository.findById(1L); + } } diff --git a/src/main/java/com/hanaro/hanafun/common/exception/GlobalExceptionHandler.java b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java similarity index 59% rename from src/main/java/com/hanaro/hanafun/common/exception/GlobalExceptionHandler.java rename to src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java index c9bb40f..4d6b16c 100644 --- a/src/main/java/com/hanaro/hanafun/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java @@ -1,16 +1,18 @@ -package com.hanaro.hanafun.common.exception; +package com.hanaro.hanafun.common.aop; import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.common.exception.BasicErrorStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @RestControllerAdvice -public class GlobalExceptionHandler { +public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(Exception.class) public ResponseEntity> handleGlobalException(Exception ex) { BasicErrorStatus error = BasicErrorStatus.INTERNAL_SERVER_ERROR; - ApiResponse response = new ApiResponse<>(false, error.getCode(), error.getMessage(), null); + ApiResponse response = new ApiResponse<>(false, ex.getMessage(), null); return new ResponseEntity<>(response, error.getHttpStatus()); } } diff --git a/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java b/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java new file mode 100644 index 0000000..c8dd550 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java @@ -0,0 +1,23 @@ +package com.hanaro.hanafun.common.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + @Column(updatable = false) + @CreatedDate + private LocalDateTime createdDate; + + @LastModifiedDate + private LocalDateTime updatedDate; +} diff --git a/src/main/java/com/hanaro/hanafun/common/dto/ApiResponse.java b/src/main/java/com/hanaro/hanafun/common/dto/ApiResponse.java index 8f9591f..8e788f7 100644 --- a/src/main/java/com/hanaro/hanafun/common/dto/ApiResponse.java +++ b/src/main/java/com/hanaro/hanafun/common/dto/ApiResponse.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.common.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; @@ -7,14 +8,15 @@ @Getter @AllArgsConstructor -@JsonPropertyOrder({"isSuccess", "code", "message", "data"}) +@JsonPropertyOrder({"isSuccess", "message", "data"}) public class ApiResponse { @JsonProperty("isSuccess") private final Boolean isSuccess; - @JsonProperty("code") - private final String code; + @JsonProperty("message") private final String message; + + @JsonInclude(JsonInclude.Include.NON_NULL) @JsonProperty("data") private T data; } \ No newline at end of file diff --git a/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java b/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java index 4c176af..ed2a81f 100644 --- a/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java +++ b/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java @@ -7,13 +7,12 @@ @Getter @AllArgsConstructor public enum BasicErrorStatus { - BAD_REQUEST(HttpStatus.BAD_REQUEST, "E001", "잘못된 요청입니다."), - UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "E002", "인증이 필요합니다."), - RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, "E003", "값을 찾을 수 없습니다."), - INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "E004", "서버 에러"), - FORBIDDEN(HttpStatus.FORBIDDEN, "E005", "금지된 작업입니다."); + BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "인증이 필요합니다."), + RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, "값을 찾을 수 없습니다."), + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 에러"), + FORBIDDEN(HttpStatus.FORBIDDEN, "금지된 작업입니다."); private final HttpStatus httpStatus; - private final String code; private final String message; -} +} \ No newline at end of file diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java index 52d5078..3d3b0b6 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java @@ -1,24 +1,16 @@ package com.hanaro.hanafun.host.domain; import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.common.domain.BaseEntity; import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.DynamicUpdate; - -import java.time.LocalDateTime; +import lombok.*; @Entity -@Table(name = "Host") -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@DynamicUpdate -public class HostEntity { +@Table(name = "host") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class HostEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "host_id") @@ -28,16 +20,10 @@ public class HostEntity { @JoinColumn(name = "user_id", nullable = false) private UserEntity userEntity; - @Column(name = "introduction", length = 255, nullable = false) + @Column(name = "introduction", nullable = false) private String introduction; @OneToOne(optional = false) @JoinColumn(name = "account_id", nullable = false) private AccountEntity accountEntity; - - @Column(name = "created_date", nullable = false) - private LocalDateTime createdDate; - - @Column(name = "updated_date", nullable = false) - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/user/controller/UserController.java b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java index d4fccf9..28fe097 100644 --- a/src/main/java/com/hanaro/hanafun/user/controller/UserController.java +++ b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java @@ -1,7 +1,26 @@ package com.hanaro.hanafun.user.controller; +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.user.dto.LoginReqDto; +import com.hanaro.hanafun.user.dto.LoginResDto; +import com.hanaro.hanafun.user.service.impl.UserServiceImpl; +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; @RestController +@RequiredArgsConstructor +@RequestMapping("/user") public class UserController { + + private final UserServiceImpl userService; + + @PostMapping("/login") + ResponseEntity loginUser(@RequestBody LoginReqDto request) { + LoginResDto loginResponse = userService.login(request); + return ResponseEntity.ok(new ApiResponse(true, "ok", loginResponse)); + } } diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java index e293020..67d8a59 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java @@ -1,29 +1,20 @@ package com.hanaro.hanafun.user.domain; +import com.hanaro.hanafun.common.domain.BaseEntity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.DynamicUpdate; - -import java.time.LocalDate; -import java.time.LocalDateTime; +import lombok.*; @Entity -@Table(name="User") -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@DynamicUpdate -public class UserEntity { +@Table(name="user") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class UserEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="user_id") private Long userId; - @Column(name="user_name", length = 255, nullable = false) + @Column(name="username", nullable = false) private String userName; @Column(name="password", length = 20, nullable = false) @@ -32,7 +23,7 @@ public class UserEntity { @Column(name = "point", nullable = false) private Integer point; - @Column(name = "email", length = 255, nullable = false) + @Column(name = "email", nullable = false) private String email; @Column(name = "is_host", nullable = false) @@ -40,10 +31,4 @@ public class UserEntity { @Column(name = "is_deleted", nullable = false) private Boolean isDeleted; - - @Column(name = "created_date", nullable = false) - private LocalDateTime createdDate; - - @Column(name = "updated_date", nullable = false) - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java index 9d4bb4b..e3b92b8 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java @@ -3,6 +3,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface UserRepository extends JpaRepository { + Optional findByPassword(String password); } diff --git a/src/main/java/com/hanaro/hanafun/user/dto/IsHostResDto.java b/src/main/java/com/hanaro/hanafun/user/dto/IsHostResDto.java new file mode 100644 index 0000000..19bd91c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/dto/IsHostResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IsHostResDto { + private Boolean isHost; +} diff --git a/src/main/java/com/hanaro/hanafun/user/dto/LoginReqDto.java b/src/main/java/com/hanaro/hanafun/user/dto/LoginReqDto.java new file mode 100644 index 0000000..aa0aa70 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/dto/LoginReqDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class LoginReqDto { + private String password; +} diff --git a/src/main/java/com/hanaro/hanafun/user/dto/LoginResDto.java b/src/main/java/com/hanaro/hanafun/user/dto/LoginResDto.java new file mode 100644 index 0000000..675a57c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/dto/LoginResDto.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class LoginResDto { + private String jwt; + private String userName; +} diff --git a/src/main/java/com/hanaro/hanafun/user/dto/PointResDto.java b/src/main/java/com/hanaro/hanafun/user/dto/PointResDto.java new file mode 100644 index 0000000..e4f8eee --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/dto/PointResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PointResDto { + private Integer point; +} diff --git a/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java b/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java new file mode 100644 index 0000000..2b9144e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java @@ -0,0 +1,5 @@ +package com.hanaro.hanafun.user.exception; + +public class UserNotFoundException extends RuntimeException{ + +} diff --git a/src/main/java/com/hanaro/hanafun/user/service/UserService.java b/src/main/java/com/hanaro/hanafun/user/service/UserService.java index aba0981..3b2a2aa 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/UserService.java +++ b/src/main/java/com/hanaro/hanafun/user/service/UserService.java @@ -1,5 +1,15 @@ package com.hanaro.hanafun.user.service; +import com.hanaro.hanafun.user.dto.IsHostResDto; +import com.hanaro.hanafun.user.dto.LoginReqDto; +import com.hanaro.hanafun.user.dto.LoginResDto; +import com.hanaro.hanafun.user.dto.PointResDto; + public interface UserService { + LoginResDto login(LoginReqDto loginReqDto); + + PointResDto getPoint(Long userId); + + IsHostResDto isHost(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java index b8cff0b..7094164 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java @@ -1,7 +1,43 @@ package com.hanaro.hanafun.user.service.impl; +import com.hanaro.hanafun.user.domain.UserEntity; +import com.hanaro.hanafun.user.domain.UserRepository; +import com.hanaro.hanafun.user.dto.IsHostResDto; +import com.hanaro.hanafun.user.dto.LoginReqDto; +import com.hanaro.hanafun.user.dto.LoginResDto; +import com.hanaro.hanafun.user.dto.PointResDto; +import com.hanaro.hanafun.user.service.UserService; +import lombok.RequiredArgsConstructor; +import org.apache.catalina.authenticator.BasicAuthenticator; import org.springframework.stereotype.Service; + @Service -public class UserServiceImpl { +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; +// private final JwtUtil jwtUtil; + + @Override + public LoginResDto login(LoginReqDto loginReqDto) { + UserEntity userEntity = userRepository.findByPassword(loginReqDto.getPassword()) + .orElseThrow(); +// String generatedJwt = jwtUtil.generateAccessToken(userEntity.getUserId()); + + return new LoginResDto().builder() + .jwt("generatedJwt") + .userName(userEntity.getUserName()) + .build(); + } + + @Override + public PointResDto getPoint(Long userId) { + return null; + } + + @Override + public IsHostResDto isHost(Long userId) { + return null; + } } From 871afe164f6a2b193573062a99313f87264eb77a Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 09:30:44 +0900 Subject: [PATCH 13/55] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20Bas?= =?UTF-8?q?eEntity=20=EC=83=81=EC=86=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hanaro/hanafun/category/domain/CategoryEntity.java | 10 ++-------- .../com/hanaro/hanafun/lesson/domain/LessonEntity.java | 10 ++-------- .../hanafun/lessondate/domain/LessonDateEntity.java | 8 ++------ .../hanafun/reservation/domain/ReservationEntity.java | 8 ++------ 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java index d0944a4..d8d5de7 100644 --- a/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java +++ b/src/main/java/com/hanaro/hanafun/category/domain/CategoryEntity.java @@ -1,26 +1,20 @@ package com.hanaro.hanafun.category.domain; +import com.hanaro.hanafun.common.domain.BaseEntity; import jakarta.persistence.*; import lombok.*; -import java.time.LocalDateTime; - @Entity @Table(name = "category") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Builder @AllArgsConstructor -public class CategoryEntity { +public class CategoryEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long categoryId; @Column(nullable = false) private String categoryName; - - @Column(nullable = false) - private LocalDateTime createdDate; - - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java index 79538d6..45f00c7 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java @@ -1,14 +1,13 @@ package com.hanaro.hanafun.lesson.domain; import com.hanaro.hanafun.category.domain.CategoryEntity; +import com.hanaro.hanafun.common.domain.BaseEntity; import com.hanaro.hanafun.host.domain.HostEntity; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; -import java.time.LocalDateTime; - @Entity @Table(name = "lesson") @Getter @@ -16,7 +15,7 @@ @Builder @AllArgsConstructor @DynamicInsert -public class LessonEntity { +public class LessonEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lessonId; @@ -56,9 +55,4 @@ public class LessonEntity { @ColumnDefault("0") @Column(nullable = false) private boolean isDeleted; - - @Column(nullable = false) - private LocalDateTime createdDate; - - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java index 6c471e3..12ca0d1 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.lessondate.domain; +import com.hanaro.hanafun.common.domain.BaseEntity; import com.hanaro.hanafun.lesson.domain.LessonEntity; import jakarta.persistence.*; import lombok.*; @@ -16,7 +17,7 @@ @Builder @AllArgsConstructor @DynamicInsert -public class LessonDateEntity { +public class LessonDateEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lessondateId; @@ -37,9 +38,4 @@ public class LessonDateEntity { @ColumnDefault("0") @Column(nullable = false) private int applicant; - - @Column(nullable = false) - private LocalDateTime createdDate; - - private LocalDateTime updatedDate; } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java index 92716b9..fcbe541 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.reservation.domain; +import com.hanaro.hanafun.common.domain.BaseEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.user.domain.UserEntity; import jakarta.persistence.*; @@ -16,7 +17,7 @@ @Builder @AllArgsConstructor @DynamicInsert -public class ReservationEntity { +public class ReservationEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long reservationId; @@ -36,9 +37,4 @@ public class ReservationEntity { @ColumnDefault("0") @Column(nullable = false) private boolean isDeleted; - - @Column(nullable = false) - private LocalDateTime createdDate; - - private LocalDateTime updatedDate; } From 017648734b7d5a77ac65fb38e2deeb3a01abc454 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 10:07:09 +0900 Subject: [PATCH 14/55] =?UTF-8?q?fix:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20REST=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hanafun/reservation/controller/ReservationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index c210bef..9738100 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -14,7 +14,7 @@ public class ReservationController { private final ReservationService reservationService; - @PostMapping("/reservation/my") + @GetMapping("/reservation/my") public MyPageResDto myPage(@RequestBody MyPageReqDto myPageReqDto) { return reservationService.myPage(myPageReqDto); } From a6735678146785dbb59a639d424b4ebdea7bed75 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 10:22:56 +0900 Subject: [PATCH 15/55] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80,=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20ApiResponse=20return=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 --- .../category/controller/CategoryController.java | 3 ++- .../hanafun/category/service/CategoryService.java | 3 ++- .../category/service/impl/CategoryServiceImpl.java | 11 +++++++++-- .../reservation/controller/ReservationController.java | 3 ++- .../reservation/service/ReservationService.java | 3 ++- .../service/impl/ReservationServiceImpl.java | 11 +++++++++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java index 4f8616e..83d077e 100644 --- a/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java +++ b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java @@ -2,6 +2,7 @@ import com.hanaro.hanafun.category.dto.response.CategoryResDto; import com.hanaro.hanafun.category.service.CategoryService; +import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -15,7 +16,7 @@ public class CategoryController { private final CategoryService categoryService; @GetMapping("/category") - public List categoryList() { + public ApiResponse> categoryList() { return categoryService.categoryList(); } } diff --git a/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java index d2d1e9d..9d0152f 100644 --- a/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java +++ b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java @@ -1,9 +1,10 @@ package com.hanaro.hanafun.category.service; import com.hanaro.hanafun.category.dto.response.CategoryResDto; +import com.hanaro.hanafun.common.dto.ApiResponse; import java.util.List; public interface CategoryService { - List categoryList(); + ApiResponse> categoryList(); } diff --git a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java index 5b1ff7a..bf4ca46 100644 --- a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java @@ -4,6 +4,7 @@ import com.hanaro.hanafun.category.domain.CategoryRepository; import com.hanaro.hanafun.category.dto.response.CategoryResDto; import com.hanaro.hanafun.category.service.CategoryService; +import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,7 +21,7 @@ public class CategoryServiceImpl implements CategoryService { // 카테고리 전체 출력 @Transactional @Override - public List categoryList() { + public ApiResponse> categoryList() { List categoryEntities = categoryRepository.findAll(); List categoryResDtoList = categoryEntities.stream() @@ -33,6 +34,12 @@ public List categoryList() { }) .collect(Collectors.toList()); - return categoryResDtoList; + ApiResponse> response = new ApiResponse<>( + true, + "카테고리 전체 출력 완료", + categoryResDtoList + ); + + return response; } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 9738100..517ef8c 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.reservation.controller; +import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; import com.hanaro.hanafun.reservation.service.ReservationService; @@ -15,7 +16,7 @@ public class ReservationController { private final ReservationService reservationService; @GetMapping("/reservation/my") - public MyPageResDto myPage(@RequestBody MyPageReqDto myPageReqDto) { + public ApiResponse myPage(@RequestBody MyPageReqDto myPageReqDto) { return reservationService.myPage(myPageReqDto); } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 23599a1..61a3566 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -1,8 +1,9 @@ package com.hanaro.hanafun.reservation.service; +import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; public interface ReservationService { - MyPageResDto myPage(MyPageReqDto myPageReqDto); + ApiResponse myPage(MyPageReqDto myPageReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 83875c1..6a8dacc 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.reservation.service.impl; +import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.reservation.domain.ReservationEntity; @@ -27,7 +28,7 @@ public class ReservationServiceImpl implements ReservationService { // 마이페이지 데이터 출력 @Transactional @Override - public MyPageResDto myPage(MyPageReqDto myPageReqDto) { + public ApiResponse myPage(MyPageReqDto myPageReqDto) { UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); @@ -56,6 +57,12 @@ public MyPageResDto myPage(MyPageReqDto myPageReqDto) { .point(user.getPoint()) .lessons(lessons).build(); - return myPageResDto; + ApiResponse response = new ApiResponse<>( + true, + "마이페이지 출력 완료", + myPageResDto + ); + + return response; } } From a0d045531310f25bfbe4820158c4ad3f96a29cea Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 10:38:30 +0900 Subject: [PATCH 16/55] =?UTF-8?q?feat:=20=EB=82=98=EC=9D=98=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=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 | 18 ++++++--- .../service/ReservationService.java | 7 ++++ .../service/impl/ReservationServiceImpl.java | 37 ++++++++++++++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 517ef8c..651f8dd 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -3,20 +3,28 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.ReservationList; import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequiredArgsConstructor +@RequestMapping("/reservation") public class ReservationController { private final ReservationService reservationService; - @GetMapping("/reservation/my") + // 마이페이지 데이터 출력 + @GetMapping("/my") public ApiResponse myPage(@RequestBody MyPageReqDto myPageReqDto) { return reservationService.myPage(myPageReqDto); } + + // 나의 신청 클래스 데이터 출력 + @GetMapping("/my/lessons") + public ApiResponse> myLessons(@RequestBody MyPageReqDto myPageReqDto) { + return reservationService.myLessons(myPageReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 61a3566..336867a 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -3,7 +3,14 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.ReservationList; + +import java.util.List; public interface ReservationService { + // 마이페이지 데이터 출력 ApiResponse myPage(MyPageReqDto myPageReqDto); + + // 나의 신청 클래스 데이터 출력 + ApiResponse> myLessons(MyPageReqDto myPageReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 6a8dacc..dd662df 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -55,7 +55,8 @@ public ApiResponse myPage(MyPageReqDto myPageReqDto) { MyPageResDto myPageResDto = MyPageResDto.builder() .point(user.getPoint()) - .lessons(lessons).build(); + .lessons(lessons) + .build(); ApiResponse response = new ApiResponse<>( true, @@ -65,4 +66,38 @@ public ApiResponse myPage(MyPageReqDto myPageReqDto) { return response; } + + // 나의 신청 클래스 데이터 출력 + @Transactional + @Override + public ApiResponse> myLessons(MyPageReqDto myPageReqDto) { + UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); + List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); + + List lessons = reservations.stream() + .map(reservation -> { + LessonDateEntity lessonDate = reservation.getLessonDateEntity(); + LessonEntity lessonEntity = lessonDate.getLessonEntity(); + + ReservationList lesson = ReservationList.builder() + .reservationId(reservation.getReservationId()) + .lessondateId(lessonDate.getLessondateId()) + .lessonId(lessonEntity.getLessonId()) + .image(lessonEntity.getImage()) + .title(lessonEntity.getTitle()) + .location(lessonEntity.getLocation()) + .date(lessonDate.getDate()) + .build(); + return lesson; + }) + .collect(Collectors.toList()); + + ApiResponse> response = new ApiResponse<>( + true, + "나의 신청 클래스 출력 완료", + lessons + ); + + return response; + } } From 47725ec5cebada95827261a3c005fe201cca248d Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 11:26:53 +0900 Subject: [PATCH 17/55] =?UTF-8?q?feat:=20=EC=8B=A0=EC=B2=AD=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9D=BC=EC=A0=95=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=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 --- .../controller/ReservationController.java | 8 ++++ .../dto/request/MyScheduleReqDto.java | 10 +++++ .../dto/response/MyScheduleResDto.java | 15 +++++++ .../service/ReservationService.java | 5 +++ .../service/impl/ReservationServiceImpl.java | 43 ++++++++++++++++++- 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/request/MyScheduleReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/MyScheduleResDto.java diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 651f8dd..eead08a 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -2,7 +2,9 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; import com.hanaro.hanafun.reservation.dto.response.ReservationList; import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -27,4 +29,10 @@ public ApiResponse myPage(@RequestBody MyPageReqDto myPageReqDto) public ApiResponse> myLessons(@RequestBody MyPageReqDto myPageReqDto) { return reservationService.myLessons(myPageReqDto); } + + // 신청 클래스 일정 데이터 출력 + @GetMapping("/my/schedule") + public ApiResponse> mySchedules(@RequestBody MyScheduleReqDto myScheduleReqDto) { + return reservationService.mySchedules(myScheduleReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyScheduleReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyScheduleReqDto.java new file mode 100644 index 0000000..08db7fa --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/MyScheduleReqDto.java @@ -0,0 +1,10 @@ +package com.hanaro.hanafun.reservation.dto.request; + +import lombok.Getter; + +@Getter +public class MyScheduleReqDto { + private Long userId; + private int year; + private int month; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyScheduleResDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyScheduleResDto.java new file mode 100644 index 0000000..2c6342c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/MyScheduleResDto.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@Builder +public class MyScheduleResDto { + private Long reservationId; + private Long lessonId; + private LocalDate date; + private String title; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 336867a..1532982 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -2,7 +2,9 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; import com.hanaro.hanafun.reservation.dto.response.ReservationList; import java.util.List; @@ -13,4 +15,7 @@ public interface ReservationService { // 나의 신청 클래스 데이터 출력 ApiResponse> myLessons(MyPageReqDto myPageReqDto); + + // 신청 클래스 일정 데이터 출력 + ApiResponse> mySchedules(MyScheduleReqDto myScheduleReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index dd662df..161bfd3 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -6,11 +6,14 @@ import com.hanaro.hanafun.reservation.domain.ReservationEntity; import com.hanaro.hanafun.reservation.domain.ReservationRepository; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; +import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; +import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; import com.hanaro.hanafun.reservation.dto.response.ReservationList; import com.hanaro.hanafun.reservation.service.ReservationService; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; +import com.hanaro.hanafun.user.exception.UserNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,7 +32,7 @@ public class ReservationServiceImpl implements ReservationService { @Transactional @Override public ApiResponse myPage(MyPageReqDto myPageReqDto) { - UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); + UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); LocalDate today = LocalDate.now(); // 오늘이후 날짜의 예약만 출력 @@ -71,7 +74,7 @@ public ApiResponse myPage(MyPageReqDto myPageReqDto) { @Transactional @Override public ApiResponse> myLessons(MyPageReqDto myPageReqDto) { - UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElse(null); + UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); List lessons = reservations.stream() @@ -100,4 +103,40 @@ public ApiResponse> myLessons(MyPageReqDto myPageReqDto) { return response; } + + // 신청 클래스 일정 데이터 출력 + @Transactional + @Override + public ApiResponse> mySchedules(MyScheduleReqDto myScheduleReqDto) { + UserEntity user = userRepository.findById(myScheduleReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); + List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); + + List mySchedules = reservations.stream() + .filter(reservation -> { + LocalDate date = reservation.getLessonDateEntity().getDate(); + return date.getYear() == myScheduleReqDto.getYear() && date.getMonthValue() == myScheduleReqDto.getMonth(); + }) + .map(reservation -> { + LessonDateEntity lessonDate = reservation.getLessonDateEntity(); + LessonEntity lessonEntity = lessonDate.getLessonEntity(); + + MyScheduleResDto mySchedule = MyScheduleResDto.builder() + .reservationId(reservation.getReservationId()) + .lessonId(lessonEntity.getLessonId()) + .date(lessonDate.getDate()) + .title(lessonEntity.getTitle()) + .build(); + + return mySchedule; + }) + .collect(Collectors.toList()); + + ApiResponse> response = new ApiResponse<>( + true, + "나의 신청 클래스 출력 완료", + mySchedules + ); + + return response; + } } From 1060d1db5595592efbb4d9499656452906c2247c Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 13:38:36 +0900 Subject: [PATCH 18/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EA=B4=80=EB=A6=AC(=EA=B0=9C=EC=84=A4=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=AA=A9=EB=A1=9D=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=EC=B6=9C=EB=A0=A5)=20=EA=B8=B0=EB=8A=A5=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 --- .../hanafun/host/domain/HostRepository.java | 4 ++ .../lesson/controller/LessonController.java | 24 +++++++++ .../lesson/domain/LessonRepository.java | 7 ++- .../dto/request/OpenedLessonsReqDto.java | 8 +++ .../dto/response/OpenedLessonsResDto.java | 12 +++++ .../hanafun/lesson/service/LessonService.java | 12 +++++ .../service/impl/LessonServiceImpl.java | 50 +++++++++++++++++++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/request/OpenedLessonsReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/response/OpenedLessonsResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java index 8626212..9182e46 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java @@ -1,6 +1,10 @@ package com.hanaro.hanafun.host.domain; +import com.hanaro.hanafun.user.domain.UserEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +@Repository public interface HostRepository extends JpaRepository { + HostEntity findHostEntityByUserEntity_UserId(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java new file mode 100644 index 0000000..9a38c8c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -0,0 +1,24 @@ +package com.hanaro.hanafun.lesson.controller; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; +import com.hanaro.hanafun.lesson.service.LessonService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +public class LessonController { + private final LessonService lessonService; + + // 개설 클래스 관리- 개설 클래스 목록 출력 + @GetMapping("/reservation/my/opened") + public ApiResponse> openedLessons(@RequestBody OpenedLessonsReqDto openedLessonsReqDto) { + return lessonService.openedLessons(openedLessonsReqDto); + } +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java index 4611782..bdd512b 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java @@ -1,7 +1,12 @@ package com.hanaro.hanafun.lesson.domain; +import com.hanaro.hanafun.host.domain.HostEntity; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository -public interface LessonRepository { +public interface LessonRepository extends JpaRepository { + List findLessonEntitiesByHostEntity(HostEntity hostEntity); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/request/OpenedLessonsReqDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/request/OpenedLessonsReqDto.java new file mode 100644 index 0000000..d1a6f1e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/request/OpenedLessonsReqDto.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.lesson.dto.request; + +import lombok.Getter; + +@Getter +public class OpenedLessonsReqDto { + private Long userId; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/response/OpenedLessonsResDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/response/OpenedLessonsResDto.java new file mode 100644 index 0000000..7ef18cb --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/response/OpenedLessonsResDto.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.lesson.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class OpenedLessonsResDto { + private Long lessonId; + private String image; + private String title; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java new file mode 100644 index 0000000..7f40c6f --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.lesson.service; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; + +import java.util.List; + +public interface LessonService { + // 개설 클래스 관리- 개설 클래스 목록 출력 + ApiResponse> openedLessons(OpenedLessonsReqDto openedLessonsReqDto); +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java new file mode 100644 index 0000000..7b01133 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -0,0 +1,50 @@ +package com.hanaro.hanafun.lesson.service.impl; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.host.domain.HostEntity; +import com.hanaro.hanafun.host.domain.HostRepository; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; +import com.hanaro.hanafun.lesson.service.LessonService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class LessonServiceImpl implements LessonService { + private final LessonRepository lessonRepository; + private final HostRepository hostRepository; + + // 개설 클래스 관리- 개설 클래스 목록 출력 + @Transactional + @Override + public ApiResponse> openedLessons(OpenedLessonsReqDto openedLessonsReqDto) { + HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(openedLessonsReqDto.getUserId()); + List lessons = lessonRepository.findLessonEntitiesByHostEntity(host); + + List openedLessons = lessons.stream() + .map(lesson -> { + OpenedLessonsResDto openedLesson = OpenedLessonsResDto.builder() + .lessonId(lesson.getLessonId()) + .image(lesson.getImage()) + .title(lesson.getTitle()) + .build(); + return openedLesson; + }) + .collect(Collectors.toList()); + + ApiResponse> response = new ApiResponse<>( + true, + "개설 클래스 목록 출력 완료", + openedLessons + ); + + return response; + } +} From 9a5ce4f36c153bee59b4e407912c8a117b822d65 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 13:59:45 +0900 Subject: [PATCH 19/55] feat: user, host domain are implemented --- .../hanaro/hanafun/HanafunApplication.java | 2 + .../exception/AccountNotFoundException.java | 16 ++++ .../hanafun/authentication/JwtAuthFilter.java | 40 +++++++++ .../hanafun/authentication/JwtUtil.java | 84 +++++++++++++++++++ .../authentication/SecurityConfig.java | 38 +++++++++ .../common/aop/GlobalExceptionHandler.java | 8 ++ .../hanafun/common/domain/BaseEntity.java | 17 +++- .../common/exception/CustomException.java | 12 +++ .../host/controller/HostController.java | 20 +++++ .../hanafun/host/domain/HostEntity.java | 2 + .../hanafun/host/dto/CreateHostReqDto.java | 15 ++++ .../hanafun/host/dto/CreateHostResDto.java | 14 ++++ .../hanafun/host/service/HostService.java | 4 + .../host/service/impl/HostServiceImpl.java | 39 ++++++++- .../controller/TransactionController.java | 7 ++ .../transaction/domain/TransactionEntity.java | 39 +++++++++ .../hanafun/transaction/enums/Type.java | 14 ++++ .../user/controller/UserController.java | 27 ++++-- .../hanafun/user/domain/UserEntity.java | 3 +- .../user/exception/UserNotFoundException.java | 14 +++- .../hanafun/user/service/UserService.java | 4 +- .../user/service/impl/UserServiceImpl.java | 34 +++++--- 22 files changed, 426 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/account/exception/AccountNotFoundException.java create mode 100644 src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java create mode 100644 src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java create mode 100644 src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java create mode 100644 src/main/java/com/hanaro/hanafun/common/exception/CustomException.java create mode 100644 src/main/java/com/hanaro/hanafun/host/dto/CreateHostReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/host/dto/CreateHostResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/enums/Type.java diff --git a/src/main/java/com/hanaro/hanafun/HanafunApplication.java b/src/main/java/com/hanaro/hanafun/HanafunApplication.java index 131783e..3d57a31 100644 --- a/src/main/java/com/hanaro/hanafun/HanafunApplication.java +++ b/src/main/java/com/hanaro/hanafun/HanafunApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing public class HanafunApplication { public static void main(String[] args) { diff --git a/src/main/java/com/hanaro/hanafun/account/exception/AccountNotFoundException.java b/src/main/java/com/hanaro/hanafun/account/exception/AccountNotFoundException.java new file mode 100644 index 0000000..301990b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/exception/AccountNotFoundException.java @@ -0,0 +1,16 @@ +package com.hanaro.hanafun.account.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class AccountNotFoundException extends CustomException { + static String MESSAGE = "ACCOUNT_NOT_FOUND"; + + public AccountNotFoundException(){ + super(MESSAGE); + } + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } +} diff --git a/src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java b/src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java new file mode 100644 index 0000000..7a2b516 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java @@ -0,0 +1,40 @@ +package com.hanaro.hanafun.authentication; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Component +@RequiredArgsConstructor +public class JwtAuthFilter extends OncePerRequestFilter { + + private final JwtUtil jwtUtil; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws ServletException, IOException { + + String bearerToken = request.getHeader(HttpHeaders.AUTHORIZATION); + if(bearerToken == null || !bearerToken.startsWith("Bearer ")){ + chain.doFilter(request, response); + return; + } + + String token = bearerToken.split(" ")[1]; + if(jwtUtil.isExpired(token)){ + chain.doFilter(request, response); + return; + } + + SecurityContextHolder.getContext().setAuthentication(jwtUtil.getAuthFromJwt(token)); + chain.doFilter(request, response); + } +} diff --git a/src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java b/src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java new file mode 100644 index 0000000..fa8a726 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java @@ -0,0 +1,84 @@ +package com.hanaro.hanafun.authentication; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.stereotype.Component; + +import java.util.Base64; +import java.util.Collections; +import java.util.Date; + +@Component +@RequiredArgsConstructor +public class JwtUtil { + + @Value("${jwt.secretKey}") + private String secretKey; + + @Value("${jwt.access-expired-ms}") + private Long accessExpiredMS; + + @Value("${jwt.claims.auth-key}") + private String authKey; + + @PostConstruct // 의존성 주입이 끝난 후 초기화를 수행!! secretKey를 암호화 + protected void init() { + secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes()); + } + + public String createToken(String username, Long userId) { + Claims claims = Jwts.claims().setSubject(username); + claims.put(authKey, userId); + + long now = System.currentTimeMillis(); + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(new Date(now)) + .setExpiration(new Date(now + accessExpiredMS)) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); + } + + //Jwt 파싱하여 만료여부를 확인한다. + public Boolean isExpired(String token) { + try { + return getClaims(token).getExpiration().before(new Date()); + } catch (Exception e) { + e.printStackTrace(); + return true; // 만료된 것으로 간주 + } + } + + //Jwt 파싱하여 인증 정보를 반환한다. + public long getAuthValue(String token) { + try { + return getClaims(token).get(authKey, Long.class); + } catch (Exception e) { + e.printStackTrace(); + return 0; // 기본값 반환 + } + } + + //클래임 건지기 + public Claims getClaims(String token){ + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getBody(); + } + + //Jwt 인증 정보를 토큰으로 반환 + public Authentication getAuthFromJwt(String token) { + Long userId = getAuthValue(token); + return new UsernamePasswordAuthenticationToken(userId, null, + Collections.singleton(new SimpleGrantedAuthority("USER"))); + } +} diff --git a/src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java b/src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java new file mode 100644 index 0000000..70613a4 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java @@ -0,0 +1,38 @@ +package com.hanaro.hanafun.authentication; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@Configuration +@EnableWebSecurity +@RequiredArgsConstructor +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SecurityConfig { + private final JwtAuthFilter jwtAuthFilter; + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http + .csrf(csrf -> csrf.disable()) + .httpBasic(httpBasic -> httpBasic.disable()) + .formLogin(formLogin -> formLogin.disable()) + .sessionManagement((sessionManagement) -> + sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) + ) + .authorizeHttpRequests((auth) -> auth + .requestMatchers("/user/login").permitAll() +// .anyRequest().permitAll() + .anyRequest().authenticated() + ) + .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); + + return http.build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java index 4d6b16c..3d6b787 100644 --- a/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java +++ b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.common.exception.BasicErrorStatus; +import com.hanaro.hanafun.common.exception.CustomException; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -15,4 +16,11 @@ public ResponseEntity> handleGlobalException(Exception ex) { ApiResponse response = new ApiResponse<>(false, ex.getMessage(), null); return new ResponseEntity<>(response, error.getHttpStatus()); } + + @ExceptionHandler(CustomException.class) + public ResponseEntity> handleCustomException (CustomException ex) { + ApiResponse response = new ApiResponse<>(false, ex.getMessage(), null); + return new ResponseEntity<>(response, ex.getHttpStatus()); + + } } diff --git a/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java b/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java index c8dd550..20067d9 100644 --- a/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java +++ b/src/main/java/com/hanaro/hanafun/common/domain/BaseEntity.java @@ -1,8 +1,6 @@ package com.hanaro.hanafun.common.domain; -import jakarta.persistence.Column; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.*; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -20,4 +18,17 @@ public abstract class BaseEntity { @LastModifiedDate private LocalDateTime updatedDate; + + @PrePersist + protected void onCreate() { + if (createdDate == null) { + createdDate = LocalDateTime.now(); + } + updatedDate = LocalDateTime.now(); + } + + @PreUpdate + protected void onUpdate() { + updatedDate = LocalDateTime.now(); + } } diff --git a/src/main/java/com/hanaro/hanafun/common/exception/CustomException.java b/src/main/java/com/hanaro/hanafun/common/exception/CustomException.java new file mode 100644 index 0000000..45ed1c3 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/common/exception/CustomException.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.common.exception; + +import org.springframework.http.HttpStatus; + +public abstract class CustomException extends RuntimeException{ + + public CustomException(String message) { + super(message); + } + + public abstract HttpStatus getHttpStatus(); +} diff --git a/src/main/java/com/hanaro/hanafun/host/controller/HostController.java b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java index 77140f4..7a78183 100644 --- a/src/main/java/com/hanaro/hanafun/host/controller/HostController.java +++ b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java @@ -1,7 +1,27 @@ package com.hanaro.hanafun.host.controller; +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.host.dto.CreateHostReqDto; +import com.hanaro.hanafun.host.dto.CreateHostResDto; +import com.hanaro.hanafun.host.service.impl.HostServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +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("/host") public class HostController { + + private final HostServiceImpl hostService; + + @PostMapping("/create") + public ResponseEntity createHost(@AuthenticationPrincipal Long userId, @RequestBody CreateHostReqDto createHostReqDto){ + CreateHostResDto createHostResDto = hostService.createHost(userId, createHostReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", createHostResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java index 3d3b0b6..f54162f 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostEntity.java @@ -9,6 +9,8 @@ @Entity @Table(name = "host") @Getter +@Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) public class HostEntity extends BaseEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/host/dto/CreateHostReqDto.java b/src/main/java/com/hanaro/hanafun/host/dto/CreateHostReqDto.java new file mode 100644 index 0000000..9d91f4c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/dto/CreateHostReqDto.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.host.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CreateHostReqDto { + private long accountId; + private String introduction; +} diff --git a/src/main/java/com/hanaro/hanafun/host/dto/CreateHostResDto.java b/src/main/java/com/hanaro/hanafun/host/dto/CreateHostResDto.java new file mode 100644 index 0000000..d3b5582 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/dto/CreateHostResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.host.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CreateHostResDto { + private Long hostId; +} diff --git a/src/main/java/com/hanaro/hanafun/host/service/HostService.java b/src/main/java/com/hanaro/hanafun/host/service/HostService.java index 328a297..eb44bc9 100644 --- a/src/main/java/com/hanaro/hanafun/host/service/HostService.java +++ b/src/main/java/com/hanaro/hanafun/host/service/HostService.java @@ -1,4 +1,8 @@ package com.hanaro.hanafun.host.service; +import com.hanaro.hanafun.host.dto.CreateHostReqDto; +import com.hanaro.hanafun.host.dto.CreateHostResDto; + public interface HostService { + CreateHostResDto createHost(Long userId, CreateHostReqDto createHostReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java index 6b83048..25f6579 100644 --- a/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java @@ -1,7 +1,44 @@ package com.hanaro.hanafun.host.service.impl; +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.exception.AccountNotFoundException; +import com.hanaro.hanafun.host.domain.HostEntity; +import com.hanaro.hanafun.host.domain.HostRepository; +import com.hanaro.hanafun.host.dto.CreateHostReqDto; +import com.hanaro.hanafun.host.dto.CreateHostResDto; +import com.hanaro.hanafun.host.service.HostService; +import com.hanaro.hanafun.user.domain.UserEntity; +import com.hanaro.hanafun.user.domain.UserRepository; +import com.hanaro.hanafun.user.exception.UserNotFoundException; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service -public class HostServiceImpl { +@RequiredArgsConstructor +public class HostServiceImpl implements HostService { + private final UserRepository userRepository; + private final AccountRepository accountRepository; + private final HostRepository hostRepository; + + @Override + @Transactional + public CreateHostResDto createHost(Long userId, CreateHostReqDto createHostReqDto) { + UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException()); + userEntity.setIsHost(true); + + AccountEntity accountEntity = accountRepository.findById(createHostReqDto.getAccountId()).orElseThrow(() -> new AccountNotFoundException()); + + HostEntity hostEntity = HostEntity.builder() + .userEntity(userEntity) + .introduction(createHostReqDto.getIntroduction()) + .accountEntity(accountEntity) + .build(); + HostEntity createdHost = hostRepository.save(hostEntity); + + return new CreateHostResDto().builder() + .hostId(createdHost.getHostId()) + .build(); + } } diff --git a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java new file mode 100644 index 0000000..5dd354e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.transaction.controller; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TransactionController { +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java new file mode 100644 index 0000000..d4f0130 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -0,0 +1,39 @@ +package com.hanaro.hanafun.transaction.domain; + +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.common.domain.BaseEntity; +import com.hanaro.hanafun.transaction.enums.Type; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "transaction") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class TransactionEntity extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "transaction_id") + private Long TransactionId; + + @ManyToOne + @JoinColumn(name = "deposit_id", nullable = false) + private AccountEntity depositAccount; + + @ManyToOne + @JoinColumn(name = "withdraw_id", nullable = false) + private AccountEntity withdrawAccount; + +// @Column(name = "reservation_id", nullable = false) +// private ReservationEntity reservationEntity; + + @Column(name = "payment", nullable = false) + private Integer payment; + + @Column(name = "point", nullable = false) + private Integer point; + + @Column(name = "type", nullable = false) + @Enumerated(EnumType.STRING) + private Type type; +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java b/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java new file mode 100644 index 0000000..7497347 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.transaction.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum Type { + QR("QR"), + PENDING("PENDING"), + COMPLETE("COMPLETE"); + + private String value; +} diff --git a/src/main/java/com/hanaro/hanafun/user/controller/UserController.java b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java index 28fe097..0345af9 100644 --- a/src/main/java/com/hanaro/hanafun/user/controller/UserController.java +++ b/src/main/java/com/hanaro/hanafun/user/controller/UserController.java @@ -1,15 +1,16 @@ package com.hanaro.hanafun.user.controller; import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.user.dto.IsHostResDto; import com.hanaro.hanafun.user.dto.LoginReqDto; import com.hanaro.hanafun.user.dto.LoginResDto; +import com.hanaro.hanafun.user.dto.PointResDto; import com.hanaro.hanafun.user.service.impl.UserServiceImpl; import lombok.RequiredArgsConstructor; +import org.apache.coyote.Response; 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; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -19,8 +20,20 @@ public class UserController { private final UserServiceImpl userService; @PostMapping("/login") - ResponseEntity loginUser(@RequestBody LoginReqDto request) { - LoginResDto loginResponse = userService.login(request); - return ResponseEntity.ok(new ApiResponse(true, "ok", loginResponse)); + ResponseEntity login(@RequestBody LoginReqDto request) { + LoginResDto loginResDto = userService.login(request); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", loginResDto)); + } + + @GetMapping("/point") + ResponseEntity readPoint(@AuthenticationPrincipal Long userId){ + PointResDto pointResDto = userService.readPoint(userId); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", pointResDto)); + } + + @GetMapping("/isHost") + ResponseEntity readIsHost(@AuthenticationPrincipal Long userId){ + IsHostResDto isHostResDto = userService.readIsHost(userId); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", isHostResDto)); } } diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java index 67d8a59..0cd30ec 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserEntity.java @@ -7,6 +7,7 @@ @Entity @Table(name="user") @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class UserEntity extends BaseEntity { @Id @@ -15,7 +16,7 @@ public class UserEntity extends BaseEntity { private Long userId; @Column(name="username", nullable = false) - private String userName; + private String username; @Column(name="password", length = 20, nullable = false) private String password; diff --git a/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java b/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java index 2b9144e..90e1c59 100644 --- a/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java +++ b/src/main/java/com/hanaro/hanafun/user/exception/UserNotFoundException.java @@ -1,5 +1,17 @@ package com.hanaro.hanafun.user.exception; -public class UserNotFoundException extends RuntimeException{ +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; +public class UserNotFoundException extends CustomException { + static String MESSAGE = "USER_NOT_FOUND"; + + public UserNotFoundException() { + super(MESSAGE); + } + + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } } diff --git a/src/main/java/com/hanaro/hanafun/user/service/UserService.java b/src/main/java/com/hanaro/hanafun/user/service/UserService.java index 3b2a2aa..1b9ecba 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/UserService.java +++ b/src/main/java/com/hanaro/hanafun/user/service/UserService.java @@ -8,8 +8,8 @@ public interface UserService { LoginResDto login(LoginReqDto loginReqDto); - PointResDto getPoint(Long userId); + PointResDto readPoint(Long userId); - IsHostResDto isHost(Long userId); + IsHostResDto readIsHost(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java index 7094164..f1bde47 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java @@ -1,43 +1,53 @@ package com.hanaro.hanafun.user.service.impl; +import com.hanaro.hanafun.authentication.JwtUtil; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; import com.hanaro.hanafun.user.dto.IsHostResDto; import com.hanaro.hanafun.user.dto.LoginReqDto; import com.hanaro.hanafun.user.dto.LoginResDto; import com.hanaro.hanafun.user.dto.PointResDto; +import com.hanaro.hanafun.user.exception.UserNotFoundException; import com.hanaro.hanafun.user.service.UserService; import lombok.RequiredArgsConstructor; -import org.apache.catalina.authenticator.BasicAuthenticator; import org.springframework.stereotype.Service; - @Service @RequiredArgsConstructor public class UserServiceImpl implements UserService { private final UserRepository userRepository; -// private final JwtUtil jwtUtil; + private final JwtUtil jwtUtil; @Override - public LoginResDto login(LoginReqDto loginReqDto) { + public LoginResDto login(LoginReqDto loginReqDto) throws UserNotFoundException{ UserEntity userEntity = userRepository.findByPassword(loginReqDto.getPassword()) - .orElseThrow(); -// String generatedJwt = jwtUtil.generateAccessToken(userEntity.getUserId()); + .orElseThrow(() -> new UserNotFoundException()); + String generatedJwt = jwtUtil.createToken(userEntity.getUsername(), userEntity.getUserId()); return new LoginResDto().builder() - .jwt("generatedJwt") - .userName(userEntity.getUserName()) + .jwt(generatedJwt) + .userName(userEntity.getUsername()) .build(); } @Override - public PointResDto getPoint(Long userId) { - return null; + public PointResDto readPoint(Long userId) throws UserNotFoundException{ + UserEntity userEntity = userRepository.findById(userId) + .orElseThrow(() -> new UserNotFoundException()); + + return new PointResDto().builder() + .point(userEntity.getPoint()) + .build(); } @Override - public IsHostResDto isHost(Long userId) { - return null; + public IsHostResDto readIsHost(Long userId) throws UserNotFoundException{ + UserEntity userEntity = userRepository.findById(userId) + .orElseThrow(() -> new UserNotFoundException()); + + return new IsHostResDto().builder() + .isHost(userEntity.getIsHost()) + .build(); } } From a715ef7cca47588e32380b2aa440fc6501d6004b Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 14:01:21 +0900 Subject: [PATCH 20/55] feat: user, host domain are implemented --- build.gradle | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 043ddad..e55c63b 100644 --- a/build.gradle +++ b/build.gradle @@ -24,15 +24,23 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-security' + //Jwt + implementation 'io.jsonwebtoken:jjwt-api:0.11.2' + implementation 'io.jsonwebtoken:jjwt-impl:0.11.2' + implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2' + + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + + // Spring Security + implementation 'org.springframework.boot:spring-boot-starter-security' testImplementation 'org.springframework.security:spring-security-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + } tasks.named('test') { From 54a5c35164e3673b07d174a74903cacf54ec01bd Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 14:06:14 +0900 Subject: [PATCH 21/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=81=EC=84=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lesson/controller/LessonController.java | 10 +++++ .../controller/LessonDateController.java | 12 +++++ .../domain/LessonDateRepository.java | 4 +- .../dto/response/LessonDetailResDto.java | 13 ++++++ .../lessondate/service/LessonDateService.java | 11 +++++ .../service/impl/LessonDateServiceImpl.java | 45 +++++++++++++++++++ 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index 9a38c8c..3554551 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -4,8 +4,11 @@ import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.service.LessonService; +import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; +import com.hanaro.hanafun.lessondate.service.LessonDateService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -15,10 +18,17 @@ @RequiredArgsConstructor public class LessonController { private final LessonService lessonService; + private final LessonDateService lessonDateService; // 개설 클래스 관리- 개설 클래스 목록 출력 @GetMapping("/reservation/my/opened") public ApiResponse> openedLessons(@RequestBody OpenedLessonsReqDto openedLessonsReqDto) { return lessonService.openedLessons(openedLessonsReqDto); } + + // 개설 클래스 상세 + @GetMapping("/reservation/my/opened/{lessonId}") + public ApiResponse> lessonDetail(@PathVariable Long lessonId) { + return lessonDateService.lessonDetail(lessonId); + } } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java new file mode 100644 index 0000000..6e5e96a --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.lessondate.controller; + +import com.hanaro.hanafun.lessondate.service.LessonDateService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class LessonDateController { + private final LessonDateService lessonDateService; + +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java index ed7856c..448526d 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java @@ -3,7 +3,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface LessonDateRepository extends JpaRepository { - + List findLessonDateEntitiesByLessonEntity_LessonId(Long lessonId); } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java new file mode 100644 index 0000000..377373b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java @@ -0,0 +1,13 @@ +package com.hanaro.hanafun.lessondate.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@Builder +public class LessonDetailResDto { + private Long lessondateId; + private LocalDate date; +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java new file mode 100644 index 0000000..f990c09 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java @@ -0,0 +1,11 @@ +package com.hanaro.hanafun.lessondate.service; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; + +import java.util.List; + +public interface LessonDateService { + // 개설 클래스 상세 + ApiResponse> lessonDetail(Long lessonId); +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java new file mode 100644 index 0000000..ef6dc6a --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java @@ -0,0 +1,45 @@ +package com.hanaro.hanafun.lessondate.service.impl; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; +import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; +import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; +import com.hanaro.hanafun.lessondate.service.LessonDateService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor + +public class LessonDateServiceImpl implements LessonDateService { + private final LessonDateRepository lessonDateRepository; + + // 개설 클래스 상세 + @Transactional + @Override + public ApiResponse> lessonDetail(Long lessonId) { + List lessonDates = lessonDateRepository.findLessonDateEntitiesByLessonEntity_LessonId(lessonId); + + List lessonDetails = lessonDates.stream() + .map(lessonDate -> { + LessonDetailResDto lessonDetail = LessonDetailResDto.builder() + .lessondateId(lessonDate.getLessondateId()) + .date(lessonDate.getDate()) + .build(); + return lessonDetail; + }) + .collect(Collectors.toList()); + + ApiResponse> response = new ApiResponse<>( + true, + "개설 클래스 상세 출력 완료", + lessonDetails + ); + + return response; + } +} From 24889967fdce8c7b2f6aa3d0a5bc11dc273e79ea Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 14:13:27 +0900 Subject: [PATCH 22/55] Update TransactionEntity.java --- .../hanaro/hanafun/transaction/domain/TransactionEntity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java index fb6e394..725a894 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -25,7 +25,8 @@ public class TransactionEntity extends BaseEntity { @JoinColumn(name = "withdraw_id", nullable = false) private AccountEntity withdrawAccount; - @Column(name = "reservation_id", nullable = false) + @ManyToOne + @JoinColumn(name = "reservation_id", nullable = false) private ReservationEntity reservationEntity; @Column(name = "payment", nullable = false) From 0199f27fb5e1828f39cd6d5154b197cca3b2661e Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 14:53:16 +0900 Subject: [PATCH 23/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=81=EC=84=B8-=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=B3=B4=20=EC=B6=9C=EB=A0=A5=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 --- .../LessonDateNotFoundException.java | 4 ++ .../controller/ReservationController.java | 8 ++++ .../domain/ReservationRepository.java | 1 + .../dto/request/LessonDateDetailReqDto.java | 8 ++++ .../dto/response/LessonDateDetailResDto.java | 14 ++++++ .../dto/response/ReservationPerson.java | 14 ++++++ .../service/ReservationService.java | 5 +++ .../service/impl/ReservationServiceImpl.java | 45 +++++++++++++++++-- 8 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/request/LessonDateDetailReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/LessonDateDetailResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationPerson.java diff --git a/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java b/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java new file mode 100644 index 0000000..aadf33b --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java @@ -0,0 +1,4 @@ +package com.hanaro.hanafun.lessondate.exception; + +public class LessonDateNotFoundException extends RuntimeException{ +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index eead08a..5b7f1df 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -1,8 +1,10 @@ package com.hanaro.hanafun.reservation.controller; import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; +import com.hanaro.hanafun.reservation.dto.response.LessonDateDetailResDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; import com.hanaro.hanafun.reservation.dto.response.ReservationList; @@ -35,4 +37,10 @@ public ApiResponse> myLessons(@RequestBody MyPageReqDto my public ApiResponse> mySchedules(@RequestBody MyScheduleReqDto myScheduleReqDto) { return reservationService.mySchedules(myScheduleReqDto); } + + // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 + @PostMapping("/my/opened/people") + public ApiResponse lessonDateDetail(@RequestBody LessonDateDetailReqDto lessonDateDetailReqDto) { + return reservationService.lessonDateDetail(lessonDateDetailReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java index cb6dce7..b6f827c 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -9,4 +9,5 @@ @Repository public interface ReservationRepository extends JpaRepository { List findReservationEntitiesByUserEntity(UserEntity userEntity); + List findReservationEntitiesByLessonDateEntity_LessondateId(Long lessondateId); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/LessonDateDetailReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/LessonDateDetailReqDto.java new file mode 100644 index 0000000..8a41398 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/LessonDateDetailReqDto.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.reservation.dto.request; + +import lombok.Getter; + +@Getter +public class LessonDateDetailReqDto { + private Long lessondateId; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/LessonDateDetailResDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/LessonDateDetailResDto.java new file mode 100644 index 0000000..2b36917 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/LessonDateDetailResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class LessonDateDetailResDto { + private int applicant; // lessondate의 신청인원 + private int capacity; // lesson의 모집인원 + private List people; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationPerson.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationPerson.java new file mode 100644 index 0000000..c5fae01 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationPerson.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class ReservationPerson { + private LocalDateTime startTime; + private String userName; + private String email; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 1532982..82e93bd 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -3,9 +3,11 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; +import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; import com.hanaro.hanafun.reservation.dto.response.ReservationList; +import com.hanaro.hanafun.reservation.dto.response.LessonDateDetailResDto; import java.util.List; @@ -18,4 +20,7 @@ public interface ReservationService { // 신청 클래스 일정 데이터 출력 ApiResponse> mySchedules(MyScheduleReqDto myScheduleReqDto); + + // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 + ApiResponse lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 161bfd3..3d7013b 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -3,13 +3,14 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; +import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; +import com.hanaro.hanafun.lessondate.exception.LessonDateNotFoundException; import com.hanaro.hanafun.reservation.domain.ReservationEntity; import com.hanaro.hanafun.reservation.domain.ReservationRepository; +import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; -import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; -import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; -import com.hanaro.hanafun.reservation.dto.response.ReservationList; +import com.hanaro.hanafun.reservation.dto.response.*; import com.hanaro.hanafun.reservation.service.ReservationService; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; @@ -27,6 +28,7 @@ public class ReservationServiceImpl implements ReservationService { private final ReservationRepository reservationRepository; private final UserRepository userRepository; + private final LessonDateRepository lessonDateRepository; // 마이페이지 데이터 출력 @Transactional @@ -139,4 +141,41 @@ public ApiResponse> mySchedules(MyScheduleReqDto mySchedu return response; } + + // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 + @Transactional + @Override + public ApiResponse lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto) { + Long lessondateId = lessonDateDetailReqDto.getLessondateId(); + LessonDateEntity lessonDate = lessonDateRepository.findById(lessondateId).orElseThrow(() -> new LessonDateNotFoundException()); + List reservations = reservationRepository.findReservationEntitiesByLessonDateEntity_LessondateId(lessondateId); + + int applicant = lessonDate.getApplicant(); // 신청인원 + int capacity = lessonDate.getLessonEntity().getCapacity(); // 모집인원 + + List people = reservations.stream() + .map(reservation -> { + ReservationPerson person = ReservationPerson.builder() + .startTime(lessonDate.getStartTime()) + .userName(reservation.getUserEntity().getUserName()) + .email(reservation.getUserEntity().getEmail()) + .build(); + return person; + }) + .collect(Collectors.toList()); + + LessonDateDetailResDto lessonDateDetailResDto = LessonDateDetailResDto.builder() + .applicant(applicant) + .capacity(capacity) + .people(people) + .build(); + + ApiResponse response = new ApiResponse<>( + true, + "예약자 정보 출력 완료", + lessonDateDetailResDto + ); + + return response; + } } From ca78900bbf92400f8e58e079e633677eb8102e53 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 14:58:32 +0900 Subject: [PATCH 24/55] feat: account domain is implemented --- .../account/controller/AccountController.java | 18 +++++++++--------- .../account/domain/AccountRepository.java | 4 ++++ .../hanafun/account/dto/AccountResDto.java | 17 +++++++++++++++++ .../hanafun/account/mapper/AccountMapper.java | 19 +++++++++++++++++++ .../account/service/AccountService.java | 5 +++++ .../service/impl/AccountServiceImpl.java | 15 +++++++++++---- .../controller/TransactionController.java | 6 ++++++ .../transaction/domain/TransactionEntity.java | 3 ++- .../domain/TransactionRepository.java | 6 ++++++ .../hanafun/transaction/dto/CheckResDto.java | 14 ++++++++++++++ .../hanafun/transaction/dto/QrReqDto.java | 17 +++++++++++++++++ .../service/TransactionService.java | 4 ++++ .../service/impl/TransactionServiceImpl.java | 11 +++++++++++ .../user/service/impl/UserServiceImpl.java | 6 +++--- 14 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/account/dto/AccountResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java index e310ef6..975d0b5 100644 --- a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java +++ b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java @@ -1,26 +1,26 @@ package com.hanaro.hanafun.account.controller; -import com.hanaro.hanafun.account.domain.AccountEntity; -import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.dto.AccountResDto; import com.hanaro.hanafun.account.service.impl.AccountServiceImpl; +import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.swing.text.html.Option; -import java.util.Optional; +import java.util.List; @RestController @RequestMapping("/account") @RequiredArgsConstructor public class AccountController { private final AccountServiceImpl accountService; - private final AccountRepository accountRepository; - @GetMapping("/test") - public ResponseEntity> test(){ - Optional test = accountRepository.findById(1L); - return ResponseEntity.ok(test); + + @GetMapping("/list") + ResponseEntity readAccountList(@AuthenticationPrincipal Long userId){ + List accountResDtoList = accountService.readAccountList(userId); + return ResponseEntity.ok(new ApiResponse(true, "ok", accountResDtoList)); } } diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java index 08203ad..6a032fd 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountRepository.java @@ -2,5 +2,9 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + public interface AccountRepository extends JpaRepository { + Optional> findByUserEntityUserId(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/account/dto/AccountResDto.java b/src/main/java/com/hanaro/hanafun/account/dto/AccountResDto.java new file mode 100644 index 0000000..08c093f --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/dto/AccountResDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.account.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class AccountResDto { + private long accountId; + private String accountName; + private String accountNumber; + private int balance; +} diff --git a/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java b/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java new file mode 100644 index 0000000..35d4762 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java @@ -0,0 +1,19 @@ +package com.hanaro.hanafun.account.mapper; + +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.dto.AccountResDto; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class AccountMapper { + public AccountResDto entityToAccountResDto(AccountEntity accountEntity){ + if(accountEntity == null) return null; + + return AccountResDto.builder() + .accountId(accountEntity.getAccountId()) + .accountNumber(accountEntity.getAccountNumber()) + .accountName(accountEntity.getAccountName()) + .balance(accountEntity.getBalance()) + .build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/account/service/AccountService.java b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java index b5ec1a0..4e306c6 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/AccountService.java +++ b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java @@ -1,4 +1,9 @@ package com.hanaro.hanafun.account.service; +import com.hanaro.hanafun.account.dto.AccountResDto; + +import java.util.List; + public interface AccountService { + List readAccountList(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java index d81fe23..9637493 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java @@ -2,16 +2,23 @@ import com.hanaro.hanafun.account.domain.AccountEntity; import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.dto.AccountResDto; +import com.hanaro.hanafun.account.exception.AccountNotFoundException; +import com.hanaro.hanafun.account.mapper.AccountMapper; +import com.hanaro.hanafun.account.service.AccountService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.Optional; +import java.util.List; @Service @RequiredArgsConstructor -public class AccountServiceImpl { +public class AccountServiceImpl implements AccountService { private final AccountRepository accountRepository; - private Optional test(){ - return accountRepository.findById(1L); + + @Override + public List readAccountList(Long userId) { + List accountEntityList = accountRepository.findByUserEntityUserId(userId).orElseThrow(() -> new AccountNotFoundException()); + return accountEntityList.stream().map(AccountMapper::entityToAccountResDto).toList(); } } diff --git a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java index 5dd354e..af59af1 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java +++ b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java @@ -1,7 +1,13 @@ package com.hanaro.hanafun.transaction.controller; +import com.hanaro.hanafun.transaction.service.impl.TransactionServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController +@RequiredArgsConstructor +@RequestMapping("/transaction") public class TransactionController { + private final TransactionServiceImpl transactionService; } diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java index fb6e394..725a894 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -25,7 +25,8 @@ public class TransactionEntity extends BaseEntity { @JoinColumn(name = "withdraw_id", nullable = false) private AccountEntity withdrawAccount; - @Column(name = "reservation_id", nullable = false) + @ManyToOne + @JoinColumn(name = "reservation_id", nullable = false) private ReservationEntity reservationEntity; @Column(name = "payment", nullable = false) diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java new file mode 100644 index 0000000..42c45df --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java @@ -0,0 +1,6 @@ +package com.hanaro.hanafun.transaction.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TransactionRepository extends JpaRepository { +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java new file mode 100644 index 0000000..a8d5e4c --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.transaction.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CheckResDto { + private long transactionId; +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java new file mode 100644 index 0000000..f711ace --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.transaction.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class QrReqDto { + private long depositId; + private long withdrawId; + private long lessondateId; + private int payment; +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java new file mode 100644 index 0000000..e1b0f7f --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java @@ -0,0 +1,4 @@ +package com.hanaro.hanafun.transaction.service; + +public interface TransactionService { +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java new file mode 100644 index 0000000..61ebdf2 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java @@ -0,0 +1,11 @@ +package com.hanaro.hanafun.transaction.service.impl; + +import com.hanaro.hanafun.transaction.domain.TransactionRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TransactionServiceImpl { + private final TransactionRepository transactionRepository; +} diff --git a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java index f1bde47..a1583e9 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java @@ -20,7 +20,7 @@ public class UserServiceImpl implements UserService { private final JwtUtil jwtUtil; @Override - public LoginResDto login(LoginReqDto loginReqDto) throws UserNotFoundException{ + public LoginResDto login(LoginReqDto loginReqDto){ UserEntity userEntity = userRepository.findByPassword(loginReqDto.getPassword()) .orElseThrow(() -> new UserNotFoundException()); String generatedJwt = jwtUtil.createToken(userEntity.getUsername(), userEntity.getUserId()); @@ -32,7 +32,7 @@ public LoginResDto login(LoginReqDto loginReqDto) throws UserNotFoundException{ } @Override - public PointResDto readPoint(Long userId) throws UserNotFoundException{ + public PointResDto readPoint(Long userId){ UserEntity userEntity = userRepository.findById(userId) .orElseThrow(() -> new UserNotFoundException()); @@ -42,7 +42,7 @@ public PointResDto readPoint(Long userId) throws UserNotFoundException{ } @Override - public IsHostResDto readIsHost(Long userId) throws UserNotFoundException{ + public IsHostResDto readIsHost(Long userId){ UserEntity userEntity = userRepository.findById(userId) .orElseThrow(() -> new UserNotFoundException()); From c8d20ad1e2c7e18933d8ceb02cc27dcf10514e5e Mon Sep 17 00:00:00 2001 From: yubin-im Date: Wed, 26 Jun 2024 15:56:42 +0900 Subject: [PATCH 25/55] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=97=90=EC=84=9C=20ResponseEntity=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=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 --- .../controller/CategoryController.java | 7 +-- .../category/service/CategoryService.java | 3 +- .../service/impl/CategoryServiceImpl.java | 12 +----- .../lesson/controller/LessonController.java | 11 +++-- .../hanafun/lesson/service/LessonService.java | 3 +- .../service/impl/LessonServiceImpl.java | 11 +---- .../LessonDateNotFoundException.java | 15 ++++++- .../lessondate/service/LessonDateService.java | 3 +- .../service/impl/LessonDateServiceImpl.java | 11 +---- .../controller/ReservationController.java | 21 +++++---- .../service/ReservationService.java | 9 ++-- .../service/impl/ReservationServiceImpl.java | 43 ++++--------------- 12 files changed, 60 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java index 83d077e..4251c1f 100644 --- a/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java +++ b/src/main/java/com/hanaro/hanafun/category/controller/CategoryController.java @@ -4,8 +4,8 @@ import com.hanaro.hanafun.category.service.CategoryService; import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; +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.RestController; import java.util.List; @@ -16,7 +16,8 @@ public class CategoryController { private final CategoryService categoryService; @GetMapping("/category") - public ApiResponse> categoryList() { - return categoryService.categoryList(); + public ResponseEntity categoryList() { + List categoryResDtoList = categoryService.categoryList(); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", categoryResDtoList)); } } diff --git a/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java index 9d0152f..d2d1e9d 100644 --- a/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java +++ b/src/main/java/com/hanaro/hanafun/category/service/CategoryService.java @@ -1,10 +1,9 @@ package com.hanaro.hanafun.category.service; import com.hanaro.hanafun.category.dto.response.CategoryResDto; -import com.hanaro.hanafun.common.dto.ApiResponse; import java.util.List; public interface CategoryService { - ApiResponse> categoryList(); + List categoryList(); } diff --git a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java index bf4ca46..5497f80 100644 --- a/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/category/service/impl/CategoryServiceImpl.java @@ -4,12 +4,10 @@ import com.hanaro.hanafun.category.domain.CategoryRepository; import com.hanaro.hanafun.category.dto.response.CategoryResDto; import com.hanaro.hanafun.category.service.CategoryService; -import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -21,7 +19,7 @@ public class CategoryServiceImpl implements CategoryService { // 카테고리 전체 출력 @Transactional @Override - public ApiResponse> categoryList() { + public List categoryList() { List categoryEntities = categoryRepository.findAll(); List categoryResDtoList = categoryEntities.stream() @@ -34,12 +32,6 @@ public ApiResponse> categoryList() { }) .collect(Collectors.toList()); - ApiResponse> response = new ApiResponse<>( - true, - "카테고리 전체 출력 완료", - categoryResDtoList - ); - - return response; + return categoryResDtoList; } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index 3554551..8b2bd13 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -7,6 +7,7 @@ import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; import com.hanaro.hanafun.lessondate.service.LessonDateService; 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.RequestBody; @@ -22,13 +23,15 @@ public class LessonController { // 개설 클래스 관리- 개설 클래스 목록 출력 @GetMapping("/reservation/my/opened") - public ApiResponse> openedLessons(@RequestBody OpenedLessonsReqDto openedLessonsReqDto) { - return lessonService.openedLessons(openedLessonsReqDto); + public ResponseEntity openedLessons(@RequestBody OpenedLessonsReqDto openedLessonsReqDto) { + List openedLessons = lessonService.openedLessons(openedLessonsReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", openedLessons)); } // 개설 클래스 상세 @GetMapping("/reservation/my/opened/{lessonId}") - public ApiResponse> lessonDetail(@PathVariable Long lessonId) { - return lessonDateService.lessonDetail(lessonId); + public ResponseEntity lessonDetail(@PathVariable Long lessonId) { + List lessonDetails = lessonDateService.lessonDetail(lessonId); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonDetails)); } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index 7f40c6f..c2f2c09 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -1,6 +1,5 @@ package com.hanaro.hanafun.lesson.service; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; @@ -8,5 +7,5 @@ public interface LessonService { // 개설 클래스 관리- 개설 클래스 목록 출력 - ApiResponse> openedLessons(OpenedLessonsReqDto openedLessonsReqDto); + List openedLessons(OpenedLessonsReqDto openedLessonsReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index 7b01133..b7403b7 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -1,6 +1,5 @@ package com.hanaro.hanafun.lesson.service.impl; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.host.domain.HostEntity; import com.hanaro.hanafun.host.domain.HostRepository; import com.hanaro.hanafun.lesson.domain.LessonEntity; @@ -24,7 +23,7 @@ public class LessonServiceImpl implements LessonService { // 개설 클래스 관리- 개설 클래스 목록 출력 @Transactional @Override - public ApiResponse> openedLessons(OpenedLessonsReqDto openedLessonsReqDto) { + public List openedLessons(OpenedLessonsReqDto openedLessonsReqDto) { HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(openedLessonsReqDto.getUserId()); List lessons = lessonRepository.findLessonEntitiesByHostEntity(host); @@ -39,12 +38,6 @@ public ApiResponse> openedLessons(OpenedLessonsReqDto }) .collect(Collectors.toList()); - ApiResponse> response = new ApiResponse<>( - true, - "개설 클래스 목록 출력 완료", - openedLessons - ); - - return response; + return openedLessons; } } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java b/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java index aadf33b..e2c972b 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/exception/LessonDateNotFoundException.java @@ -1,4 +1,17 @@ package com.hanaro.hanafun.lessondate.exception; -public class LessonDateNotFoundException extends RuntimeException{ +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class LessonDateNotFoundException extends CustomException { + static String MESSAGE = "LESSONDATE_NOT_FOUND"; + + public LessonDateNotFoundException() { + super(MESSAGE); + } + + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java index f990c09..cba8a51 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java @@ -1,11 +1,10 @@ package com.hanaro.hanafun.lessondate.service; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; import java.util.List; public interface LessonDateService { // 개설 클래스 상세 - ApiResponse> lessonDetail(Long lessonId); + List lessonDetail(Long lessonId); } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java index ef6dc6a..9013b0e 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java @@ -1,6 +1,5 @@ package com.hanaro.hanafun.lessondate.service.impl; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; @@ -21,7 +20,7 @@ public class LessonDateServiceImpl implements LessonDateService { // 개설 클래스 상세 @Transactional @Override - public ApiResponse> lessonDetail(Long lessonId) { + public List lessonDetail(Long lessonId) { List lessonDates = lessonDateRepository.findLessonDateEntitiesByLessonEntity_LessonId(lessonId); List lessonDetails = lessonDates.stream() @@ -34,12 +33,6 @@ public ApiResponse> lessonDetail(Long lessonId) { }) .collect(Collectors.toList()); - ApiResponse> response = new ApiResponse<>( - true, - "개설 클래스 상세 출력 완료", - lessonDetails - ); - - return response; + return lessonDetails; } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index 5b7f1df..cf8aa3b 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -10,6 +10,7 @@ import com.hanaro.hanafun.reservation.dto.response.ReservationList; import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -22,25 +23,29 @@ public class ReservationController { // 마이페이지 데이터 출력 @GetMapping("/my") - public ApiResponse myPage(@RequestBody MyPageReqDto myPageReqDto) { - return reservationService.myPage(myPageReqDto); + public ResponseEntity myPage(@RequestBody MyPageReqDto myPageReqDto) { + MyPageResDto myPageResDto = reservationService.myPage(myPageReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", myPageResDto)); } // 나의 신청 클래스 데이터 출력 @GetMapping("/my/lessons") - public ApiResponse> myLessons(@RequestBody MyPageReqDto myPageReqDto) { - return reservationService.myLessons(myPageReqDto); + public ResponseEntity myLessons(@RequestBody MyPageReqDto myPageReqDto) { + List lessons = reservationService.myLessons(myPageReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessons)); } // 신청 클래스 일정 데이터 출력 @GetMapping("/my/schedule") - public ApiResponse> mySchedules(@RequestBody MyScheduleReqDto myScheduleReqDto) { - return reservationService.mySchedules(myScheduleReqDto); + public ResponseEntity mySchedules(@RequestBody MyScheduleReqDto myScheduleReqDto) { + List mySchedules = reservationService.mySchedules(myScheduleReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", mySchedules)); } // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 @PostMapping("/my/opened/people") - public ApiResponse lessonDateDetail(@RequestBody LessonDateDetailReqDto lessonDateDetailReqDto) { - return reservationService.lessonDateDetail(lessonDateDetailReqDto); + public ResponseEntity lessonDateDetail(@RequestBody LessonDateDetailReqDto lessonDateDetailReqDto) { + LessonDateDetailResDto lessonDateDetailResDto = reservationService.lessonDateDetail(lessonDateDetailReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonDateDetailResDto)); } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 82e93bd..aa94033 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -1,6 +1,5 @@ package com.hanaro.hanafun.reservation.service; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; @@ -13,14 +12,14 @@ public interface ReservationService { // 마이페이지 데이터 출력 - ApiResponse myPage(MyPageReqDto myPageReqDto); + MyPageResDto myPage(MyPageReqDto myPageReqDto); // 나의 신청 클래스 데이터 출력 - ApiResponse> myLessons(MyPageReqDto myPageReqDto); + List myLessons(MyPageReqDto myPageReqDto); // 신청 클래스 일정 데이터 출력 - ApiResponse> mySchedules(MyScheduleReqDto myScheduleReqDto); + List mySchedules(MyScheduleReqDto myScheduleReqDto); // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 - ApiResponse lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); + LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 3d7013b..661e2d2 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -1,6 +1,5 @@ package com.hanaro.hanafun.reservation.service.impl; -import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; @@ -33,7 +32,7 @@ public class ReservationServiceImpl implements ReservationService { // 마이페이지 데이터 출력 @Transactional @Override - public ApiResponse myPage(MyPageReqDto myPageReqDto) { + public MyPageResDto myPage(MyPageReqDto myPageReqDto) { UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); @@ -63,19 +62,13 @@ public ApiResponse myPage(MyPageReqDto myPageReqDto) { .lessons(lessons) .build(); - ApiResponse response = new ApiResponse<>( - true, - "마이페이지 출력 완료", - myPageResDto - ); - - return response; + return myPageResDto; } // 나의 신청 클래스 데이터 출력 @Transactional @Override - public ApiResponse> myLessons(MyPageReqDto myPageReqDto) { + public List myLessons(MyPageReqDto myPageReqDto) { UserEntity user = userRepository.findById(myPageReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); @@ -97,19 +90,13 @@ public ApiResponse> myLessons(MyPageReqDto myPageReqDto) { }) .collect(Collectors.toList()); - ApiResponse> response = new ApiResponse<>( - true, - "나의 신청 클래스 출력 완료", - lessons - ); - - return response; + return lessons; } // 신청 클래스 일정 데이터 출력 @Transactional @Override - public ApiResponse> mySchedules(MyScheduleReqDto myScheduleReqDto) { + public List mySchedules(MyScheduleReqDto myScheduleReqDto) { UserEntity user = userRepository.findById(myScheduleReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByUserEntity(user); @@ -133,19 +120,13 @@ public ApiResponse> mySchedules(MyScheduleReqDto mySchedu }) .collect(Collectors.toList()); - ApiResponse> response = new ApiResponse<>( - true, - "나의 신청 클래스 출력 완료", - mySchedules - ); - - return response; + return mySchedules; } // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 @Transactional @Override - public ApiResponse lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto) { + public LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto) { Long lessondateId = lessonDateDetailReqDto.getLessondateId(); LessonDateEntity lessonDate = lessonDateRepository.findById(lessondateId).orElseThrow(() -> new LessonDateNotFoundException()); List reservations = reservationRepository.findReservationEntitiesByLessonDateEntity_LessondateId(lessondateId); @@ -157,7 +138,7 @@ public ApiResponse lessonDateDetail(LessonDateDetailReqD .map(reservation -> { ReservationPerson person = ReservationPerson.builder() .startTime(lessonDate.getStartTime()) - .userName(reservation.getUserEntity().getUserName()) + .userName(reservation.getUserEntity().getUsername()) .email(reservation.getUserEntity().getEmail()) .build(); return person; @@ -170,12 +151,6 @@ public ApiResponse lessonDateDetail(LessonDateDetailReqD .people(people) .build(); - ApiResponse response = new ApiResponse<>( - true, - "예약자 정보 출력 완료", - lessonDateDetailResDto - ); - - return response; + return lessonDateDetailResDto; } } From 79e1afac6e620ad07b098e3fee85f3544d0e851f Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Wed, 26 Jun 2024 17:40:25 +0900 Subject: [PATCH 26/55] feat: QR pay is implemented --- .../hanafun/account/domain/AccountEntity.java | 2 +- .../domain/ReservationRepository.java | 2 + .../service/impl/ReservationServiceImpl.java | 2 +- .../revenue/controller/RevenueController.java | 11 +++ .../hanafun/revenue/domain/RevenueEntity.java | 39 ++++++++ .../revenue/domain/RevenueRepository.java | 10 ++ .../controller/TransactionController.java | 12 +++ .../transaction/domain/TransactionEntity.java | 2 + .../dto/{CheckResDto.java => PayResDto.java} | 2 +- .../hanafun/transaction/dto/QrReqDto.java | 4 +- .../service/TransactionService.java | 4 + .../service/impl/TransactionServiceImpl.java | 99 ++++++++++++++++++- 12 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java rename src/main/java/com/hanaro/hanafun/transaction/dto/{CheckResDto.java => PayResDto.java} (90%) diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 1fcf926..31b2ea1 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -7,7 +7,7 @@ @Entity @Table(name = "account") -@Getter +@Data @NoArgsConstructor(access = AccessLevel.PROTECTED) public class AccountEntity extends BaseEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java index b6f827c..c88cad5 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -5,9 +5,11 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface ReservationRepository extends JpaRepository { List findReservationEntitiesByUserEntity(UserEntity userEntity); List findReservationEntitiesByLessonDateEntity_LessondateId(Long lessondateId); + Optional findByUserEntityUserIdAndLessonDateEntityLessondateId(Long userId, Long lessondateId); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 3d7013b..3319e2d 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -157,7 +157,7 @@ public ApiResponse lessonDateDetail(LessonDateDetailReqD .map(reservation -> { ReservationPerson person = ReservationPerson.builder() .startTime(lessonDate.getStartTime()) - .userName(reservation.getUserEntity().getUserName()) + .userName(reservation.getUserEntity().getUsername()) .email(reservation.getUserEntity().getEmail()) .build(); return person; diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java new file mode 100644 index 0000000..1aeee03 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java @@ -0,0 +1,11 @@ +package com.hanaro.hanafun.revenue.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/revenue") +public class RevenueController { +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java new file mode 100644 index 0000000..4fddd13 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java @@ -0,0 +1,39 @@ +package com.hanaro.hanafun.revenue.domain; + +import com.hanaro.hanafun.common.domain.BaseEntity; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; + +@Entity +@Table(name = "revenue") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RevenueEntity extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "revenue_id") + private Long revenueId; + + @ManyToOne + @JoinColumn(name = "lesson_id") + private LessonEntity lessonEntity; + + @Column(name = "revenue", nullable = false) + private Long revenue; + + @Column(name = "material_price", nullable = false) + @ColumnDefault("0") + private Integer materialPrice; + + @Column(name = "rental_price", nullable = false) + @ColumnDefault("0") + private Integer rentalPrice; + + @Column(name = "etc_price", nullable = false) + @ColumnDefault("0") + private Integer etcPrice; +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java new file mode 100644 index 0000000..48cab83 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java @@ -0,0 +1,10 @@ +package com.hanaro.hanafun.revenue.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +import java.time.LocalDateTime; +import java.util.Optional; + +public interface RevenueRepository extends JpaRepository { + Optional findByCreatedDateBetween(LocalDateTime startDateTime, LocalDateTime endDateTime); +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java index af59af1..65642cc 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java +++ b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java @@ -1,7 +1,13 @@ package com.hanaro.hanafun.transaction.controller; +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.QrReqDto; import com.hanaro.hanafun.transaction.service.impl.TransactionServiceImpl; 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; @@ -10,4 +16,10 @@ @RequestMapping("/transaction") public class TransactionController { private final TransactionServiceImpl transactionService; + + @PostMapping("/qr") + public ResponseEntity qrPay(@RequestBody QrReqDto qrReqDto){ + PayResDto payResDto = transactionService.qrPay(qrReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", payResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java index 725a894..bd2a926 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -10,6 +10,8 @@ @Entity @Table(name = "transaction") @Data +@Builder +@AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) public class TransactionEntity extends BaseEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/PayResDto.java similarity index 90% rename from src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java rename to src/main/java/com/hanaro/hanafun/transaction/dto/PayResDto.java index a8d5e4c..6e30cb5 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/dto/CheckResDto.java +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/PayResDto.java @@ -9,6 +9,6 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class CheckResDto { +public class PayResDto { private long transactionId; } diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java index f711ace..55a6401 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java @@ -10,8 +10,10 @@ @AllArgsConstructor @NoArgsConstructor public class QrReqDto { - private long depositId; + private long guestId; private long withdrawId; + private long depositId; + private long lessonId; private long lessondateId; private int payment; } diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java index e1b0f7f..c716055 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java +++ b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java @@ -1,4 +1,8 @@ package com.hanaro.hanafun.transaction.service; +import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.QrReqDto; + public interface TransactionService { + PayResDto qrPay(QrReqDto qrReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java index 61ebdf2..f09b99b 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java @@ -1,11 +1,108 @@ package com.hanaro.hanafun.transaction.service.impl; +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.exception.AccountNotFoundException; +import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; +import com.hanaro.hanafun.reservation.domain.ReservationRepository; +import com.hanaro.hanafun.revenue.domain.RevenueEntity; +import com.hanaro.hanafun.revenue.domain.RevenueRepository; +import com.hanaro.hanafun.transaction.domain.TransactionEntity; import com.hanaro.hanafun.transaction.domain.TransactionRepository; +import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.QrReqDto; +import com.hanaro.hanafun.transaction.enums.Type; +import com.hanaro.hanafun.transaction.service.TransactionService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.util.Optional; @Service @RequiredArgsConstructor -public class TransactionServiceImpl { +public class TransactionServiceImpl implements TransactionService { + private final LessonRepository lessonRepository; + private final LessonDateRepository lessonDateRepository; + private final ReservationRepository reservationRepository; + private final RevenueRepository revenueRepository; + private final AccountRepository accountRepository; private final TransactionRepository transactionRepository; + + @Override + @Transactional + public PayResDto qrPay(QrReqDto qrReqDto) { + //계좌 잔액 업데이트 + AccountEntity withdrawAccount = calcWithdraw(qrReqDto.getWithdrawId(), qrReqDto.getPayment(), "qr"); + AccountEntity depositAccount = calcDeposit(qrReqDto.getDepositId(), qrReqDto.getPayment(), "qr"); + + //매출 변경 업데이트 + calcRevenue(qrReqDto.getLessonId(), qrReqDto.getPayment()); + + //거래 내역 저장 + TransactionEntity transactionEntity = TransactionEntity.builder() + .depositAccount(depositAccount) + .withdrawAccount(withdrawAccount) + .reservationEntity(reservationRepository + .findByUserEntityUserIdAndLessonDateEntityLessondateId(qrReqDto.getGuestId(), qrReqDto.getLessondateId()) + .get()) + .payment(qrReqDto.getPayment()) + .point(0) + .type(Type.QR) + .build(); + TransactionEntity createdTransaction = transactionRepository.save(transactionEntity); + + return new PayResDto().builder() + .transactionId(createdTransaction.getTransactionId()) + .build(); + } + + @Transactional + public AccountEntity calcWithdraw(Long withdrawId, int payment, String type){ + AccountEntity withdrawAccount = accountRepository.findById(withdrawId).orElseThrow(() -> new AccountNotFoundException()); + if(type.equals("qr")){ + withdrawAccount.setBalance(withdrawAccount.getBalance() - payment); + } else if(type.equals("reserve")) { + + } else if(type.equals("refund")) { + + } + + return withdrawAccount; + } + + @Transactional + public AccountEntity calcDeposit(Long depositId, int payment, String type){ + AccountEntity depositAccount = accountRepository.findById(depositId).orElseThrow(() -> new AccountNotFoundException()); + + if(type.equals("qr")){ + depositAccount.setBalance(depositAccount.getBalance() + payment); + } + + return depositAccount; + } + + @Transactional + public void calcRevenue(Long lessonId, int payment){ + LocalDateTime startOfMonth = YearMonth.now().atDay(1).atStartOfDay(); + LocalDateTime endOfMonth = YearMonth.now().atEndOfMonth().atTime(23, 59, 59); + + RevenueEntity revenueEntity = revenueRepository.findByCreatedDateBetween(startOfMonth, endOfMonth).orElse(null); + + if (revenueEntity != null) { + revenueEntity.setRevenue(revenueEntity.getRevenue() + payment); + } else { + RevenueEntity newRevenue = RevenueEntity.builder() + .lessonEntity(lessonRepository.findById(lessonId).get()) + .revenue((long) payment) + .materialPrice(0) + .rentalPrice(0) + .etcPrice(0) + .build(); + revenueRepository.save(newRevenue); + } + } } From a3fffe6f114d3507f5cbef341398f5119c733513 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Thu, 27 Jun 2024 09:40:15 +0900 Subject: [PATCH 27/55] fix: account password data type --- .../java/com/hanaro/hanafun/account/domain/AccountEntity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 31b2ea1..01f7438 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -25,8 +25,8 @@ public class AccountEntity extends BaseEntity { @Column(name = "account_name", length = 50) private String accountName; - @Column(name = "password", nullable = false) - private Integer password; + @Column(name = "password", length = 20, nullable = false) + private String password; @Column(name = "balance", nullable = false) private Integer balance; From 01afbeeb694cf0e200daee73b69a241ccb6dd24d Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 09:43:58 +0900 Subject: [PATCH 28/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=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 --- .../hanafun/account/domain/AccountEntity.java | 4 +- .../lessondate/domain/LessonDateEntity.java | 5 ++ .../domain/LessonDateRepository.java | 2 + .../controller/ReservationController.java | 7 +++ .../domain/ReservationRepository.java | 2 + .../dto/request/BookLessonReqDto.java | 12 +++++ .../service/ReservationService.java | 4 ++ .../service/impl/ReservationServiceImpl.java | 46 +++++++++++++++++++ .../hanafun/user/domain/UserRepository.java | 1 + 9 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 1fcf926..07a117c 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -25,8 +25,8 @@ public class AccountEntity extends BaseEntity { @Column(name = "account_name", length = 50) private String accountName; - @Column(name = "password", nullable = false) - private Integer password; + @Column(name = "password", length = 20, nullable = false) + private String password; @Column(name = "balance", nullable = false) private Integer balance; diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java index 12ca0d1..4f04c4f 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateEntity.java @@ -38,4 +38,9 @@ public class LessonDateEntity extends BaseEntity { @ColumnDefault("0") @Column(nullable = false) private int applicant; + + // 신청인원 업데이트 + public void updateApplicant(int applicant) { + this.applicant = applicant; + } } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java index 448526d..b194344 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/domain/LessonDateRepository.java @@ -4,8 +4,10 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface LessonDateRepository extends JpaRepository { List findLessonDateEntitiesByLessonEntity_LessonId(Long lessonId); + Optional findLessonDateEntityByLessondateId(Long lessondateId); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index cf8aa3b..b104eae 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -1,6 +1,7 @@ package com.hanaro.hanafun.reservation.controller; import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; @@ -48,4 +49,10 @@ public ResponseEntity lessonDateDetail(@RequestBody LessonDateDetai LessonDateDetailResDto lessonDateDetailResDto = reservationService.lessonDateDetail(lessonDateDetailReqDto); return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonDateDetailResDto)); } + + // 클래스 예약하기 + @PostMapping("/check") + public String bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) { + return reservationService.bookLesson(bookLessonReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java index b6f827c..97b98ca 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationRepository.java @@ -5,9 +5,11 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface ReservationRepository extends JpaRepository { List findReservationEntitiesByUserEntity(UserEntity userEntity); List findReservationEntitiesByLessonDateEntity_LessondateId(Long lessondateId); + Optional findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId(Long userId, Long lessondateId); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java new file mode 100644 index 0000000..271d8a9 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/BookLessonReqDto.java @@ -0,0 +1,12 @@ +package com.hanaro.hanafun.reservation.dto.request; + +import lombok.Getter; + +@Getter +public class BookLessonReqDto { + private Long lessondateId; + private Long userId; + private int applicant; // 예약 수량 + private Long accountId; + private String password; // 계좌 비밀번호 확인 +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index aa94033..07876a4 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.reservation.service; +import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; @@ -22,4 +23,7 @@ public interface ReservationService { // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); + + // 클래스 예약하기 + String bookLesson(BookLessonReqDto bookLessonReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 661e2d2..768432f 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -1,11 +1,15 @@ package com.hanaro.hanafun.reservation.service.impl; +import com.hanaro.hanafun.account.domain.AccountEntity; +import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.exception.AccountNotFoundException; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import com.hanaro.hanafun.lessondate.exception.LessonDateNotFoundException; import com.hanaro.hanafun.reservation.domain.ReservationEntity; import com.hanaro.hanafun.reservation.domain.ReservationRepository; +import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; @@ -20,6 +24,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -28,6 +33,7 @@ public class ReservationServiceImpl implements ReservationService { private final ReservationRepository reservationRepository; private final UserRepository userRepository; private final LessonDateRepository lessonDateRepository; + private final AccountRepository accountRepository; // 마이페이지 데이터 출력 @Transactional @@ -153,4 +159,44 @@ public LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDate return lessonDateDetailResDto; } + + // 클래스 예약하기 + @Transactional + @Override + public String bookLesson(BookLessonReqDto bookLessonReqDto) { + // 계좌 비밀번호 확인 + AccountEntity account = accountRepository.findById(bookLessonReqDto.getAccountId()).orElseThrow(() -> new AccountNotFoundException()); + if (!account.getPassword().equals(bookLessonReqDto.getPassword())) { + return "계좌 비밀번호가 맞지 않습니다."; + } + + // 모집인원 초과 확인 + LessonDateEntity lessonDate = lessonDateRepository.findLessonDateEntityByLessondateId(bookLessonReqDto.getLessondateId()).orElseThrow(() -> new LessonDateNotFoundException()); + LessonEntity lesson = lessonDate.getLessonEntity(); + if(lesson.getCapacity() < lessonDate.getApplicant() + bookLessonReqDto.getApplicant()) { + return "모집인원이 초과되었습니다."; + } + + // 해당 날짜에 예약 이미 있는지 확인 + Optional existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId( + bookLessonReqDto.getUserId(), bookLessonReqDto.getLessondateId()); + if (existingReservation.isPresent()) { + return "이미 예약이 존재합니다."; + } + + // 예약 추가 + UserEntity user = userRepository.findUserEntityByUserId(bookLessonReqDto.getUserId()).orElseThrow(() -> new UserNotFoundException()); + ReservationEntity reservation = ReservationEntity.builder() + .userEntity(user) + .lessonDateEntity(lessonDate) + .applicant(bookLessonReqDto.getApplicant()) + .build(); + reservationRepository.save(reservation); + + // 강좌 신청인원 증가 + lessonDate.updateApplicant(lessonDate.getApplicant() + bookLessonReqDto.getApplicant()); + lessonDateRepository.save(lessonDate); + + return "예약완료"; + } } diff --git a/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java index e3b92b8..2d7a390 100644 --- a/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java +++ b/src/main/java/com/hanaro/hanafun/user/domain/UserRepository.java @@ -8,4 +8,5 @@ @Repository public interface UserRepository extends JpaRepository { Optional findByPassword(String password); + Optional findUserEntityByUserId(Long userId); } From 4d513880c1bff53f118232f5ecde524718c401a1 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 10:03:42 +0900 Subject: [PATCH 29/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5-=20Dt?= =?UTF-8?q?o=20return=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 --- .../controller/ReservationController.java | 10 ++++------ .../dto/response/BookLessonResDto.java | 10 ++++++++++ .../service/ReservationService.java | 7 ++----- .../service/impl/ReservationServiceImpl.java | 18 +++++++++++++----- 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/response/BookLessonResDto.java diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index b104eae..c21fac5 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -5,10 +5,7 @@ import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; -import com.hanaro.hanafun.reservation.dto.response.LessonDateDetailResDto; -import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; -import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; -import com.hanaro.hanafun.reservation.dto.response.ReservationList; +import com.hanaro.hanafun.reservation.dto.response.*; import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -52,7 +49,8 @@ public ResponseEntity lessonDateDetail(@RequestBody LessonDateDetai // 클래스 예약하기 @PostMapping("/check") - public String bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) { - return reservationService.bookLesson(bookLessonReqDto); + public ResponseEntity bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) { + BookLessonResDto bookLessonResDto = reservationService.bookLesson(bookLessonReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", bookLessonResDto)); } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/BookLessonResDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/BookLessonResDto.java new file mode 100644 index 0000000..d3f3167 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/BookLessonResDto.java @@ -0,0 +1,10 @@ +package com.hanaro.hanafun.reservation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class BookLessonResDto { + private String message; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 07876a4..8986176 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -4,10 +4,7 @@ import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; -import com.hanaro.hanafun.reservation.dto.response.MyPageResDto; -import com.hanaro.hanafun.reservation.dto.response.MyScheduleResDto; -import com.hanaro.hanafun.reservation.dto.response.ReservationList; -import com.hanaro.hanafun.reservation.dto.response.LessonDateDetailResDto; +import com.hanaro.hanafun.reservation.dto.response.*; import java.util.List; @@ -25,5 +22,5 @@ public interface ReservationService { LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); // 클래스 예약하기 - String bookLesson(BookLessonReqDto bookLessonReqDto); + BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 768432f..ca41f0a 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -163,25 +163,31 @@ public LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDate // 클래스 예약하기 @Transactional @Override - public String bookLesson(BookLessonReqDto bookLessonReqDto) { + public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { // 계좌 비밀번호 확인 AccountEntity account = accountRepository.findById(bookLessonReqDto.getAccountId()).orElseThrow(() -> new AccountNotFoundException()); if (!account.getPassword().equals(bookLessonReqDto.getPassword())) { - return "계좌 비밀번호가 맞지 않습니다."; + return BookLessonResDto.builder() + .message("계좌 비밀번호가 맞지 않습니다.") + .build(); } // 모집인원 초과 확인 LessonDateEntity lessonDate = lessonDateRepository.findLessonDateEntityByLessondateId(bookLessonReqDto.getLessondateId()).orElseThrow(() -> new LessonDateNotFoundException()); LessonEntity lesson = lessonDate.getLessonEntity(); if(lesson.getCapacity() < lessonDate.getApplicant() + bookLessonReqDto.getApplicant()) { - return "모집인원이 초과되었습니다."; + return BookLessonResDto.builder() + .message("모집인원이 초과되었습니다.") + .build(); } // 해당 날짜에 예약 이미 있는지 확인 Optional existingReservation = reservationRepository.findReservationEntityByUserEntity_UserIdAndLessonDateEntity_LessondateId( bookLessonReqDto.getUserId(), bookLessonReqDto.getLessondateId()); if (existingReservation.isPresent()) { - return "이미 예약이 존재합니다."; + return BookLessonResDto.builder() + .message("이미 예약이 존재합니다.") + .build(); } // 예약 추가 @@ -197,6 +203,8 @@ public String bookLesson(BookLessonReqDto bookLessonReqDto) { lessonDate.updateApplicant(lessonDate.getApplicant() + bookLessonReqDto.getApplicant()); lessonDateRepository.save(lessonDate); - return "예약완료"; + return BookLessonResDto.builder() + .message("예약완료") + .build(); } } From a86a0a17d93f4204ee81ce47d2f7cbff006e761a Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 10:15:46 +0900 Subject: [PATCH 30/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=9C=EB=A0=A5=EC=8B=9C=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=9D=B4=EB=A6=84=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 --- .../hanafun/reservation/dto/response/ReservationList.java | 1 + .../reservation/service/impl/ReservationServiceImpl.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java index 583ff14..9bb1ef7 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/response/ReservationList.java @@ -15,4 +15,5 @@ public class ReservationList { private String title; private String location; private LocalDate date; + private String categoryName; } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index ca41f0a..f4af851 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -58,6 +58,7 @@ public MyPageResDto myPage(MyPageReqDto myPageReqDto) { .title(lessonEntity.getTitle()) .location(lessonEntity.getLocation()) .date(lessonDate.getDate()) + .categoryName(lessonEntity.getCategoryEntity().getCategoryName()) .build(); return lesson; }) @@ -91,6 +92,7 @@ public List myLessons(MyPageReqDto myPageReqDto) { .title(lessonEntity.getTitle()) .location(lessonEntity.getLocation()) .date(lessonDate.getDate()) + .categoryName(lessonEntity.getCategoryEntity().getCategoryName()) .build(); return lesson; }) From 1b913a96bcc68ff6dd25057f111d7dc854ee47be Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Thu, 27 Jun 2024 10:58:06 +0900 Subject: [PATCH 31/55] feat: host info --- .../hanafun/account/domain/AccountEntity.java | 4 +-- .../host/controller/HostController.java | 12 +++++--- .../hanafun/host/domain/HostRepository.java | 3 ++ .../hanafun/host/dto/HostAccountDto.java | 17 +++++++++++ .../hanafun/host/dto/HostInfoResDto.java | 17 +++++++++++ .../hanafun/host/dto/HostLessonDto.java | 15 ++++++++++ .../host/exception/HostNotFoundException.java | 16 ++++++++++ .../hanafun/host/mapper/HostMapper.java | 17 +++++++++++ .../hanafun/host/service/HostService.java | 3 ++ .../host/service/impl/HostServiceImpl.java | 30 +++++++++++++++++-- .../lesson/domain/LessonRepository.java | 4 +++ 11 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/host/dto/HostAccountDto.java create mode 100644 src/main/java/com/hanaro/hanafun/host/dto/HostInfoResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/host/dto/HostLessonDto.java create mode 100644 src/main/java/com/hanaro/hanafun/host/exception/HostNotFoundException.java create mode 100644 src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 1fcf926..07a117c 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -25,8 +25,8 @@ public class AccountEntity extends BaseEntity { @Column(name = "account_name", length = 50) private String accountName; - @Column(name = "password", nullable = false) - private Integer password; + @Column(name = "password", length = 20, nullable = false) + private String password; @Column(name = "balance", nullable = false) private Integer balance; diff --git a/src/main/java/com/hanaro/hanafun/host/controller/HostController.java b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java index 7a78183..048435a 100644 --- a/src/main/java/com/hanaro/hanafun/host/controller/HostController.java +++ b/src/main/java/com/hanaro/hanafun/host/controller/HostController.java @@ -3,14 +3,12 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.host.dto.CreateHostReqDto; import com.hanaro.hanafun.host.dto.CreateHostResDto; +import com.hanaro.hanafun.host.dto.HostInfoResDto; import com.hanaro.hanafun.host.service.impl.HostServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -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; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -24,4 +22,10 @@ public ResponseEntity createHost(@AuthenticationPrincipal Long user CreateHostResDto createHostResDto = hostService.createHost(userId, createHostReqDto); return ResponseEntity.ok(new ApiResponse(true, "ok", createHostResDto)); } + + @GetMapping("/info") + public ResponseEntity readHostInfo(@AuthenticationPrincipal Long userId){ + HostInfoResDto hostInfoResDto = hostService.readHostInfo(userId); + return ResponseEntity.ok(new ApiResponse(true, "ok", hostInfoResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java index 8626212..34514a9 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java @@ -2,5 +2,8 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface HostRepository extends JpaRepository { + Optional findByUserEntityUserId(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/host/dto/HostAccountDto.java b/src/main/java/com/hanaro/hanafun/host/dto/HostAccountDto.java new file mode 100644 index 0000000..bb160d4 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/dto/HostAccountDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.host.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HostAccountDto { + private long accountId; + private String accountName; + private String accountNumber; + private int balance; +} diff --git a/src/main/java/com/hanaro/hanafun/host/dto/HostInfoResDto.java b/src/main/java/com/hanaro/hanafun/host/dto/HostInfoResDto.java new file mode 100644 index 0000000..e730562 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/dto/HostInfoResDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.host.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HostInfoResDto { + private HostAccountDto account; + private List lessonList; +} diff --git a/src/main/java/com/hanaro/hanafun/host/dto/HostLessonDto.java b/src/main/java/com/hanaro/hanafun/host/dto/HostLessonDto.java new file mode 100644 index 0000000..c19a174 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/dto/HostLessonDto.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.host.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HostLessonDto { + private Long lessonId; + private String title; +} diff --git a/src/main/java/com/hanaro/hanafun/host/exception/HostNotFoundException.java b/src/main/java/com/hanaro/hanafun/host/exception/HostNotFoundException.java new file mode 100644 index 0000000..d8b76cc --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/exception/HostNotFoundException.java @@ -0,0 +1,16 @@ +package com.hanaro.hanafun.host.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class HostNotFoundException extends CustomException { + static String MESSAGE = "HOST_NOT_FOUND"; + + public HostNotFoundException(){ + super(MESSAGE); + } + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } +} diff --git a/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java b/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java new file mode 100644 index 0000000..7a770c7 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.host.mapper; + +import com.hanaro.hanafun.host.dto.HostLessonDto; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class HostMapper { + public HostLessonDto LessonEntityToHostLessonDto(LessonEntity lessonEntity){ + if(lessonEntity == null) return null; + + return new HostLessonDto().builder() + .lessonId(lessonEntity.getLessonId()) + .title(lessonEntity.getTitle()) + .build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/host/service/HostService.java b/src/main/java/com/hanaro/hanafun/host/service/HostService.java index eb44bc9..cdc99ab 100644 --- a/src/main/java/com/hanaro/hanafun/host/service/HostService.java +++ b/src/main/java/com/hanaro/hanafun/host/service/HostService.java @@ -2,7 +2,10 @@ import com.hanaro.hanafun.host.dto.CreateHostReqDto; import com.hanaro.hanafun.host.dto.CreateHostResDto; +import com.hanaro.hanafun.host.dto.HostInfoResDto; public interface HostService { CreateHostResDto createHost(Long userId, CreateHostReqDto createHostReqDto); + + HostInfoResDto readHostInfo(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java index 25f6579..6feefcd 100644 --- a/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/host/service/impl/HostServiceImpl.java @@ -5,9 +5,12 @@ import com.hanaro.hanafun.account.exception.AccountNotFoundException; import com.hanaro.hanafun.host.domain.HostEntity; import com.hanaro.hanafun.host.domain.HostRepository; -import com.hanaro.hanafun.host.dto.CreateHostReqDto; -import com.hanaro.hanafun.host.dto.CreateHostResDto; +import com.hanaro.hanafun.host.dto.*; +import com.hanaro.hanafun.host.exception.HostNotFoundException; +import com.hanaro.hanafun.host.mapper.HostMapper; import com.hanaro.hanafun.host.service.HostService; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import com.hanaro.hanafun.lesson.domain.LessonRepository; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; import com.hanaro.hanafun.user.exception.UserNotFoundException; @@ -15,11 +18,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @RequiredArgsConstructor public class HostServiceImpl implements HostService { private final UserRepository userRepository; private final AccountRepository accountRepository; + private final LessonRepository lessonRepository; private final HostRepository hostRepository; @Override @@ -41,4 +47,24 @@ public CreateHostResDto createHost(Long userId, CreateHostReqDto createHostReqDt .hostId(createdHost.getHostId()) .build(); } + + @Override + public HostInfoResDto readHostInfo(Long userId) { + HostEntity hostEntity = hostRepository.findByUserEntityUserId(userId).orElseThrow(() -> new HostNotFoundException()); + AccountEntity accountEntity = hostEntity.getAccountEntity(); + HostAccountDto hostAccountDto = HostAccountDto.builder() + .accountId(accountEntity.getAccountId()) + .accountName(accountEntity.getAccountName()) + .accountNumber(accountEntity.getAccountNumber()) + .balance(accountEntity.getBalance()) + .build(); + + List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(); + List hostLessonDtoList = lessonEntityList.stream().map(HostMapper::LessonEntityToHostLessonDto).toList(); + + return new HostInfoResDto().builder() + .account(hostAccountDto) + .lessonList(hostLessonDtoList) + .build(); + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java index 4611782..ff2ce61 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java @@ -2,6 +2,10 @@ import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface LessonRepository { + Optional> findByHostEntityHostId(Long hostId); } From 17fc38ea8432cb557db8d732cdd0eb0227246dc5 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 10:58:10 +0900 Subject: [PATCH 32/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=B7=A8=EC=86=8C=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=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 --- .../controller/ReservationController.java | 13 ++++++---- .../reservation/domain/ReservationEntity.java | 5 ++++ .../dto/request/CancelLessonReqDto.java | 8 +++++++ .../ReservationNotFounException.java | 17 +++++++++++++ .../service/ReservationService.java | 10 ++++---- .../service/impl/ReservationServiceImpl.java | 24 +++++++++++++++---- 6 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/reservation/dto/request/CancelLessonReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/reservation/exception/ReservationNotFounException.java diff --git a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java index c21fac5..8fcf120 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java +++ b/src/main/java/com/hanaro/hanafun/reservation/controller/ReservationController.java @@ -1,10 +1,7 @@ package com.hanaro.hanafun.reservation.controller; import com.hanaro.hanafun.common.dto.ApiResponse; -import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; -import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; +import com.hanaro.hanafun.reservation.dto.request.*; import com.hanaro.hanafun.reservation.dto.response.*; import com.hanaro.hanafun.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -47,10 +44,16 @@ public ResponseEntity lessonDateDetail(@RequestBody LessonDateDetai return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonDateDetailResDto)); } - // 클래스 예약하기 + // 클래스 예약하기 (결제 제외) @PostMapping("/check") public ResponseEntity bookLesson(@RequestBody BookLessonReqDto bookLessonReqDto) { BookLessonResDto bookLessonResDto = reservationService.bookLesson(bookLessonReqDto); return ResponseEntity.ok(new ApiResponse<>(true, "ok", bookLessonResDto)); } + + // 클래스 취소하기 (환불 제외) + @PostMapping("/cancel") + public void cancelLesson(@RequestBody CancelLessonReqDto cancelLessonReqDto) { + reservationService.cancelLesson(cancelLessonReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java index fcbe541..c294e27 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java +++ b/src/main/java/com/hanaro/hanafun/reservation/domain/ReservationEntity.java @@ -37,4 +37,9 @@ public class ReservationEntity extends BaseEntity { @ColumnDefault("0") @Column(nullable = false) private boolean isDeleted; + + // 삭제 업데이트 + public void updateIsDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/dto/request/CancelLessonReqDto.java b/src/main/java/com/hanaro/hanafun/reservation/dto/request/CancelLessonReqDto.java new file mode 100644 index 0000000..e93bcd6 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/dto/request/CancelLessonReqDto.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.reservation.dto.request; + +import lombok.Getter; + +@Getter +public class CancelLessonReqDto { + private Long reservationId; +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/exception/ReservationNotFounException.java b/src/main/java/com/hanaro/hanafun/reservation/exception/ReservationNotFounException.java new file mode 100644 index 0000000..ab1b8bd --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/reservation/exception/ReservationNotFounException.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.reservation.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class ReservationNotFounException extends CustomException { + static String MESSAGE = "RESERVATION_NOT_FOUND"; + + public ReservationNotFounException() { + super(MESSAGE); + } + + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } +} diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java index 8986176..1977b85 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/ReservationService.java @@ -1,9 +1,6 @@ package com.hanaro.hanafun.reservation.service; -import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; -import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; +import com.hanaro.hanafun.reservation.dto.request.*; import com.hanaro.hanafun.reservation.dto.response.*; import java.util.List; @@ -21,6 +18,9 @@ public interface ReservationService { // 개설 클래스 상세- 강좌날짜 별 예약자 정보 출력 LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDateDetailReqDto); - // 클래스 예약하기 + // 클래스 예약하기 (결제 제외) BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto); + + // 클래스 취소하기 (환불 제외) + void cancelLesson(CancelLessonReqDto cancelLessonReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index f4af851..39766c4 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -9,11 +9,9 @@ import com.hanaro.hanafun.lessondate.exception.LessonDateNotFoundException; import com.hanaro.hanafun.reservation.domain.ReservationEntity; import com.hanaro.hanafun.reservation.domain.ReservationRepository; -import com.hanaro.hanafun.reservation.dto.request.BookLessonReqDto; -import com.hanaro.hanafun.reservation.dto.request.LessonDateDetailReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyPageReqDto; -import com.hanaro.hanafun.reservation.dto.request.MyScheduleReqDto; +import com.hanaro.hanafun.reservation.dto.request.*; import com.hanaro.hanafun.reservation.dto.response.*; +import com.hanaro.hanafun.reservation.exception.ReservationNotFounException; import com.hanaro.hanafun.reservation.service.ReservationService; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; @@ -162,7 +160,7 @@ public LessonDateDetailResDto lessonDateDetail(LessonDateDetailReqDto lessonDate return lessonDateDetailResDto; } - // 클래스 예약하기 + // 클래스 예약하기 (결제 제외) @Transactional @Override public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { @@ -209,4 +207,20 @@ public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { .message("예약완료") .build(); } + + // 클래스 취소하기 (환불 제외) + @Transactional + @Override + public void cancelLesson(CancelLessonReqDto cancelLessonReqDto) { + ReservationEntity reservation = reservationRepository.findById(cancelLessonReqDto.getReservationId()).orElseThrow(() -> new ReservationNotFounException()); + + // 클래스 취소 (논리적 삭제) + reservation.updateIsDeleted(true); + reservationRepository.save(reservation); + + // 신청 인원 제거 + LessonDateEntity lessonDate = reservation.getLessonDateEntity(); + lessonDate.updateApplicant(lessonDate.getApplicant() - reservation.getApplicant()); + lessonDateRepository.save(lessonDate); + } } From d4ec7a0637654753984218936c4c32a13f8d1305 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Thu, 27 Jun 2024 11:10:26 +0900 Subject: [PATCH 33/55] feat: host info --- src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java | 1 - .../java/com/hanaro/hanafun/lesson/domain/LessonRepository.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java index 6b39173..9705895 100644 --- a/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java +++ b/src/main/java/com/hanaro/hanafun/host/domain/HostRepository.java @@ -1,7 +1,6 @@ package com.hanaro.hanafun.host.domain; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; import java.util.Optional; diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java index c0ad97d..db8d731 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java @@ -10,6 +10,5 @@ @Repository public interface LessonRepository extends JpaRepository { List findLessonEntitiesByHostEntity(HostEntity hostEntity); - Optional> findByHostEntityHostId(Long hostId); } From 7903cd138028ecab80ccabfd0e6c3d43d2431ea1 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 11:25:35 +0900 Subject: [PATCH 34/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=98=88=EC=95=BD/=EC=B7=A8=EC=86=8C=20=EC=8B=9C=20=EA=B0=95?= =?UTF-8?q?=EC=A2=8C=20=EC=8B=A0=EC=B2=AD=20=EB=88=84=EC=A0=81=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hanaro/hanafun/lesson/domain/LessonEntity.java | 5 +++++ .../service/impl/ReservationServiceImpl.java | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java index 45f00c7..20048ee 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonEntity.java @@ -55,4 +55,9 @@ public class LessonEntity extends BaseEntity { @ColumnDefault("0") @Column(nullable = false) private boolean isDeleted; + + // 강좌신청 누적인원 업데이트 + public void updateApplicantSum(int applicantSum) { + this.applicantSum = applicantSum; + } } diff --git a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java index 39766c4..ad9dbbd 100644 --- a/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/reservation/service/impl/ReservationServiceImpl.java @@ -4,6 +4,7 @@ import com.hanaro.hanafun.account.domain.AccountRepository; import com.hanaro.hanafun.account.exception.AccountNotFoundException; import com.hanaro.hanafun.lesson.domain.LessonEntity; +import com.hanaro.hanafun.lesson.domain.LessonRepository; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import com.hanaro.hanafun.lessondate.exception.LessonDateNotFoundException; @@ -32,6 +33,7 @@ public class ReservationServiceImpl implements ReservationService { private final UserRepository userRepository; private final LessonDateRepository lessonDateRepository; private final AccountRepository accountRepository; + private final LessonRepository lessonRepository; // 마이페이지 데이터 출력 @Transactional @@ -203,6 +205,10 @@ public BookLessonResDto bookLesson(BookLessonReqDto bookLessonReqDto) { lessonDate.updateApplicant(lessonDate.getApplicant() + bookLessonReqDto.getApplicant()); lessonDateRepository.save(lessonDate); + // 강좌 신청 누적인원 증가 + lesson.updateApplicantSum(lesson.getApplicantSum() + bookLessonReqDto.getApplicant()); + lessonRepository.save(lesson); + return BookLessonResDto.builder() .message("예약완료") .build(); @@ -222,5 +228,10 @@ public void cancelLesson(CancelLessonReqDto cancelLessonReqDto) { LessonDateEntity lessonDate = reservation.getLessonDateEntity(); lessonDate.updateApplicant(lessonDate.getApplicant() - reservation.getApplicant()); lessonDateRepository.save(lessonDate); + + // 강좌 신청 누적인원 제거 + LessonEntity lesson = lessonDate.getLessonEntity(); + lesson.updateApplicantSum(lesson.getApplicantSum() - reservation.getApplicant()); + lessonRepository.save(lesson); } } From 8e9f383b18a95eb57fd4cd70899527510ac20370 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 11:34:54 +0900 Subject: [PATCH 35/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=81=EC=84=B8-=20lessonId=20return=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 --- .../hanafun/lessondate/dto/response/LessonDetailResDto.java | 1 + .../hanafun/lessondate/service/impl/LessonDateServiceImpl.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java index 377373b..4c63790 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java @@ -10,4 +10,5 @@ public class LessonDetailResDto { private Long lessondateId; private LocalDate date; + private Long lessonId; } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java index 9013b0e..77d7148 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java @@ -28,6 +28,7 @@ public List lessonDetail(Long lessonId) { LessonDetailResDto lessonDetail = LessonDetailResDto.builder() .lessondateId(lessonDate.getLessondateId()) .date(lessonDate.getDate()) + .lessonId(lessonId) .build(); return lessonDetail; }) From 599326f34723fa9ce18fffe238f500761e4b6bec Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 13:16:59 +0900 Subject: [PATCH 36/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=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 --- .../lesson/controller/LessonController.java | 10 +++++++- .../lesson/dto/response/LessonInfoResDto.java | 18 +++++++++++++++ .../exception/LessonNotFoundException.java | 17 ++++++++++++++ .../hanafun/lesson/service/LessonService.java | 4 ++++ .../service/impl/LessonServiceImpl.java | 23 +++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/response/LessonInfoResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/exception/LessonNotFoundException.java diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index 8b2bd13..ada165a 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -2,6 +2,7 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.service.LessonService; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; @@ -30,8 +31,15 @@ public ResponseEntity openedLessons(@RequestBody OpenedLessonsReqDt // 개설 클래스 상세 @GetMapping("/reservation/my/opened/{lessonId}") - public ResponseEntity lessonDetail(@PathVariable Long lessonId) { + public ResponseEntity lessonDetail(@PathVariable Long lessonId) { List lessonDetails = lessonDateService.lessonDetail(lessonId); return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonDetails)); } + + // 클래스 상세보기 + @GetMapping("/lesson/{lessonId}") + public ResponseEntity lessonInfo(@PathVariable Long lessonId) { + LessonInfoResDto lessonInfoResDto = lessonService.lessonInfo(lessonId); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonInfoResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/response/LessonInfoResDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/response/LessonInfoResDto.java new file mode 100644 index 0000000..2e91ea9 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/response/LessonInfoResDto.java @@ -0,0 +1,18 @@ +package com.hanaro.hanafun.lesson.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class LessonInfoResDto { + private Long lessonId; + private String image; + private String title; + private int price; + private String description; + private String location; + private String materials; + private int capacity; + private String categoryName; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/exception/LessonNotFoundException.java b/src/main/java/com/hanaro/hanafun/lesson/exception/LessonNotFoundException.java new file mode 100644 index 0000000..ec3f7a3 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/exception/LessonNotFoundException.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.lesson.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class LessonNotFoundException extends CustomException { + static String MESSAGE = "LESSON_NOT_FOUND"; + + public LessonNotFoundException() { + super(MESSAGE); + } + + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index c2f2c09..36e2db3 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -1,6 +1,7 @@ package com.hanaro.hanafun.lesson.service; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import java.util.List; @@ -8,4 +9,7 @@ public interface LessonService { // 개설 클래스 관리- 개설 클래스 목록 출력 List openedLessons(OpenedLessonsReqDto openedLessonsReqDto); + + // 클래스 상세보기 + LessonInfoResDto lessonInfo(Long lessonId); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index b7403b7..72a5418 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -5,7 +5,9 @@ import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lesson.domain.LessonRepository; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; +import com.hanaro.hanafun.lesson.exception.LessonNotFoundException; import com.hanaro.hanafun.lesson.service.LessonService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -40,4 +42,25 @@ public List openedLessons(OpenedLessonsReqDto openedLessons return openedLessons; } + + // 클래스 상세보기 + @Transactional + @Override + public LessonInfoResDto lessonInfo(Long lessonId) { + LessonEntity lesson = lessonRepository.findById(lessonId).orElseThrow(() -> new LessonNotFoundException()); + + LessonInfoResDto lessonInfoResDto = LessonInfoResDto.builder() + .lessonId(lessonId) + .image(lesson.getImage()) + .title(lesson.getTitle()) + .price(lesson.getPrice()) + .description(lesson.getDescription()) + .location(lesson.getLocation()) + .materials(lesson.getMaterials()) + .capacity(lesson.getCapacity()) + .categoryName(lesson.getCategoryEntity().getCategoryName()) + .build(); + + return lessonInfoResDto; + } } From 691b16361b140a698a2818081b431c709347a4e7 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 13:53:51 +0900 Subject: [PATCH 37/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=20=EA=B0=80=EB=8A=A5=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=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 --- .../controller/LessonDateController.java | 14 ++++++++ .../dto/request/AvailableDateReqDto.java | 8 +++++ .../dto/response/AvailableDateResDto.java | 17 ++++++++++ .../lessondate/service/LessonDateService.java | 5 +++ .../service/impl/LessonDateServiceImpl.java | 34 +++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lessondate/dto/response/AvailableDateResDto.java diff --git a/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java index 6e5e96a..2cfdfc1 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/controller/LessonDateController.java @@ -1,12 +1,26 @@ package com.hanaro.hanafun.lessondate.controller; +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lessondate.dto.request.AvailableDateReqDto; +import com.hanaro.hanafun.lessondate.dto.response.AvailableDateResDto; import com.hanaro.hanafun.lessondate.service.LessonDateService; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequiredArgsConstructor public class LessonDateController { private final LessonDateService lessonDateService; + // 클래스 예약 가능 날짜 출력 + @GetMapping("/lesson/date-select") + public ResponseEntity availableDate(@RequestBody AvailableDateReqDto availableDateReqDto) { + List availableDateResDtoList = lessonDateService.availableDate(availableDateReqDto); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", availableDateResDtoList)); + } } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java new file mode 100644 index 0000000..be291bd --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/request/AvailableDateReqDto.java @@ -0,0 +1,8 @@ +package com.hanaro.hanafun.lessondate.dto.request; + +import lombok.Getter; + +@Getter +public class AvailableDateReqDto { + private Long lessonId; +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/AvailableDateResDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/AvailableDateResDto.java new file mode 100644 index 0000000..c3f1d71 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/AvailableDateResDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.lessondate.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Getter +@Builder +public class AvailableDateResDto { + private Long lessondateId; + private LocalDate date; + private LocalDateTime startTime; + private LocalDateTime endTime; + private int quantityLeft; // 잔여수량 (모집인원 - 신청인원) +} diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java index cba8a51..d3fcbd3 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/LessonDateService.java @@ -1,5 +1,7 @@ package com.hanaro.hanafun.lessondate.service; +import com.hanaro.hanafun.lessondate.dto.request.AvailableDateReqDto; +import com.hanaro.hanafun.lessondate.dto.response.AvailableDateResDto; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; import java.util.List; @@ -7,4 +9,7 @@ public interface LessonDateService { // 개설 클래스 상세 List lessonDetail(Long lessonId); + + // 클래스 예약 가능 날짜 출력 + List availableDate(AvailableDateReqDto availableDateReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java index 77d7148..57f5409 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java @@ -1,7 +1,10 @@ package com.hanaro.hanafun.lessondate.service.impl; +import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; +import com.hanaro.hanafun.lessondate.dto.request.AvailableDateReqDto; +import com.hanaro.hanafun.lessondate.dto.response.AvailableDateResDto; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; import com.hanaro.hanafun.lessondate.service.LessonDateService; import lombok.RequiredArgsConstructor; @@ -9,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -36,4 +40,34 @@ public List lessonDetail(Long lessonId) { return lessonDetails; } + + // 클래스 예약 가능 날짜 출력 + @Transactional + @Override + public List availableDate(AvailableDateReqDto availableDateReqDto) { + List lessonDates = lessonDateRepository.findLessonDateEntitiesByLessonEntity_LessonId(availableDateReqDto.getLessonId()); + + List availableDateResDtos = lessonDates.stream() + .map(lessonDate -> { + LessonEntity lesson = lessonDate.getLessonEntity(); + int quantityLeft = lesson.getCapacity() - lessonDate.getApplicant(); + + // 잔여 수량 0 이하 날짜 필터링 + if (quantityLeft <= 0) { + return null; + } + + return AvailableDateResDto.builder() + .lessondateId(lessonDate.getLessondateId()) + .date(lessonDate.getDate()) + .startTime(lessonDate.getStartTime()) + .endTime(lessonDate.getEndTime()) + .quantityLeft(quantityLeft) + .build(); + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + return availableDateResDtos; + } } From 5fb900ea1de25a6990307fe328a51b75c4ed8449 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 15:17:39 +0900 Subject: [PATCH 38/55] =?UTF-8?q?feat:=20S3=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EA=B8=B0=EB=8A=A5=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 --- build.gradle | 3 ++ .../com/hanaro/hanafun/config/S3Config.java | 32 +++++++++++++++++ .../lesson/controller/LessonController.java | 20 ++++++++--- .../lesson/service/S3UploadService.java | 34 +++++++++++++++++++ 4 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/config/S3Config.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/service/S3UploadService.java diff --git a/build.gradle b/build.gradle index 1475434..e2fa5c8 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,9 @@ dependencies { // Spring Security implementation 'org.springframework.boot:spring-boot-starter-security' testImplementation 'org.springframework.security:spring-security-test' + + // AWS S3 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' } tasks.named('test') { diff --git a/src/main/java/com/hanaro/hanafun/config/S3Config.java b/src/main/java/com/hanaro/hanafun/config/S3Config.java new file mode 100644 index 0000000..8e79340 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/config/S3Config.java @@ -0,0 +1,32 @@ +package com.hanaro.hanafun.config; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class S3Config { + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + + @Value("${cloud.aws.region.static}") + private String region; + + @Bean + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); + + return (AmazonS3Client) AmazonS3ClientBuilder + .standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index ada165a..e903416 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -5,15 +5,15 @@ import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.service.LessonService; +import com.hanaro.hanafun.lesson.service.S3UploadService; import com.hanaro.hanafun.lessondate.dto.response.LessonDetailResDto; import com.hanaro.hanafun.lessondate.service.LessonDateService; 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.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; @RestController @@ -21,6 +21,7 @@ public class LessonController { private final LessonService lessonService; private final LessonDateService lessonDateService; + private final S3UploadService s3UploadService; // 개설 클래스 관리- 개설 클래스 목록 출력 @GetMapping("/reservation/my/opened") @@ -42,4 +43,15 @@ public ResponseEntity lessonInfo(@PathVariable Long lessonId) { LessonInfoResDto lessonInfoResDto = lessonService.lessonInfo(lessonId); return ResponseEntity.ok(new ApiResponse<>(true, "ok", lessonInfoResDto)); } + + // 클래스 이미지 업로드 + @PostMapping("/lesson/image-upload") + public ResponseEntity uploadImage(@RequestParam("file") MultipartFile file) { + try { + String imageUrl = s3UploadService.saveFile(file); + return ResponseEntity.ok(imageUrl); + } catch (IOException e) { + return ResponseEntity.status(500).body("파일 업로드 중 오류가 발생했습니다."); + } + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/S3UploadService.java b/src/main/java/com/hanaro/hanafun/lesson/service/S3UploadService.java new file mode 100644 index 0000000..469a9ac --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/service/S3UploadService.java @@ -0,0 +1,34 @@ +package com.hanaro.hanafun.lesson.service; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.ObjectMetadata; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@RequiredArgsConstructor +@Service +public class S3UploadService { + private final AmazonS3 amazonS3; + + @Value("${cloud.aws.s3.bucket}") + private String bucket; + + public String saveFile(MultipartFile multipartFile) throws IOException { + String originalFilename = multipartFile.getOriginalFilename(); + + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentLength(multipartFile.getSize()); + metadata.setContentType(multipartFile.getContentType()); + + amazonS3.putObject(bucket, originalFilename, multipartFile.getInputStream(), metadata); + // 파일을 퍼블릭으로 설정 + amazonS3.setObjectAcl(bucket, originalFilename, CannedAccessControlList.PublicRead); + + return amazonS3.getUrl(bucket, originalFilename).toString(); + } +} From eba5fbc52748249bda7fcb0ebab2691d36b377f8 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 15:39:58 +0900 Subject: [PATCH 39/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=81=EC=84=B8-=20title=20return=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 --- .../hanafun/lessondate/dto/response/LessonDetailResDto.java | 1 + .../hanafun/lessondate/service/impl/LessonDateServiceImpl.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java index 4c63790..fb41fbb 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/dto/response/LessonDetailResDto.java @@ -11,4 +11,5 @@ public class LessonDetailResDto { private Long lessondateId; private LocalDate date; private Long lessonId; + private String title; } diff --git a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java index 57f5409..36dfb37 100644 --- a/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lessondate/service/impl/LessonDateServiceImpl.java @@ -33,6 +33,7 @@ public List lessonDetail(Long lessonId) { .lessondateId(lessonDate.getLessondateId()) .date(lessonDate.getDate()) .lessonId(lessonId) + .title(lessonDate.getLessonEntity().getTitle()) .build(); return lessonDetail; }) From 577668336b970670febf853bfc83a469353750ca Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Thu, 27 Jun 2024 16:22:18 +0900 Subject: [PATCH 40/55] feat: trasaction apis are implemented --- .../hanaro/hanafun/HanafunApplication.java | 2 + .../exception/AccountBalanceException.java | 15 ++ .../scheduler/AutoTransferScheduler.java | 17 ++ .../hanastorage/domain/HanastorageEntity.java | 30 ++++ .../domain/HanastorageRepository.java | 13 ++ .../revenue/controller/RevenueController.java | 11 -- .../controller/TransactionController.java | 21 +++ .../transaction/domain/TransactionEntity.java | 2 +- .../domain/TransactionRepository.java | 4 + .../transaction/dto/PaybackReqDto.java | 14 ++ .../hanafun/transaction/dto/SimpleReqDto.java | 18 +++ .../hanafun/transaction/enums/Type.java | 3 +- .../service/TransactionService.java | 4 + .../service/impl/TransactionServiceImpl.java | 146 +++++++++++++++--- 14 files changed, 267 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/account/exception/AccountBalanceException.java create mode 100644 src/main/java/com/hanaro/hanafun/common/scheduler/AutoTransferScheduler.java create mode 100644 src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageEntity.java create mode 100644 src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageRepository.java delete mode 100644 src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/dto/PaybackReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/transaction/dto/SimpleReqDto.java diff --git a/src/main/java/com/hanaro/hanafun/HanafunApplication.java b/src/main/java/com/hanaro/hanafun/HanafunApplication.java index 3d57a31..f50b9e9 100644 --- a/src/main/java/com/hanaro/hanafun/HanafunApplication.java +++ b/src/main/java/com/hanaro/hanafun/HanafunApplication.java @@ -3,9 +3,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableJpaAuditing +@EnableScheduling public class HanafunApplication { public static void main(String[] args) { diff --git a/src/main/java/com/hanaro/hanafun/account/exception/AccountBalanceException.java b/src/main/java/com/hanaro/hanafun/account/exception/AccountBalanceException.java new file mode 100644 index 0000000..b4de724 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/exception/AccountBalanceException.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.account.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class AccountBalanceException extends CustomException { + static String MESSAGE = "INSUFFICIENT_BALANCE"; + public AccountBalanceException(){ + super(MESSAGE); + } + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.BAD_REQUEST; + } +} diff --git a/src/main/java/com/hanaro/hanafun/common/scheduler/AutoTransferScheduler.java b/src/main/java/com/hanaro/hanafun/common/scheduler/AutoTransferScheduler.java new file mode 100644 index 0000000..9d178b3 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/common/scheduler/AutoTransferScheduler.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.common.scheduler; + +import com.hanaro.hanafun.transaction.service.impl.TransactionServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class AutoTransferScheduler { + private final TransactionServiceImpl transactionService; + + @Scheduled(cron = "0 0 0 * * ?") //매일 0시 + public void runAutoTransfer(){ + transactionService.autoTransfer(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageEntity.java b/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageEntity.java new file mode 100644 index 0000000..3ab4481 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageEntity.java @@ -0,0 +1,30 @@ +package com.hanaro.hanafun.hanastorage.domain; + +import com.hanaro.hanafun.transaction.domain.TransactionEntity; +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDate; + +@Entity +@Table(name = "hanastorage") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class HanastorageEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "hanastorage_id") + private Long hanastorageId; + + @OneToOne + @JoinColumn(name = "transaction_id") + private TransactionEntity transactionEntity; + + @Column(name = "lessondate") + private LocalDate lessondate; + + @Column(name = "is_deleted") + private Boolean isDeleted; +} diff --git a/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageRepository.java b/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageRepository.java new file mode 100644 index 0000000..0d7bfb1 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/hanastorage/domain/HanastorageRepository.java @@ -0,0 +1,13 @@ +package com.hanaro.hanafun.hanastorage.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +import java.time.LocalDate; +import java.util.List; +import java.util.Optional; + +public interface HanastorageRepository extends JpaRepository { + + List findByLessondateAndIsDeleted(LocalDate lessondate, Boolean isDeleted); + Optional findByTransactionEntityTransactionId(Long transactionId); +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java deleted file mode 100644 index 1aeee03..0000000 --- a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hanaro.hanafun.revenue.controller; - -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/revenue") -public class RevenueController { -} diff --git a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java index 65642cc..640170a 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java +++ b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java @@ -2,10 +2,13 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.PaybackReqDto; import com.hanaro.hanafun.transaction.dto.QrReqDto; +import com.hanaro.hanafun.transaction.dto.SimpleReqDto; import com.hanaro.hanafun.transaction.service.impl.TransactionServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -22,4 +25,22 @@ public ResponseEntity qrPay(@RequestBody QrReqDto qrReqDto){ PayResDto payResDto = transactionService.qrPay(qrReqDto); return ResponseEntity.ok(new ApiResponse(true, "ok", payResDto)); } + + @PostMapping("/simple") + public ResponseEntity simplePay(@AuthenticationPrincipal Long userId, @RequestBody SimpleReqDto simpleReqDto){ + PayResDto payResDto = transactionService.simplePay(userId, simpleReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", payResDto)); + } + + @PostMapping("/payback") + public ResponseEntity payback(@AuthenticationPrincipal Long userId, @RequestBody PaybackReqDto paybackReqDto){ + PayResDto payResDto = transactionService.payback(userId, paybackReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", payResDto)); + } + + @PostMapping("/test") + public ResponseEntity test(){ + transactionService.autoTransfer(); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", null)); + } } diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java index bd2a926..62c9916 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -17,7 +17,7 @@ public class TransactionEntity extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "transaction_id") - private Long TransactionId; + private Long transactionId; @ManyToOne @JoinColumn(name = "deposit_id", nullable = false) diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java index 42c45df..97e634b 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionRepository.java @@ -1,6 +1,10 @@ package com.hanaro.hanafun.transaction.domain; +import com.hanaro.hanafun.transaction.enums.Type; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface TransactionRepository extends JpaRepository { + Optional findByReservationEntityReservationIdAndType(Long reservationId, Type type); } diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/PaybackReqDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/PaybackReqDto.java new file mode 100644 index 0000000..06bc3a2 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/PaybackReqDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.transaction.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PaybackReqDto { + private long reservationId; +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/SimpleReqDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/SimpleReqDto.java new file mode 100644 index 0000000..1901727 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/SimpleReqDto.java @@ -0,0 +1,18 @@ +package com.hanaro.hanafun.transaction.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class SimpleReqDto { + private long withdrawId; + private long lessondateId; + private long reservationId; + private int payment; + private int point; +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java b/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java index 7497347..cf38380 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java +++ b/src/main/java/com/hanaro/hanafun/transaction/enums/Type.java @@ -8,7 +8,8 @@ public enum Type { QR("QR"), PENDING("PENDING"), - COMPLETE("COMPLETE"); + COMPLETED("COMPLETED"), + CANCELED("CANCELED"); private String value; } diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java index c716055..734bae3 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java +++ b/src/main/java/com/hanaro/hanafun/transaction/service/TransactionService.java @@ -1,8 +1,12 @@ package com.hanaro.hanafun.transaction.service; import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.PaybackReqDto; import com.hanaro.hanafun.transaction.dto.QrReqDto; +import com.hanaro.hanafun.transaction.dto.SimpleReqDto; public interface TransactionService { PayResDto qrPay(QrReqDto qrReqDto); + PayResDto simplePay(Long userId, SimpleReqDto simpleReqDto); + PayResDto payback(Long userId, PaybackReqDto paybackReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java index f09b99b..0af7a12 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java @@ -2,8 +2,14 @@ import com.hanaro.hanafun.account.domain.AccountEntity; import com.hanaro.hanafun.account.domain.AccountRepository; +import com.hanaro.hanafun.account.exception.AccountBalanceException; import com.hanaro.hanafun.account.exception.AccountNotFoundException; +import com.hanaro.hanafun.hanastorage.domain.HanastorageEntity; +import com.hanaro.hanafun.hanastorage.domain.HanastorageRepository; +import com.hanaro.hanafun.host.domain.HostEntity; +import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import com.hanaro.hanafun.reservation.domain.ReservationRepository; import com.hanaro.hanafun.revenue.domain.RevenueEntity; @@ -11,35 +17,48 @@ import com.hanaro.hanafun.transaction.domain.TransactionEntity; import com.hanaro.hanafun.transaction.domain.TransactionRepository; import com.hanaro.hanafun.transaction.dto.PayResDto; +import com.hanaro.hanafun.transaction.dto.PaybackReqDto; import com.hanaro.hanafun.transaction.dto.QrReqDto; +import com.hanaro.hanafun.transaction.dto.SimpleReqDto; import com.hanaro.hanafun.transaction.enums.Type; import com.hanaro.hanafun.transaction.service.TransactionService; +import com.hanaro.hanafun.user.domain.UserEntity; +import com.hanaro.hanafun.user.domain.UserRepository; +import com.hanaro.hanafun.user.exception.UserNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; +import java.util.List; import java.util.Optional; @Service @RequiredArgsConstructor public class TransactionServiceImpl implements TransactionService { + private final UserRepository userRepository; private final LessonRepository lessonRepository; private final LessonDateRepository lessonDateRepository; private final ReservationRepository reservationRepository; private final RevenueRepository revenueRepository; private final AccountRepository accountRepository; + private final HanastorageRepository hanastorageRepository; private final TransactionRepository transactionRepository; + static private String PLUS = "PLUS"; + static private String MINUS = "MINUS"; + static private String ZERO = "ZERO"; + @Override @Transactional public PayResDto qrPay(QrReqDto qrReqDto) { - //계좌 잔액 업데이트 - AccountEntity withdrawAccount = calcWithdraw(qrReqDto.getWithdrawId(), qrReqDto.getPayment(), "qr"); - AccountEntity depositAccount = calcDeposit(qrReqDto.getDepositId(), qrReqDto.getPayment(), "qr"); + //계좌 업데이트 + AccountEntity withdrawAccount = calcAccount(qrReqDto.getWithdrawId(), qrReqDto.getPayment(), MINUS); + AccountEntity depositAccount = calcAccount(qrReqDto.getDepositId(), qrReqDto.getPayment(), PLUS); - //매출 변경 업데이트 + //매출 업데이트 calcRevenue(qrReqDto.getLessonId(), qrReqDto.getPayment()); //거래 내역 저장 @@ -60,37 +79,124 @@ public PayResDto qrPay(QrReqDto qrReqDto) { .build(); } + @Override @Transactional - public AccountEntity calcWithdraw(Long withdrawId, int payment, String type){ - AccountEntity withdrawAccount = accountRepository.findById(withdrawId).orElseThrow(() -> new AccountNotFoundException()); - if(type.equals("qr")){ - withdrawAccount.setBalance(withdrawAccount.getBalance() - payment); - } else if(type.equals("reserve")) { + public PayResDto simplePay(Long userId, SimpleReqDto simpleReqDto) { + //호스트 계좌번호 가져오기 + LessonDateEntity lessonDateEntity = lessonDateRepository.findById(simpleReqDto.getLessondateId()) + .orElse(null); + Long depositId = lessonDateEntity.getLessonEntity().getHostEntity().getAccountEntity().getAccountId(); + + //계좌 잔액 업데이트 + AccountEntity withdrawAccount = calcAccount(simpleReqDto.getWithdrawId(), simpleReqDto.getPayment() - simpleReqDto.getPoint(), MINUS); + AccountEntity depositAccount = calcAccount(depositId, 0, ZERO); - } else if(type.equals("refund")) { + //게스트 포인트 소멸 + UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException()); + userEntity.setPoint(userEntity.getPoint() - simpleReqDto.getPoint()); - } + //거래 내역 저장 _ PENDING + TransactionEntity transactionEntity = TransactionEntity.builder() + .depositAccount(depositAccount) + .withdrawAccount(withdrawAccount) + .reservationEntity(reservationRepository.findById(simpleReqDto.getReservationId()).get()) + .payment(simpleReqDto.getPayment()) + .point(simpleReqDto.getPoint()) + .type(Type.PENDING) + .build(); + TransactionEntity createdTransaction = transactionRepository.save(transactionEntity); + + //하나은행 저장소 저장 + HanastorageEntity hanastorageEntity = HanastorageEntity.builder() + .transactionEntity(createdTransaction) + .lessondate(lessonDateEntity.getDate()) + .isDeleted(false) + .build(); + hanastorageRepository.save(hanastorageEntity); - return withdrawAccount; + return new PayResDto().builder() + .transactionId(createdTransaction.getTransactionId()) + .build(); } + @Override @Transactional - public AccountEntity calcDeposit(Long depositId, int payment, String type){ - AccountEntity depositAccount = accountRepository.findById(depositId).orElseThrow(() -> new AccountNotFoundException()); + public PayResDto payback(Long userId, PaybackReqDto paybackReqDto) { + //거래에서 거래 타입 변경 + TransactionEntity transactionEntity = transactionRepository.findByReservationEntityReservationIdAndType(paybackReqDto.getReservationId(), Type.PENDING).orElseThrow(); + transactionEntity.setType(Type.CANCELED); + + //하나은행 저장소 삭제 처리 + HanastorageEntity hanastorageEntity = hanastorageRepository.findByTransactionEntityTransactionId(transactionEntity.getTransactionId()).orElseThrow(); + hanastorageEntity.setIsDeleted(true); + + //게스트 계좌에 송금 + Long guestAccountId = transactionEntity.getWithdrawAccount().getAccountId(); + calcAccount(guestAccountId, transactionEntity.getPayment() - transactionEntity.getPoint(), PLUS); + + //게스트 포인트 적립 + UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException()); + userEntity.setPoint(userEntity.getPoint() + transactionEntity.getPoint()); + + return new PayResDto().builder() + .transactionId(transactionEntity.getTransactionId()) + .build(); + } - if(type.equals("qr")){ - depositAccount.setBalance(depositAccount.getBalance() + payment); + @Transactional + public void autoTransfer(){ + LocalDate yesterday = LocalDate.now().minusDays(1); + List hanastorageEntityList = hanastorageRepository.findByLessondateAndIsDeleted(yesterday, false); + hanastorageEntityList.forEach(this::doAutoTransfer); + } + + @Transactional + private void doAutoTransfer(HanastorageEntity hanastorageEntity){ + //하나은행 저장소 삭제 처리 + hanastorageEntity.setIsDeleted(true); + + //거래에서 거래 타입 변경 + TransactionEntity transactionEntity = transactionRepository.findById(hanastorageEntity.getTransactionEntity().getTransactionId()) + .orElse(null); + transactionEntity.setType(Type.COMPLETED); + + //호스트 계좌에 송금 + Long hostAccountId = transactionEntity.getDepositAccount().getAccountId(); + calcAccount(hostAccountId, transactionEntity.getPayment(), PLUS); + + //매출 업데이트 + Long lessonId = transactionEntity + .getReservationEntity() + .getLessonDateEntity() + .getLessonEntity() + .getLessonId(); + calcRevenue(lessonId, transactionEntity.getPayment()); + } + + @Transactional + private AccountEntity calcAccount(Long accountId, int payment, String type){ + AccountEntity accountEntity = accountRepository.findById(accountId) + .orElseThrow(() -> new AccountNotFoundException()); + + if(type.equals(PLUS)){ + accountEntity.setBalance(accountEntity.getBalance() + payment); + } else if(type.equals(MINUS)) { + if(accountEntity.getBalance() < payment){ + throw new AccountBalanceException(); + } + accountEntity.setBalance(accountEntity.getBalance() - payment); } - return depositAccount; + return accountEntity; } @Transactional - public void calcRevenue(Long lessonId, int payment){ + private void calcRevenue(Long lessonId, int payment){ LocalDateTime startOfMonth = YearMonth.now().atDay(1).atStartOfDay(); LocalDateTime endOfMonth = YearMonth.now().atEndOfMonth().atTime(23, 59, 59); - RevenueEntity revenueEntity = revenueRepository.findByCreatedDateBetween(startOfMonth, endOfMonth).orElse(null); + RevenueEntity revenueEntity = revenueRepository.findByCreatedDateBetween(startOfMonth, endOfMonth) + .orElse(null); if (revenueEntity != null) { revenueEntity.setRevenue(revenueEntity.getRevenue() + payment); @@ -105,4 +211,4 @@ public void calcRevenue(Long lessonId, int payment){ revenueRepository.save(newRevenue); } } -} +} \ No newline at end of file From 6a52a79121e5142811bf5a6b43dafa2ccb67fdcf Mon Sep 17 00:00:00 2001 From: yubin-im Date: Thu, 27 Jun 2024 16:37:20 +0900 Subject: [PATCH 41/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=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 --- .../exception/CategoryNotFoundException.java | 17 ++++++++ .../lesson/controller/LessonController.java | 7 +++ .../dto/request/CreateLessonDateReqDto.java | 19 ++++++++ .../dto/request/CreateLessonReqDto.java | 19 ++++++++ .../hanafun/lesson/service/LessonService.java | 4 ++ .../service/impl/LessonServiceImpl.java | 43 +++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/category/exception/CategoryNotFoundException.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonDateReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java diff --git a/src/main/java/com/hanaro/hanafun/category/exception/CategoryNotFoundException.java b/src/main/java/com/hanaro/hanafun/category/exception/CategoryNotFoundException.java new file mode 100644 index 0000000..b053183 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/category/exception/CategoryNotFoundException.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.category.exception; + +import com.hanaro.hanafun.common.exception.CustomException; +import org.springframework.http.HttpStatus; + +public class CategoryNotFoundException extends CustomException { + static String MESSAGE = "CATEGORY_NOT_FOUND"; + + public CategoryNotFoundException() { + super(MESSAGE); + } + + @Override + public HttpStatus getHttpStatus() { + return HttpStatus.NOT_FOUND; + } +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index e903416..0b88c12 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -1,6 +1,7 @@ package com.hanaro.hanafun.lesson.controller; import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; @@ -54,4 +55,10 @@ public ResponseEntity uploadImage(@RequestParam("file") MultipartFile fi return ResponseEntity.status(500).body("파일 업로드 중 오류가 발생했습니다."); } } + + // 클래스 등록하기 + @PostMapping("/lesson/create") + public void createLesson(@RequestBody CreateLessonReqDto createLessonReqDto) { + lessonService.createLesson(createLessonReqDto); + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonDateReqDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonDateReqDto.java new file mode 100644 index 0000000..882da02 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonDateReqDto.java @@ -0,0 +1,19 @@ +package com.hanaro.hanafun.lesson.dto.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Getter +public class CreateLessonDateReqDto { + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate date; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime startTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime endTime; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java new file mode 100644 index 0000000..207c653 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/request/CreateLessonReqDto.java @@ -0,0 +1,19 @@ +package com.hanaro.hanafun.lesson.dto.request; + +import lombok.Getter; + +import java.util.List; + +@Getter +public class CreateLessonReqDto { + private Long userId; + private Long categoryId; + private String title; + private String location; + private int price; + private int capacity; + private String image; + private String description; + private String materials; + private List lessonDate; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index 36e2db3..22a6037 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -1,5 +1,6 @@ package com.hanaro.hanafun.lesson.service; +import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; @@ -12,4 +13,7 @@ public interface LessonService { // 클래스 상세보기 LessonInfoResDto lessonInfo(Long lessonId); + + // 클래스 등록하기 + void createLesson(CreateLessonReqDto createLessonReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index 72a5418..bc1c436 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -1,14 +1,21 @@ package com.hanaro.hanafun.lesson.service.impl; +import com.hanaro.hanafun.category.domain.CategoryEntity; +import com.hanaro.hanafun.category.domain.CategoryRepository; +import com.hanaro.hanafun.category.exception.CategoryNotFoundException; import com.hanaro.hanafun.host.domain.HostEntity; import com.hanaro.hanafun.host.domain.HostRepository; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.lesson.dto.request.CreateLessonDateReqDto; +import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.exception.LessonNotFoundException; import com.hanaro.hanafun.lesson.service.LessonService; +import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; +import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,6 +28,8 @@ public class LessonServiceImpl implements LessonService { private final LessonRepository lessonRepository; private final HostRepository hostRepository; + private final CategoryRepository categoryRepository; + private final LessonDateRepository lessonDateRepository; // 개설 클래스 관리- 개설 클래스 목록 출력 @Transactional @@ -63,4 +72,38 @@ public LessonInfoResDto lessonInfo(Long lessonId) { return lessonInfoResDto; } + + // 클래스 등록하기 + @Transactional + @Override + public void createLesson(CreateLessonReqDto createLessonReqDto) { + HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(createLessonReqDto.getUserId()); + CategoryEntity category = categoryRepository.findById(createLessonReqDto.getCategoryId()).orElseThrow(() -> new CategoryNotFoundException()); + + // Lesson 추가 + LessonEntity lesson = LessonEntity.builder() + .hostEntity(host) + .categoryEntity(category) + .title(createLessonReqDto.getTitle()) + .location(createLessonReqDto.getLocation()) + .price(createLessonReqDto.getPrice()) + .capacity(createLessonReqDto.getCapacity()) + .image(createLessonReqDto.getImage()) + .description(createLessonReqDto.getDescription()) + .materials(createLessonReqDto.getMaterials()) + .build(); + lessonRepository.save(lesson); + + // LessonDate 추가 + List lessonDates = createLessonReqDto.getLessonDate(); + for (CreateLessonDateReqDto lessonDateReqDto: lessonDates) { + LessonDateEntity lessonDate = LessonDateEntity.builder() + .lessonEntity(lesson) + .date(lessonDateReqDto.getDate()) + .startTime(lessonDateReqDto.getStartTime()) + .endTime(lessonDateReqDto.getEndTime()) + .build(); + lessonDateRepository.save(lessonDate); + } + } } From f092f039f631b0c7f53fa5445b3ecf2dddb4298f Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Thu, 27 Jun 2024 17:46:18 +0900 Subject: [PATCH 42/55] feat: revenue --- .../hanafun/account/domain/AccountEntity.java | 1 + .../revenue/controller/RevenueController.java | 24 ++++++++++++ .../hanafun/revenue/domain/RevenueEntity.java | 1 + .../revenue/domain/RevenueRepository.java | 6 +++ .../revenue/dto/YearRevenueResDto.java | 14 +++++++ .../revenue/service/RevenueService.java | 7 ++++ .../service/impl/RevenueServiceImpl.java | 37 +++++++++++++++++++ .../transaction/domain/TransactionEntity.java | 1 + 8 files changed, 91 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java diff --git a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java index 01f7438..163cbc1 100644 --- a/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java +++ b/src/main/java/com/hanaro/hanafun/account/domain/AccountEntity.java @@ -8,6 +8,7 @@ @Entity @Table(name = "account") @Data +@EqualsAndHashCode(callSuper = false) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class AccountEntity extends BaseEntity { @Id diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java new file mode 100644 index 0000000..31eda7e --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java @@ -0,0 +1,24 @@ +package com.hanaro.hanafun.revenue.controller; + +import com.hanaro.hanafun.common.dto.ApiResponse; +import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; +import com.hanaro.hanafun.revenue.service.impl.RevenueServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +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 +@RequiredArgsConstructor +@RequestMapping("/revenue") +public class RevenueController { + private final RevenueServiceImpl revenueService; + @GetMapping("/year/{year}") + public ResponseEntity yearRevenue(@AuthenticationPrincipal Long userId, @PathVariable Integer year){ + YearRevenueResDto yearRevenueResDto = revenueService.yearRevenue(userId, year); + return ResponseEntity.ok(new ApiResponse(true, "ok", yearRevenueResDto)); + } +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java index 4fddd13..29ebc5d 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueEntity.java @@ -9,6 +9,7 @@ @Entity @Table(name = "revenue") @Data +@EqualsAndHashCode(callSuper = false) @Builder @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java index 48cab83..0ad350f 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java @@ -1,10 +1,16 @@ package com.hanaro.hanafun.revenue.domain; +import com.hanaro.hanafun.lesson.domain.LessonEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.time.LocalDateTime; import java.util.Optional; public interface RevenueRepository extends JpaRepository { Optional findByCreatedDateBetween(LocalDateTime startDateTime, LocalDateTime endDateTime); + + @Query(value = "SELECT SUM(R.revenue) FROM RevenueEntity R WHERE R.lessonEntity = :lessonEntity") + Long yearRevenueByLessonId(@Param("lessonEntity") LessonEntity lessonEntity); } diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java new file mode 100644 index 0000000..8215a8a --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.revenue.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class YearRevenueResDto { + private long yearRevenue; +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java new file mode 100644 index 0000000..5132aa8 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java @@ -0,0 +1,7 @@ +package com.hanaro.hanafun.revenue.service; + +import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; + +public interface RevenueService { + YearRevenueResDto yearRevenue(Long userId, Integer year); +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java new file mode 100644 index 0000000..820490f --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java @@ -0,0 +1,37 @@ +package com.hanaro.hanafun.revenue.service.impl; + +import com.hanaro.hanafun.host.domain.HostEntity; +import com.hanaro.hanafun.host.domain.HostRepository; +import com.hanaro.hanafun.host.exception.HostNotFoundException; +import com.hanaro.hanafun.lesson.domain.LessonEntity; +import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.revenue.domain.RevenueRepository; +import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; +import com.hanaro.hanafun.revenue.service.RevenueService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class RevenueServiceImpl implements RevenueService { + private final HostRepository hostRepository; + private final LessonRepository lessonRepository; + private final RevenueRepository revenueRepository; + + @Override + @Transactional + public YearRevenueResDto yearRevenue(Long userId, Integer year) { + Long yearRevenue; + HostEntity hostEntity = hostRepository.findByUserEntityUserId(userId).orElseThrow(() -> new HostNotFoundException()); + + List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(() -> new HostNotFoundException()); + yearRevenue = lessonEntityList.stream().mapToLong(lessonEntity -> revenueRepository.yearRevenueByLessonId(lessonEntity)).sum(); + + return new YearRevenueResDto().builder() + .yearRevenue(yearRevenue) + .build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java index 62c9916..b1fef8a 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java +++ b/src/main/java/com/hanaro/hanafun/transaction/domain/TransactionEntity.java @@ -10,6 +10,7 @@ @Entity @Table(name = "transaction") @Data +@EqualsAndHashCode(callSuper = false) @Builder @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) From 94e4e42eb5c51c6e898d8b39e82be5f5b8eb470d Mon Sep 17 00:00:00 2001 From: yubin-im Date: Fri, 28 Jun 2024 09:38:55 +0900 Subject: [PATCH 43/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C(=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=ED=83=90=EC=83=89)=20=EA=B8=B0=EB=8A=A5=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 --- .../lesson/controller/LessonController.java | 8 +++++++ .../lesson/dto/response/FullLessonResDto.java | 14 +++++++++++ .../hanafun/lesson/service/LessonService.java | 4 ++++ .../service/impl/LessonServiceImpl.java | 23 +++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 src/main/java/com/hanaro/hanafun/lesson/dto/response/FullLessonResDto.java diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index 0b88c12..a5a7254 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -3,6 +3,7 @@ import com.hanaro.hanafun.common.dto.ApiResponse; import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.FullLessonResDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.service.LessonService; @@ -61,4 +62,11 @@ public ResponseEntity uploadImage(@RequestParam("file") MultipartFile fi public void createLesson(@RequestBody CreateLessonReqDto createLessonReqDto) { lessonService.createLesson(createLessonReqDto); } + + // 클래스 전체 조회 (클래스 탐색) + @GetMapping("/category/all") + public ResponseEntity fullLesson() { + List fullLessonResDtos = lessonService.fullLesson(); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", fullLessonResDtos)); + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/dto/response/FullLessonResDto.java b/src/main/java/com/hanaro/hanafun/lesson/dto/response/FullLessonResDto.java new file mode 100644 index 0000000..92f8264 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/lesson/dto/response/FullLessonResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.lesson.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class FullLessonResDto { + private Long lessonId; + private String image; + private String title; + private int price; + private String hostName; +} diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index 22a6037..e1e9b99 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -2,6 +2,7 @@ import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.FullLessonResDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; @@ -16,4 +17,7 @@ public interface LessonService { // 클래스 등록하기 void createLesson(CreateLessonReqDto createLessonReqDto); + + // 클래스 전체 조회 (클래스 탐색) + List fullLesson(); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index bc1c436..00644bc 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -10,6 +10,7 @@ import com.hanaro.hanafun.lesson.dto.request.CreateLessonDateReqDto; import com.hanaro.hanafun.lesson.dto.request.CreateLessonReqDto; import com.hanaro.hanafun.lesson.dto.request.OpenedLessonsReqDto; +import com.hanaro.hanafun.lesson.dto.response.FullLessonResDto; import com.hanaro.hanafun.lesson.dto.response.LessonInfoResDto; import com.hanaro.hanafun.lesson.dto.response.OpenedLessonsResDto; import com.hanaro.hanafun.lesson.exception.LessonNotFoundException; @@ -106,4 +107,26 @@ public void createLesson(CreateLessonReqDto createLessonReqDto) { lessonDateRepository.save(lessonDate); } } + + // 클래스 전체 조회 (클래스 탐색) + @Transactional + @Override + public List fullLesson() { + List lessonList = lessonRepository.findAll(); + + List fullLessonResDtos = lessonList.stream() + .map(lesson -> { + FullLessonResDto fullLessonResDto = FullLessonResDto.builder() + .lessonId(lesson.getLessonId()) + .image(lesson.getImage()) + .title(lesson.getTitle()) + .price(lesson.getPrice()) + .hostName(lesson.getHostEntity().getUserEntity().getUsername()) + .build(); + return fullLessonResDto; + }) + .collect(Collectors.toList()); + + return fullLessonResDtos; + } } From 4b21fbdf2d485a90f3b38f09855a640b2a6d7535 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Fri, 28 Jun 2024 13:56:25 +0900 Subject: [PATCH 44/55] fix: revenue total --- .../hanaro/hanafun/account/mapper/AccountMapper.java | 2 +- .../hanafun/common/aop/GlobalExceptionHandler.java | 3 ++- .../{ => common}/authentication/JwtAuthFilter.java | 2 +- .../hanafun/{ => common}/authentication/JwtUtil.java | 4 ++-- .../hanaro/hanafun/{ => common}/config/S3Config.java | 2 +- .../config}/SecurityConfig.java | 6 ++++-- .../hanafun/common/exception/BasicErrorStatus.java | 10 +++++----- .../com/hanaro/hanafun/host/mapper/HostMapper.java | 2 +- .../hanafun/revenue/controller/RevenueController.java | 11 +++++------ .../hanafun/revenue/domain/RevenueRepository.java | 3 ++- ...YearRevenueResDto.java => totalRevenueResDto.java} | 2 +- .../hanafun/revenue/service/RevenueService.java | 4 ++-- .../revenue/service/impl/RevenueServiceImpl.java | 8 ++++---- .../transaction/controller/TransactionController.java | 5 +---- .../hanafun/user/service/impl/UserServiceImpl.java | 2 +- 15 files changed, 33 insertions(+), 33 deletions(-) rename src/main/java/com/hanaro/hanafun/{ => common}/authentication/JwtAuthFilter.java (96%) rename src/main/java/com/hanaro/hanafun/{ => common}/authentication/JwtUtil.java (94%) rename src/main/java/com/hanaro/hanafun/{ => common}/config/S3Config.java (96%) rename src/main/java/com/hanaro/hanafun/{authentication => common/config}/SecurityConfig.java (88%) rename src/main/java/com/hanaro/hanafun/revenue/dto/{YearRevenueResDto.java => totalRevenueResDto.java} (87%) diff --git a/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java b/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java index 35d4762..076b431 100644 --- a/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java +++ b/src/main/java/com/hanaro/hanafun/account/mapper/AccountMapper.java @@ -6,7 +6,7 @@ @UtilityClass public class AccountMapper { - public AccountResDto entityToAccountResDto(AccountEntity accountEntity){ + public static AccountResDto entityToAccountResDto(AccountEntity accountEntity){ if(accountEntity == null) return null; return AccountResDto.builder() diff --git a/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java index 3d6b787..342207c 100644 --- a/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java +++ b/src/main/java/com/hanaro/hanafun/common/aop/GlobalExceptionHandler.java @@ -4,6 +4,8 @@ import com.hanaro.hanafun.common.exception.BasicErrorStatus; import com.hanaro.hanafun.common.exception.CustomException; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.AuthenticationException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @@ -21,6 +23,5 @@ public ResponseEntity> handleGlobalException(Exception ex) { public ResponseEntity> handleCustomException (CustomException ex) { ApiResponse response = new ApiResponse<>(false, ex.getMessage(), null); return new ResponseEntity<>(response, ex.getHttpStatus()); - } } diff --git a/src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java b/src/main/java/com/hanaro/hanafun/common/authentication/JwtAuthFilter.java similarity index 96% rename from src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java rename to src/main/java/com/hanaro/hanafun/common/authentication/JwtAuthFilter.java index 7a2b516..0f9d9af 100644 --- a/src/main/java/com/hanaro/hanafun/authentication/JwtAuthFilter.java +++ b/src/main/java/com/hanaro/hanafun/common/authentication/JwtAuthFilter.java @@ -1,4 +1,4 @@ -package com.hanaro.hanafun.authentication; +package com.hanaro.hanafun.common.authentication; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; diff --git a/src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java b/src/main/java/com/hanaro/hanafun/common/authentication/JwtUtil.java similarity index 94% rename from src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java rename to src/main/java/com/hanaro/hanafun/common/authentication/JwtUtil.java index fa8a726..adade3a 100644 --- a/src/main/java/com/hanaro/hanafun/authentication/JwtUtil.java +++ b/src/main/java/com/hanaro/hanafun/common/authentication/JwtUtil.java @@ -1,4 +1,4 @@ -package com.hanaro.hanafun.authentication; +package com.hanaro.hanafun.common.authentication; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; @@ -28,7 +28,7 @@ public class JwtUtil { @Value("${jwt.claims.auth-key}") private String authKey; - @PostConstruct // 의존성 주입이 끝난 후 초기화를 수행!! secretKey를 암호화 + @PostConstruct protected void init() { secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes()); } diff --git a/src/main/java/com/hanaro/hanafun/config/S3Config.java b/src/main/java/com/hanaro/hanafun/common/config/S3Config.java similarity index 96% rename from src/main/java/com/hanaro/hanafun/config/S3Config.java rename to src/main/java/com/hanaro/hanafun/common/config/S3Config.java index 8e79340..cef8cba 100644 --- a/src/main/java/com/hanaro/hanafun/config/S3Config.java +++ b/src/main/java/com/hanaro/hanafun/common/config/S3Config.java @@ -1,4 +1,4 @@ -package com.hanaro.hanafun.config; +package com.hanaro.hanafun.common.config; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; diff --git a/src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java b/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java similarity index 88% rename from src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java rename to src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java index 70613a4..738cc08 100644 --- a/src/main/java/com/hanaro/hanafun/authentication/SecurityConfig.java +++ b/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java @@ -1,5 +1,6 @@ -package com.hanaro.hanafun.authentication; +package com.hanaro.hanafun.common.config; +import com.hanaro.hanafun.common.authentication.JwtAuthFilter; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -7,6 +8,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @@ -18,7 +20,7 @@ public class SecurityConfig { private final JwtAuthFilter jwtAuthFilter; @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception, AuthenticationException { http .csrf(csrf -> csrf.disable()) .httpBasic(httpBasic -> httpBasic.disable()) diff --git a/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java b/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java index ed2a81f..b03bcc8 100644 --- a/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java +++ b/src/main/java/com/hanaro/hanafun/common/exception/BasicErrorStatus.java @@ -7,11 +7,11 @@ @Getter @AllArgsConstructor public enum BasicErrorStatus { - BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), - UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "인증이 필요합니다."), - RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, "값을 찾을 수 없습니다."), - INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 에러"), - FORBIDDEN(HttpStatus.FORBIDDEN, "금지된 작업입니다."); + BAD_REQUEST(HttpStatus.BAD_REQUEST, "BAD_REQUEST"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "NO_ACCESS_AUTH"), + RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, "NOT_FOUND"), + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR"), + FORBIDDEN(HttpStatus.FORBIDDEN, "FORBIDDEN"); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java b/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java index 7a770c7..9310cc8 100644 --- a/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java +++ b/src/main/java/com/hanaro/hanafun/host/mapper/HostMapper.java @@ -6,7 +6,7 @@ @UtilityClass public class HostMapper { - public HostLessonDto LessonEntityToHostLessonDto(LessonEntity lessonEntity){ + public static HostLessonDto LessonEntityToHostLessonDto(LessonEntity lessonEntity){ if(lessonEntity == null) return null; return new HostLessonDto().builder() diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java index 31eda7e..44b2a04 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java +++ b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java @@ -1,13 +1,12 @@ package com.hanaro.hanafun.revenue.controller; import com.hanaro.hanafun.common.dto.ApiResponse; -import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; +import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; import com.hanaro.hanafun.revenue.service.impl.RevenueServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; 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; @@ -16,9 +15,9 @@ @RequestMapping("/revenue") public class RevenueController { private final RevenueServiceImpl revenueService; - @GetMapping("/year/{year}") - public ResponseEntity yearRevenue(@AuthenticationPrincipal Long userId, @PathVariable Integer year){ - YearRevenueResDto yearRevenueResDto = revenueService.yearRevenue(userId, year); - return ResponseEntity.ok(new ApiResponse(true, "ok", yearRevenueResDto)); + @GetMapping("/total") + public ResponseEntity totalRevenue(@AuthenticationPrincipal Long userId){ + totalRevenueResDto totalRevenueResDto = revenueService.totalRevenue(userId); + return ResponseEntity.ok(new ApiResponse(true, "ok", totalRevenueResDto)); } } diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java index 0ad350f..7ebecba 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java @@ -12,5 +12,6 @@ public interface RevenueRepository extends JpaRepository { Optional findByCreatedDateBetween(LocalDateTime startDateTime, LocalDateTime endDateTime); @Query(value = "SELECT SUM(R.revenue) FROM RevenueEntity R WHERE R.lessonEntity = :lessonEntity") - Long yearRevenueByLessonId(@Param("lessonEntity") LessonEntity lessonEntity); + Long totalRevenueByLessonId(@Param("lessonEntity") LessonEntity lessonEntity); + } diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java similarity index 87% rename from src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java rename to src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java index 8215a8a..c8d17f8 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/dto/YearRevenueResDto.java +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java @@ -9,6 +9,6 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class YearRevenueResDto { +public class totalRevenueResDto { private long yearRevenue; } diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java index 5132aa8..aa22123 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java +++ b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java @@ -1,7 +1,7 @@ package com.hanaro.hanafun.revenue.service; -import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; +import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; public interface RevenueService { - YearRevenueResDto yearRevenue(Long userId, Integer year); + totalRevenueResDto totalRevenue(Long userId); } diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java index 820490f..56882bc 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java @@ -6,7 +6,7 @@ import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lesson.domain.LessonRepository; import com.hanaro.hanafun.revenue.domain.RevenueRepository; -import com.hanaro.hanafun.revenue.dto.YearRevenueResDto; +import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; import com.hanaro.hanafun.revenue.service.RevenueService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,14 +23,14 @@ public class RevenueServiceImpl implements RevenueService { @Override @Transactional - public YearRevenueResDto yearRevenue(Long userId, Integer year) { + public totalRevenueResDto totalRevenue(Long userId) { Long yearRevenue; HostEntity hostEntity = hostRepository.findByUserEntityUserId(userId).orElseThrow(() -> new HostNotFoundException()); List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(() -> new HostNotFoundException()); - yearRevenue = lessonEntityList.stream().mapToLong(lessonEntity -> revenueRepository.yearRevenueByLessonId(lessonEntity)).sum(); + yearRevenue = lessonEntityList.stream().mapToLong(lessonEntity -> revenueRepository.totalRevenueByLessonId(lessonEntity)).sum(); - return new YearRevenueResDto().builder() + return new totalRevenueResDto().builder() .yearRevenue(yearRevenue) .build(); } diff --git a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java index 640170a..b66d1a7 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java +++ b/src/main/java/com/hanaro/hanafun/transaction/controller/TransactionController.java @@ -9,10 +9,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -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; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor diff --git a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java index a1583e9..c260e86 100644 --- a/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/user/service/impl/UserServiceImpl.java @@ -1,6 +1,6 @@ package com.hanaro.hanafun.user.service.impl; -import com.hanaro.hanafun.authentication.JwtUtil; +import com.hanaro.hanafun.common.authentication.JwtUtil; import com.hanaro.hanafun.user.domain.UserEntity; import com.hanaro.hanafun.user.domain.UserRepository; import com.hanaro.hanafun.user.dto.IsHostResDto; From c4e37a1a70d9e5c16a601b180db9474e87be6c94 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Fri, 28 Jun 2024 16:55:03 +0900 Subject: [PATCH 45/55] fix: exception --- .../hanafun/account/service/impl/AccountServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java index 9637493..1d7fcdb 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java @@ -19,6 +19,10 @@ public class AccountServiceImpl implements AccountService { @Override public List readAccountList(Long userId) { List accountEntityList = accountRepository.findByUserEntityUserId(userId).orElseThrow(() -> new AccountNotFoundException()); + if(accountEntityList.isEmpty()){ + throw new AccountNotFoundException(); + } + return accountEntityList.stream().map(AccountMapper::entityToAccountResDto).toList(); } } From b9aaa696338d95b64267e49437139e17e22d8154 Mon Sep 17 00:00:00 2001 From: seoyeon08 Date: Fri, 28 Jun 2024 16:55:53 +0900 Subject: [PATCH 46/55] =?UTF-8?q?feat:=20=EC=9B=94=EB=B3=84=20=EB=A7=A4?= =?UTF-8?q?=EC=B6=9C=EC=95=A1=20&=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=B3=84?= =?UTF-8?q?=20=EB=A7=A4=EC=B6=9C=EC=95=A1=20&=20=EC=A7=80=EC=B6=9C?= =?UTF-8?q?=EC=95=A1=20=EC=88=98=EC=A0=95=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../revenue/controller/RevenueController.java | 28 ++++++-- .../revenue/domain/RevenueRepository.java | 3 + .../revenue/dto/LessonRevenueResDto.java | 20 ++++++ .../revenue/dto/MonthRevenueResDto.java | 18 +++++ ...nueResDto.java => TotalRevenueResDto.java} | 2 +- .../revenue/dto/UpdatePriceReqDto.java | 19 +++++ .../revenue/dto/UpdatePriceResDto.java | 17 +++++ .../hanafun/revenue/mapper/RevenueMapper.java | 33 +++++++++ .../revenue/service/RevenueService.java | 9 ++- .../service/impl/RevenueServiceImpl.java | 69 +++++++++++++++++-- 10 files changed, 206 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/hanaro/hanafun/revenue/dto/LessonRevenueResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/dto/MonthRevenueResDto.java rename src/main/java/com/hanaro/hanafun/revenue/dto/{totalRevenueResDto.java => TotalRevenueResDto.java} (87%) create mode 100644 src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceReqDto.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceResDto.java create mode 100644 src/main/java/com/hanaro/hanafun/revenue/mapper/RevenueMapper.java diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java index 44b2a04..7a5d5f7 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java +++ b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java @@ -1,14 +1,14 @@ package com.hanaro.hanafun.revenue.controller; import com.hanaro.hanafun.common.dto.ApiResponse; -import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; +import com.hanaro.hanafun.revenue.dto.*; import com.hanaro.hanafun.revenue.service.impl.RevenueServiceImpl; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @RestController @RequiredArgsConstructor @@ -17,7 +17,25 @@ public class RevenueController { private final RevenueServiceImpl revenueService; @GetMapping("/total") public ResponseEntity totalRevenue(@AuthenticationPrincipal Long userId){ - totalRevenueResDto totalRevenueResDto = revenueService.totalRevenue(userId); + TotalRevenueResDto totalRevenueResDto = revenueService.totalRevenue(userId); return ResponseEntity.ok(new ApiResponse(true, "ok", totalRevenueResDto)); } + + @GetMapping("/{year}/{month}") + public ResponseEntity monthRevenue(@AuthenticationPrincipal Long userId, @PathVariable Integer year, @PathVariable Integer month){ + List monthRevenueResDtoList = revenueService.monthRevenue(userId, year, month); + return ResponseEntity.ok(new ApiResponse(true, "ok", monthRevenueResDtoList)); + } + + @GetMapping("/lesson/{year}/{lessonId}") + public ResponseEntity lessonRevenue(@PathVariable Integer year, @PathVariable Long lessonId){ + List lessonRevenueResDtoList = revenueService.lessonRevenue(year, lessonId); + return ResponseEntity.ok(new ApiResponse(true, "ok", lessonRevenueResDtoList)); + } + + @PostMapping("/update") + public ResponseEntity updatePrice(@RequestBody UpdatePriceReqDto updatePriceReqDto){ + UpdatePriceResDto updatePriceResDto = revenueService.updatePrice(updatePriceReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", updatePriceResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java index 7ebecba..42b5f04 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java +++ b/src/main/java/com/hanaro/hanafun/revenue/domain/RevenueRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; public interface RevenueRepository extends JpaRepository { @@ -14,4 +15,6 @@ public interface RevenueRepository extends JpaRepository { @Query(value = "SELECT SUM(R.revenue) FROM RevenueEntity R WHERE R.lessonEntity = :lessonEntity") Long totalRevenueByLessonId(@Param("lessonEntity") LessonEntity lessonEntity); + Optional findByLessonEntityAndCreatedDateBetween(LessonEntity lessonEntity, LocalDateTime startDateTime, LocalDateTime endDateTime); + Optional> findByLessonEntityLessonIdAndCreatedDateBetween(Long lessonId, LocalDateTime startDateTime, LocalDateTime endDateTime); } diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/LessonRevenueResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/LessonRevenueResDto.java new file mode 100644 index 0000000..433a6a2 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/LessonRevenueResDto.java @@ -0,0 +1,20 @@ +package com.hanaro.hanafun.revenue.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class LessonRevenueResDto { + private Integer month; + private Long lessonId; + private String title; + private Long revenue; + private Integer materialPrice; + private Integer rentalPrice; + private Integer etcPrice; +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/MonthRevenueResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/MonthRevenueResDto.java new file mode 100644 index 0000000..6fd0b7f --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/MonthRevenueResDto.java @@ -0,0 +1,18 @@ +package com.hanaro.hanafun.revenue.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MonthRevenueResDto { + + private Long lessonId; + private String title; + private Long revenue; + +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/TotalRevenueResDto.java similarity index 87% rename from src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java rename to src/main/java/com/hanaro/hanafun/revenue/dto/TotalRevenueResDto.java index c8d17f8..b74ef53 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/dto/totalRevenueResDto.java +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/TotalRevenueResDto.java @@ -9,6 +9,6 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class totalRevenueResDto { +public class TotalRevenueResDto { private long yearRevenue; } diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceReqDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceReqDto.java new file mode 100644 index 0000000..0ac1bfa --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceReqDto.java @@ -0,0 +1,19 @@ +package com.hanaro.hanafun.revenue.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class UpdatePriceReqDto { + private Long lessonId; + private Integer year; + private Integer month; + private Integer materialPrice; + private Integer rentalPrice; + private Integer etcPrice; +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceResDto.java b/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceResDto.java new file mode 100644 index 0000000..788edbf --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/dto/UpdatePriceResDto.java @@ -0,0 +1,17 @@ +package com.hanaro.hanafun.revenue.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class UpdatePriceResDto { + private Long lessonId; + private Integer materialPrice; + private Integer rentalPrice; + private Integer etcPrice; +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/mapper/RevenueMapper.java b/src/main/java/com/hanaro/hanafun/revenue/mapper/RevenueMapper.java new file mode 100644 index 0000000..c289f23 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/revenue/mapper/RevenueMapper.java @@ -0,0 +1,33 @@ +package com.hanaro.hanafun.revenue.mapper; + +import com.hanaro.hanafun.revenue.domain.RevenueEntity; +import com.hanaro.hanafun.revenue.dto.LessonRevenueResDto; +import com.hanaro.hanafun.revenue.dto.MonthRevenueResDto; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RevenueMapper { + public static MonthRevenueResDto revenueEntityToMonthRevenueDto(RevenueEntity revenueEntity){ + if(revenueEntity == null) return null; + + return MonthRevenueResDto.builder() + .lessonId(revenueEntity.getLessonEntity().getLessonId()) + .title(revenueEntity.getLessonEntity().getTitle()) + .revenue(revenueEntity.getRevenue()) + .build(); + } + + public static LessonRevenueResDto revenueEntityToLessonRevenueResDto(RevenueEntity revenueEntity){ + if(revenueEntity == null) return null; + + return LessonRevenueResDto.builder() + .month(revenueEntity.getCreatedDate().getMonthValue()) + .lessonId(revenueEntity.getLessonEntity().getLessonId()) + .title(revenueEntity.getLessonEntity().getTitle()) + .revenue(revenueEntity.getRevenue()) + .materialPrice(revenueEntity.getMaterialPrice()) + .rentalPrice(revenueEntity.getRentalPrice()) + .etcPrice(revenueEntity.getEtcPrice()) + .build(); + } +} diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java index aa22123..f4388a0 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java +++ b/src/main/java/com/hanaro/hanafun/revenue/service/RevenueService.java @@ -1,7 +1,12 @@ package com.hanaro.hanafun.revenue.service; -import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; +import com.hanaro.hanafun.revenue.dto.*; + +import java.util.List; public interface RevenueService { - totalRevenueResDto totalRevenue(Long userId); + TotalRevenueResDto totalRevenue(Long userId); + List monthRevenue(Long userId, Integer year, Integer month); + List lessonRevenue(Integer year, Long lessonId); + UpdatePriceResDto updatePrice(UpdatePriceReqDto updatePriceReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java index 56882bc..e0ab032 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java @@ -5,14 +5,21 @@ import com.hanaro.hanafun.host.exception.HostNotFoundException; import com.hanaro.hanafun.lesson.domain.LessonEntity; import com.hanaro.hanafun.lesson.domain.LessonRepository; +import com.hanaro.hanafun.revenue.domain.RevenueEntity; import com.hanaro.hanafun.revenue.domain.RevenueRepository; -import com.hanaro.hanafun.revenue.dto.totalRevenueResDto; +import com.hanaro.hanafun.revenue.dto.*; +import com.hanaro.hanafun.revenue.mapper.RevenueMapper; import com.hanaro.hanafun.revenue.service.RevenueService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.time.Year; +import java.time.YearMonth; +import java.util.Date; import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -23,15 +30,69 @@ public class RevenueServiceImpl implements RevenueService { @Override @Transactional - public totalRevenueResDto totalRevenue(Long userId) { + public TotalRevenueResDto totalRevenue(Long userId) { Long yearRevenue; HostEntity hostEntity = hostRepository.findByUserEntityUserId(userId).orElseThrow(() -> new HostNotFoundException()); - List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(() -> new HostNotFoundException()); + List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(); yearRevenue = lessonEntityList.stream().mapToLong(lessonEntity -> revenueRepository.totalRevenueByLessonId(lessonEntity)).sum(); - return new totalRevenueResDto().builder() + return new TotalRevenueResDto().builder() .yearRevenue(yearRevenue) .build(); } + + @Override + @Transactional + public List monthRevenue(Long userId, Integer year, Integer month) { + HostEntity hostEntity = hostRepository.findByUserEntityUserId(userId).orElseThrow(() -> new HostNotFoundException()); + List lessonEntityList = lessonRepository.findByHostEntityHostId(hostEntity.getHostId()).orElseThrow(); + + YearMonth yearMonth = YearMonth.of(year, month); + LocalDateTime startOfMonth = yearMonth.atDay(1).atStartOfDay(); + LocalDateTime endOfMonth = yearMonth.atEndOfMonth().atTime(23, 59, 59); + + List revenueEntityList = lessonEntityList.stream() + .flatMap(lessonEntity -> revenueRepository.findByLessonEntityAndCreatedDateBetween(lessonEntity, startOfMonth, endOfMonth).stream()) + .collect(Collectors.toList()); + + List monthRevenueResDtoList = revenueEntityList.stream().map(RevenueMapper::revenueEntityToMonthRevenueDto).toList(); + return monthRevenueResDtoList; + } + + @Override + @Transactional + public List lessonRevenue(Integer year, Long lessonId) { + Year searchYear = Year.of(year); + LocalDateTime startOfYear = searchYear.atMonth(1).atDay(1).atStartOfDay(); + LocalDateTime endOfYear = searchYear.atMonth(12).atEndOfMonth().atTime(23,59,59); + + List revenueEntityList = revenueRepository.findByLessonEntityLessonIdAndCreatedDateBetween(lessonId, startOfYear, endOfYear).orElseThrow(); + List lessonRevenueResDtoList = revenueEntityList.stream().map(RevenueMapper::revenueEntityToLessonRevenueResDto).toList(); + + return lessonRevenueResDtoList; + } + + @Override + @Transactional + public UpdatePriceResDto updatePrice(UpdatePriceReqDto updatePriceReqDto) { + LessonEntity lessonEntity = lessonRepository.findById(updatePriceReqDto.getLessonId()).orElseThrow(); + + YearMonth yearMonth = YearMonth.of(updatePriceReqDto.getYear(), updatePriceReqDto.getMonth()); + LocalDateTime startOfMonth = yearMonth.atDay(1).atStartOfDay(); + LocalDateTime endOfMonth = yearMonth.atEndOfMonth().atTime(23, 59, 59); + + RevenueEntity revenueEntity = revenueRepository.findByLessonEntityAndCreatedDateBetween(lessonEntity, startOfMonth, endOfMonth).orElseThrow(); + revenueEntity.setMaterialPrice(updatePriceReqDto.getMaterialPrice()); + revenueEntity.setRentalPrice(updatePriceReqDto.getRentalPrice()); + revenueEntity.setEtcPrice(updatePriceReqDto.getEtcPrice()); + + return new UpdatePriceResDto().builder() + .lessonId(revenueEntity.getLessonEntity().getLessonId()) + .materialPrice(revenueEntity.getMaterialPrice()) + .rentalPrice(revenueEntity.getRentalPrice()) + .etcPrice(revenueEntity.getEtcPrice()) + .build(); + } + } From 5dd2677b6bb365a59957488eb27c757f9ed7a08e Mon Sep 17 00:00:00 2001 From: alswlfl29 Date: Fri, 28 Jun 2024 17:20:34 +0900 Subject: [PATCH 47/55] =?UTF-8?q?feat:=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4/=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EB=B0=8F=20=ED=95=84=ED=84=B0=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 --- .../lesson/controller/LessonController.java | 37 +++++++- .../lesson/domain/LessonRepository.java | 26 ++++++ .../hanafun/lesson/service/LessonService.java | 15 ++++ .../service/impl/LessonServiceImpl.java | 86 ++++++++++++++++--- 4 files changed, 150 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index a5a7254..1c5e59b 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -64,9 +64,44 @@ public void createLesson(@RequestBody CreateLessonReqDto createLessonReqDto) { } // 클래스 전체 조회 (클래스 탐색) - @GetMapping("/category/all") + @GetMapping("/category/search/all") public ResponseEntity fullLesson() { List fullLessonResDtos = lessonService.fullLesson(); return ResponseEntity.ok(new ApiResponse<>(true, "ok", fullLessonResDtos)); } + + // 카테고리 별 클래스 조회 + @GetMapping("/category/search/{categoryId}") + public ResponseEntity categoryLesson(@PathVariable Long categoryId) { + List fullLessonResDtos = lessonService.categoryLesson(categoryId); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", fullLessonResDtos)); + } + + // 클래스 검색(전체) + @GetMapping("/category/all/search") + public ResponseEntity searchLessonAll(@RequestParam("query") String query){ + List fullLessonResDtos = lessonService.searchLessonAll(query); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", fullLessonResDtos)); + } + + // 클래스 검색(카테고리) + @GetMapping("/category/{categoryId}/search") + public ResponseEntity searchLessonCategory(@PathVariable Long categoryId, @RequestParam("query") String query){ + List fullLessonResDtos = lessonService.searchLessonCategory(categoryId, query); + return ResponseEntity.ok(new ApiResponse<>(true, "ok", fullLessonResDtos)); + } + + // 클래스 필터(전체) + @GetMapping("/category/all") + public ResponseEntity searchFilterLessonAll(@RequestParam("query") String query, @RequestParam("sort") String sort){ + List fullLessonResDtos = lessonService.searchFilterLessonAll(query, sort); + return ResponseEntity.ok(new ApiResponse(true, "ok", fullLessonResDtos)); + } + + // 클래스 필터(카테고리) + @GetMapping("/category/{categoryId}") + public ResponseEntity searchFilterLessonCategory(@PathVariable Long categoryId, @RequestParam("query") String query, @RequestParam("sort") String sort){ + List fullLessonResDtos = lessonService.searchFilterLessonCategory(categoryId, query, sort); + return ResponseEntity.ok(new ApiResponse(true, "ok", fullLessonResDtos)); + } } diff --git a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java index db8d731..026e9c2 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java +++ b/src/main/java/com/hanaro/hanafun/lesson/domain/LessonRepository.java @@ -2,6 +2,8 @@ import com.hanaro.hanafun.host.domain.HostEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -11,4 +13,28 @@ public interface LessonRepository extends JpaRepository { List findLessonEntitiesByHostEntity(HostEntity hostEntity); Optional> findByHostEntityHostId(Long hostId); + Optional> findByCategoryEntityCategoryId(Long categoryId); + + @Query("SELECT L FROM LessonEntity L WHERE L.title Like %:query% OR L.description Like %:query%") + List findBySearchLessonAll(String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.categoryEntity.categoryId = :categoryId AND (L.title Like %:query% OR L.description Like %:query%)") + List findBySearchLessonCategory(Long categoryId, String query); + + @Query(value = "SELECT L FROM LessonEntity L WHERE L.title Like %:query% OR L.description Like %:query% ORDER BY L.createdDate DESC") + List findSearchFilterLessonAllByOrderByDate(String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.title Like %:query% OR L.description Like %:query% ORDER BY L.applicantSum DESC") + List findSearchFilterLessonAllByOrderByApplicantSum(String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.title Like %:query% OR L.description Like %:query% ORDER BY L.price ASC") + List findSearchFilterLessonAllByOrderByPriceAsc(String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.title Like %:query% OR L.description Like %:query% ORDER BY L.price DESC") + List findSearchFilterLessonAllByOrderByPriceDesc(String query); + + @Query(value = "SELECT L FROM LessonEntity L WHERE L.categoryEntity.categoryId = :categoryId AND (L.title Like %:query% OR L.description Like %:query%) ORDER BY L.createdDate DESC") + List findSearchFilterLessonCategoryByOrderByDate(Long categoryId, String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.categoryEntity.categoryId = :categoryId AND (L.title Like %:query% OR L.description Like %:query%) ORDER BY L.applicantSum DESC") + List findSearchFilterLessonCategoryByOrderByApplicantSum(Long categoryId, String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.categoryEntity.categoryId = :categoryId AND (L.title Like %:query% OR L.description Like %:query%) ORDER BY L.price ASC") + List findSearchFilterLessonCategoryByOrderByPriceAsc(Long categoryId, String query); + @Query(value = "SELECT L FROM LessonEntity L WHERE L.categoryEntity.categoryId = :categoryId AND (L.title Like %:query% OR L.description Like %:query%) ORDER BY L.price DESC") + List findSearchFilterLessonCategoryByOrderByPriceDesc(Long categoryId, String query); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index e1e9b99..f6c297d 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -20,4 +20,19 @@ public interface LessonService { // 클래스 전체 조회 (클래스 탐색) List fullLesson(); + + // 카테고리별 클래스 조회 + List categoryLesson(Long categoryId); + + // 클래스 검색(전체) + List searchLessonAll(String query); + + // 클래스 검색(카테고리) + List searchLessonCategory(Long categoryId, String query); + + // 클래스 필터(전체) + List searchFilterLessonAll(String query, String sort); + + // 클래스 필터(카테고리) + List searchFilterLessonCategory(Long categoryId, String query, String sort); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index 00644bc..87a1cc6 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -18,10 +18,12 @@ import com.hanaro.hanafun.lessondate.domain.LessonDateEntity; import com.hanaro.hanafun.lessondate.domain.LessonDateRepository; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -114,19 +116,77 @@ public void createLesson(CreateLessonReqDto createLessonReqDto) { public List fullLesson() { List lessonList = lessonRepository.findAll(); - List fullLessonResDtos = lessonList.stream() - .map(lesson -> { - FullLessonResDto fullLessonResDto = FullLessonResDto.builder() - .lessonId(lesson.getLessonId()) - .image(lesson.getImage()) - .title(lesson.getTitle()) - .price(lesson.getPrice()) - .hostName(lesson.getHostEntity().getUserEntity().getUsername()) - .build(); - return fullLessonResDto; - }) - .collect(Collectors.toList()); + return searchLessonList(lessonList); + } + + // 카테고리 별 클래스 조회 + @Transactional + @Override + public List categoryLesson(Long categoryId) { + List lessonList = lessonRepository.findByCategoryEntityCategoryId(categoryId) + .orElseThrow(()->new CategoryNotFoundException()); + + if(lessonList.isEmpty()) throw new CategoryNotFoundException(); + + return searchLessonList(lessonList); + } + + // 클래스 검색(전체) + @Transactional + @Override + public List searchLessonAll(String query) { + List lessonList = lessonRepository.findBySearchLessonAll(query); - return fullLessonResDtos; + return searchLessonList(lessonList); + } + + // 클래스 검색(카테고리) + @Transactional + @Override + public List searchLessonCategory(Long categoryId, String query) { + List lessonList = lessonRepository.findBySearchLessonCategory(categoryId, query); + + return searchLessonList(lessonList); + } + + // 클래스 필터(전체) + @Transactional + @Override + public List searchFilterLessonAll(String query, String sort) { + List lessonList = switch (sort) { + case "date" -> lessonRepository.findSearchFilterLessonAllByOrderByDate(query); + case "popular" -> lessonRepository.findSearchFilterLessonAllByOrderByApplicantSum(query); + case "priceAsc" -> lessonRepository.findSearchFilterLessonAllByOrderByPriceAsc(query); + case "priceDesc" -> lessonRepository.findSearchFilterLessonAllByOrderByPriceDesc(query); + default -> throw new LessonNotFoundException(); + }; + + return searchLessonList(lessonList); + } + + @Transactional + @Override + public List searchFilterLessonCategory(Long categoryId, String query, String sort) { + List lessonList = switch (sort) { + case "date" -> lessonRepository.findSearchFilterLessonCategoryByOrderByDate(categoryId, query); + case "popular" -> lessonRepository.findSearchFilterLessonCategoryByOrderByApplicantSum(categoryId, query); + case "priceAsc" -> lessonRepository.findSearchFilterLessonCategoryByOrderByPriceAsc(categoryId, query); + case "priceDesc" -> lessonRepository.findSearchFilterLessonCategoryByOrderByPriceDesc(categoryId, query); + default -> throw new LessonNotFoundException(); + }; + return searchLessonList(lessonList); + } + + public List searchLessonList(List lessonlist){ + return lessonlist.stream().map(lesson -> { + FullLessonResDto fullLessonResDto = FullLessonResDto.builder() + .lessonId(lesson.getLessonId()) + .image(lesson.getImage()) + .title(lesson.getTitle()) + .price(lesson.getPrice()) + .hostName(lesson.getHostEntity().getUserEntity().getUsername()) + .build(); + return fullLessonResDto; + }).collect(Collectors.toList()); } } From 11447799b066e55b132022267c06ddff8446319c Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 2 Jul 2024 09:27:38 +0900 Subject: [PATCH 48/55] fix: revenue http method type --- .../hanafun/revenue/controller/RevenueController.java | 2 +- .../revenue/service/impl/RevenueServiceImpl.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java index 7a5d5f7..9533a24 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java +++ b/src/main/java/com/hanaro/hanafun/revenue/controller/RevenueController.java @@ -33,7 +33,7 @@ public ResponseEntity lessonRevenue(@PathVariable Integer year, @Pa return ResponseEntity.ok(new ApiResponse(true, "ok", lessonRevenueResDtoList)); } - @PostMapping("/update") + @PutMapping("/update") public ResponseEntity updatePrice(@RequestBody UpdatePriceReqDto updatePriceReqDto){ UpdatePriceResDto updatePriceResDto = revenueService.updatePrice(updatePriceReqDto); return ResponseEntity.ok(new ApiResponse(true, "ok", updatePriceResDto)); diff --git a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java index e0ab032..d55be5e 100644 --- a/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/revenue/service/impl/RevenueServiceImpl.java @@ -56,8 +56,9 @@ public List monthRevenue(Long userId, Integer year, Integer .flatMap(lessonEntity -> revenueRepository.findByLessonEntityAndCreatedDateBetween(lessonEntity, startOfMonth, endOfMonth).stream()) .collect(Collectors.toList()); - List monthRevenueResDtoList = revenueEntityList.stream().map(RevenueMapper::revenueEntityToMonthRevenueDto).toList(); - return monthRevenueResDtoList; + return revenueEntityList.stream() + .map(RevenueMapper::revenueEntityToMonthRevenueDto) + .toList(); } @Override @@ -68,9 +69,10 @@ public List lessonRevenue(Integer year, Long lessonId) { LocalDateTime endOfYear = searchYear.atMonth(12).atEndOfMonth().atTime(23,59,59); List revenueEntityList = revenueRepository.findByLessonEntityLessonIdAndCreatedDateBetween(lessonId, startOfYear, endOfYear).orElseThrow(); - List lessonRevenueResDtoList = revenueEntityList.stream().map(RevenueMapper::revenueEntityToLessonRevenueResDto).toList(); - return lessonRevenueResDtoList; + return revenueEntityList.stream() + .map(RevenueMapper::revenueEntityToLessonRevenueResDto) + .toList(); } @Override @@ -94,5 +96,4 @@ public UpdatePriceResDto updatePrice(UpdatePriceReqDto updatePriceReqDto) { .etcPrice(revenueEntity.getEtcPrice()) .build(); } - } From ec6c8788a0a2d17455332d0b92d15b55689c9926 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 2 Jul 2024 10:14:45 +0900 Subject: [PATCH 49/55] =?UTF-8?q?build:=20Dokcerfile=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 ++++++ build.gradle | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b24d96 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM openjdk:17-jdk +LABEL maintainer="yubin" +ARG JAR_FILE=build/libs/*.jar +ADD ${JAR_FILE} app.jar +EXPOSE 8099 +ENTRYPOINT ["java","-jar","/app.jar"] diff --git a/build.gradle b/build.gradle index e2fa5c8..6b0ecc1 100644 --- a/build.gradle +++ b/build.gradle @@ -48,3 +48,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +bootJar { + duplicatesStrategy = 'exclude' +} \ No newline at end of file From 01139f0cac8a0a63e64a2c75b6e05c88b1e92677 Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 2 Jul 2024 14:32:57 +0900 Subject: [PATCH 50/55] Update SecurityConfig.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cors 추가 --- .../hanafun/common/config/SecurityConfig.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java b/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java index 738cc08..f0f7bfe 100644 --- a/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java +++ b/src/main/java/com/hanaro/hanafun/common/config/SecurityConfig.java @@ -12,6 +12,10 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -22,6 +26,7 @@ public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception, AuthenticationException { http + .cors(cors -> cors.configurationSource(corsConfigurationSource())) .csrf(csrf -> csrf.disable()) .httpBasic(httpBasic -> httpBasic.disable()) .formLogin(formLogin -> formLogin.disable()) @@ -33,8 +38,29 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception, Auth // .anyRequest().permitAll() .anyRequest().authenticated() ) + .addFilterBefore(corsFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class); return http.build(); } + + @Bean + public UrlBasedCorsConfigurationSource corsConfigurationSource() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // TODO CORS 설정 변경 필요 + config.addAllowedOrigin("http://localhost:3000"); + config.addAllowedOrigin("https://hana-fun-fe.vercel.app"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + return source; + } + + @Bean + public CorsFilter corsFilter() { + return new CorsFilter(corsConfigurationSource()); + } } From 69b14169096d6c1148e907b9712b6fa6f65513cf Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 2 Jul 2024 14:33:32 +0900 Subject: [PATCH 51/55] Update QrReqDto.java --- src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java index 55a6401..803aebb 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java +++ b/src/main/java/com/hanaro/hanafun/transaction/dto/QrReqDto.java @@ -10,7 +10,6 @@ @AllArgsConstructor @NoArgsConstructor public class QrReqDto { - private long guestId; private long withdrawId; private long depositId; private long lessonId; From 376572b1ecbc2694e0b919a92dc4cf959d9a42ff Mon Sep 17 00:00:00 2001 From: doSeung11 Date: Tue, 2 Jul 2024 14:34:27 +0900 Subject: [PATCH 52/55] Update TransactionServiceImpl.java --- .../transaction/service/impl/TransactionServiceImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java index 0af7a12..9b74f56 100644 --- a/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/transaction/service/impl/TransactionServiceImpl.java @@ -61,12 +61,16 @@ public PayResDto qrPay(QrReqDto qrReqDto) { //매출 업데이트 calcRevenue(qrReqDto.getLessonId(), qrReqDto.getPayment()); + //게스트 id 건지기 + AccountEntity accountEntity = accountRepository.findById(qrReqDto.getWithdrawId()).orElseThrow(() -> new AccountNotFoundException()); + Long guestId = accountEntity.getUserEntity().getUserId(); + //거래 내역 저장 TransactionEntity transactionEntity = TransactionEntity.builder() .depositAccount(depositAccount) .withdrawAccount(withdrawAccount) .reservationEntity(reservationRepository - .findByUserEntityUserIdAndLessonDateEntityLessondateId(qrReqDto.getGuestId(), qrReqDto.getLessondateId()) + .findByUserEntityUserIdAndLessonDateEntityLessondateId(guestId, qrReqDto.getLessondateId()) .get()) .payment(qrReqDto.getPayment()) .point(0) @@ -211,4 +215,4 @@ private void calcRevenue(Long lessonId, int payment){ revenueRepository.save(newRevenue); } } -} \ No newline at end of file +} From f464479f46f40a036cc3124264f8a59ee8293e71 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 2 Jul 2024 14:39:52 +0900 Subject: [PATCH 53/55] =?UTF-8?q?build:=20=EC=9E=90=EB=8F=99=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 58 ++++++++++++++++++++++++++++++++++++ build.gradle | 4 ++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..2f99506 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,58 @@ +name: CD with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout source code + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: make application yml + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION_YML }}" > ./application.yml + shell: bash + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew clean build -x test + + - name: Docker build & push to docker repo + run: | + docker login -u ${{ secrets.DOCKER_USERNAME_YUB }} -p ${{ secrets.DOCKER_PASSWORD_YUB }} + docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun . + docker push ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun + + - name: Deploy to server + uses: appleboy/ssh-action@master + id: deploy + with: + host: ${{ secrets.EC2_HOST }} + username: ec2-user + key: ${{ secrets.EC2_SSH_KEY }} + envs: GITHUB_SHA + script: | + sudo docker ps + sudo docker pull ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun + sudo docker stop hanafun + sudo docker rm hanafun + sudo docker run -it -d -p 8099:8080 --name hanafun ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun + sudo docker image prune -f \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6b0ecc1..c140101 100644 --- a/build.gradle +++ b/build.gradle @@ -51,4 +51,6 @@ tasks.named('test') { bootJar { duplicatesStrategy = 'exclude' -} \ No newline at end of file +} + +jar { enabled = false } \ No newline at end of file From 78260af94bfa2777f78302be39b7417f181a4375 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 2 Jul 2024 15:41:04 +0900 Subject: [PATCH 54/55] =?UTF-8?q?feat:=20=EA=B0=9C=EC=84=A4=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EB=AA=A9=EB=A1=9D=20userId->=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EC=82=AC=EC=9A=A9=EC=9C=BC=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 --- .github/workflows/deploy.yml | 58 ------------------- .../lesson/controller/LessonController.java | 5 +- .../hanafun/lesson/service/LessonService.java | 2 +- .../service/impl/LessonServiceImpl.java | 4 +- 4 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 2f99506..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: CD with Gradle - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout source code - - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - - name: make application yml - run: | - cd ./src/main/resources - touch ./application.yml - echo "${{ secrets.APPLICATION_YML }}" > ./application.yml - shell: bash - - - name: Build with Gradle - run: | - chmod +x ./gradlew - ./gradlew clean build -x test - - - name: Docker build & push to docker repo - run: | - docker login -u ${{ secrets.DOCKER_USERNAME_YUB }} -p ${{ secrets.DOCKER_PASSWORD_YUB }} - docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun . - docker push ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun - - - name: Deploy to server - uses: appleboy/ssh-action@master - id: deploy - with: - host: ${{ secrets.EC2_HOST }} - username: ec2-user - key: ${{ secrets.EC2_SSH_KEY }} - envs: GITHUB_SHA - script: | - sudo docker ps - sudo docker pull ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun - sudo docker stop hanafun - sudo docker rm hanafun - sudo docker run -it -d -p 8099:8080 --name hanafun ${{ secrets.DOCKER_USERNAME_YUB }}/hanafun - sudo docker image prune -f \ No newline at end of file diff --git a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java index 1c5e59b..a707dcb 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java +++ b/src/main/java/com/hanaro/hanafun/lesson/controller/LessonController.java @@ -12,6 +12,7 @@ import com.hanaro.hanafun.lessondate.service.LessonDateService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -27,8 +28,8 @@ public class LessonController { // 개설 클래스 관리- 개설 클래스 목록 출력 @GetMapping("/reservation/my/opened") - public ResponseEntity openedLessons(@RequestBody OpenedLessonsReqDto openedLessonsReqDto) { - List openedLessons = lessonService.openedLessons(openedLessonsReqDto); + public ResponseEntity openedLessons(@AuthenticationPrincipal Long userId) { + List openedLessons = lessonService.openedLessons(userId); return ResponseEntity.ok(new ApiResponse<>(true, "ok", openedLessons)); } diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java index f6c297d..38d58ba 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/LessonService.java @@ -10,7 +10,7 @@ public interface LessonService { // 개설 클래스 관리- 개설 클래스 목록 출력 - List openedLessons(OpenedLessonsReqDto openedLessonsReqDto); + List openedLessons(Long userId); // 클래스 상세보기 LessonInfoResDto lessonInfo(Long lessonId); diff --git a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java index 87a1cc6..300e735 100644 --- a/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/lesson/service/impl/LessonServiceImpl.java @@ -37,8 +37,8 @@ public class LessonServiceImpl implements LessonService { // 개설 클래스 관리- 개설 클래스 목록 출력 @Transactional @Override - public List openedLessons(OpenedLessonsReqDto openedLessonsReqDto) { - HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(openedLessonsReqDto.getUserId()); + public List openedLessons(Long userId) { + HostEntity host = hostRepository.findHostEntityByUserEntity_UserId(userId); List lessons = lessonRepository.findLessonEntitiesByHostEntity(host); List openedLessons = lessons.stream() From f5b215e39982630e3787e4b3591458ed5d97ffb5 Mon Sep 17 00:00:00 2001 From: yubin-im Date: Tue, 2 Jul 2024 16:22:24 +0900 Subject: [PATCH 55/55] =?UTF-8?q?build:=20=EC=9E=90=EB=8F=99=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=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 --- .github/workflows/gradle.yml | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..beba430 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,55 @@ +name: CD with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +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: make application yml + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION_YML }}" > ./application.yml + shell: bash + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew clean build -x test + + - name: Docker build & push to docker repo + run: | + docker login -u ${{ secrets.DOCKER_USERNAME_YUB }} -p ${{ secrets.DOCKER_PASSWORD_YUB }} + docker build -f Dockerfile -t "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" . + docker push "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" + + - name: Deploy to server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ec2-user + key: ${{ secrets.EC2_SSH_KEY }} + script: | + sudo docker ps + sudo docker pull "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" + sudo docker stop hanafun + sudo docker rm hanafun + sudo docker run -d -p 8080:8080 --name hanafun "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest" + sudo docker image prune -f \ No newline at end of file