Skip to content

Commit

Permalink
feat: 곽두철 뼈대 엔티티 재정의
Browse files Browse the repository at this point in the history
  • Loading branch information
SeonJuuuun committed Mar 3, 2024
1 parent 3db1674 commit 9ebbfc1
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 37 deletions.
20 changes: 20 additions & 0 deletions doochul/src/main/java/org/doochul/application/ProductService.java
Original file line number Diff line number Diff line change
@@ -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<ProductResponse> findMemberShipsById(Long userId) {
List<Product> products = productRepository.findByUserId(userId);
return ProductResponse.fromList(products);
}
}
8 changes: 4 additions & 4 deletions doochul/src/main/java/org/doochul/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 11 additions & 5 deletions doochul/src/main/java/org/doochul/domain/lesson/Lesson.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Lesson, Long> {
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<MemberShip,Long> {
public interface MemberShipRepository extends JpaRepository<MemberShip, Long> {
}
36 changes: 36 additions & 0 deletions doochul/src/main/java/org/doochul/domain/product/Product.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<ProductRepository, Long> {
List<Product> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.doochul.domain.product;

public enum ProductType {
LOL, TFT
}
28 changes: 10 additions & 18 deletions doochul/src/main/java/org/doochul/domain/user/User.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.doochul.ui;

import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemberShipController {


}
25 changes: 25 additions & 0 deletions doochul/src/main/java/org/doochul/ui/ProductController.java
Original file line number Diff line number Diff line change
@@ -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<List<ProductResponse>> findMemberShipsById(@PathVariable Long userId) {
List<ProductResponse> response = productService.findMemberShipsById(userId);
return ResponseEntity.ok(response);
}
}
27 changes: 27 additions & 0 deletions doochul/src/main/java/org/doochul/ui/dto/ProductResponse.java
Original file line number Diff line number Diff line change
@@ -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<ProductResponse> fromList(List<Product> products) {
return products.stream()
.map(ProductResponse::from)
.toList();
}
}

0 comments on commit 9ebbfc1

Please sign in to comment.