Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

재성님 안녕하세요! lms 마지막 요구사항 변경 부분 진행해봤습니다! #396

Open
wants to merge 12 commits into
base: jhd7130
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions STEP2.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@
* [x] 강의 테이블 추가
* [x] 강의 저장 조회 테스트

## Step4 변경 요구사항
* [x] 강의가 하나 이상의 커버 이미지를 가질 수 있다.
* [x] 커버 이미지 일급 컬렉션 만들기
* [x] 강의 진행 중 상태일 때도 수강 신청이 가능해야한다.
* [x] 강의 상태를 강의 진행 상태, 모집 상태로 분리
* [x] 강의 진행 상태
* [x] 모집 상태
* [x] 강의 진행 상태가 '진행 중'일 경우도 수강신청 가능
* [x] 선발된 인원만 수강 신청이 가능하다.
* [x] 선발된 인원에 대해서만 수강 승인이 가능하다.
* [x] 선발되지 않은 인원은 수강 취소를 할 수 있어야한다. -> 제 코드에서 선발되지 않은 인원은 아예 수강신청이 불가능하기 때문에 추가하지 않아도 될 것 같습니다.

### Step4 프로그래밍 요구사항
* 리팩터링할 때 컴파일 에러와 기존의 단위 테스트의 실패를 최소화하면서 점진적인 리팩터링이 가능하도록 한다.
* DB 테이블에 데이터가 존재한다는 가정하에 리팩터링해야 한다.
* 즉, 기존에 쌓인 데이터를 제거하지 않은 상태로 리팩터링 해야 한다.
7 changes: 3 additions & 4 deletions src/main/java/nextstep/courses/BaseTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/nextstep/courses/domain/Students.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("수강인원이 가득찼습니다.");
}
}
Expand All @@ -37,4 +37,7 @@ public Integer size() {
return this.students.size();
}

public boolean contain(NsUser nsUser) {
return this.students.contains(nsUser);
}
}
13 changes: 4 additions & 9 deletions src/main/java/nextstep/courses/domain/coverimage/CoverImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface CoverImageRepository {

int save(CoverImage coverImage);

void saveAll(CoverImages coverImages);
CoverImage findById(Long id);

}
35 changes: 35 additions & 0 deletions src/main/java/nextstep/courses/domain/coverimage/CoverImages.java
Original file line number Diff line number Diff line change
@@ -0,0 +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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


private Set<CoverImage> coverImages = new HashSet<>();

public CoverImages() {
}

public CoverImages(Set<CoverImage> 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<CoverImage> coverImages() {
return new ArrayList<>(coverImages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nextstep.courses.domain.coverimage;

import nextstep.courses.domain.lectures.LectureEntity;

public interface LectureCoverImageMappingRepository {
void save(LectureEntity lecture, CoverImages coverImages);
}
75 changes: 48 additions & 27 deletions src/main/java/nextstep/courses/domain/lectures/FreeLecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,100 @@
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 LectureRecruitingStatus lectureRecruitingStatus;
private final RegistrationPeriod registrationPeriod;
private final Students students = Students.defaultOf(); // 강의 기본정보와는 다름

public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus,
RegistrationPeriod registrationPeriod) {
super();
this.id = id;
this.title = title;
this.coverImage = coverImage;
this.lectureStatus = lectureStatus;
this.registrationPeriod = registrationPeriod;
}
public FreeLecture(Long id, String title, CoverImage coverImage, LectureStatus lectureStatus,
// primary constructor
public FreeLecture(Long id, String title, CoverImages coverImages,
LectureRecruitingStatus lectureRecruitingStatus, LectureStatus lectureStatus,
RegistrationPeriod registrationPeriod, LocalDateTime createdAt, LocalDateTime updatedAt) {
super(createdAt, updatedAt);
this.id = id;
this.title = title;
this.coverImage = coverImage;
this.coverImages.addAll(coverImages);
this.lectureStatus = lectureStatus;
this.lectureRecruitingStatus = lectureRecruitingStatus;
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();

public FreeLecture(Long id, String title, CoverImages coverImages,
LectureRecruitingStatus lectureRecruitingStatus,
RegistrationPeriod registrationPeriod) {
this(id, title, coverImages, lectureRecruitingStatus, LectureStatus.YET, registrationPeriod,
LocalDateTime.now(), null);
}

public FreeLecture(Long id, String title, CoverImages coverImages, LectureStatus lectureStatus,
LectureRecruitingStatus lectureRecruitingStatus,
RegistrationPeriod registrationPeriod) {
this(id, title, coverImages, lectureRecruitingStatus, lectureStatus, registrationPeriod,
LocalDateTime.now(), null);
}

@Override
public boolean isFree() {
return LectureType.FREE.equals(this.lectureType);
return lectureType.isFree();
}

@Override
public boolean recruiting() {
return LectureStatus.RECRUITING.equals(this.lectureStatus);
public boolean isRecruiting() {
return this.lectureRecruitingStatus.isRecruiting();
}

@Override
public void enrollment(NsUser nsUser) {
if (recruiting()) {
public void canEnrollment(NsUser nsUser, Students selectedStudents) {
if (!isRecruiting()) {
throw new IllegalArgumentException("모집중이지 않습니다.");
}
students.add(nsUser);

if (selectedStudents.contain(nsUser)) {
throw new IllegalArgumentException("선발된 인원만 수강신청이 가능합니다.");
}
}

@Override
public void enrollment(NsUser nsUser, Students selectedStudents) {
this.canEnrollment(nsUser, selectedStudents);
this.students.add(nsUser);
}

@Override
public Lecture recruitingStart() {
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.coverImage, LectureStatus.RECRUITING, this.registrationPeriod);
return new FreeLecture(this.id, this.title, this.coverImages, LectureStatus.DOING,
LectureRecruitingStatus.RECRUITING, this.registrationPeriod);
}

@Override
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.lectureRecruitingStatus
, this.registrationPeriod
, null
, null
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/nextstep/courses/domain/lectures/Lecture.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package nextstep.courses.domain.lectures;

import nextstep.courses.domain.Students;
import nextstep.users.domain.NsUser;

public interface Lecture {

boolean isFree();
boolean recruiting();
void enrollment(NsUser nsUser);
boolean isRecruiting();
void canEnrollment(NsUser nsUser, Students selectedStudents);
void enrollment(NsUser nsUser, Students selectedStudents);
Lecture recruitingStart();
Lecture start();
Integer numberOfStudent();
}
33 changes: 19 additions & 14 deletions src/main/java/nextstep/courses/domain/lectures/LectureEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,67 @@

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 LectureRecruitingStatus lectureRecruitingStatus;
private final RegistrationPeriod registrationPeriod;
private final Price price;
private final Integer limitStudentCount;

public LectureEntity(Long id, String title, CoverImage coverImage, LectureType lectureType,
LectureStatus lectureStatus, RegistrationPeriod registrationPeriod, Price price,
public LectureEntity(Long id, String title, CoverImages coverImages, LectureType lectureType,
LectureStatus lectureStatus,LectureRecruitingStatus lectureRecruitingStatus, 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.lectureRecruitingStatus = lectureRecruitingStatus;
this.registrationPeriod = registrationPeriod;
this.price = price;
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 LectureRecruitingStatus lectureRecruitingStatus() {
return lectureRecruitingStatus;
}
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;
}
}
Loading