From ff5e7b64bf9e55dc553e1045e09ed77e0825b98d Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:51:44 +0900 Subject: [PATCH 01/12] =?UTF-8?q?docs=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/STEP2.md b/STEP2.md index 1c345dc13..f9084ce28 100644 --- a/STEP2.md +++ b/STEP2.md @@ -36,3 +36,19 @@ * [x] 강의 테이블 추가 * [x] 강의 저장 조회 테스트 +## Step4 변경 요구사항 +* [ ] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다. + * [ ] 강의 상태를 강의 진행 상태, 모집 상태로 분리 + * [ ] 강의 진행 상태 + * [ ] 모집 상태 + * [ ] 강의 진행 상태가 '진행 중'일 경우 +* [ ] 강의가 하나 이상의 커버 이미지를 가질 수 있다. + * [ ] 커버 이미지 일급 컬렉션 만들기 +* [ ] 선발된 인원만 수강 신청이 가능하다. + * [ ] 선발된 인원에 대해서만 수강 승인이 가능하다. + * [ ] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. + +### Step4 프로그래밍 요구사항 +* 리팩터링할 때 컴파일 에러와 기존의 단위 테스트의 실패를 최소화하면서 점진적인 리팩터링이 가능하도록 한다. +* DB 테이블에 데이터가 존재한다는 가정하에 리팩터링해야 한다. + * 즉, 기존에 쌓인 데이터를 제거하지 않은 상태로 리팩터링 해야 한다. \ No newline at end of file From d918b0cb678c51825838201c6f8e19e7d3b4cdda Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:26:57 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat=20:=20CoverImage=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=89=20=EC=BB=AC=EB=A0=89=EC=85=98=20=EB=A7=8C=EB=93=A4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coverimage/CoverImages.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/nextstep/courses/domain/coverimage/CoverImages.java diff --git a/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java b/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java new file mode 100644 index 000000000..e0fd87886 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java @@ -0,0 +1,21 @@ +package nextstep.courses.domain.coverimage; + +import java.util.HashSet; +import java.util.Set; + +public class CoverImages { + + private Set coverImages = new HashSet<>(); + + public CoverImages(Set coverImages) { + this.coverImages = coverImages; + } + + public void add(CoverImage coverImage) { + this.coverImages.add(coverImage); + } + + public boolean has(CoverImage coverImage) { + return this.coverImages.contains(coverImage); + } +} From 96d1b0199926d1fdeaecfe8c1e3cc2705d57031d Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:56:02 +0900 Subject: [PATCH 03/12] =?UTF-8?q?refact=20:=20=EA=B0=95=EC=9D=98=EA=B0=80?= =?UTF-8?q?=20=ED=95=98=EB=82=98=20=EC=9D=B4=EC=83=81=EC=9D=98=20=EC=BB=A4?= =?UTF-8?q?=EB=B2=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=A5=BC=20=EA=B0=80?= =?UTF-8?q?=EC=A7=88=20=EC=88=98=20=EC=9E=88=EB=8B=A4.=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=EC=97=90=20=EB=94=B0=EB=A5=B8=20DB?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A6=AC=ED=8E=99=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 4 +- .../coverimage/CoverImageRepository.java | 2 +- .../domain/coverimage/CoverImages.java | 14 +++++++ .../courses/domain/coverimage/ImageSize.java | 4 +- .../LectureCoverImageMappingRepository.java | 7 ++++ .../courses/domain/lectures/FreeLecture.java | 32 ++++++++++----- .../domain/lectures/LectureEntity.java | 25 +++++------ .../courses/domain/lectures/PaidLecture.java | 41 ++++++++++++------- ...DBCLectureCoverImageMappingRepository.java | 37 +++++++++++++++++ .../JdbcCoverImageRepository.java | 32 +++++++++++++-- .../infrastructure/JdbcLectureRepository.java | 25 ++++++----- src/main/resources/application.properties | 2 +- src/main/resources/schema.sql | 11 ++++- .../CoverImageRepositoryTest.java | 12 ++++++ .../infrastructure/LectureRepositoryTest.java | 10 ++++- 15 files changed, 198 insertions(+), 60 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/coverimage/LectureCoverImageMappingRepository.java create mode 100644 src/main/java/nextstep/courses/infrastructure/JDBCLectureCoverImageMappingRepository.java diff --git a/STEP2.md b/STEP2.md index f9084ce28..90f2ebe58 100644 --- a/STEP2.md +++ b/STEP2.md @@ -37,13 +37,13 @@ * [x] 강의 저장 조회 테스트 ## Step4 변경 요구사항 +* [x] 강의가 하나 이상의 커버 이미지를 가질 수 있다. + * [x] 커버 이미지 일급 컬렉션 만들기 * [ ] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다. * [ ] 강의 상태를 강의 진행 상태, 모집 상태로 분리 * [ ] 강의 진행 상태 * [ ] 모집 상태 * [ ] 강의 진행 상태가 '진행 중'일 경우 -* [ ] 강의가 하나 이상의 커버 이미지를 가질 수 있다. - * [ ] 커버 이미지 일급 컬렉션 만들기 * [ ] 선발된 인원만 수강 신청이 가능하다. * [ ] 선발된 인원에 대해서만 수강 승인이 가능하다. * [ ] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. diff --git a/src/main/java/nextstep/courses/domain/coverimage/CoverImageRepository.java b/src/main/java/nextstep/courses/domain/coverimage/CoverImageRepository.java index a00ce0a3e..71d040ad9 100644 --- a/src/main/java/nextstep/courses/domain/coverimage/CoverImageRepository.java +++ b/src/main/java/nextstep/courses/domain/coverimage/CoverImageRepository.java @@ -3,7 +3,7 @@ public interface CoverImageRepository { int save(CoverImage coverImage); - + void saveAll(CoverImages coverImages); CoverImage findById(Long id); } diff --git a/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java b/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java index e0fd87886..ae4ebb4f3 100644 --- a/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java +++ b/src/main/java/nextstep/courses/domain/coverimage/CoverImages.java @@ -1,21 +1,35 @@ package nextstep.courses.domain.coverimage; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; public class CoverImages { private Set coverImages = new HashSet<>(); + public CoverImages() { + } + public CoverImages(Set coverImages) { this.coverImages = coverImages; } + public CoverImages(CoverImage coverImages) { + this.coverImages.add(coverImages); + } public void add(CoverImage coverImage) { this.coverImages.add(coverImage); } + public void addAll(CoverImages coverImages) { + this.coverImages.addAll(coverImages.coverImages); + } public boolean has(CoverImage coverImage) { return this.coverImages.contains(coverImage); } + public List coverImages() { + return new ArrayList<>(coverImages); + } } diff --git a/src/main/java/nextstep/courses/domain/coverimage/ImageSize.java b/src/main/java/nextstep/courses/domain/coverimage/ImageSize.java index eea45a755..6db5a7d51 100644 --- a/src/main/java/nextstep/courses/domain/coverimage/ImageSize.java +++ b/src/main/java/nextstep/courses/domain/coverimage/ImageSize.java @@ -20,11 +20,11 @@ public ImageSize(long width, long height) { this.height = height; } - public double getWidth() { + public long getWidth() { return width; } - public double getHeight() { + public long getHeight() { return height; } } diff --git a/src/main/java/nextstep/courses/domain/coverimage/LectureCoverImageMappingRepository.java b/src/main/java/nextstep/courses/domain/coverimage/LectureCoverImageMappingRepository.java new file mode 100644 index 000000000..6a87b9ffe --- /dev/null +++ b/src/main/java/nextstep/courses/domain/coverimage/LectureCoverImageMappingRepository.java @@ -0,0 +1,7 @@ +package nextstep.courses.domain.coverimage; + +import nextstep.courses.domain.lectures.LectureEntity; + +public interface LectureCoverImageMappingRepository { + void save(LectureEntity lecture, CoverImages coverImages); +} diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index 8e80a0ac3..559069930 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -4,13 +4,14 @@ import nextstep.courses.BaseTime; import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.Students; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.users.domain.NsUser; public class FreeLecture extends BaseTime implements Lecture { private final LectureType lectureType = LectureType.FREE; private final Long id; private final String title; - private final CoverImage coverImage; + private final CoverImages coverImages = new CoverImages(); private final LectureStatus lectureStatus; private final RegistrationPeriod registrationPeriod; private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름 @@ -20,7 +21,17 @@ public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus l super(); this.id = id; this.title = title; - this.coverImage = coverImage; + this.coverImages.add(coverImage); + this.lectureStatus = lectureStatus; + this.registrationPeriod = registrationPeriod; + } + + public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + RegistrationPeriod registrationPeriod) { + super(); + this.id = id; + this.title = title; + this.coverImages.addAll(coverImages); this.lectureStatus = lectureStatus; this.registrationPeriod = registrationPeriod; } @@ -29,17 +40,17 @@ public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus l super(createdAt, updatedAt); this.id = id; this.title = title; - this.coverImage = coverImage; + this.coverImages.add(coverImage); this.lectureStatus = lectureStatus; this.registrationPeriod = registrationPeriod; } public FreeLecture(LectureEntity lecture) { super(lecture.getCreatedAt(), lecture.getUpdatedAt()); - this.id = lecture.getId(); - this.title = lecture.getTitle(); - this.coverImage = lecture.getCoverImage(); - this.lectureStatus = lecture.getLectureStatus(); - this.registrationPeriod = lecture.getRegistrationPeriod(); + this.id = lecture.id(); + this.title = lecture.title(); + this.coverImages.addAll(lecture.coverImage()); + this.lectureStatus = lecture.lectureStatus(); + this.registrationPeriod = lecture.registrationPeriod(); } @Override @@ -62,7 +73,7 @@ public void enrollment(NsUser nsUser) { @Override public Lecture start() { - return new FreeLecture(this.id, this.title, this.coverImage, LectureStatus.RECRUITING, this.registrationPeriod); + return new FreeLecture(this.id, this.title, this.coverImages, LectureStatus.RECRUITING, this.registrationPeriod); } @Override @@ -70,11 +81,12 @@ public Integer numberOfStudent() { return students.size(); } + public LectureEntity toEntity() { return new LectureEntity( this.id , this.title - , this.coverImage + , this.coverImages , this.lectureType , this.lectureStatus , this.registrationPeriod diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java index 3c2c71274..683572107 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java @@ -3,25 +3,26 @@ import java.time.LocalDateTime; import nextstep.courses.BaseTime; import nextstep.courses.domain.coverimage.CoverImage; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.users.domain.Price; public class LectureEntity extends BaseTime { private final LectureType lectureType; private final Long id; private final String title; - private final CoverImage coverImage; + private final CoverImages coverImages = new CoverImages(); private final LectureStatus lectureStatus; private final RegistrationPeriod registrationPeriod; private final Price price; private final Integer limitStudentCount; - public LectureEntity(Long id, String title, CoverImage coverImage, LectureType lectureType, + public LectureEntity(Long id, String title, CoverImages coverImages, LectureType lectureType, LectureStatus lectureStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; - this.coverImage = coverImage; + this.coverImages.addAll(coverImages); this.lectureType = lectureType; this.lectureStatus = lectureStatus; this.registrationPeriod = registrationPeriod; @@ -29,35 +30,35 @@ public LectureEntity(Long id, String title, CoverImage coverImage, LectureType this.limitStudentCount = limitStudentCount; } - public LectureType getLectureType() { + public LectureType lectureType() { return lectureType; } - public Long getId() { + public Long id() { return id; } - public String getTitle() { + public String title() { return title; } - public CoverImage getCoverImage() { - return coverImage; + public CoverImages coverImage() { + return coverImages; } - public LectureStatus getLectureStatus() { + public LectureStatus lectureStatus() { return lectureStatus; } - public RegistrationPeriod getRegistrationPeriod() { + public RegistrationPeriod registrationPeriod() { return registrationPeriod; } - public Price getPrice() { + public Price price() { return price; } - public Integer getLimitStudentCount() { + public Integer limitStudentCount() { return limitStudentCount; } } diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index a02f84024..6f1feea4f 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -4,6 +4,7 @@ import nextstep.courses.BaseTime; import nextstep.courses.domain.Students; import nextstep.courses.domain.coverimage.CoverImage; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.users.domain.NsUser; import nextstep.users.domain.Price; @@ -11,7 +12,7 @@ public class PaidLecture extends BaseTime implements Lecture { private final LectureType lectureType = LectureType.PAID; private final Long id; private final String title; - private final CoverImage coverImage; + private final CoverImages coverImages = new CoverImages(); private final LectureStatus lectureStatus; private final RegistrationPeriod registrationPeriod; private final Price price; @@ -24,7 +25,19 @@ public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus l super(); this.id = id; this.title = title; - this.coverImage = coverImage; + this.coverImages.add(coverImage); + this.lectureStatus = lectureStatus; + this.registrationPeriod = registrationPeriod; + this.price = price; + this.limitStudentCount = limitStudentCount; + } + + public PaidLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { + super(); + this.id = id; + this.title = title; + this.coverImages.addAll(coverImages); this.lectureStatus = lectureStatus; this.registrationPeriod = registrationPeriod; this.price = price; @@ -38,7 +51,7 @@ public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus l super(createdAt, updatedAt); this.id = id; this.title = title; - this.coverImage = coverImage; + this.coverImages.add(coverImage); this.lectureStatus = lectureStatus; this.registrationPeriod = registrationPeriod; this.price = price; @@ -47,13 +60,13 @@ public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus l public PaidLecture(LectureEntity lecture) { super(lecture.getCreatedAt(), lecture.getUpdatedAt()); - this.id = lecture.getId(); - this.title = lecture.getTitle(); - this.coverImage = lecture.getCoverImage(); - this.lectureStatus = lecture.getLectureStatus(); - this.registrationPeriod = lecture.getRegistrationPeriod(); - this.price = lecture.getPrice(); - this.limitStudentCount = lecture.getLimitStudentCount(); + this.id = lecture.id(); + this.title = lecture.title(); + this.coverImages.addAll(lecture.coverImage()); + this.lectureStatus = lecture.lectureStatus(); + this.registrationPeriod = lecture.registrationPeriod(); + this.price = lecture.price(); + this.limitStudentCount = lecture.limitStudentCount(); } @Override @@ -77,7 +90,7 @@ public void enrollment(NsUser nsUser) { @Override public Lecture start() { - return new PaidLecture(this.id,this.title,this.coverImage,LectureStatus.RECRUITING, this.registrationPeriod,this.price,this.limitStudentCount); + return new PaidLecture(this.id,this.title,this.coverImages,LectureStatus.RECRUITING, this.registrationPeriod,this.price,this.limitStudentCount); } @Override @@ -97,8 +110,8 @@ public String getTitle() { return title; } - public CoverImage getCoverImage() { - return coverImage; + public CoverImages getCoverImage() { + return this.coverImages; } public LectureStatus getLectureStatus() { @@ -121,7 +134,7 @@ public LectureEntity toEntity() { return new LectureEntity( this.id , this.title - , this.coverImage + , this.coverImages , this.lectureType , this.lectureStatus , this.registrationPeriod diff --git a/src/main/java/nextstep/courses/infrastructure/JDBCLectureCoverImageMappingRepository.java b/src/main/java/nextstep/courses/infrastructure/JDBCLectureCoverImageMappingRepository.java new file mode 100644 index 000000000..97668d8f9 --- /dev/null +++ b/src/main/java/nextstep/courses/infrastructure/JDBCLectureCoverImageMappingRepository.java @@ -0,0 +1,37 @@ +package nextstep.courses.infrastructure; + + +import java.sql.PreparedStatement; +import java.sql.Timestamp; +import java.util.List; +import nextstep.courses.domain.coverimage.CoverImage; +import nextstep.courses.domain.coverimage.CoverImages; +import nextstep.courses.domain.coverimage.LectureCoverImageMappingRepository; +import nextstep.courses.domain.lectures.LectureEntity; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.stereotype.Repository; + +@Repository("LectureCoverImageMappingRepository") +public class JDBCLectureCoverImageMappingRepository implements LectureCoverImageMappingRepository { + + private JdbcOperations jdbcTemplate; + + public JDBCLectureCoverImageMappingRepository(JdbcOperations jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public void save(LectureEntity lecture, CoverImages coverImages) { + String sql = "insert into cover_image_lecture_mapping (lecture_id, cover_image_id, created_at) values(?,?,?)"; + List coverImagesList = coverImages.coverImages(); + Long lectureId = lecture.id(); + jdbcTemplate.batchUpdate(sql + , coverImagesList + , coverImagesList.size() + , (PreparedStatement ps, CoverImage coverImage) -> { + ps.setLong(1, lectureId); + ps.setLong(2, coverImage.getId()); + ps.setTimestamp(3, Timestamp.valueOf(coverImage.getCreatedAt())); + }); + } +} diff --git a/src/main/java/nextstep/courses/infrastructure/JdbcCoverImageRepository.java b/src/main/java/nextstep/courses/infrastructure/JdbcCoverImageRepository.java index 23d33cd2e..0ec7cbf69 100644 --- a/src/main/java/nextstep/courses/infrastructure/JdbcCoverImageRepository.java +++ b/src/main/java/nextstep/courses/infrastructure/JdbcCoverImageRepository.java @@ -1,9 +1,12 @@ package nextstep.courses.infrastructure; +import java.sql.PreparedStatement; import java.sql.Timestamp; import java.time.LocalDateTime; +import java.util.List; import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImageRepository; +import nextstep.courses.domain.coverimage.CoverImages; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; @@ -20,9 +23,30 @@ public JdbcCoverImageRepository(JdbcOperations jdbcTemplate) { @Override public int save(CoverImage coverImage) { String sql = "insert into cover_image (name, cover_image_type, image_file_size, width, height,created_at) values(?, ?, ?, ?, ?, ?)"; - return jdbcTemplate.update(sql, coverImage.getName(), coverImage.getCoverImageType().getName(), - coverImage.getImageFileSize().getSize(), coverImage.getImageSize().getWidth(), - coverImage.getImageSize().getHeight(),coverImage.getCreatedAt()); + return jdbcTemplate.update(sql, + coverImage.getName() + , coverImage.getCoverImageType().getName() + , coverImage.getImageFileSize().getSize() + , coverImage.getImageSize().getWidth() + , coverImage.getImageSize().getHeight() + , coverImage.getCreatedAt()); + } + + @Override + public void saveAll(CoverImages coverImages) { + List coverImageList = coverImages.coverImages(); + String sql = "insert into cover_image (name, cover_image_type, image_file_size, width, height,created_at) values(?, ?, ?, ?, ?, ?)"; + jdbcTemplate.batchUpdate(sql, + coverImageList, + coverImageList.size(), + (PreparedStatement ps, CoverImage coverImage) -> { + ps.setString(1, coverImage.getName()); + ps.setString(2, coverImage.getCoverImageType().getName()); + ps.setLong(3, coverImage.getImageFileSize().getSize()); + ps.setLong(4, coverImage.getImageSize().getWidth()); + ps.setLong(5, coverImage.getImageSize().getHeight()); + ps.setTimestamp(6, Timestamp.valueOf(coverImage.getCreatedAt())); + }); } @Override @@ -37,7 +61,7 @@ public CoverImage findById(Long id) { rs.getLong(6), toLocalDateTime(rs.getTimestamp(7)), toLocalDateTime(rs.getTimestamp(8)) - ); + ); return jdbcTemplate.queryForObject(sql, rowMapper, id); } diff --git a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java index 1126c44d6..240e3fef2 100644 --- a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java +++ b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImageType; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.courses.domain.coverimage.ImageFileSize; import nextstep.courses.domain.coverimage.ImageSize; import nextstep.courses.domain.lectures.LectureEntity; @@ -27,16 +28,15 @@ public JdbcLectureRepository(JdbcOperations jdbcTemplate) { @Override public int save(LectureEntity lectureEntity) { - String sql = "insert into lecture (title, cover_image_id, lecture_status, started_at, ended_at, price, limit_student_count, lecture_type, created_at, updated_at) values(?, ?, ?, ?, ?, ? ,? ,? ,? ,?)"; + String sql = "insert into lecture (title, lecture_status, started_at, ended_at, price, limit_student_count, lecture_type, created_at, updated_at) values(?, ?, ?, ?, ? ,? ,? ,? ,?)"; return jdbcTemplate.update(sql, - lectureEntity.getTitle(), - lectureEntity.getCoverImage().getId(), - lectureEntity.getLectureStatus().getName(), - lectureEntity.getRegistrationPeriod().getStartedAt(), - lectureEntity.getRegistrationPeriod().getEndedAt(), - lectureEntity.getPrice().getPrice(), - lectureEntity.getLimitStudentCount(), - lectureEntity.getLectureType().getName(), + lectureEntity.title(), + lectureEntity.lectureStatus().getName(), + lectureEntity.registrationPeriod().getStartedAt(), + lectureEntity.registrationPeriod().getEndedAt(), + lectureEntity.price().getPrice(), + lectureEntity.limitStudentCount(), + lectureEntity.lectureType().getName(), lectureEntity.getCreatedAt(), lectureEntity.getUpdatedAt() ); @@ -64,12 +64,15 @@ public LectureEntity findById(Long id) { + ", l.created_at" + ", l.updated_at " + "from lecture as l" + + " inner join cover_image_lecture_mapping as lcim" + + " on l.id = lcim.lecture_id" + " inner join cover_image as c" - + " on l.cover_image_id = c.id " + + " on lcim.cover_image_id = c.id " + " where l.id = ?"; RowMapper rowMapper = (rs, rowNum) -> new LectureEntity( rs.getLong(1), rs.getString(2), + new CoverImages( CoverImage.defaultOf( rs.getLong(3) , rs.getString(4) @@ -78,7 +81,7 @@ public LectureEntity findById(Long id) { , new ImageSize(rs.getLong(7), rs.getLong(8)) , toLocalDateTime(rs.getTimestamp(9)) , toLocalDateTime(rs.getTimestamp(10)) - ), + )), LectureType.valueOf(rs.getString(11)), LectureStatus.valueOf(rs.getString(12)), new RegistrationPeriod( diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 219fe02ad..7a0c82196 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.h2.console.enabled=true -spring.datasource.url=jdbc:h2:mem://localhost/~/java-lms;DB_CLOSE_ON_EXIT=FALSE +spring.datasource.url=jdbc:h2:mem://localhost/~/java-lms;DB_CLOSE_ON_EXIT=FALSE&rewriteBatchedStatements=true&profileSQL=true&logger=Slf4JLogger&maxQuerySizeToLog=999999 logging.level.org.springframework.jdbc.core=TRACE logging.level.org.springframework.jdbc.datasource.init=TRACE diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 438dbc887..68a51f541 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -58,7 +58,6 @@ create table lecture ( id bigint generated by default as identity, title varchar(255) not null, - cover_image_id bigint not null, lecture_type varchar(50) not null, lecture_status varchar(50) not null, started_at timestamp not null, @@ -83,4 +82,12 @@ create table cover_image primary key (id) ); - +create table cover_image_lecture_mapping +( + id bigint generated by default as identity, + lecture_id bigint not null , + cover_image_id bigint not null , + created_at timestamp not null, + updated_at timestamp, + primary key (id) +); diff --git a/src/test/java/nextstep/courses/infrastructure/CoverImageRepositoryTest.java b/src/test/java/nextstep/courses/infrastructure/CoverImageRepositoryTest.java index 542c73d17..0d7da9073 100644 --- a/src/test/java/nextstep/courses/infrastructure/CoverImageRepositoryTest.java +++ b/src/test/java/nextstep/courses/infrastructure/CoverImageRepositoryTest.java @@ -8,6 +8,7 @@ import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImageRepository; import nextstep.courses.domain.coverimage.CoverImageType; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.courses.domain.coverimage.ImageFileSize; import nextstep.courses.domain.coverimage.ImageSize; import org.junit.jupiter.api.BeforeEach; @@ -42,4 +43,15 @@ void crud() { assertThat(coverImage.getName()).isEqualTo(savedCoverImage.getName()); LOGGER.debug("Course: {}", savedCoverImage); } + + @Test + void save_many() { + CoverImage coverImage = CoverImage.defaultOf(1L,"test", CoverImageType.GIF,new ImageFileSize(50),new ImageSize(300,200), + LocalDateTime.now() ,null); + CoverImages coverImages = new CoverImages(coverImage); + coverImageRepository.saveAll(coverImages); + CoverImage savedCoverImage = coverImageRepository.findById(1L); + assertThat(coverImage.getName()).isEqualTo(savedCoverImage.getName()); + LOGGER.debug("Course: {}", savedCoverImage); + } } diff --git a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java index d72b3078b..17630ab3e 100644 --- a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java +++ b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java @@ -9,8 +9,10 @@ import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImageRepository; import nextstep.courses.domain.coverimage.CoverImageType; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.courses.domain.coverimage.ImageFileSize; import nextstep.courses.domain.coverimage.ImageSize; +import nextstep.courses.domain.coverimage.LectureCoverImageMappingRepository; import nextstep.courses.domain.lectures.Lecture; import nextstep.courses.domain.lectures.LectureEntity; import nextstep.courses.domain.lectures.LectureRepository; @@ -35,18 +37,22 @@ public class LectureRepositoryTest { private LectureRepository lectureRepository; private CoverImageRepository coverImageRepository; + private LectureCoverImageMappingRepository lectureCoverImageMappingRepository; @BeforeEach void setUp() { lectureRepository = new JdbcLectureRepository(jdbcTemplate); coverImageRepository = new JdbcCoverImageRepository(jdbcTemplate); + lectureCoverImageMappingRepository = new JDBCLectureCoverImageMappingRepository(jdbcTemplate); } @Test void crud() { CoverImage coverImage = CoverImage.defaultOf(1L,"test", CoverImageType.GIF,new ImageFileSize(50),new ImageSize(300,200), LocalDateTime.now() ,null); - coverImageRepository.save(coverImage); + CoverImages coverImages = new CoverImages(coverImage); + coverImageRepository.saveAll(coverImages); + PaidLecture lecture = new PaidLecture( 1L , "test" @@ -56,6 +62,8 @@ void crud() { , new Price(BigDecimal.TEN) , 10 ); + + lectureCoverImageMappingRepository.save(lecture.toEntity(), coverImages); LectureEntity entity = lecture.toEntity(); int count = lectureRepository.save(entity); assertThat(count).isEqualTo(1); From 04fade3f6c40b87c8eb78d0948a19d5119c02d36 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:09:16 +0900 Subject: [PATCH 04/12] =?UTF-8?q?=EA=B0=95=EC=9D=98=20=EB=AA=A8=EC=A7=91?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=EB=A6=AC=EB=84=A4=EC=9D=B4=EB=B0=8D=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B0=95=EC=9D=98=20=EA=B0=80=EB=8A=A5=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EC=B2=B4=ED=82=B9=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/domain/lectures/FreeLecture.java | 31 +++++++++-------- .../courses/domain/lectures/Lecture.java | 1 + .../domain/lectures/LectureEntity.java | 12 +++---- .../lectures/LectureRecruitingStatus.java | 18 ++++++++++ .../domain/lectures/LectureStatus.java | 16 ++------- .../courses/domain/lectures/PaidLecture.java | 33 +++++++++++-------- .../infrastructure/JdbcLectureRepository.java | 4 +-- .../nextstep/courses/domain/CourseTest.java | 4 +-- .../nextstep/courses/domain/LectureTest.java | 12 +++---- .../infrastructure/LectureRepositoryTest.java | 7 ++-- 10 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index 559069930..a99d435be 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -12,36 +12,36 @@ public class FreeLecture extends BaseTime implements Lecture { private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); - private final LectureStatus lectureStatus; + private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름 - public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + public FreeLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; this.title = title; this.coverImages.add(coverImage); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; this.title = title; this.coverImages.addAll(coverImages); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + public FreeLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; this.coverImages.add(coverImage); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } public FreeLecture(LectureEntity lecture) { @@ -49,7 +49,7 @@ public FreeLecture(LectureEntity lecture) { this.id = lecture.id(); this.title = lecture.title(); this.coverImages.addAll(lecture.coverImage()); - this.lectureStatus = lecture.lectureStatus(); + this.lectureRecruitingStatus = lecture.lectureStatus(); this.registrationPeriod = lecture.registrationPeriod(); } @@ -60,20 +60,25 @@ public boolean isFree() { @Override public boolean recruiting() { - return LectureStatus.RECRUITING.equals(this.lectureStatus); + return LectureRecruitingStatus.RECRUITING.equals(this.lectureRecruitingStatus); } @Override - public void enrollment(NsUser nsUser) { - if (recruiting()) { + public void canEnrollment() { + if (!recruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } + } + + @Override + public void enrollment(NsUser nsUser) { + this.canEnrollment(); students.add(nsUser); } @Override public Lecture start() { - return new FreeLecture(this.id, this.title, this.coverImages, LectureStatus.RECRUITING, this.registrationPeriod); + return new FreeLecture(this.id, this.title, this.coverImages, LectureRecruitingStatus.RECRUITING, this.registrationPeriod); } @Override @@ -88,7 +93,7 @@ public LectureEntity toEntity() { , this.title , this.coverImages , this.lectureType - , this.lectureStatus + , this.lectureRecruitingStatus , this.registrationPeriod , null , null diff --git a/src/main/java/nextstep/courses/domain/lectures/Lecture.java b/src/main/java/nextstep/courses/domain/lectures/Lecture.java index 0c2882a58..f8b5e9e7a 100644 --- a/src/main/java/nextstep/courses/domain/lectures/Lecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/Lecture.java @@ -6,6 +6,7 @@ public interface Lecture { boolean isFree(); boolean recruiting(); + void canEnrollment(); void enrollment(NsUser nsUser); Lecture start(); Integer numberOfStudent(); diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java index 683572107..00eaa4bfa 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java @@ -2,7 +2,6 @@ import java.time.LocalDateTime; import nextstep.courses.BaseTime; -import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImages; import nextstep.users.domain.Price; @@ -11,20 +10,21 @@ public class LectureEntity extends BaseTime { private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); - private final LectureStatus lectureStatus; + private final Lecture + private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Price price; private final Integer limitStudentCount; public LectureEntity(Long id, String title, CoverImages coverImages, LectureType lectureType, - LectureStatus lectureStatus, RegistrationPeriod registrationPeriod, Price price, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; this.coverImages.addAll(coverImages); this.lectureType = lectureType; - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; @@ -46,8 +46,8 @@ public CoverImages coverImage() { return coverImages; } - public LectureStatus lectureStatus() { - return lectureStatus; + public LectureRecruitingStatus lectureStatus() { + return lectureRecruitingStatus; } public RegistrationPeriod registrationPeriod() { diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java new file mode 100644 index 000000000..596a53022 --- /dev/null +++ b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java @@ -0,0 +1,18 @@ +package nextstep.courses.domain.lectures; + +public enum LectureRecruitingStatus { + RECRUITING("RECRUITING") + , CLOSING("CLOSING") + , PREPARING("PREPARING") + , NO_MATCH("NO_MATCH") + ; + private final String name; + + LectureRecruitingStatus(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java b/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java index cff2d110e..11e889389 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java @@ -1,18 +1,6 @@ package nextstep.courses.domain.lectures; public enum LectureStatus { - RECRUITING("RECRUITING") - , CLOSING("CLOSING") - , PREPARING("PREPARING") - , NO_MATCH("NO_MATCH") - ; - private final String name; - - LectureStatus(String name) { - this.name = name; - } - - public String getName() { - return name; - } + DOING + , DONE } diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index 6f1feea4f..6613feded 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -13,37 +13,37 @@ public class PaidLecture extends BaseTime implements Lecture { private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); - private final LectureStatus lectureStatus; + private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Price price; private final Integer limitStudentCount; private final Students students = Students.defaultOf();; // 강의 기본정보와는 다름 - public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + public PaidLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { super(); this.id = id; this.title = title; this.coverImages.add(coverImage); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; } - public PaidLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + public PaidLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { super(); this.id = id; this.title = title; this.coverImages.addAll(coverImages); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; } - public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + public PaidLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount , LectureType lectureType , LocalDateTime createdAt @@ -52,7 +52,7 @@ public PaidLecture(Long id, String title, CoverImage coverImage, LectureStatus l this.id = id; this.title = title; this.coverImages.add(coverImage); - this.lectureStatus = lectureStatus; + this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; @@ -63,7 +63,7 @@ public PaidLecture(LectureEntity lecture) { this.id = lecture.id(); this.title = lecture.title(); this.coverImages.addAll(lecture.coverImage()); - this.lectureStatus = lecture.lectureStatus(); + this.lectureRecruitingStatus = lecture.lectureStatus(); this.registrationPeriod = lecture.registrationPeriod(); this.price = lecture.price(); this.limitStudentCount = lecture.limitStudentCount(); @@ -76,21 +76,26 @@ public boolean isFree() { @Override public boolean recruiting() { - return LectureStatus.RECRUITING.equals(this.lectureStatus); + return LectureRecruitingStatus.RECRUITING.equals(this.lectureRecruitingStatus); } @Override - public void enrollment(NsUser nsUser) { + public void canEnrollment() { if (!recruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } + } + + @Override + public void enrollment(NsUser nsUser) { + this.canEnrollment(); nsUser.hasPayment(price); students.addWithLimitCount(nsUser, limitStudentCount); } @Override public Lecture start() { - return new PaidLecture(this.id,this.title,this.coverImages,LectureStatus.RECRUITING, this.registrationPeriod,this.price,this.limitStudentCount); + return new PaidLecture(this.id,this.title,this.coverImages, LectureRecruitingStatus.RECRUITING, this.registrationPeriod,this.price,this.limitStudentCount); } @Override @@ -114,8 +119,8 @@ public CoverImages getCoverImage() { return this.coverImages; } - public LectureStatus getLectureStatus() { - return lectureStatus; + public LectureRecruitingStatus getLectureStatus() { + return lectureRecruitingStatus; } public RegistrationPeriod getRegistrationPeriod() { @@ -136,7 +141,7 @@ public LectureEntity toEntity() { , this.title , this.coverImages , this.lectureType - , this.lectureStatus + , this.lectureRecruitingStatus , this.registrationPeriod , this.price , this.limitStudentCount diff --git a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java index 240e3fef2..4d296b3a3 100644 --- a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java +++ b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java @@ -9,7 +9,7 @@ import nextstep.courses.domain.coverimage.ImageSize; import nextstep.courses.domain.lectures.LectureEntity; import nextstep.courses.domain.lectures.LectureRepository; -import nextstep.courses.domain.lectures.LectureStatus; +import nextstep.courses.domain.lectures.LectureRecruitingStatus; import nextstep.courses.domain.lectures.LectureType; import nextstep.courses.domain.lectures.RegistrationPeriod; import nextstep.users.domain.Price; @@ -83,7 +83,7 @@ public LectureEntity findById(Long id) { , toLocalDateTime(rs.getTimestamp(10)) )), LectureType.valueOf(rs.getString(11)), - LectureStatus.valueOf(rs.getString(12)), + LectureRecruitingStatus.valueOf(rs.getString(12)), new RegistrationPeriod( toLocalDateTime(rs.getTimestamp(13)) , toLocalDateTime(rs.getTimestamp(14)) diff --git a/src/test/java/nextstep/courses/domain/CourseTest.java b/src/test/java/nextstep/courses/domain/CourseTest.java index f06ff9630..ca1119847 100644 --- a/src/test/java/nextstep/courses/domain/CourseTest.java +++ b/src/test/java/nextstep/courses/domain/CourseTest.java @@ -4,7 +4,7 @@ import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.lectures.FreeLecture; import nextstep.courses.domain.lectures.Lecture; -import nextstep.courses.domain.lectures.LectureStatus; +import nextstep.courses.domain.lectures.LectureRecruitingStatus; import nextstep.courses.domain.lectures.RegistrationPeriod; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -21,7 +21,7 @@ public void writingMethodName() throws Exception { CoverImage coverImage = CoverImage.defaultOf("file.png", 2000L, 900, 600); Course course = new Course(1L, "test", 1L, LocalDateTime.of(2023, 11, 23, 15, 30, 00), LocalDateTime.of(2023, 11, 30, 15, 30, 00)); - Lecture lecture = new FreeLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new FreeLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate)); // when diff --git a/src/test/java/nextstep/courses/domain/LectureTest.java b/src/test/java/nextstep/courses/domain/LectureTest.java index 49000ed7b..ad4bf810c 100644 --- a/src/test/java/nextstep/courses/domain/LectureTest.java +++ b/src/test/java/nextstep/courses/domain/LectureTest.java @@ -8,7 +8,7 @@ import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.lectures.FreeLecture; import nextstep.courses.domain.lectures.Lecture; -import nextstep.courses.domain.lectures.LectureStatus; +import nextstep.courses.domain.lectures.LectureRecruitingStatus; import nextstep.courses.domain.lectures.PaidLecture; import nextstep.courses.domain.lectures.RegistrationPeriod; import nextstep.users.domain.NsUser; @@ -36,7 +36,7 @@ void setting() { @DisplayName("무료 강의 생성") public void free_lecture_test() { // given - Lecture lecture = new FreeLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new FreeLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate)); // when boolean result = lecture.isFree(); @@ -49,7 +49,7 @@ public void free_lecture_test() { public void paid_lecture_person_limit_test() { // given int maxStudent = 0; - Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); // then @@ -62,7 +62,7 @@ public void paid_lecture_person_limit_test() { public void lecture_enrolment() { // given int maxStudent = 1; - Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); NsUser javajigi = NsUserTest.JAVAJIGI; javajigi.payment(new Payment(new Price(BigDecimal.TEN))); @@ -80,7 +80,7 @@ public void lecture_enrolment() { public void lecture_enrolment_status() { // given int maxStudent = 1; - Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); // then @@ -92,7 +92,7 @@ public void lecture_enrolment_status() { @DisplayName("수강신청에서 결제가 다를 경우") public void lecture_enrolment_different_fail() { int maxStudent = 1; - Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureStatus.PREPARING, + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); NsUser javajigi = NsUserTest.JAVAJIGI; javajigi.payment(new Payment(new Price(BigDecimal.ONE))); diff --git a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java index 17630ab3e..7cef23552 100644 --- a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java +++ b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java @@ -4,8 +4,6 @@ import java.math.BigDecimal; import java.time.LocalDateTime; -import nextstep.courses.domain.Course; -import nextstep.courses.domain.CourseRepository; import nextstep.courses.domain.coverimage.CoverImage; import nextstep.courses.domain.coverimage.CoverImageRepository; import nextstep.courses.domain.coverimage.CoverImageType; @@ -13,10 +11,9 @@ import nextstep.courses.domain.coverimage.ImageFileSize; import nextstep.courses.domain.coverimage.ImageSize; import nextstep.courses.domain.coverimage.LectureCoverImageMappingRepository; -import nextstep.courses.domain.lectures.Lecture; import nextstep.courses.domain.lectures.LectureEntity; import nextstep.courses.domain.lectures.LectureRepository; -import nextstep.courses.domain.lectures.LectureStatus; +import nextstep.courses.domain.lectures.LectureRecruitingStatus; import nextstep.courses.domain.lectures.PaidLecture; import nextstep.courses.domain.lectures.RegistrationPeriod; import nextstep.users.domain.Price; @@ -57,7 +54,7 @@ void crud() { 1L , "test" , coverImage - , LectureStatus.PREPARING + , LectureRecruitingStatus.PREPARING , new RegistrationPeriod(LocalDateTime.now(), LocalDateTime.now().plusMonths(1)) , new Price(BigDecimal.TEN) , 10 From 2c000d7118575bd8a39b8b35201bdca63059aa11 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:48:55 +0900 Subject: [PATCH 05/12] =?UTF-8?q?refact=20:=20LectureStatus,=20LectureRecr?= =?UTF-8?q?uitingStatus=20=EC=83=81=ED=83=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 2 +- .../courses/domain/lectures/FreeLecture.java | 18 ++++++---- .../courses/domain/lectures/Lecture.java | 2 +- .../domain/lectures/LectureEntity.java | 10 ++++-- .../domain/lectures/LectureStatus.java | 1 + .../courses/domain/lectures/PaidLecture.java | 33 +++++++++++++------ .../infrastructure/JdbcLectureRepository.java | 22 ++++++++----- src/main/resources/schema.sql | 31 ++++++++--------- .../nextstep/courses/domain/CourseTest.java | 3 +- .../nextstep/courses/domain/LectureTest.java | 23 ++++++++++--- .../infrastructure/LectureRepositoryTest.java | 1 + 11 files changed, 96 insertions(+), 50 deletions(-) diff --git a/STEP2.md b/STEP2.md index 90f2ebe58..e5dcef47e 100644 --- a/STEP2.md +++ b/STEP2.md @@ -39,7 +39,7 @@ ## Step4 변경 요구사항 * [x] 강의가 하나 이상의 커버 이미지를 가질 수 있다. * [x] 커버 이미지 일급 컬렉션 만들기 -* [ ] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다. +* [x] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다. * [ ] 강의 상태를 강의 진행 상태, 모집 상태로 분리 * [ ] 강의 진행 상태 * [ ] 모집 상태 diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index a99d435be..44f1374fc 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -12,35 +12,39 @@ public class FreeLecture extends BaseTime implements Lecture { private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); + private final LectureStatus lectureStatus; private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름 - public FreeLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; this.title = title; - this.coverImages.add(coverImage); + this.coverImages.addAll(coverImages); + this.lectureStatus = LectureStatus.YET; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; this.title = title; this.coverImages.addAll(coverImages); + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, + public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; this.coverImages.add(coverImage); + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } @@ -49,7 +53,8 @@ public FreeLecture(LectureEntity lecture) { this.id = lecture.id(); this.title = lecture.title(); this.coverImages.addAll(lecture.coverImage()); - this.lectureRecruitingStatus = lecture.lectureStatus(); + this.lectureStatus = lecture.lectureStatus(); + this.lectureRecruitingStatus = lecture.lectureRecruitingStatus(); this.registrationPeriod = lecture.registrationPeriod(); } @@ -77,7 +82,7 @@ public void enrollment(NsUser nsUser) { } @Override - public Lecture start() { + public Lecture recruitingStart() { return new FreeLecture(this.id, this.title, this.coverImages, LectureRecruitingStatus.RECRUITING, this.registrationPeriod); } @@ -93,6 +98,7 @@ public LectureEntity toEntity() { , this.title , this.coverImages , this.lectureType + , this.lectureStatus , this.lectureRecruitingStatus , this.registrationPeriod , null diff --git a/src/main/java/nextstep/courses/domain/lectures/Lecture.java b/src/main/java/nextstep/courses/domain/lectures/Lecture.java index f8b5e9e7a..83212b6d4 100644 --- a/src/main/java/nextstep/courses/domain/lectures/Lecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/Lecture.java @@ -8,6 +8,6 @@ public interface Lecture { boolean recruiting(); void canEnrollment(); void enrollment(NsUser nsUser); - Lecture start(); + Lecture recruitingStart(); Integer numberOfStudent(); } diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java index 00eaa4bfa..e58d4cef7 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureEntity.java @@ -10,20 +10,21 @@ public class LectureEntity extends BaseTime { private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); - private final Lecture + private final LectureStatus lectureStatus; private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Price price; private final Integer limitStudentCount; public LectureEntity(Long id, String title, CoverImages coverImages, LectureType lectureType, - LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, + LectureStatus lectureStatus,LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; this.coverImages.addAll(coverImages); this.lectureType = lectureType; + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; @@ -46,9 +47,12 @@ public CoverImages coverImage() { return coverImages; } - public LectureRecruitingStatus lectureStatus() { + public LectureRecruitingStatus lectureRecruitingStatus() { return lectureRecruitingStatus; } + public LectureStatus lectureStatus() { + return lectureStatus; + } public RegistrationPeriod registrationPeriod() { return registrationPeriod; diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java b/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java index 11e889389..e22a07940 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureStatus.java @@ -2,5 +2,6 @@ public enum LectureStatus { DOING + , YET , DONE } diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index 6613feded..2bf66bd83 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -8,50 +8,59 @@ import nextstep.users.domain.NsUser; import nextstep.users.domain.Price; -public class PaidLecture extends BaseTime implements Lecture { +public class PaidLecture extends BaseTime implements Lecture { + private final LectureType lectureType = LectureType.PAID; private final Long id; private final String title; private final CoverImages coverImages = new CoverImages(); + private final LectureStatus lectureStatus; private final LectureRecruitingStatus lectureRecruitingStatus; private final RegistrationPeriod registrationPeriod; private final Price price; private final Integer limitStudentCount; - private final Students students = Students.defaultOf();; // 강의 기본정보와는 다름 + private final Students students = Students.defaultOf(); + ; // 강의 기본정보와는 다름 - public PaidLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, + public PaidLecture(Long id, String title, CoverImage coverImage, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { super(); this.id = id; this.title = title; this.coverImages.add(coverImage); + this.lectureStatus = LectureStatus.YET; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; } - public PaidLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, + public PaidLecture(Long id, String title, CoverImages coverImages, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { super(); this.id = id; this.title = title; this.coverImages.addAll(coverImages); + this.lectureStatus = LectureStatus.YET; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; this.limitStudentCount = limitStudentCount; } - public PaidLecture(Long id, String title, CoverImage coverImage, LectureRecruitingStatus lectureRecruitingStatus, + + public PaidLecture(Long id, String title, CoverImages coverImage, LectureStatus lectureStatus, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount - , LectureType lectureType , LocalDateTime createdAt , LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; this.title = title; - this.coverImages.add(coverImage); + this.coverImages.addAll(coverImage); + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; @@ -63,7 +72,8 @@ public PaidLecture(LectureEntity lecture) { this.id = lecture.id(); this.title = lecture.title(); this.coverImages.addAll(lecture.coverImage()); - this.lectureRecruitingStatus = lecture.lectureStatus(); + this.lectureStatus = lecture.lectureStatus(); + this.lectureRecruitingStatus = lecture.lectureRecruitingStatus(); this.registrationPeriod = lecture.registrationPeriod(); this.price = lecture.price(); this.limitStudentCount = lecture.limitStudentCount(); @@ -94,8 +104,10 @@ public void enrollment(NsUser nsUser) { } @Override - public Lecture start() { - return new PaidLecture(this.id,this.title,this.coverImages, LectureRecruitingStatus.RECRUITING, this.registrationPeriod,this.price,this.limitStudentCount); + public Lecture recruitingStart() { + return new PaidLecture(this.id, this.title, this.coverImages, this.lectureStatus, + LectureRecruitingStatus.RECRUITING, this.registrationPeriod, this.price, + this.limitStudentCount, this.getCreatedAt(), this.getUpdatedAt()); } @Override @@ -141,6 +153,7 @@ public LectureEntity toEntity() { , this.title , this.coverImages , this.lectureType + , this.lectureStatus , this.lectureRecruitingStatus , this.registrationPeriod , this.price diff --git a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java index 4d296b3a3..ebbd35afd 100644 --- a/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java +++ b/src/main/java/nextstep/courses/infrastructure/JdbcLectureRepository.java @@ -10,6 +10,7 @@ import nextstep.courses.domain.lectures.LectureEntity; import nextstep.courses.domain.lectures.LectureRepository; import nextstep.courses.domain.lectures.LectureRecruitingStatus; +import nextstep.courses.domain.lectures.LectureStatus; import nextstep.courses.domain.lectures.LectureType; import nextstep.courses.domain.lectures.RegistrationPeriod; import nextstep.users.domain.Price; @@ -28,10 +29,11 @@ public JdbcLectureRepository(JdbcOperations jdbcTemplate) { @Override public int save(LectureEntity lectureEntity) { - String sql = "insert into lecture (title, lecture_status, started_at, ended_at, price, limit_student_count, lecture_type, created_at, updated_at) values(?, ?, ?, ?, ? ,? ,? ,? ,?)"; + String sql = "insert into lecture (title, lecture_status, lecture_recruiting_status, started_at, ended_at, price, limit_student_count, lecture_type, created_at, updated_at) values(?, ?, ?, ?, ?, ? ,? ,? ,? ,?)"; return jdbcTemplate.update(sql, lectureEntity.title(), - lectureEntity.lectureStatus().getName(), + lectureEntity.lectureStatus().toString(), + lectureEntity.lectureRecruitingStatus().getName(), lectureEntity.registrationPeriod().getStartedAt(), lectureEntity.registrationPeriod().getEndedAt(), lectureEntity.price().getPrice(), @@ -57,6 +59,7 @@ public LectureEntity findById(Long id) { + ", c.updated_at" + ", l.lecture_type" + ", l.lecture_status" + + ", l.lecture_recruiting_status" + ", l.started_at" + ", l.ended_at" + ", l.price" @@ -83,15 +86,16 @@ public LectureEntity findById(Long id) { , toLocalDateTime(rs.getTimestamp(10)) )), LectureType.valueOf(rs.getString(11)), - LectureRecruitingStatus.valueOf(rs.getString(12)), + LectureStatus.valueOf(rs.getString(12)), + LectureRecruitingStatus.valueOf(rs.getString(13)), new RegistrationPeriod( - toLocalDateTime(rs.getTimestamp(13)) - , toLocalDateTime(rs.getTimestamp(14)) + toLocalDateTime(rs.getTimestamp(14)) + , toLocalDateTime(rs.getTimestamp(15)) ), - new Price(rs.getBigDecimal(15)), - rs.getInt(16), - toLocalDateTime(rs.getTimestamp(17)), - toLocalDateTime(rs.getTimestamp(18)) + new Price(rs.getBigDecimal(16)), + rs.getInt(17), + toLocalDateTime(rs.getTimestamp(18)), + toLocalDateTime(rs.getTimestamp(19)) ); return jdbcTemplate.queryForObject(sql, rowMapper, id); } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 68a51f541..c9cacb0ee 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -56,16 +56,17 @@ create table delete_history create table lecture ( - id bigint generated by default as identity, - title varchar(255) not null, - lecture_type varchar(50) not null, - lecture_status varchar(50) not null, - started_at timestamp not null, - ended_at timestamp, - price bigint not null default 0, - limit_student_count bigint not null default 0, - created_at timestamp not null, - updated_at timestamp, + id bigint generated by default as identity, + title varchar(255) not null, + lecture_type varchar(50) not null, + lecture_status varchar(50) not null, + lecture_recruiting_status varchar(50) not null, + started_at timestamp not null, + ended_at timestamp, + price bigint not null default 0, + limit_student_count bigint not null default 0, + created_at timestamp not null, + updated_at timestamp, primary key (id) ); @@ -84,10 +85,10 @@ create table cover_image create table cover_image_lecture_mapping ( - id bigint generated by default as identity, - lecture_id bigint not null , - cover_image_id bigint not null , - created_at timestamp not null, - updated_at timestamp, + id bigint generated by default as identity, + lecture_id bigint not null, + cover_image_id bigint not null, + created_at timestamp not null, + updated_at timestamp, primary key (id) ); diff --git a/src/test/java/nextstep/courses/domain/CourseTest.java b/src/test/java/nextstep/courses/domain/CourseTest.java index ca1119847..17e21d583 100644 --- a/src/test/java/nextstep/courses/domain/CourseTest.java +++ b/src/test/java/nextstep/courses/domain/CourseTest.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; import nextstep.courses.domain.coverimage.CoverImage; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.courses.domain.lectures.FreeLecture; import nextstep.courses.domain.lectures.Lecture; import nextstep.courses.domain.lectures.LectureRecruitingStatus; @@ -21,7 +22,7 @@ public void writingMethodName() throws Exception { CoverImage coverImage = CoverImage.defaultOf("file.png", 2000L, 900, 600); Course course = new Course(1L, "test", 1L, LocalDateTime.of(2023, 11, 23, 15, 30, 00), LocalDateTime.of(2023, 11, 30, 15, 30, 00)); - Lecture lecture = new FreeLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, + Lecture lecture = new FreeLecture(0L, "test", new CoverImages(coverImage), LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate)); // when diff --git a/src/test/java/nextstep/courses/domain/LectureTest.java b/src/test/java/nextstep/courses/domain/LectureTest.java index ad4bf810c..8f5a4fb0b 100644 --- a/src/test/java/nextstep/courses/domain/LectureTest.java +++ b/src/test/java/nextstep/courses/domain/LectureTest.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import java.time.LocalDateTime; import nextstep.courses.domain.coverimage.CoverImage; +import nextstep.courses.domain.coverimage.CoverImages; import nextstep.courses.domain.lectures.FreeLecture; import nextstep.courses.domain.lectures.Lecture; import nextstep.courses.domain.lectures.LectureRecruitingStatus; @@ -23,13 +24,14 @@ public class LectureTest { private LocalDateTime startDate; private LocalDateTime endDate; - private CoverImage coverImage; + private CoverImages coverImage; @BeforeEach void setting() { startDate = LocalDateTime.of(2023, 4, 3, 11, 30); endDate = LocalDateTime.of(2023, 6, 3, 11, 30); - coverImage = CoverImage.defaultOf("file.png", 2000L, 900, 600); + CoverImage coverImageOne = CoverImage.defaultOf("file.png", 2000L, 900, 600); + coverImage = new CoverImages(coverImageOne); } @Test @@ -68,7 +70,7 @@ public void lecture_enrolment() { javajigi.payment(new Payment(new Price(BigDecimal.TEN))); // when - Lecture newLecture = lecture.start(); + Lecture newLecture = lecture.recruitingStart(); newLecture.enrollment(javajigi); // then @@ -88,6 +90,19 @@ public void lecture_enrolment_status() { , () -> lecture.enrollment(NsUserTest.SANJIGI)); } + @Test + @DisplayName("진행 중인 강의 수강신청 테스트") + public void lecture_enrolment_status_by_doing() { + // given + int maxStudent = 1; + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, + new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); + + // then + assertThrows(IllegalArgumentException.class + , () -> lecture.enrollment(NsUserTest.SANJIGI)); + } + @Test @DisplayName("수강신청에서 결제가 다를 경우") public void lecture_enrolment_different_fail() { @@ -96,7 +111,7 @@ public void lecture_enrolment_different_fail() { new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); NsUser javajigi = NsUserTest.JAVAJIGI; javajigi.payment(new Payment(new Price(BigDecimal.ONE))); - Lecture startLecture = lecture.start(); + Lecture startLecture = lecture.recruitingStart(); assertThrows(IllegalArgumentException.class , () -> startLecture.enrollment(javajigi)); diff --git a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java index 7cef23552..b9cec1604 100644 --- a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java +++ b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java @@ -14,6 +14,7 @@ import nextstep.courses.domain.lectures.LectureEntity; import nextstep.courses.domain.lectures.LectureRepository; import nextstep.courses.domain.lectures.LectureRecruitingStatus; +import nextstep.courses.domain.lectures.LectureStatus; import nextstep.courses.domain.lectures.PaidLecture; import nextstep.courses.domain.lectures.RegistrationPeriod; import nextstep.users.domain.Price; From 1cbd5395bc74890b9b0dcb3e2943636407f2ca87 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:33:30 +0900 Subject: [PATCH 06/12] =?UTF-8?q?refact=20:=20=EA=B0=95=EC=9D=98=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=A5=BC=20=EA=B0=95=EC=9D=98=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=20=EC=83=81=ED=83=9C,=20=EB=AA=A8=EC=A7=91=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 8 +++--- .../courses/domain/lectures/FreeLecture.java | 25 ++++++++++++++----- .../courses/domain/lectures/Lecture.java | 3 ++- .../courses/domain/lectures/PaidLecture.java | 15 +++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/STEP2.md b/STEP2.md index e5dcef47e..8bad1883b 100644 --- a/STEP2.md +++ b/STEP2.md @@ -40,10 +40,10 @@ * [x] 강의가 하나 이상의 커버 이미지를 가질 수 있다. * [x] 커버 이미지 일급 컬렉션 만들기 * [x] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다. - * [ ] 강의 상태를 강의 진행 상태, 모집 상태로 분리 - * [ ] 강의 진행 상태 - * [ ] 모집 상태 - * [ ] 강의 진행 상태가 '진행 중'일 경우 + * [x] 강의 상태를 강의 진행 상태, 모집 상태로 분리 + * [x] 강의 진행 상태 + * [x] 모집 상태 + * [x] 강의 진행 상태가 '진행 중'일 경우도 수강신청 가능 * [ ] 선발된 인원만 수강 신청이 가능하다. * [ ] 선발된 인원에 대해서만 수강 승인이 가능하다. * [ ] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index 44f1374fc..b264264e0 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -8,6 +8,7 @@ import nextstep.users.domain.NsUser; public class FreeLecture extends BaseTime implements Lecture { + private final LectureType lectureType = LectureType.FREE; private final Long id; private final String title; @@ -17,7 +18,8 @@ public class FreeLecture extends BaseTime implements Lecture { private final RegistrationPeriod registrationPeriod; private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름 - public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; @@ -28,7 +30,8 @@ public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecrui this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { super(); this.id = id; @@ -38,7 +41,9 @@ public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, + + public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; @@ -48,6 +53,7 @@ public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus l this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } + public FreeLecture(LectureEntity lecture) { super(lecture.getCreatedAt(), lecture.getUpdatedAt()); this.id = lecture.id(); @@ -64,13 +70,13 @@ public boolean isFree() { } @Override - public boolean recruiting() { + public boolean isRecruiting() { return LectureRecruitingStatus.RECRUITING.equals(this.lectureRecruitingStatus); } @Override public void canEnrollment() { - if (!recruiting()) { + if (!isRecruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } } @@ -83,7 +89,14 @@ public void enrollment(NsUser nsUser) { @Override public Lecture recruitingStart() { - return new FreeLecture(this.id, this.title, this.coverImages, LectureRecruitingStatus.RECRUITING, this.registrationPeriod); + return new FreeLecture(this.id, this.title, this.coverImages, + LectureRecruitingStatus.RECRUITING, this.registrationPeriod); + } + + @Override + public Lecture start() { + return new FreeLecture(this.id, this.title, this.coverImages, LectureStatus.DOING, + LectureRecruitingStatus.RECRUITING, this.registrationPeriod); } @Override diff --git a/src/main/java/nextstep/courses/domain/lectures/Lecture.java b/src/main/java/nextstep/courses/domain/lectures/Lecture.java index 83212b6d4..286716178 100644 --- a/src/main/java/nextstep/courses/domain/lectures/Lecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/Lecture.java @@ -5,9 +5,10 @@ public interface Lecture { boolean isFree(); - boolean recruiting(); + boolean isRecruiting(); void canEnrollment(); void enrollment(NsUser nsUser); Lecture recruitingStart(); + Lecture start(); Integer numberOfStudent(); } diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index 2bf66bd83..40d034fbd 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -85,15 +85,19 @@ public boolean isFree() { } @Override - public boolean recruiting() { + public boolean isRecruiting() { return LectureRecruitingStatus.RECRUITING.equals(this.lectureRecruitingStatus); } @Override public void canEnrollment() { - if (!recruiting()) { + if (!isRecruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } + + if (this.lectureStatus == LectureStatus.DONE) { + throw new IllegalArgumentException("이미 종료된 강의입니다."); + } } @Override @@ -110,6 +114,13 @@ public Lecture recruitingStart() { this.limitStudentCount, this.getCreatedAt(), this.getUpdatedAt()); } + @Override + public Lecture start() { + return new PaidLecture(this.id, this.title, this.coverImages, LectureStatus.DOING, + LectureRecruitingStatus.RECRUITING, this.registrationPeriod, this.price, + this.limitStudentCount, this.getCreatedAt(), this.getUpdatedAt()); + } + @Override public Integer numberOfStudent() { return students.size(); From 02ee984d15360a5c04eda52458d2f54cfb3fc1a7 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:54:48 +0900 Subject: [PATCH 07/12] =?UTF-8?q?refact=20:=20=EC=84=A0=EB=B0=9C=EB=90=9C?= =?UTF-8?q?=20=EC=9D=B8=EC=9B=90=EC=97=90=20=EB=8C=80=ED=95=B4=EC=84=9C?= =?UTF-8?q?=EB=A7=8C=20=EC=88=98=EA=B0=95=20=EC=8A=B9=EC=9D=B8=EC=9D=B4=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=98=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nextstep/courses/domain/Students.java | 5 ++- .../courses/domain/lectures/FreeLecture.java | 12 ++++-- .../courses/domain/lectures/Lecture.java | 5 ++- .../courses/domain/lectures/PaidLecture.java | 12 ++++-- .../nextstep/courses/domain/LectureTest.java | 40 +++++++++++++++---- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/main/java/nextstep/courses/domain/Students.java b/src/main/java/nextstep/courses/domain/Students.java index 5390677b7..ad5c30c52 100644 --- a/src/main/java/nextstep/courses/domain/Students.java +++ b/src/main/java/nextstep/courses/domain/Students.java @@ -15,7 +15,7 @@ public static Students defaultOf() { return new Students(new ArrayList<>()); } public void canAdd(int limitSize) { - if (this.students.size() >= limitSize) { + if (this.students.size() > limitSize) { throw new IllegalArgumentException("수강인원이 가득찼습니다."); } } @@ -37,4 +37,7 @@ public Integer size() { return this.students.size(); } + public boolean contain(NsUser nsUser) { + return this.students.contains(nsUser); + } } diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index b264264e0..6b8561983 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -75,16 +75,20 @@ public boolean isRecruiting() { } @Override - public void canEnrollment() { + public void canEnrollment(NsUser nsUser, Students selectedStudents) { if (!isRecruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } + + if (selectedStudents.contain(nsUser)) { + throw new IllegalArgumentException("선발된 인원만 수강신청이 가능합니다."); + } } @Override - public void enrollment(NsUser nsUser) { - this.canEnrollment(); - students.add(nsUser); + public void enrollment(NsUser nsUser, Students selectedStudents) { + this.canEnrollment(nsUser,selectedStudents); + this.students.add(nsUser); } @Override diff --git a/src/main/java/nextstep/courses/domain/lectures/Lecture.java b/src/main/java/nextstep/courses/domain/lectures/Lecture.java index 286716178..176081d6d 100644 --- a/src/main/java/nextstep/courses/domain/lectures/Lecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/Lecture.java @@ -1,13 +1,14 @@ package nextstep.courses.domain.lectures; +import nextstep.courses.domain.Students; import nextstep.users.domain.NsUser; public interface Lecture { boolean isFree(); boolean isRecruiting(); - void canEnrollment(); - void enrollment(NsUser nsUser); + void canEnrollment(NsUser nsUser, Students selectedStudents); + void enrollment(NsUser nsUser, Students selectedStudents); Lecture recruitingStart(); Lecture start(); Integer numberOfStudent(); diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index 40d034fbd..9c7fd69d3 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -90,7 +90,7 @@ public boolean isRecruiting() { } @Override - public void canEnrollment() { + public void canEnrollment(NsUser nsUser, Students selectedStudents) { if (!isRecruiting()) { throw new IllegalArgumentException("모집중이지 않습니다."); } @@ -98,13 +98,17 @@ public void canEnrollment() { if (this.lectureStatus == LectureStatus.DONE) { throw new IllegalArgumentException("이미 종료된 강의입니다."); } + + if (!selectedStudents.contain(nsUser)) { + throw new IllegalArgumentException("선발된 인원만 수강신청이 가능합니다."); + } } @Override - public void enrollment(NsUser nsUser) { - this.canEnrollment(); + public void enrollment(NsUser nsUser, Students selectedStudents) { + this.canEnrollment(nsUser,selectedStudents); nsUser.hasPayment(price); - students.addWithLimitCount(nsUser, limitStudentCount); + this.students.addWithLimitCount(nsUser, limitStudentCount); } @Override diff --git a/src/test/java/nextstep/courses/domain/LectureTest.java b/src/test/java/nextstep/courses/domain/LectureTest.java index 8f5a4fb0b..4a63d9861 100644 --- a/src/test/java/nextstep/courses/domain/LectureTest.java +++ b/src/test/java/nextstep/courses/domain/LectureTest.java @@ -53,10 +53,12 @@ public void paid_lecture_person_limit_test() { int maxStudent = 0; Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); + Students students = Students.defaultOf(); + students.add(NsUserTest.SANJIGI); // then assertThrows(IllegalArgumentException.class - , () -> lecture.enrollment(NsUserTest.SANJIGI)); + , () -> lecture.enrollment(NsUserTest.SANJIGI, students)); } @Test @@ -68,10 +70,11 @@ public void lecture_enrolment() { new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); NsUser javajigi = NsUserTest.JAVAJIGI; javajigi.payment(new Payment(new Price(BigDecimal.TEN))); - + Students students = Students.defaultOf(); + students.add(javajigi); // when Lecture newLecture = lecture.recruitingStart(); - newLecture.enrollment(javajigi); + newLecture.enrollment(javajigi, students); // then assertThat(newLecture.numberOfStudent()).isEqualTo(1); @@ -84,10 +87,11 @@ public void lecture_enrolment_status() { int maxStudent = 1; Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); - + Students students = Students.defaultOf(); + students.add(NsUserTest.SANJIGI); // then assertThrows(IllegalArgumentException.class - , () -> lecture.enrollment(NsUserTest.SANJIGI)); + , () -> lecture.enrollment(NsUserTest.SANJIGI, students)); } @Test @@ -97,10 +101,11 @@ public void lecture_enrolment_status_by_doing() { int maxStudent = 1; Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); - + Students selectedStudents = Students.defaultOf(); + selectedStudents.add(NsUserTest.SANJIGI); // then assertThrows(IllegalArgumentException.class - , () -> lecture.enrollment(NsUserTest.SANJIGI)); + , () -> lecture.enrollment(NsUserTest.SANJIGI, selectedStudents)); } @Test @@ -112,8 +117,27 @@ public void lecture_enrolment_different_fail() { NsUser javajigi = NsUserTest.JAVAJIGI; javajigi.payment(new Payment(new Price(BigDecimal.ONE))); Lecture startLecture = lecture.recruitingStart(); + Students selectedStudents = Students.defaultOf(); + selectedStudents.add(NsUserTest.SANJIGI); + + assertThrows(IllegalArgumentException.class + , () -> startLecture.enrollment(javajigi, selectedStudents)); + } + + @Test + @DisplayName("선정되지 않은 학생이 수강신청을 하는 경우") + public void enrollment_fail_when_try_to_enroll_lecture() { + int maxStudent = 1; + Lecture lecture = new PaidLecture(0L, "test", coverImage, LectureRecruitingStatus.PREPARING, + new RegistrationPeriod(startDate, endDate), new Price(BigDecimal.TEN), maxStudent); + NsUser javajigi = NsUserTest.JAVAJIGI; + javajigi.payment(new Payment(new Price(BigDecimal.ONE))); + Lecture startLecture = lecture.recruitingStart(); + Students selectedStudents = Students.defaultOf(); + selectedStudents.add(NsUserTest.SANJIGI); + assertThrows(IllegalArgumentException.class - , () -> startLecture.enrollment(javajigi)); + , () -> startLecture.enrollment(javajigi, selectedStudents)); } } From 0ac6372c833f99f4e0aa9af17403dc3e74538deb Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:55:09 +0900 Subject: [PATCH 08/12] =?UTF-8?q?docs=20:=20=EC=B2=B4=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/STEP2.md b/STEP2.md index 8bad1883b..d8d1fbf79 100644 --- a/STEP2.md +++ b/STEP2.md @@ -44,8 +44,8 @@ * [x] 강의 진행 상태 * [x] 모집 상태 * [x] 강의 진행 상태가 '진행 중'일 경우도 수강신청 가능 -* [ ] 선발된 인원만 수강 신청이 가능하다. - * [ ] 선발된 인원에 대해서만 수강 승인이 가능하다. +* [x] 선발된 인원만 수강 신청이 가능하다. + * [x] 선발된 인원에 대해서만 수강 승인이 가능하다. * [ ] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. ### Step4 프로그래밍 요구사항 From 7c5e351c6a8128adb33ef6b6b3556008528aaa79 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Fri, 22 Dec 2023 12:57:25 +0900 Subject: [PATCH 09/12] =?UTF-8?q?docs=20:=20=EB=A7=88=EC=A7=80=EB=A7=89=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STEP2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STEP2.md b/STEP2.md index d8d1fbf79..99c4bc722 100644 --- a/STEP2.md +++ b/STEP2.md @@ -46,7 +46,7 @@ * [x] 강의 진행 상태가 '진행 중'일 경우도 수강신청 가능 * [x] 선발된 인원만 수강 신청이 가능하다. * [x] 선발된 인원에 대해서만 수강 승인이 가능하다. - * [ ] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. + * [x] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. -> 제 코드에서 선발되지 않은 인원은 아예 수강신청이 불가능하기 때문에 추가하지 않아도 될 것 같습니다. ### Step4 프로그래밍 요구사항 * 리팩터링할 때 컴파일 에러와 기존의 단위 테스트의 실패를 최소화하면서 점진적인 리팩터링이 가능하도록 한다. From 088f5ddedc6b8905150ed7a6973a3d072243199f Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Sun, 24 Dec 2023 16:42:43 +0900 Subject: [PATCH 10/12] =?UTF-8?q?fix=20:=20LectureRecruitingStatus=20?= =?UTF-8?q?=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B0=94=EA=BF=94=EB=B3=B4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/domain/lectures/LectureRecruitingStatus.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java index 596a53022..fd57b79ff 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java @@ -1,10 +1,10 @@ package nextstep.courses.domain.lectures; public enum LectureRecruitingStatus { - RECRUITING("RECRUITING") - , CLOSING("CLOSING") - , PREPARING("PREPARING") - , NO_MATCH("NO_MATCH") + RECRUITING("RECRUITING"), + CLOSING("CLOSING"), + PREPARING("PREPARING"), + NO_MATCH("NO_MATCH") ; private final String name; From 6838fcac96307e38363d2b80bcce5b732073a970 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Sun, 24 Dec 2023 17:03:29 +0900 Subject: [PATCH 11/12] =?UTF-8?q?refact=20:=20=EC=A3=BC=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EB=B6=80=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=A7=80=EC=A0=95?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=BD=94=EB=93=9C=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/nextstep/courses/BaseTime.java | 7 ++- .../courses/domain/coverimage/CoverImage.java | 13 ++---- .../courses/domain/lectures/FreeLecture.java | 45 ++++++------------- .../courses/domain/lectures/PaidLecture.java | 39 ++++++---------- .../infrastructure/LectureRepositoryTest.java | 2 +- 5 files changed, 34 insertions(+), 72 deletions(-) diff --git a/src/main/java/nextstep/courses/BaseTime.java b/src/main/java/nextstep/courses/BaseTime.java index e27565219..59f7df927 100644 --- a/src/main/java/nextstep/courses/BaseTime.java +++ b/src/main/java/nextstep/courses/BaseTime.java @@ -7,15 +7,14 @@ public class BaseTime { private final LocalDateTime createdAt; private final LocalDateTime updatedAt; - public BaseTime() { - this.createdAt = LocalDateTime.now(); - this.updatedAt = null; - } public BaseTime(LocalDateTime createdAt, LocalDateTime updatedAt) { this.createdAt = createdAt; this.updatedAt = updatedAt; } + public BaseTime() { + this(LocalDateTime.now(), null); + } public LocalDateTime getCreatedAt() { return createdAt; diff --git a/src/main/java/nextstep/courses/domain/coverimage/CoverImage.java b/src/main/java/nextstep/courses/domain/coverimage/CoverImage.java index ddb929536..8d2066d6c 100644 --- a/src/main/java/nextstep/courses/domain/coverimage/CoverImage.java +++ b/src/main/java/nextstep/courses/domain/coverimage/CoverImage.java @@ -11,15 +11,6 @@ public class CoverImage extends BaseTime { private final ImageFileSize imageFileSize; private final ImageSize imageSize; - private CoverImage(String name, CoverImageType coverImageType, ImageFileSize size, ImageSize imageSize) { - super(); - this.id = 0L; - this.name = name; - this.coverImageType = coverImageType; - this.imageFileSize = size; - this.imageSize = imageSize; - } - private CoverImage(Long id, String name, CoverImageType coverImageType, ImageFileSize size, ImageSize imageSize, LocalDateTime createdAt, LocalDateTime updatedAt) { super(createdAt, updatedAt); this.id = id; @@ -28,6 +19,10 @@ private CoverImage(Long id, String name, CoverImageType coverImageType, ImageFil this.imageFileSize = size; this.imageSize = imageSize; } + private CoverImage(String name, CoverImageType coverImageType, ImageFileSize size, ImageSize imageSize) { + this(0L, name, coverImageType, size,imageSize, LocalDateTime.now(), null); + } + public static CoverImage defaultOf(String fileName, long size, long width, long height) { String name = fileName(fileName); diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index 6b8561983..31c6785ef 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -18,50 +18,31 @@ public class FreeLecture extends BaseTime implements Lecture { private final RegistrationPeriod registrationPeriod; private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름 + // primary constructor public FreeLecture(Long id, String title, CoverImages coverImages, - LectureRecruitingStatus lectureRecruitingStatus, - RegistrationPeriod registrationPeriod) { - super(); + LectureRecruitingStatus lectureRecruitingStatus, LectureStatus lectureStatus, + RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) { + super(createdAt, updatedAt); this.id = id; this.title = title; this.coverImages.addAll(coverImages); - this.lectureStatus = LectureStatus.YET; + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; } - public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod) { - super(); - this.id = id; - this.title = title; - this.coverImages.addAll(coverImages); - this.lectureStatus = lectureStatus; - this.lectureRecruitingStatus = lectureRecruitingStatus; - this.registrationPeriod = registrationPeriod; + this(id, title, coverImages, lectureRecruitingStatus, LectureStatus.YET, registrationPeriod, + LocalDateTime.now(), null); } - public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus, + public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, - RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) { - super(createdAt, updatedAt); - this.id = id; - this.title = title; - this.coverImages.add(coverImage); - this.lectureStatus = lectureStatus; - this.lectureRecruitingStatus = lectureRecruitingStatus; - this.registrationPeriod = registrationPeriod; - } - - public FreeLecture(LectureEntity lecture) { - super(lecture.getCreatedAt(), lecture.getUpdatedAt()); - this.id = lecture.id(); - this.title = lecture.title(); - this.coverImages.addAll(lecture.coverImage()); - this.lectureStatus = lecture.lectureStatus(); - this.lectureRecruitingStatus = lecture.lectureRecruitingStatus(); - this.registrationPeriod = lecture.registrationPeriod(); + RegistrationPeriod registrationPeriod) { + this(id, title, coverImages, lectureRecruitingStatus, lectureStatus, registrationPeriod, + LocalDateTime.now(), null); } @Override @@ -87,7 +68,7 @@ public void canEnrollment(NsUser nsUser, Students selectedStudents) { @Override public void enrollment(NsUser nsUser, Students selectedStudents) { - this.canEnrollment(nsUser,selectedStudents); + this.canEnrollment(nsUser, selectedStudents); this.students.add(nsUser); } diff --git a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java index 9c7fd69d3..1a5f975f5 100644 --- a/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/PaidLecture.java @@ -23,14 +23,15 @@ public class PaidLecture extends BaseTime implements Lecture { ; // 강의 기본정보와는 다름 - public PaidLecture(Long id, String title, CoverImage coverImage, - LectureRecruitingStatus lectureRecruitingStatus, - RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { - super(); + public PaidLecture(Long id, String title, CoverImages coverImages, + LectureRecruitingStatus lectureRecruitingStatus, LectureStatus lectureStatus, + RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount, + LocalDateTime createdAt, LocalDateTime updatedAt) { + super(createdAt, updatedAt); this.id = id; this.title = title; - this.coverImages.add(coverImage); - this.lectureStatus = LectureStatus.YET; + this.coverImages.addAll(coverImages); + this.lectureStatus = lectureStatus; this.lectureRecruitingStatus = lectureRecruitingStatus; this.registrationPeriod = registrationPeriod; this.price = price; @@ -40,31 +41,17 @@ public PaidLecture(Long id, String title, CoverImage coverImage, public PaidLecture(Long id, String title, CoverImages coverImages, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount) { - super(); - this.id = id; - this.title = title; - this.coverImages.addAll(coverImages); - this.lectureStatus = LectureStatus.YET; - this.lectureRecruitingStatus = lectureRecruitingStatus; - this.registrationPeriod = registrationPeriod; - this.price = price; - this.limitStudentCount = limitStudentCount; + this(id, title, coverImages, LectureStatus.YET, lectureRecruitingStatus, registrationPeriod, + price, limitStudentCount, LocalDateTime.now(), null); } - public PaidLecture(Long id, String title, CoverImages coverImage, LectureStatus lectureStatus, + public PaidLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus, LectureRecruitingStatus lectureRecruitingStatus, RegistrationPeriod registrationPeriod, Price price, Integer limitStudentCount , LocalDateTime createdAt , LocalDateTime updatedAt) { - super(createdAt, updatedAt); - this.id = id; - this.title = title; - this.coverImages.addAll(coverImage); - this.lectureStatus = lectureStatus; - this.lectureRecruitingStatus = lectureRecruitingStatus; - this.registrationPeriod = registrationPeriod; - this.price = price; - this.limitStudentCount = limitStudentCount; + this(id, title, coverImages, lectureRecruitingStatus, LectureStatus.YET, registrationPeriod, + price, limitStudentCount, createdAt, updatedAt); } public PaidLecture(LectureEntity lecture) { @@ -106,7 +93,7 @@ public void canEnrollment(NsUser nsUser, Students selectedStudents) { @Override public void enrollment(NsUser nsUser, Students selectedStudents) { - this.canEnrollment(nsUser,selectedStudents); + this.canEnrollment(nsUser, selectedStudents); nsUser.hasPayment(price); this.students.addWithLimitCount(nsUser, limitStudentCount); } diff --git a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java index b9cec1604..f477f2d0d 100644 --- a/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java +++ b/src/test/java/nextstep/courses/infrastructure/LectureRepositoryTest.java @@ -54,7 +54,7 @@ void crud() { PaidLecture lecture = new PaidLecture( 1L , "test" - , coverImage + , coverImages , LectureRecruitingStatus.PREPARING , new RegistrationPeriod(LocalDateTime.now(), LocalDateTime.now().plusMonths(1)) , new Price(BigDecimal.TEN) From ebbc440add8e325f493a9707ffcd430fbd47d1d0 Mon Sep 17 00:00:00 2001 From: HeeDoo Logan Jeong <78134917+jhd7130@users.noreply.github.com> Date: Mon, 25 Dec 2023 15:31:00 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refact=20:=20enum=EC=97=90=EA=B2=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=A0=84=EB=8B=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B5=AC=EC=A1=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/nextstep/courses/domain/lectures/FreeLecture.java | 4 ++-- .../courses/domain/lectures/LectureRecruitingStatus.java | 4 ++++ .../java/nextstep/courses/domain/lectures/LectureType.java | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java index 31c6785ef..697710b4b 100644 --- a/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java +++ b/src/main/java/nextstep/courses/domain/lectures/FreeLecture.java @@ -47,12 +47,12 @@ public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus @Override public boolean isFree() { - return LectureType.FREE.equals(this.lectureType); + return lectureType.isFree(); } @Override public boolean isRecruiting() { - return LectureRecruitingStatus.RECRUITING.equals(this.lectureRecruitingStatus); + return this.lectureRecruitingStatus.isRecruiting(); } @Override diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java index fd57b79ff..f5fa1fd0c 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureRecruitingStatus.java @@ -15,4 +15,8 @@ public enum LectureRecruitingStatus { public String getName() { return name; } + + public boolean isRecruiting() { + return this.equals(LectureRecruitingStatus.RECRUITING); + } } diff --git a/src/main/java/nextstep/courses/domain/lectures/LectureType.java b/src/main/java/nextstep/courses/domain/lectures/LectureType.java index 4254c5a05..ff11e8fad 100644 --- a/src/main/java/nextstep/courses/domain/lectures/LectureType.java +++ b/src/main/java/nextstep/courses/domain/lectures/LectureType.java @@ -13,4 +13,8 @@ public enum LectureType { public String getName() { return name; } + + public boolean isFree() { + return this.equals(LectureType.FREE); + } }