-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3db1674
commit 9ebbfc1
Showing
13 changed files
with
169 additions
and
37 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
doochul/src/main/java/org/doochul/application/ProductService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
doochul/src/main/java/org/doochul/domain/lesson/LessonRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
doochul/src/main/java/org/doochul/domain/membership/MemberShipRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
doochul/src/main/java/org/doochul/domain/product/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
10 changes: 10 additions & 0 deletions
10
doochul/src/main/java/org/doochul/domain/product/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
5 changes: 5 additions & 0 deletions
5
doochul/src/main/java/org/doochul/domain/product/ProductType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.doochul.domain.product; | ||
|
||
public enum ProductType { | ||
LOL, TFT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
doochul/src/main/java/org/doochul/ui/MemberShipController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
doochul/src/main/java/org/doochul/ui/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
doochul/src/main/java/org/doochul/ui/dto/ProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |