-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Lesson 저장 로직 구현 #17
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3db1674
feat: 곽두철 뼈대 엔티티 정의
ingpyo 9ebbfc1
feat: 곽두철 뼈대 엔티티 재정의
SeonJuuuun de57354
[Feat] fcm 메시지 알람 기능 구현 (#9)
ingpyo 6524bbc
refactor: 중복 코드 삭제
SeonJuuuun 99650a3
refactor: 잘못된 코드 리팩터링
SeonJuuuun 1e51675
feat/16-create-lesson
yukudaa c355f71
feat/16-create-lesson
yukudaa 7f7c569
feat/16-create-lesson
yukudaa 8082eb8
feat/16-save-lesson
yukudaa 63cbc46
feat/16-create-lesson
yukudaa 1d0e4a6
refactor: 사용하지 않는 메소드 제거
yukudaa 595a665
feat: record로 변환
yukudaa 74c3cc7
feat: Lesson 수정
yukudaa f69fc5d
feat: Lesson 수정
yukudaa d23599c
feat: LessonService 수정
yukudaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
doochul/src/main/java/org/doochul/application/LessonService.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,31 @@ | ||
package org.doochul.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.doochul.domain.lesson.Lesson; | ||
import org.doochul.domain.lesson.LessonRepository; | ||
import org.doochul.domain.membership.MemberShip; | ||
import org.doochul.domain.membership.MemberShipRepository; | ||
import org.doochul.domain.product.Product; | ||
import org.doochul.domain.product.ProductRepository; | ||
import org.doochul.domain.user.User; | ||
import org.doochul.domain.user.UserRepository; | ||
import org.doochul.ui.dto.LessonRequest; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LessonService { | ||
|
||
private final LessonRepository lessonRepository; | ||
private final MemberShipRepository memberShipRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Transactional | ||
public Long save(final Long userId, final Long membershipId, final LessonRequest lessonRequest) { | ||
final User user = userRepository.findById(userId).orElseThrow(); | ||
final MemberShip memberShip = memberShipRepository.findById(membershipId).orElseThrow(); | ||
|
||
return lessonRepository.save(Lesson.of(user, memberShip.getProduct().getTeacher(),memberShip, lessonRequest.startedAt(), lessonRequest.endedAt(), lessonRequest.record())).getId(); | ||
} | ||
} |
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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
doochul/src/main/java/org/doochul/application/RedisService.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.application; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.Duration; | ||
|
||
@Service | ||
public class RedisService { | ||
|
||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
public RedisService(final RedisTemplate<String, String> redisTemplate) { | ||
this.redisTemplate = redisTemplate; | ||
} | ||
|
||
public void delete(final String key) { | ||
redisTemplate.delete(key); | ||
} | ||
|
||
|
||
public boolean setNX(final String key, final String value, final Duration duration) { | ||
return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, value, duration)); | ||
} | ||
} |
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,22 @@ | ||
package org.doochul.config; | ||
|
||
import java.time.Clock; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
|
||
@Bean | ||
public Clock clock() { | ||
return Clock.systemDefaultZone(); | ||
} | ||
|
||
@Bean | ||
public ThreadPoolTaskScheduler taskScheduler() { | ||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); | ||
scheduler.setPoolSize(2); | ||
return scheduler; | ||
} | ||
} |
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,26 @@ | ||
package org.doochul.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate() { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
return redisTemplate; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
doochul/src/main/java/org/doochul/config/SchedulingConfig.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.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulingConfig { | ||
|
||
} |
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,29 @@ | ||
package org.doochul.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.MappedSuperclass; | ||
import jakarta.persistence.PreUpdate; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
public abstract class BaseEntity { | ||
|
||
@Column(updatable = false, nullable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@Column(nullable = false) | ||
private LocalDateTime updatedAt; | ||
|
||
public BaseEntity() { | ||
this.createdAt = LocalDateTime.now(); | ||
this.updatedAt = LocalDateTime.now(); | ||
} | ||
|
||
@PreUpdate | ||
public void update() { | ||
this.updatedAt = LocalDateTime.now(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
doochul/src/main/java/org/doochul/domain/lesson/Lesson.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,59 @@ | ||
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 java.time.LocalDateTime; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.doochul.domain.BaseEntity; | ||
import org.doochul.domain.membership.MemberShip; | ||
import org.doochul.domain.user.User; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Lesson extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "membership_id") | ||
private MemberShip memberShip; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "teacher_id") | ||
private User teacher; | ||
|
||
private LocalDateTime startedAt; | ||
|
||
private LocalDateTime endedAt; | ||
|
||
private String record; | ||
|
||
private Lesson(Long id, User user, User teacher, MemberShip memberShip, LocalDateTime startedAt, LocalDateTime endedAt, String record) { | ||
this.id = id; | ||
this.user = user; | ||
this.teacher = teacher; | ||
this.memberShip = memberShip; | ||
this.startedAt = startedAt; | ||
this.endedAt = endedAt; | ||
this.record = record; | ||
} | ||
|
||
public static Lesson of(User user, User teacher, MemberShip memberShip, LocalDateTime startedAt, LocalDateTime endedAt, String record) { | ||
return new Lesson(null, user, teacher,memberShip, startedAt, endedAt, record); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.doochul.domain.lesson; | ||
|
||
import org.doochul.domain.product.Product; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface LessonRepository extends JpaRepository<Lesson, Long> { | ||
default Lesson getById(final Long id) { | ||
return findById(id).orElseThrow(() -> new IllegalArgumentException("해당 수업이 없습니다.")); | ||
} | ||
List<Lesson> findByStartedAtBefore(final LocalDateTime currentServerTime); | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
doochul/src/main/java/org/doochul/domain/membership/MemberShip.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,49 @@ | ||
package org.doochul.domain.membership; | ||
|
||
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 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 | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MemberShip extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User student; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "product_id") | ||
private Product product; | ||
|
||
private Integer remainingCount; | ||
|
||
public void decreasedCount() { | ||
validateMinRemainingCount(); | ||
remainingCount -= 1; | ||
} | ||
|
||
public boolean isCountZero() { | ||
return remainingCount == 0; | ||
} | ||
|
||
private void validateMinRemainingCount() { | ||
if (remainingCount < 1) { | ||
throw new IllegalArgumentException("안돼"); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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> { | ||
} |
5 changes: 5 additions & 0 deletions
5
doochul/src/main/java/org/doochul/domain/membership/MemberShipType.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.membership; | ||
|
||
public enum MemberShipType { | ||
LOL, TFT | ||
} |
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; | ||
} |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
package org.doochul.domain.product; | ||
|
||
import java.util.List; | ||
|
||
import org.doochul.domain.user.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, Long> { | ||
List<Product> findAll(); | ||
List<Product> findByUserId(Long userId); | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 둘다 없애도될거같아요! |
||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.doochul.domain.user; | ||
|
||
public enum Gender { | ||
MEN, WOMEN | ||
} |
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.user; | ||
|
||
public enum Identity { | ||
GENERAL, TEACHER | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파라미터랑 products에 final 키워드 붙혀주세요