diff --git a/doochul/src/main/java/org/doochul/application/ProductService.java b/doochul/src/main/java/org/doochul/application/ProductService.java new file mode 100644 index 0000000..67d57da --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/ProductService.java @@ -0,0 +1,20 @@ +package org.doochul.application; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.doochul.domain.product.Product; +import org.doochul.domain.product.ProductRepository; +import org.doochul.ui.dto.ProductResponse; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ProductService { + + private final ProductRepository productRepository; + + public List findMemberShipsById(Long userId) { + List products = productRepository.findByUserId(userId); + return ProductResponse.fromList(products); + } +} diff --git a/doochul/src/main/java/org/doochul/domain/BaseEntity.java b/doochul/src/main/java/org/doochul/domain/BaseEntity.java index 9b9df2b..47e1958 100644 --- a/doochul/src/main/java/org/doochul/domain/BaseEntity.java +++ b/doochul/src/main/java/org/doochul/domain/BaseEntity.java @@ -4,17 +4,17 @@ import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PreUpdate; import lombok.Getter; -import org.antlr.v4.runtime.misc.NotNull; import java.time.LocalDateTime; @Getter @MappedSuperclass public abstract class BaseEntity { - @NotNull - @Column(updatable = false) + + @Column(updatable = false, nullable = false) private LocalDateTime createdAt; - @NotNull + + @Column(nullable = false) private LocalDateTime updatedAt; public BaseEntity() { diff --git a/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java b/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java index 0df947b..0110daf 100644 --- a/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java +++ b/doochul/src/main/java/org/doochul/domain/lesson/Lesson.java @@ -1,15 +1,21 @@ package org.doochul.domain.lesson; +import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import org.doochul.domain.BaseEntity; -import org.doochul.domain.membership.MemberShip; - import java.time.LocalDateTime; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.doochul.domain.BaseEntity; +import org.doochul.domain.memberShip.MemberShip; +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Lesson extends BaseEntity { @Id @@ -20,9 +26,9 @@ public class Lesson extends BaseEntity { @JoinColumn(name = "membership_id") private MemberShip memberShip; - private String record; - private LocalDateTime startedAt; private LocalDateTime endedAt; + + private String record; } diff --git a/doochul/src/main/java/org/doochul/domain/lesson/LessonRepository.java b/doochul/src/main/java/org/doochul/domain/lesson/LessonRepository.java index d01d19c..eecf4d6 100644 --- a/doochul/src/main/java/org/doochul/domain/lesson/LessonRepository.java +++ b/doochul/src/main/java/org/doochul/domain/lesson/LessonRepository.java @@ -1,8 +1,6 @@ package org.doochul.domain.lesson; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -@Repository public interface LessonRepository extends JpaRepository { } diff --git a/doochul/src/main/java/org/doochul/domain/membership/MemberShip.java b/doochul/src/main/java/org/doochul/domain/membership/MemberShip.java index 8c8a9d4..822fbbb 100644 --- a/doochul/src/main/java/org/doochul/domain/membership/MemberShip.java +++ b/doochul/src/main/java/org/doochul/domain/membership/MemberShip.java @@ -1,14 +1,16 @@ -package org.doochul.domain.membership; +package org.doochul.domain.memberShip; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import org.doochul.domain.BaseEntity; +import org.doochul.domain.product.Product; import org.doochul.domain.user.User; @Entity @@ -20,11 +22,13 @@ public class MemberShip extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne + @ManyToOne + @JoinColumn(name = "user_id") private User student; - @OneToOne - private User trainer; + @ManyToOne + @JoinColumn(name = "product_id") + private Product product; - private Integer count; + private Integer remainingCount; } diff --git a/doochul/src/main/java/org/doochul/domain/membership/MemberShipRepository.java b/doochul/src/main/java/org/doochul/domain/membership/MemberShipRepository.java index ae66143..e255ab2 100644 --- a/doochul/src/main/java/org/doochul/domain/membership/MemberShipRepository.java +++ b/doochul/src/main/java/org/doochul/domain/membership/MemberShipRepository.java @@ -1,8 +1,8 @@ -package org.doochul.domain.membership; +package org.doochul.domain.memberShip; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface MemberShipRepository extends JpaRepository { +public interface MemberShipRepository extends JpaRepository { } diff --git a/doochul/src/main/java/org/doochul/domain/product/Product.java b/doochul/src/main/java/org/doochul/domain/product/Product.java new file mode 100644 index 0000000..f9ba1b5 --- /dev/null +++ b/doochul/src/main/java/org/doochul/domain/product/Product.java @@ -0,0 +1,36 @@ +package org.doochul.domain.product; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.doochul.domain.BaseEntity; +import org.doochul.domain.user.User; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Product extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + @Enumerated(EnumType.STRING) + private ProductType type; + + @ManyToOne + @JoinColumn(name = "teacher_id") + private User teacher; + + private Integer count; +} diff --git a/doochul/src/main/java/org/doochul/domain/product/ProductRepository.java b/doochul/src/main/java/org/doochul/domain/product/ProductRepository.java new file mode 100644 index 0000000..1cb880e --- /dev/null +++ b/doochul/src/main/java/org/doochul/domain/product/ProductRepository.java @@ -0,0 +1,10 @@ +package org.doochul.domain.product; + +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepository extends JpaRepository { + List findByUserId(Long userId); +} diff --git a/doochul/src/main/java/org/doochul/domain/product/ProductType.java b/doochul/src/main/java/org/doochul/domain/product/ProductType.java new file mode 100644 index 0000000..458dd86 --- /dev/null +++ b/doochul/src/main/java/org/doochul/domain/product/ProductType.java @@ -0,0 +1,5 @@ +package org.doochul.domain.product; + +public enum ProductType { + LOL, TFT +} diff --git a/doochul/src/main/java/org/doochul/domain/user/User.java b/doochul/src/main/java/org/doochul/domain/user/User.java index 0a9bdad..db23e27 100644 --- a/doochul/src/main/java/org/doochul/domain/user/User.java +++ b/doochul/src/main/java/org/doochul/domain/user/User.java @@ -1,48 +1,40 @@ package org.doochul.domain.user; +import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import org.antlr.v4.runtime.misc.NotNull; +import lombok.RequiredArgsConstructor; import org.doochul.domain.BaseEntity; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "users") +@RequiredArgsConstructor public class User extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @NotNull + @Column(nullable = false) private String name; private String deviceToken; private String passWord; + @Enumerated(EnumType.STRING) private Gender gender; + @Enumerated(EnumType.STRING) private Identity identity; - - public User( - final Long id, - final String name, - final String deviceToken, - final String passWord, - final Gender gender, - final Identity identity - ) { - this.id = id; - this.name = name; - this.deviceToken = deviceToken; - this.passWord = passWord; - this.gender = gender; - this.identity = identity; - } } diff --git a/doochul/src/main/java/org/doochul/ui/MemberShipController.java b/doochul/src/main/java/org/doochul/ui/MemberShipController.java new file mode 100644 index 0000000..69b77ad --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/MemberShipController.java @@ -0,0 +1,9 @@ +package org.doochul.ui; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MemberShipController { + + +} diff --git a/doochul/src/main/java/org/doochul/ui/ProductController.java b/doochul/src/main/java/org/doochul/ui/ProductController.java new file mode 100644 index 0000000..fbf9524 --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/ProductController.java @@ -0,0 +1,25 @@ +package org.doochul.ui; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.doochul.application.ProductService; +import org.doochul.ui.dto.ProductResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/memberShip") +public class ProductController { + + private final ProductService productService; + + @GetMapping("/{userId}") + private ResponseEntity> findMemberShipsById(@PathVariable Long userId) { + List response = productService.findMemberShipsById(userId); + return ResponseEntity.ok(response); + } +} diff --git a/doochul/src/main/java/org/doochul/ui/dto/ProductResponse.java b/doochul/src/main/java/org/doochul/ui/dto/ProductResponse.java new file mode 100644 index 0000000..1852217 --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/dto/ProductResponse.java @@ -0,0 +1,27 @@ +package org.doochul.ui.dto; + +import java.time.LocalDateTime; +import java.util.List; +import org.doochul.domain.product.Product; +import org.doochul.domain.product.ProductType; +import org.doochul.domain.user.User; + +public record ProductResponse( + Long id, + ProductType type, + User user, + int count, + LocalDateTime createdAt, + LocalDateTime updatedAt +) { + public static ProductResponse from(Product product) { + return new ProductResponse(product.getId(), product.getType(), product.getTeacher(), + product.getCount(), product.getCreatedAt(), product.getUpdatedAt()); + } + + public static List fromList(List products) { + return products.stream() + .map(ProductResponse::from) + .toList(); + } +}