Skip to content
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
23 changes: 23 additions & 0 deletions STEP3README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 학습 관리 시스템(Learning Management System)

## step3 요구사항

1. [x] 앞단계에서 구현한 도메인 모델 DB와 매핑하고 데이터 저장
2.
2. 테이블 설계하고 객체매핑
2. [x] Payments는 테이블 매핑 미고려

## 관련 클래스

1. DB 테이블 resources/schema.sql
2. jdbcCourseRepository
3. CourseRepositoryTest


## 주요 피드백
1. 숫자로 순서를 써서 하는건 실수 및 어려운 문제가 있음
-> NamedParameterJdbcTemplate사용해보기


TODO
findSessions 메서드 테스트 코드 추가하기
20 changes: 0 additions & 20 deletions src/main/java/nextstep/courses/Exception/ResponseType.java

This file was deleted.

23 changes: 18 additions & 5 deletions src/main/java/nextstep/courses/domain/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@ public class Course {
private Long creatorId;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private List<Session> sessionList;
private List<Session> sessions;
Copy link
Member

Choose a reason for hiding this comment

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

연관관계를 가지도록 매핑하셨네요
Course를 조회하는 시점에 같이 조회해야하지 않을까요?
따로 Session 리스트를 주입하는 부분을 찾을 수 없는 것 같아서요

Copy link
Author

Choose a reason for hiding this comment

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

@nooose
안녕하세요 조회시 getSessions 메서드를 통해 같이 조회하도록 수정했습니다.


public Course() {
}

public Course(String title, Long creatorId) {
this(0L, title, creatorId, LocalDateTime.now(), null);
this(0L, title, creatorId, LocalDateTime.now(), null,1);
}
public Course(Long id, String title, Long creatorId, List<Session> sessions) {
this(id, title, creatorId, LocalDateTime.now(), null,1, sessions);
}

public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, int classNumber) {
this(id, title, creatorId, createdAt, updatedAt, classNumber, new ArrayList<>());
}

public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt) {
public Course(Long id, String title, Long creatorId, LocalDateTime createdAt, LocalDateTime updatedAt, int classNumber, List<Session> sessions) {
this.id = id;
this.title = title;
this.creatorId = creatorId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
sessionList = new ArrayList<>();
classNumber = count.incrementAndGet();
this.classNumber = classNumber;
this.sessions = sessions;
}

public String getTitle() {
Expand All @@ -45,14 +52,20 @@ public LocalDateTime getCreatedAt() {
return createdAt;
}

public int getClassNumber() {
return classNumber;
}

@Override
public String toString() {
return "Course{" +
"id=" + id +
", classNumber=" + classNumber +
", title='" + title + '\'' +
", creatorId=" + creatorId +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", sessions=" + sessions +
'}';
}
}
10 changes: 10 additions & 0 deletions src/main/java/nextstep/courses/domain/CourseType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nextstep.courses.domain;

public enum CourseType {
PREMIUM, BASIC;

public static CourseType getCourseType(String courseType) {
return CourseType.valueOf(courseType.toUpperCase());
}
}

30 changes: 20 additions & 10 deletions src/main/java/nextstep/courses/domain/PricingType.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package nextstep.courses.domain;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.exception.CustomException;
import nextstep.payments.domain.Payment;

public class PricingType {

private final int sessionAmount;
private boolean isPremium;
private final CourseType courseType;

public PricingType(boolean isPremium, int sessionAmount) {
validate(isPremium,sessionAmount);
this.isPremium = isPremium;


public PricingType(CourseType courseType, int sessionAmount) {
this.courseType = courseType;
this.sessionAmount = sessionAmount;
validate(sessionAmount);
}

private void validate(boolean isPremium, int sessionAmount) {
if (isPremium && sessionAmount <= 0) {
private void validate(int sessionAmount) {
if (isPremium() && sessionAmount <= 0) {
throw CustomException.NOT_ALLOWED_PREMIUM_AMOUNT;
}
if (!isPremium && sessionAmount > 0) {
if (!isPremium() && sessionAmount > 0) {
throw CustomException.NOT_ALLOWED_FREE_AMOUNT;
}
}

public boolean isPremium() {
return isPremium;
return courseType.equals(CourseType.PREMIUM);
}

public void validateAmount(Payment payment) {
if (isPremium && !payment.matchingAmount(sessionAmount)) {
if (isPremium() && !payment.matchingAmount(sessionAmount)) {
throw CustomException.NOT_MATCHING_SESSION_AMOUNT;
}
}

public int getSessionAmount() {
return sessionAmount;
}

public CourseType getCourseType() {
return courseType;
}
}
59 changes: 52 additions & 7 deletions src/main/java/nextstep/courses/domain/Session.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
package nextstep.courses.domain;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.domain.sessionimage.SessionImage;
import nextstep.courses.exception.CustomException;
import nextstep.courses.domain.image.SessionImage;
import nextstep.payments.domain.Payment;
import nextstep.users.domain.NsUser;

import java.util.ArrayList;
import java.util.List;

public class Session {
private List<NsUser> students;
private Long id;
private List<Long> students;
private PricingType pricingType;
private SessionState state;
private SessionImage image;
private int maxStudentCount;
private SessionDate date;
private Long courseId;



public Session(PricingType pricingType, int maxStudentCount, SessionState state, SessionDate date
, SessionImage image) {
this(0L, new ArrayList<Long>(),pricingType,state,image,maxStudentCount,date,0L );
}

public Session(List<Long> students, PricingType pricingType, SessionState state, SessionImage image, int maxStudentCount, SessionDate date) {
this.id = 0L;
this.students = students;
this.pricingType = pricingType;
this.students = new ArrayList<>();
this.maxStudentCount = maxStudentCount;
this.state = state;
this.date = date;
this.image = image;
this.maxStudentCount = maxStudentCount;
this.date = date;
this.courseId = 0L;
}

public Session(Long id, List<Long> students, PricingType pricingType, SessionState state, SessionImage image, int maxStudentCount, SessionDate date, Long courseId) {
this.id = id;
this.students = students;
this.pricingType = pricingType;
this.state = state;
this.image = image;
this.maxStudentCount = maxStudentCount;
this.date = date;
this.courseId = courseId;
}

public void requestSession(Payment payment) {
Expand All @@ -47,4 +66,30 @@ private void validateSessionState() {

}

public List<Long> getStudents() {
return students;
}

public PricingType getPricingType() {
return pricingType;
}

public SessionState getState() {
return state;
}

public SessionImage getImage() {
return image;
}

public int getMaxStudentCount() {
return maxStudentCount;
}

public SessionDate getDate() {
return date;
}
public Long getCourseId() {
return courseId;
}
}
10 changes: 9 additions & 1 deletion src/main/java/nextstep/courses/domain/SessionDate.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.courses.domain;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.exception.CustomException;

import java.time.LocalDateTime;

Expand All @@ -15,4 +15,12 @@ public SessionDate(LocalDateTime startDate, LocalDateTime endDate) {
this.startDate = startDate;
this.endDate = endDate;
}

public LocalDateTime getStartDate() {
return startDate;
}

public LocalDateTime getEndDate() {
return endDate;
}
}
10 changes: 2 additions & 8 deletions src/main/java/nextstep/courses/domain/SessionState.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package nextstep.courses.domain;

public enum SessionState {
READY("READY"), START("START"), END("END");
READY, START, END;


public String state;

SessionState(String state) {
this.state = state;
}

public boolean isRequestSession() {
return START.state.equals(this.state);
return this == START;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.courses.domain.sessionimage;
package nextstep.courses.domain.image;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.exception.CustomException;

public class ImageCapacity {

Expand All @@ -9,6 +9,7 @@ public class ImageCapacity {

private final int imageSize;


public ImageCapacity(int imageSize) {
validateSize(imageSize);
this.imageSize = imageSize;
Expand All @@ -19,4 +20,9 @@ private void validateSize(int imageSize) {
throw CustomException.OVER_MAX_IMAGE_CAPACITY;
}
}

public int getImageSize() {
return imageSize;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.courses.domain.sessionimage;
package nextstep.courses.domain.image;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.exception.CustomException;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand Down Expand Up @@ -29,4 +29,13 @@ private void validateSize(int width, int height) {
throw CustomException.IMAGE_PERCENT_ERROR;
}
}


public int getWidth() {
return width;
}

public int getHeight() {
return height;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nextstep.courses.domain.sessionimage;
package nextstep.courses.domain.image;

import nextstep.courses.Exception.CustomException;
import nextstep.courses.exception.CustomException;

import java.util.Arrays;

Expand All @@ -12,7 +12,6 @@ public enum ImageType {
png,
svg;


public static ImageType validateType(String imageType) {
return Arrays.stream(values()).filter(type -> type.name().equals(imageType))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package nextstep.courses.domain.sessionimage;
package nextstep.courses.domain.image;

public class SessionImage {

private final ImageCapacity capacity;
private final ImageType type;
private final ImageSize size;


public SessionImage(ImageCapacity capacity, ImageType type, ImageSize size) {
ImageType.validateType(type.name());
this.capacity = capacity;
this.type = type;
this.size = size;
}

public ImageCapacity getCapacity() {
return capacity;
}

public ImageType getType() {
return type;
}

public ImageSize getSize() {
return size;
}

}
Loading