Skip to content

Commit 21170bc

Browse files
authored
πŸš€ 4단계 - μˆ˜κ°•μ‹ μ²­(μš”κ΅¬μ‚¬ν•­ λ³€κ²½) (#808)
* docs : λͺ©ν‘œ 및 μš”κ΅¬μ‚¬ν•­ md 파일 μž‘μ„± * refactor : ν”Όλ“œλ°± 받은 λ‚΄μš© μˆ˜μ • μ§„ν–‰(Session, SessionRecordμ—μ„œ 직접 λ³€ν™˜ν•˜μ§€ μ•Šκ³  Mapper ν†΅ν•΄μ„œ Entity, Domain 클래슀 λ°˜ν™˜) * refactor : Session ν΄λž˜μŠ€μ—μ„œ 상속 λ°›λ˜ SessionCore μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ‘œ 이동, BaseEntity 생성 ν›„ ν•„μš”ν•œ ν΄λž˜μŠ€μ— 상속(SessionCore μš”κ΅¬μ‚¬ν•­ μΆ”κ°€λ‘œ 인해 상속이 μ•„λ‹Œ μΈμŠ€ν„΄μŠ€ λ³€μˆ˜λ‘œ μ‚¬μš©ν•˜λŠ” 것이 μ’‹κ² λ‹€κ³  νŒλ‹¨.) * refactor : SessionCoreFacade interface 생성, SessionCoreV2 생성 SessionCoreV2μ—μ„œ μΆ”κ°€λœ μš”κ΅¬μ‚¬ν•­ 적용 μ˜ˆμ • * refactor : κ°•μ˜ μ§„ν–‰ μƒνƒœ enum 정보 λ³€κ²½, SessionCoreV2 ν΄λž˜μŠ€μ— λͺ¨μ§‘ μƒνƒœ κ°’ μΆ”κ°€ 및 ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„± * feat : 컀버 이미지 μΌκΈ‰μ»¬λž™μ…˜ 생성 및 ν…ŒμŠ€νŠΈ μ½”λ“œ 생성 * refactor : κ°•μ˜μ— μ—¬λŸ¬ 이미지 등둝할 수 μžˆλ„λ‘ μˆ˜μ • - session ν…Œμ΄λΈ” μ—μ„œ cover_image_idλ₯Ό κ΄€λ¦¬ν–ˆλŠ”λ° cover_image ν…Œμ΄λΈ”μ—μ„œ session_id 관리할 수 μžˆλ„λ‘ μˆ˜μ • - DB ν…Œμ΄λΈ”μ— 데이터가 μ‘΄μž¬ν•œλ‹€λŠ” κ°€μ •ν•˜μ— λ¦¬νŒ©ν„°λ§ μ§„ν–‰ν•˜λΌλŠ” μš”κ΅¬μ‚¬ν•­μ΄ μžˆμ—ˆλŠ”λ°, 졜초 DB 섀계 μ‹œ 문제둜 이λ₯Ό μ§€ν‚€μ§€ λͺ»ν–ˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ μ‹€λ¬΄μ—μ„œ 이런 상황이 μ˜¨λ‹€λ©΄, κΈ°μ‘΄ 데이터에 λ¬Έμ œλ˜μ§€ μ•Šλ„λ‘ 슀크립트λ₯Ό μž‘μ„±ν•  κ²ƒκ°™μŠ΅λ‹ˆλ‹€. * feat : μ„ λ°œ μ—¬λΆ€, 승인 μ—¬λΆ€ μƒνƒœ Enum 생성 refactor : μˆ˜κ°•μ‹ μ²­ 객체에 μƒνƒœκ°’ μΆ”κ°€ 및 ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„± * refactor : μŠ€ν‚€λ§ˆ, sql μˆ˜μ •, Jdbc μˆ˜κ°•μ‹ μ²­ 등둝, 쑰회 μˆ˜μ • * refactor : enum에 λ©”μ‹œμ§€ 보낼 수 μžˆλ„λ‘ λ©”μ„œλ“œ μΆ”κ°€ * refactor : SessionCoreFacade λ©”μ„œλ“œ 제거, SessionCoreV2λ₯Ό SessionCore둜 λ¦¬νŒ©ν„°λ§ * refactor : μˆ˜κ°•μ‹ μ²­ κ²€μ¦λ‘œμ§ Sessionμ—μ„œ EnrollmentApply 클래슀둜 이동 및 ν…ŒμŠ€νŠΈ μ½”λ“œ 일괄 μˆ˜μ •(컴파일 였λ₯˜ λ°œμƒν•˜μ§€ μ•Šλ„λ‘ μž‘μ—… μ§„ν–‰) * docs : pr 링크 κΈ°μž… 및 README μˆ˜μ •
1 parent 5dcd2cc commit 21170bc

36 files changed

+759
-180
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [πŸš€ 1단계 - λ ˆκ±°μ‹œ μ½”λ“œ λ¦¬νŒ©ν„°λ§](./docs/01-refactoring.md)
55
- [πŸš€ 2단계 - μˆ˜κ°•μ‹ μ²­(도메인 λͺ¨λΈ)](./docs/02-lms-domain-model.md)
66
- [πŸš€ 3단계 - μˆ˜κ°•μ‹ μ²­(DB 적용)](./docs/03-lms-db.md)
7+
- [πŸš€ 4단계 - μˆ˜κ°•μ‹ μ²­(μš”κ΅¬μ‚¬ν•­ λ³€κ²½)](./docs/04-lms-refactor.md)
78

89
## μ§„ν–‰ 방법
910
* ν•™μŠ΅ 관리 μ‹œμŠ€ν…œμ˜ μˆ˜κ°•μ‹ μ²­ μš”κ΅¬μ‚¬ν•­μ„ νŒŒμ•…ν•œλ‹€.

β€Ždocs/04-lms-refactor.mdβ€Ž

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# πŸš€ 4단계 - μˆ˜κ°•μ‹ μ²­(μš”κ΅¬μ‚¬ν•­ λ³€κ²½)
2+
3+
***
4+
5+
## μ½”λ“œ 리뷰
6+
7+
> PR 링크 : [#808](https://github.com/next-step/java-lms/pull/808)
8+
9+
## λ‚˜μ˜ ν•™μŠ΅ λͺ©ν‘œ
10+
11+
### 1. 컴파일 였λ₯˜κ°€ λ°œμƒν•˜μ§€ μ•Šλ„λ‘ λ¦¬νŒ©ν„°λ§ν•˜μž.
12+
13+
- ν”„λ‘œκ·Έλž˜λ° μš”κ΅¬μ‚¬ν•­μ—μ„œμ™€ 같이 λ¦¬νŒ©ν„°λ§ν•  λ•Œ 컴파일 μ—λŸ¬κ°€ μ΅œλŒ€ν•œ λ°œμƒν•˜μ§€ μ•Šλ„λ‘ κ΅¬ν˜„ν•œλ‹€.
14+
- 이 λͺ©ν‘œλ₯Ό μ§€ν‚€λ €λ©΄ κΈ°μ‘΄ μ½”λ“œλ₯Ό λ°”λ‘œ μˆ˜μ •ν•˜λŠ” 것이 μ•„λ‹Œ κΈ°μ‘΄ μ½”λ“œλ₯Ό λ³΅μ‚¬ν•œ λ’€ μ μ§„μ μœΌλ‘œ μ½”λ“œλ₯Ό μˆ˜μ •ν•΄ λ‚˜μ•„κ°„λ‹€.
15+
16+
## 핡심 ν•™μŠ΅ λͺ©ν‘œ
17+
18+
- DB ν…Œμ΄λΈ”μ΄ 변경될 λ•Œλ„ μŠ€νŠΈλž­κΈ€λŸ¬ νŒ¨ν„΄μ„ μ μš©ν•΄ 점진적인 λ¦¬νŒ©ν„°λ§μ„ μ—°μŠ΅ν•œλ‹€.
19+
- [μŠ€νŠΈλž­κΈ€λŸ¬(κ΅μ‚΄μž) νŒ¨ν„΄ - λ§ˆν‹΄ 파울러](https://martinfowler.com/bliki/StranglerFigApplication.html)
20+
- [μŠ€νŠΈλž­κΈ€λŸ¬ 무화과 νŒ¨ν„΄](https://learn.microsoft.com/ko-kr/azure/architecture/patterns/strangler-fig)
21+
22+
## λ³€κ²½λœ κΈ°λŠ₯ μš”κ΅¬μ‚¬ν•­
23+
24+
### κ°•μ˜ μˆ˜κ°•μ‹ μ²­μ€ κ°•μ˜ μƒνƒœκ°€ λͺ¨μ§‘쀑일 λ•Œλ§Œ κ°€λŠ₯ν•˜λ‹€.
25+
26+
- κ°•μ˜κ°€ μ§„ν–‰ 쀑인 μƒνƒœμ—μ„œλ„ μˆ˜κ°•μ‹ μ²­μ΄ κ°€λŠ₯ν•΄μ•Ό ν•œλ‹€.
27+
- κ°•μ˜ μ§„ν–‰ μƒνƒœ(쀀비쀑, 진행쀑, μ’…λ£Œ)와 λͺ¨μ§‘ μƒνƒœ(λΉ„λͺ¨μ§‘쀑, λͺ¨μ§‘쀑)둜 μƒνƒœ 값을 뢄리해야 ν•œλ‹€.
28+
29+
### κ°•μ˜λŠ” κ°•μ˜ 컀버 이미지 정보λ₯Ό κ°€μ§„λ‹€.
30+
31+
- κ°•μ˜λŠ” ν•˜λ‚˜ μ΄μƒμ˜ 컀버 이미지λ₯Ό κ°€μ§ˆ 수 μžˆλ‹€.
32+
33+
### 강사가 μŠΉμΈν•˜μ§€ μ•Šμ•„λ„ μˆ˜κ°• μ‹ μ²­ν•˜λŠ” λͺ¨λ“  μ‚¬λžŒμ΄ μˆ˜κ°• κ°€λŠ₯ν•˜λ‹€.
34+
35+
- μš°μ•„ν•œν…Œν¬μ½”μŠ€(무료), μš°μ•„ν•œν…Œν¬μΊ ν”„ Pro(유료)와 같이 μ„ λ°œλœ μΈμ›λ§Œ μˆ˜κ°• κ°€λŠ₯ν•΄μ•Ό ν•œλ‹€.
36+
- κ°•μ‚¬λŠ” μˆ˜κ°•μ‹ μ²­ν•œ μ‚¬λžŒ 쀑 μ„ λ°œλœ 인원에 λŒ€ν•΄μ„œλ§Œ μˆ˜κ°• 승인이 κ°€λŠ₯ν•΄μ•Ό ν•œλ‹€.
37+
- κ°•μ‚¬λŠ” μˆ˜κ°•μ‹ μ²­ν•œ μ‚¬λžŒ 쀑 μ„ λ°œλ˜μ§€ μ•Šμ€ μ‚¬λžŒμ€ μˆ˜κ°•μ„ μ·¨μ†Œν•  수 μžˆμ–΄μ•Ό ν•œλ‹€.
38+
39+
## ν”„λ‘œκ·Έλž˜λ° μš”κ΅¬μ‚¬ν•­
40+
41+
- λ¦¬νŒ©ν„°λ§ν•  λ•Œ 컴파일 μ—λŸ¬μ™€ 기쑴의 λ‹¨μœ„ ν…ŒμŠ€νŠΈμ˜ μ‹€νŒ¨λ₯Ό μ΅œμ†Œν™”ν•˜λ©΄μ„œ 점진적인 λ¦¬νŒ©ν„°λ§μ΄ κ°€λŠ₯ν•˜λ„λ‘ ν•œλ‹€.
42+
- DB ν…Œμ΄λΈ”μ— 데이터가 μ‘΄μž¬ν•œλ‹€λŠ” κ°€μ •ν•˜μ— λ¦¬νŒ©ν„°λ§ν•΄μ•Ό ν•œλ‹€.
43+
- 즉, 기쑴에 μŒ“μΈ 데이터λ₯Ό μ œκ±°ν•˜μ§€ μ•Šμ€ μƒνƒœλ‘œ λ¦¬νŒ©ν„°λ§ ν•΄μ•Ό ν•œλ‹€.
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
package nextstep.courses.domain;
22

3+
import nextstep.courses.domain.session.BaseEntity;
34
import nextstep.courses.domain.session.Session;
45

56
import java.time.LocalDateTime;
67
import java.util.ArrayList;
78
import java.util.List;
89

9-
public class Course {
10-
private Long id;
10+
public class Course extends BaseEntity {
1111

1212
private String title;
1313

1414
private Long creatorId;
1515

16-
private LocalDateTime createdAt;
17-
18-
private LocalDateTime updatedAt;
19-
2016
private List<Session> sessions = new ArrayList<>();
2117

22-
public Course() {
23-
}
2418

2519
public Course(String title, Long creatorId) {
2620
this(0L, title, creatorId, LocalDateTime.now(), null);
2721
}
2822

2923
public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) {
30-
this.id = id;
24+
super(id, createdAt, updatedAt);
3125
this.title = title;
3226
this.creatorId = creatorId;
33-
this.createdAt = createdAt;
34-
this.updatedAt = updatedAt;
3527
}
3628

3729
public void addSession(Session session) {
3830
this.sessions.add(session);
3931
}
4032

41-
public Long getId() {
42-
return id;
43-
}
44-
4533
public String getTitle() {
4634
return title;
4735
}
@@ -50,18 +38,12 @@ public Long getCreatorId() {
5038
return creatorId;
5139
}
5240

53-
public LocalDateTime getCreatedAt() {
54-
return createdAt;
55-
}
5641

5742
@Override
5843
public String toString() {
5944
return "Course{" +
60-
"id=" + id +
61-
", title='" + title + '\'' +
45+
" title='" + title + '\'' +
6246
", creatorId=" + creatorId +
63-
", createdAt=" + createdAt +
64-
", updatedAt=" + updatedAt +
6547
'}';
6648
}
6749
}

β€Žsrc/main/java/nextstep/courses/domain/image/CoverImage.javaβ€Ž

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class CoverImage {
77
public static final double MAX_FILE_SIZE = 1024 * 1024; // 1MB
88

99
private Long id;
10+
private final long sessionId;
1011
private final long size;
1112
private final ImageType type;
1213
private final ImageDimentsion dimentsion;
@@ -15,21 +16,22 @@ public CoverImage(long size, String type, int width, int height) {
1516
this(size, ImageType.fromName(type.toUpperCase()), width, height);
1617
}
1718

18-
public CoverImage(Long id, long size, String type, int width, int height) {
19-
this(id, size, ImageType.fromName(type.toUpperCase()), width, height);
19+
public CoverImage(Long id, Long sessionId, long size, String type, int width, int height) {
20+
this(id, sessionId, size, ImageType.fromName(type.toUpperCase()), width, height);
2021
}
2122

22-
public CoverImage(long size, ImageType type, int width, int height) {
23-
this(0L, size, type, new ImageDimentsion(width, height));
23+
public CoverImage(long size, ImageType type, int width, int height) {
24+
this(0L, 0L, size, type, new ImageDimentsion(width, height));
2425
}
2526

26-
public CoverImage(Long id, long size, ImageType type, int width, int height) {
27-
this(id, size, type, new ImageDimentsion(width, height));
27+
public CoverImage(Long id, Long sessionId,long size, ImageType type, int width, int height) {
28+
this(id, sessionId, size, type, new ImageDimentsion(width, height));
2829
}
2930

30-
public CoverImage(Long id, long size, ImageType type, ImageDimentsion dimentsion) {
31+
public CoverImage(Long id, Long sessionId, long size, ImageType type, ImageDimentsion dimentsion) {
3132
validateFileSize(size);
3233
this.id = id;
34+
this.sessionId = sessionId;
3335
this.size = size;
3436
this.type = type;
3537
this.dimentsion = dimentsion;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package nextstep.courses.domain.image;
22

3+
import java.util.List;
4+
35
public interface CoverImageRepository {
46

57
int save(CoverImage coverImage);
68

7-
CoverImage findById(Long id);
9+
List<CoverImage> findBySessionId(Long id);
810
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package nextstep.courses.domain.image;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class CoverImages {
7+
8+
private List<CoverImage> coverImages;
9+
10+
public CoverImages() {
11+
this.coverImages = new ArrayList<>();
12+
}
13+
14+
public CoverImages(CoverImage... coverImage) {
15+
this.coverImages = List.of(coverImage);
16+
}
17+
18+
public CoverImages(List<CoverImage> coverImages) {
19+
this.coverImages = coverImages;
20+
}
21+
22+
public void add(CoverImage coverImage) {
23+
coverImages.add(coverImage);
24+
}
25+
26+
public int size() {
27+
return coverImages.size();
28+
}
29+
30+
public List<CoverImage> getCoverImages() {
31+
return coverImages;
32+
}
33+
34+
}

β€Žsrc/main/java/nextstep/courses/domain/service/SessionService.javaβ€Ž

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import nextstep.courses.domain.CourseRepository;
55
import nextstep.courses.domain.image.CoverImage;
66
import nextstep.courses.domain.image.CoverImageRepository;
7+
import nextstep.courses.domain.image.CoverImages;
78
import nextstep.courses.domain.session.Enrollment;
9+
import nextstep.courses.domain.session.EnrollmentApply;
810
import nextstep.courses.domain.session.Enrollments;
911
import nextstep.courses.domain.session.Session;
12+
import nextstep.courses.domain.session.mapper.SessionMapper;
1013
import nextstep.courses.domain.session.repository.EnrollmentRepository;
1114
import nextstep.courses.domain.session.repository.SessionRepository;
1215
import nextstep.courses.record.EnrollmentRecord;
@@ -22,7 +25,7 @@
2225
import java.util.Optional;
2326

2427
@Service
25-
public class SessionService {
28+
public class SessionService {
2629

2730
private final SessionRepository sessionRepository;
2831
private final CoverImageRepository coverImageRepository;
@@ -47,26 +50,29 @@ public SessionService(SessionRepository sessionRepository,
4750

4851
public Session findById(Long id) {
4952
SessionRecord sessionRecord = sessionRepository.findById(id);
50-
CoverImage saveCoverImage = coverImageRepository.findById(sessionRecord.getCoverImageId());
53+
List<CoverImage> saveCoverImages = coverImageRepository.findBySessionId(id);
5154
Course saveCourse = courseRepository.findById(sessionRecord.getCourseId());
5255
List<EnrollmentRecord> enrollmentRecords = enrollmentRepository.findBySessionId(id);
5356
Enrollments enrollments = toEnrollments(enrollmentRecords);
5457

55-
return sessionRecord.toSession(saveCourse, saveCoverImage, enrollments);
58+
return SessionMapper.toDomain(sessionRecord, saveCourse, saveCoverImages, enrollments);
5659
}
5760

5861
@Transactional
5962
public int save(Session session) {
60-
coverImageRepository.save(session.getCoverImage());
61-
return sessionRepository.save(session.toSessionRecord());
63+
for (CoverImage coverImage : session.getCoverImages()) {
64+
coverImageRepository.save(coverImage);
65+
}
66+
67+
return sessionRepository.save(SessionMapper.toEntity(session));
6268
}
6369

6470
@Transactional
65-
public int saveEnrollment(Enrollment enrollment, Payment payment) {
66-
SessionRecord sessionRecord = sessionRepository.findById(enrollment.getSessionId());
67-
List<EnrollmentRecord> enrollmentRecords = enrollmentRepository.findBySessionId(enrollment.getSessionId());
68-
Session session = sessionRecord.toSession(null, null, toEnrollments(enrollmentRecords));
69-
session.addEnrollment(enrollment, payment);
71+
public int saveEnrollment(NsUser user, Long sessionId, Payment payment) {
72+
SessionRecord sessionRecord = sessionRepository.findById(sessionId);
73+
List<EnrollmentRecord> enrollmentRecords = enrollmentRepository.findBySessionId(sessionId);
74+
EnrollmentApply enrollmentApply = new EnrollmentApply(toEnrollments(enrollmentRecords), payment, sessionRecord.createdSessionCore());
75+
Enrollment enrollment = enrollmentApply.enroll(user, sessionId);
7076

7177
paymentRepository.save(payment);
7278

@@ -84,5 +90,4 @@ private Enrollments toEnrollments(List<EnrollmentRecord> enrollmentRecords) {
8490
return enrollments;
8591
}
8692

87-
8893
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package nextstep.courses.domain.session;
2+
3+
import java.time.LocalDateTime;
4+
5+
public abstract class BaseEntity {
6+
7+
private final Long id;
8+
private final LocalDateTime createdAt;
9+
private final LocalDateTime updatedAt;
10+
11+
public BaseEntity(Long id, LocalDateTime createdAt, LocalDateTime updatedAt) {
12+
this.id = id;
13+
this.createdAt = createdAt;
14+
this.updatedAt = updatedAt;
15+
}
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public LocalDateTime getCreatedAt() {
22+
return createdAt;
23+
}
24+
25+
public LocalDateTime getUpdatedAt() {
26+
return updatedAt;
27+
}
28+
}

0 commit comments

Comments
Β (0)