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

[Step4] 수강신청(요구사항 변경) #512

Open
wants to merge 24 commits into
base: danden1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4825879
refact: 피드백 반영
Danden1 Apr 14, 2024
7db46f5
feat: 강의 DB에 저장하고 조회하는 기능 추가
Danden1 Apr 14, 2024
82afb5f
feat: 과정/강의 DB에 저장하고 조회하는 기능 추가
Danden1 Apr 14, 2024
690897c
refact: 피드백 반영
Danden1 Apr 15, 2024
372a860
refact: 불필요한 메서드 제거
Danden1 Apr 15, 2024
977df36
refact: 생성자 변경
Danden1 Apr 16, 2024
cb8eb42
docs: 기능 목록
Danden1 Apr 16, 2024
c81b977
feat: 이미지 여러장 저장 기능 추가
Danden1 Apr 16, 2024
9f9f537
docs: 체크 박스 표시
Danden1 Apr 16, 2024
44ed16a
feat: 강의가 진행 중인 상태에서도 수강신청 가능하도록 하는 기능 구현
Danden1 Apr 17, 2024
b9b560a
feat: 승인된 유저만 수강승인 하는 기능 추가
Danden1 Apr 17, 2024
1c0881a
refact: Free/Pay Session Repository 분리
Danden1 Apr 17, 2024
bad0ea4
conflict 해결
Danden1 Apr 17, 2024
c2213de
fix: conflict 해결
Danden1 Apr 14, 2024
e8faf76
fix: conflict 해결
Danden1 Apr 14, 2024
df34cef
fix: conflict 해결
Danden1 Apr 15, 2024
f01b24a
refact: 불필요한 메서드 제거
Danden1 Apr 15, 2024
747c740
refact: 생성자 변경
Danden1 Apr 16, 2024
8ce5938
conflict 해결
Danden1 Apr 16, 2024
fe7d691
fix: conflict 해결
Danden1 Apr 16, 2024
34b4074
docs: 체크 박스 표시
Danden1 Apr 16, 2024
46b8d46
fix: conflict 해결
Danden1 Apr 17, 2024
bd50aa3
feat: 승인된 유저만 수강승인 하는 기능 추가
Danden1 Apr 17, 2024
7da41fc
refact: Free/Pay Session Repository 분리
Danden1 Apr 17, 2024
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@
- [x] 이미지 타입은 gif, jpg, jpeg, png, svg만 허용한다.
- [x] 이미지의 width 는 300픽셀, height는 200픽셀 이상이어야 하며, width : height 은 3:2 여야 한다.

## Step4

### 기능 목록
- [x] 강의는 하나 이상 강의 이미지를 가질 수 있다.
- [x] 강의가 진행 중인 상태에서도 수강신청이 가능하다.
- 강의 진행 상태(준비중, 진행중, 종료)와 모집 상태(비모집중, 모집중)로 상태 분리 필요.
- [x] 강사는 수강신청한 사람 중, 선발된 인원에 대해서만 수강 승인이 가능해야 한다.
- [x] 강사는 수강신청한 사람 중, 선발되지 않은 사람은 수강 취소할 수 있다.
## 온라인 코드 리뷰 과정
* [텍스트와 이미지로 살펴보는 온라인 코드 리뷰 과정](https://github.com/next-step/nextstep-docs/tree/master/codereview)
13 changes: 9 additions & 4 deletions src/main/java/nextstep/courses/domain/FreeSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;

import java.util.List;
import java.util.Set;

public class FreeSession extends Session {
public FreeSession(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate) {
super(id, sessionImage, sessionStatus, sessionDate);
public FreeSession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate) {
super(id, sessionImage, recruitStatus, sessionDate);
}

public FreeSession(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate, Set<NsUser> students) {
super(id, sessionImage, sessionStatus, sessionDate, students);
public FreeSession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate, Set<NsUser> students) {
super(id, sessionImage, recruitStatus, sessionDate, students);
}

public FreeSession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionProgressStatus sessionProgressStatus, SessionDate sessionDate, Set<NsUser> students, Set<NsUser> approveStudents) {
super(id, sessionImage, recruitStatus, sessionProgressStatus, sessionDate, students, approveStudents);
}


Expand Down
11 changes: 11 additions & 0 deletions src/main/java/nextstep/courses/domain/FreeSessionRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nextstep.courses.domain;

import java.util.Optional;

public interface FreeSessionRepository {
Sessions findByCourseId(Long courseId);

Optional<FreeSession> findBySessionId(Long sessionId);

void saveSession(FreeSession session, Long courseId);
}
17 changes: 13 additions & 4 deletions src/main/java/nextstep/courses/domain/PaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;

import java.util.List;
import java.util.Set;

public class PaySession extends Session {

private final int maximumStudents;
private final long amount;

public PaySession(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate, int maximumStudents, long amount) {
super(id, sessionImage, sessionStatus, sessionDate);
public PaySession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate, int maximumStudents, long amount) {
super(id, sessionImage, recruitStatus, sessionDate);
assertValidMaximumStudents(maximumStudents);
assertValidAmount(amount);
this.amount = amount;
this.maximumStudents = maximumStudents;
}

public PaySession(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate, Set<NsUser> students, int maximumStudents, long amount) {
super(id, sessionImage, sessionStatus, sessionDate, students);
public PaySession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate, Set<NsUser> students, int maximumStudents, long amount) {
super(id, sessionImage, recruitStatus, sessionDate, students);
assertValidMaximumStudents(maximumStudents);
assertValidAmount(amount);
this.amount = amount;
this.maximumStudents = maximumStudents;
}

public PaySession(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionProgressStatus sessionProgressStatus, SessionDate sessionDate, Set<NsUser> students, Set<NsUser> approveStudents, int maximumStudents, long amount) {
super(id, sessionImage, recruitStatus, sessionProgressStatus, sessionDate, students, approveStudents);
assertValidMaximumStudents(maximumStudents);
assertValidAmount(amount);
this.amount = amount;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/nextstep/courses/domain/PaySessionRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nextstep.courses.domain;

import java.util.Optional;

public interface PaySessionRepository {
Sessions findByCourseId(Long courseId);

Optional<PaySession> findBySessionId(Long sessionId);

void saveSession(PaySession session, Long courseId);
}
17 changes: 17 additions & 0 deletions src/main/java/nextstep/courses/domain/RecruitStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package nextstep.courses.domain;

public enum RecruitStatus {

RECRUIT,
NOT_RECRUIT;

public static RecruitStatus findByName(String name) {
return RecruitStatus.valueOf(name.toUpperCase());
}

public boolean isRecruit() {
return this.equals(RECRUIT);
}


}
59 changes: 45 additions & 14 deletions src/main/java/nextstep/courses/domain/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;

import java.time.LocalDate;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.*;

public abstract class Session {

private final Long id;
private final SessionImage sessionImage;
private SessionStatus sessionStatus;
private final List<SessionImage> sessionImage;
private RecruitStatus recruitStatus;
private SessionProgressStatus sessionProgressStatus;
private final Set<NsUser> students;
private final Set<NsUser> approveStudents;
Comment on lines 15 to +16
Copy link
Member

Choose a reason for hiding this comment

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

선발 과정이후 students, approveStudents 두 필드의 요소는 같을 것으로 예상됩니다.
두 가지를 모두 가지고 있을 필요가 있을까요?

Comment on lines +12 to +16
Copy link
Member

Choose a reason for hiding this comment

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

규칙 7: 3개 이상의 인스턴스 변수를 가진 클래스를 쓰지 않는다.
인스턴스 변수의 수를 줄이기 위해 도전한다.

'수강신청'과 관련된 필드만 모아서 객체를 도출하면 어떨까요?

private final SessionDate sessionDate;

public Session(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate) {
this(id, sessionImage,sessionStatus, sessionDate, new HashSet<>());

public Session(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate) {
this(id, sessionImage, recruitStatus, sessionDate, new HashSet<>());
}

public Session(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionProgressStatus sessionProgressStatus, SessionDate sessionDate) {
this(id, sessionImage, recruitStatus, sessionProgressStatus, sessionDate, new HashSet<>(), new HashSet<>());
}

public Session(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionDate sessionDate, Set<NsUser> students) {
this(id, sessionImage, recruitStatus, SessionProgressStatus.PREPARE, sessionDate, students, new HashSet<>());
}

public Session(Long id, SessionImage sessionImage, SessionStatus sessionStatus, SessionDate sessionDate, Set<NsUser> students) {
public Session(Long id, List<SessionImage> sessionImage, RecruitStatus recruitStatus, SessionProgressStatus sessionProgressStatus, SessionDate sessionDate, Set<NsUser> students, Set<NsUser> approveStudents) {
this.id = id;
this.sessionImage = sessionImage;
this.sessionStatus = sessionStatus;
this.recruitStatus = recruitStatus;
this.sessionProgressStatus = sessionProgressStatus;
this.sessionDate = sessionDate;
this.students = students;
this.approveStudents = approveStudents;

}

public final void enrollmentUser(NsUser user, Payment payment) {
Expand All @@ -37,14 +48,22 @@ public final void enrollmentUser(NsUser user, Payment payment) {
students.add(user);
}

public final void removeNotApproveUser() {
students.removeIf(student -> !approveStudents.contains(student));
}
Comment on lines +51 to +53
Copy link
Member

Choose a reason for hiding this comment

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

수강을 취소하더라도 신청 내역을 존재할 수 있을 것 같은데요
취소된 수강생을 삭제하기 보다 '수강생' 이라는 도메인을 도출해서 승인/선발 이라는 상태를 추가하면 어떨까요?


public final void addApproveStudent(NsUser nsUser) {
approveStudents.add(nsUser);
}

private void assertNotDuplicateStudents(NsUser user) {
if (students.contains(user)) {
throw new NotRecruitException();
}
}

private void assertRecruit() {
if (!sessionStatus.isRecruit()) {
if (!recruitStatus.isRecruit()) {
throw new NotRecruitException();
}
}
Expand All @@ -53,22 +72,34 @@ public Set<NsUser> getStudents() {
return new HashSet<>(students);
}

public Set<NsUser> getApproveStudents() {
return new HashSet<>(approveStudents);
}

public Long getId() {
return id;
}

public SessionImage getSessionImage() {
public List<SessionImage> getSessionImage() {
return sessionImage;
}

public SessionStatus getSessionStatus() {
return sessionStatus;
public RecruitStatus getRecruitStatus() {
return recruitStatus;
}

public SessionProgressStatus getSessionProgressStatus() {
return sessionProgressStatus;
}

public SessionDate getSessionDate() {
return sessionDate;
}

public void changeProgressStatus(SessionProgressStatus sessionProgressStatus) {
this.sessionProgressStatus = sessionProgressStatus;
}


abstract protected void assertSatisfiedCondition(NsUser user, Payment payment);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/nextstep/courses/domain/SessionProgressStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package nextstep.courses.domain;

public enum SessionProgressStatus {
PREPARE,
RUN,
END;

public static SessionProgressStatus findByName(String name) {
return SessionProgressStatus.valueOf(name.toUpperCase());
}
}
9 changes: 0 additions & 9 deletions src/main/java/nextstep/courses/domain/SessionRepository.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/nextstep/courses/domain/SessionStatus.java

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/java/nextstep/courses/domain/Sessions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public Sessions() {
this.sessions = new HashSet<>();
}

public static Sessions concatSessions(Sessions sessions1, Sessions sessions2) {
Set<Session> concatResult = new HashSet<>(sessions1.sessions);
concatResult.addAll(new HashSet<>(sessions2.sessions));

return new Sessions(concatResult);
}

public void addSession(Session session) {
String errorMessage = "이미 등록된 강의입니다.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
public class JdbcCourseRepository implements CourseRepository {
private JdbcOperations jdbcTemplate;

private final SessionRepository sessionRepository;
private final FreeSessionRepository freeSessionRepository;
private final PaySessionRepository paySessionRepository;

public JdbcCourseRepository(JdbcOperations jdbcTemplate, SessionRepository sessionRepository) {
public JdbcCourseRepository(JdbcOperations jdbcTemplate, FreeSessionRepository freeSessionRepository, PaySessionRepository paySessionRepository) {
this.jdbcTemplate = jdbcTemplate;
this.sessionRepository = sessionRepository;
this.freeSessionRepository = freeSessionRepository;
this.paySessionRepository = paySessionRepository;
}

@Override
Expand All @@ -38,8 +40,15 @@ public int save(Course course) {
return ps;
}, keyHolder);

course.getSessions().getSessions().forEach(session ->
sessionRepository.saveSession(session, (long) keyHolder.getKey())
course.getSessions().getSessions().forEach(session -> {
if (session instanceof PaySession) {
paySessionRepository.saveSession((PaySession) session, (long) keyHolder.getKey());
}

if (session instanceof FreeSession) {
freeSessionRepository.saveSession((FreeSession) session, (long) keyHolder.getKey());
}
}
);

return result;
Expand All @@ -48,7 +57,7 @@ public int save(Course course) {
@Override
public Course findById(Long id) {
String sql = "select id, title, creator_id, created_at, updated_at from course where id = ?";
Sessions sessions = sessionRepository.findByCourseId(id);
Sessions sessions = Sessions.concatSessions(freeSessionRepository.findByCourseId(id), paySessionRepository.findByCourseId(id));

RowMapper<Course> rowMapper = (rs, rowNum) -> new Course(
rs.getLong(1),
Expand Down
Loading