-
Notifications
You must be signed in to change notification settings - Fork 247
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
3단계 - 수강신청(DB 적용) #532
Open
sm9171
wants to merge
27
commits into
next-step:sm9171
Choose a base branch
from
sm9171:step3
base: sm9171
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
3단계 - 수강신청(DB 적용) #532
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6546c05
docs: 2단계 요구사항
sm9171 0fee513
feat: 과정은 기수를 가지고 생성된다 test 및 기능 구현
sm9171 a2616d3
test: 과정은 여러 개의 강의를 가지고 생성된다. fail test
sm9171 9af8b2e
feat: 강의 도메인 생성
sm9171 d06b825
feat: image 도메인 생성
sm9171 e2096c1
refactor: ImageSize 래퍼클래스 생성 및 테스트 성공
sm9171 19e2c38
refactor: ImageHeight, ImageWidth 래퍼클래스 생성 및 테스트 성공
sm9171 0ad242c
refactor: image, session 도메인 분리
sm9171 d8a8613
Merge remote-tracking branch 'origin/step2' into step2
sm9171 c780198
feat: Seccions 일급 컬랙션 생성
sm9171 d192c42
feat: 무료강의, 유료강의 타입 생성, 테스트 2개 성공
sm9171 99445e9
feat: '유료 강의는 수강생이 결제한 금액과 수강료가 일치할 때 수강 신청이 가능' 테스트 성공
sm9171 6b42b1e
feat: '강의 수강신청은 강의 상태가 모집중일 때만 가능' 테스트 성공
sm9171 0896fa9
refactor: 사용안하는 테스트 제거
sm9171 29bd931
Merge remote-tracking branch 'refs/remotes/javajigi/sm9171' into step2
sm9171 25a6931
refactor: imageWidth, imageHeight 필드명 변경
sm9171 8ca928b
refactor: EndedAt, StartedAt 래핑클래스로 분리
sm9171 d62232c
refactor: sessionType description 필드 추가
sm9171 409d49c
refactor: Charge,Enrollment,SessionInfo 클래스 분리
sm9171 785c218
test: payment 완료 테스트 성공
sm9171 91cfaef
test: 결제금액과 강의금액이 다르면 결제가 되지 않는다
sm9171 fdf3e6d
refactor: Payment 생성자에 ChargeStatus 인수값 추가
sm9171 d58ad38
feat: sessionRepository 생성
sm9171 00ce7b2
test: imageRepositoryTest 완료
sm9171 5bd6404
test: sessionRepositoryTest 수정
sm9171 26946f9
Merge remote-tracking branch 'javajigy/sm9171' into step3
sm9171 7eef947
test: sessionRepositoryTest 완료
sm9171 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
package nextstep.image.domain; | ||
|
||
public class Image { | ||
private Long id; | ||
private Long sessionId; | ||
private String url; | ||
private ImageType type; | ||
private ImageShape shape; | ||
private Integer size; | ||
|
||
public Image(final ImageType type, final ImageShape shape, final Integer size) { | ||
public Image(final long id, final long sessionId, final String url, final ImageType type, final ImageShape shape, final Integer size) { | ||
this.id = id; | ||
this.sessionId = sessionId; | ||
this.url = url; | ||
this.type = type; | ||
this.shape = shape; | ||
this.size = size; | ||
} | ||
|
||
public Long getSessionId() { | ||
return sessionId; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getType() { | ||
return type.name(); | ||
} | ||
|
||
public int getImageWidth() { | ||
return shape.getWidth(); | ||
} | ||
|
||
public int getImageHeight() { | ||
return shape.getHeight(); | ||
} | ||
|
||
public int getSize() { | ||
return size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nextstep.image.domain; | ||
|
||
public interface ImageRepository { | ||
int save(final Image image); | ||
Image findById(final Long id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/nextstep/image/infrastructure/JdbcImageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nextstep.image.infrastructure; | ||
|
||
import nextstep.courses.domain.Course; | ||
import nextstep.image.domain.*; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
|
||
public class JdbcImageRepository implements ImageRepository { | ||
private JdbcOperations jdbcTemplate; | ||
|
||
public JdbcImageRepository(JdbcOperations jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public int save(Image image) { | ||
String sql = "insert into image (session_id, url, image_type, image_height, image_width, size) values(?, ?, ?,?, ?, ?)"; | ||
return jdbcTemplate.update(sql, image.getSessionId(), image.getUrl(), image.getType(), image.getImageHeight(), image.getImageWidth(), image.getSize()); | ||
} | ||
|
||
@Override | ||
public Image findById(Long id) { | ||
String sql = "select id, session_id, url, image_type, image_width, image_height, size from image where id = ?"; | ||
RowMapper<Image> rowMapper = (rs, rowNum) -> new Image( | ||
rs.getLong(1), | ||
rs.getLong(2), | ||
rs.getString(3), | ||
ImageType.valueOf(rs.getString(4)), | ||
new ImageShape(rs.getInt(5), rs.getInt(6)), | ||
rs.getInt(7)); | ||
return jdbcTemplate.queryForObject(sql, rowMapper, id); | ||
} | ||
|
||
private LocalDateTime toLocalDateTime(Timestamp timestamp) { | ||
if (timestamp == null) { | ||
return null; | ||
} | ||
return timestamp.toLocalDateTime(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,59 @@ | |
|
||
public class Session { | ||
|
||
private final SessionInfo sessionInfo; | ||
private final Charge charge; | ||
private final Long id; | ||
private final SessionInfo sessionInfo; | ||
private final Charge charge; | ||
private final Enrollment enrollment; | ||
private final SessionDate sessionDate; | ||
private final SessionDate sessionDate; | ||
|
||
public Session(String title, Long creatorId, | ||
ChargeStatus chargeStatus, int price, | ||
int capacity, SessionStatus sessionStatus, | ||
LocalDate startDate, LocalDate endDate) { | ||
this(new SessionInfo(title, creatorId, null), | ||
public Session(final Long id, String title, Long creatorId, | ||
ChargeStatus chargeStatus, int price, | ||
int capacity, SessionStatus sessionStatus, | ||
LocalDate startDate, LocalDate endDate) { | ||
this(id, new SessionInfo(title, creatorId, null), | ||
new Charge(chargeStatus, price), | ||
new Enrollment(sessionStatus, capacity), | ||
new SessionDate(new StartedAt(startDate), new EndedAt(endDate))); | ||
} | ||
|
||
public Session(SessionInfo sessionInfo, Charge charge, Enrollment enrollment, SessionDate sessionDate) { | ||
public Session(final Long id, SessionInfo sessionInfo, Charge charge, Enrollment enrollment, SessionDate sessionDate) { | ||
this.id = id; | ||
this.sessionInfo = sessionInfo; | ||
this.charge = charge; | ||
this.enrollment = enrollment; | ||
this.sessionDate = sessionDate; | ||
} | ||
|
||
public String getTitle() { | ||
return sessionInfo.getTitle(); | ||
} | ||
|
||
public Long getCreatorId() { | ||
return sessionInfo.getCreatorId(); | ||
} | ||
|
||
public String getChargeStatus() { | ||
return charge.getStatus().name(); | ||
} | ||
|
||
public int getPrice() { | ||
return charge.getPrice(); | ||
} | ||
|
||
public LocalDate getStartedAt() { | ||
return sessionDate.getStartedAt(); | ||
} | ||
|
||
public LocalDate getEndedAt() { | ||
return sessionDate.getEndedAt(); | ||
} | ||
|
||
public String getSessionStatus() { | ||
return enrollment.getSessionStatus().name(); | ||
} | ||
|
||
public int getCapacity() { | ||
return enrollment.getCapacity(); | ||
} | ||
} | ||
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. Session과 NsUser의 관계는 어떻게 될까?
위와 같은 관계이므로 Session : NsUser는 m : n 관계이다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/nextstep/sessions/domain/SessionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nextstep.sessions.domain; | ||
|
||
public interface SessionRepository { | ||
int save(final Session session); | ||
Session findById(Long id); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/nextstep/sessions/infrastructure/JdbcSessionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package nextstep.sessions.infrastructure; | ||
|
||
import nextstep.sessions.domain.*; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDate; | ||
|
||
public class JdbcSessionRepository implements SessionRepository { | ||
private JdbcOperations jdbcTemplate; | ||
|
||
public JdbcSessionRepository(JdbcOperations jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public int save(Session session) { | ||
String sql = "insert into session (title, creator_id, charge_status, price, session_status, capacity, started_at, ended_at) values(?, ?, ?,?, ?, ?, ?, ?)"; | ||
return jdbcTemplate.update(sql, session.getTitle(), session.getCreatorId(),session.getChargeStatus(), session.getPrice(), session.getSessionStatus(), session.getCapacity(), session.getStartedAt(), session.getEndedAt()); | ||
} | ||
|
||
@Override | ||
public Session findById(Long id) { | ||
String sql = "select session.id, session.title, session.creator_id, session.charge_status, session.price, session.capacity, session.session_status,session.started_at, session.ended_at " + | ||
"from session where id = ?"; | ||
|
||
RowMapper<Session> rowMapper = (rs, rowNum) -> new Session( | ||
rs.getLong(1), | ||
rs.getString(2), | ||
rs.getLong(3), | ||
ChargeStatus.valueOf(rs.getString(4)), | ||
rs.getInt(5), | ||
rs.getInt(6), | ||
SessionStatus.valueOf(rs.getString(7)), | ||
toLocalDate(rs.getTimestamp(8)), | ||
toLocalDate(rs.getTimestamp(9)) | ||
); | ||
|
||
return jdbcTemplate.queryForObject(sql, rowMapper, id); | ||
} | ||
|
||
private LocalDate toLocalDate(Timestamp timestamp) { | ||
if (timestamp == null) { | ||
return null; | ||
} | ||
return timestamp.toLocalDateTime().toLocalDate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package nextstep.image.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; | ||
|
||
public class ImageTest { | ||
@DisplayName("이미지 크기는 1MB 이하여야 한다.") | ||
@Test | ||
public void imageSizeLessThan1MB() { | ||
//given & when & then | ||
assertThatExceptionOfType(IllegalArgumentException.class) | ||
.isThrownBy(() -> { | ||
new ImageSize(1000000); | ||
}).withMessageMatching("이미지 크기는 1메가 바이트를 넘을 수 없습니다."); | ||
} | ||
|
||
@DisplayName("이미지의 width는 300픽셀 이상이어야 한다.") | ||
@Test | ||
public void imageWidthOver300Pixel() { | ||
//given | ||
assertThatExceptionOfType(IllegalArgumentException.class) | ||
.isThrownBy(() -> { | ||
new ImageWidth(200); | ||
}).withMessageMatching("이미지 너비는 300px보다 커야 합니다."); | ||
} | ||
|
||
@DisplayName("이미지의 height는 200픽셀 이상이어야 한다.") | ||
@Test | ||
public void imageHeightOver200Pixel() { | ||
//given | ||
assertThatExceptionOfType(IllegalArgumentException.class) | ||
.isThrownBy(() -> { | ||
new ImageHeight(100); | ||
}).withMessageMatching("이미지 높이는 200px보다 커야 합니다."); | ||
} | ||
|
||
@DisplayName("이미지의 width와 height의 비율은 3:2여야 한다.") | ||
@Test | ||
public void widthAndHeightRatioEqual3To2() { | ||
//given | ||
assertThatExceptionOfType(IllegalArgumentException.class) | ||
.isThrownBy(() -> { | ||
new ImageShape(new ImageWidth(400), new ImageHeight(400)); | ||
}).withMessageMatching("가로 세로 비율은 3:2이어야 합니다."); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍