-
Notifications
You must be signed in to change notification settings - Fork 301
Step4 #772
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
base: cm0x0x0x0
Are you sure you want to change the base?
Step4 #772
Changes from all commits
a5e7074
6567248
4cc11b9
e1db975
1ce727a
06ea9e5
5c95f8e
987d58b
504f5a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nextstep.courses.domain; | ||
|
||
public class Enrollment { | ||
private Member student; | ||
private Session session; | ||
private EnrollmentStatus status; // PENDING, APPROVED, REJECTED | ||
|
||
public Enrollment(Member student, Session session) { | ||
this.student = student; | ||
this.session = session; | ||
this.status = EnrollmentStatus.PENDING; | ||
} | ||
|
||
public void approve() { | ||
if (this.status == EnrollmentStatus.APPROVED) { | ||
throw new IllegalStateException("이미 승인된 수강 신청입니다."); | ||
} | ||
|
||
this.status = EnrollmentStatus.APPROVED; | ||
session.accept(); | ||
} | ||
|
||
public void reject() { | ||
this.status = EnrollmentStatus.REJECTED; | ||
} | ||
|
||
public boolean isApproved() { | ||
return status == EnrollmentStatus.APPROVED; | ||
} | ||
|
||
public Member getStudent() { | ||
return student; | ||
} | ||
|
||
public EnrollmentStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public Session getSession() { | ||
return session; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package nextstep.courses.domain; | ||
|
||
public enum EnrollmentStatus { | ||
PENDING, APPROVED, REJECTED; | ||
} | ||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Enrollments { | ||
private final List<Enrollment> values = new ArrayList<>(); | ||
|
||
public void addEnrollment(Enrollment enrollment) { | ||
values.add(enrollment); | ||
} | ||
|
||
public boolean isEnrolledBy(Member student) { | ||
return values.stream() | ||
.anyMatch(e -> e.getStudent().equals(student)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public Enrollment findByMember(Member student) { | ||
return values.stream() | ||
.filter(e -> e.getStudent().equals(student)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("해당 회원의 수강 신청이 존재하지 않습니다.")); | ||
} | ||
|
||
public List<Enrollment> getValues() { | ||
return Collections.unmodifiableList(values); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Images { | ||
private List<Image> images; | ||
|
||
public Images(List<Image> images) { | ||
this.images = List.copyOf(images); | ||
} | ||
|
||
public List<Image> getImages() { | ||
return Collections.unmodifiableList(images); | ||
} | ||
} | ||
Comment on lines
+6
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.Objects; | ||
|
||
public class Member { | ||
private final Long id; | ||
private final String name; | ||
private final String email; | ||
|
||
public Member(Long id, String name, String email) { | ||
this.id = id; | ||
this.name = name; | ||
this.email = email; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
// Member 식별 비교 (예: Set 사용 시 필요) | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof Member)) return false; | ||
Member member = (Member) o; | ||
return Objects.equals(id, member.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nextstep.courses.domain; | ||
|
||
public enum RecruitmentStatus { | ||
NOT_RECRUITING, | ||
RECRUITING | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
public enum SessionStatus { | ||
PREPARING, | ||
RECRUITING, | ||
ONGOING, | ||
CLOSED | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package nextstep.courses.infrastructure; | ||
|
||
import nextstep.courses.domain.Enrollment; | ||
import nextstep.courses.domain.EnrollmentStatus; | ||
import nextstep.courses.domain.Member; | ||
import nextstep.courses.domain.Session; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class JdbcEnrollmentRepository { | ||
|
||
private final JdbcOperations jdbc; | ||
private final JdbcSessionRepository jdbcSessionRepository; | ||
|
||
public JdbcEnrollmentRepository(JdbcOperations jdbc, JdbcSessionRepository jdbcSessionRepository) { | ||
this.jdbc = jdbc; | ||
this.jdbcSessionRepository = jdbcSessionRepository; | ||
} | ||
|
||
public void save(Long sessionId, Long memberId, EnrollmentStatus status) { | ||
String sql = "INSERT INTO enrollment (session_id, member_id, status) VALUES (?, ?, ?)"; | ||
jdbc.update(sql, sessionId, memberId, status.name()); | ||
} | ||
|
||
public void updateStatus(Long sessionId, Long memberId, EnrollmentStatus status) { | ||
String sql = "UPDATE enrollment SET status = ? WHERE session_id = ? AND member_id = ?"; | ||
jdbc.update(sql, status.name(), sessionId, memberId); | ||
} | ||
|
||
public List<Enrollment> findBySessionId(Long sessionId) { | ||
String sql = | ||
"SELECT e.*, m.id as member_id, m.name, m.email " + | ||
"FROM enrollment e " + | ||
"JOIN member m ON e.member_id = m.id " + | ||
"WHERE e.session_id = ?"; | ||
|
||
|
||
return jdbc.query(sql, (rs, rowNum) -> { | ||
Member member = new Member( | ||
rs.getLong("member_id"), | ||
rs.getString("name"), | ||
rs.getString("email") | ||
); | ||
|
||
Session session = jdbcSessionRepository.findById(sessionId); | ||
Enrollment enrollment = new Enrollment(member, session); | ||
EnrollmentStatus status = EnrollmentStatus.valueOf(rs.getString("status")); | ||
if (status == EnrollmentStatus.APPROVED) { | ||
enrollment.approve(); | ||
} else if (status == EnrollmentStatus.REJECTED) { | ||
enrollment.reject(); | ||
} | ||
Comment on lines
+51
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return enrollment; | ||
}, sessionId); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.