Skip to content

Commit

Permalink
[REFACTOR] Category enum 도메인 수정 (#178)
Browse files Browse the repository at this point in the history
* refactor: Category enum 도메인 수정 (#177)

* refactor: 코드 리팩토링 (#177)
  • Loading branch information
hyunmin0317 authored Jan 29, 2025
1 parent 2328ec6 commit b8dfce7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class Standard {
@JoinColumn(name = "year_id")
private Year year;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Category category;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.smunity.server.domain.course.entity.Course;
import com.smunity.server.domain.course.repository.course.CourseRepository;
import com.smunity.server.global.common.entity.Member;
import com.smunity.server.global.common.entity.enums.Category;
import com.smunity.server.global.common.repository.MemberRepository;
import com.smunity.server.global.exception.GeneralException;
import com.smunity.server.global.exception.code.ErrorCode;
Expand Down Expand Up @@ -38,7 +37,7 @@ public ResultResponseDto<CourseResponseDto> createCourses(Long memberId, AuthReq
.toList();
courseRepository.saveAll(courses);
List<CourseResponseDto> responseDtoList = CourseResponseDto.from(member.getCourses());
int total = standardService.getTotal(member.getYear(), Category.ALL);
int total = standardService.getTotal(member.getYear());
return ResultResponseDto.of(total, member.getCompletedCredits(), responseDtoList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public ResultResponseDto<CourseResponseDto> readCourses(Long memberId, Category
.orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND));
List<Course> courses = courseRepository.findByMemberIdAndCategory(memberId, category);
List<CourseResponseDto> responseDtoList = CourseResponseDto.from(courses);
int total = standardService.getTotal(member.getYear(), member.getDepartment(), getCategory(category));
int total = standardService.getTotal(member.getYear(), member.getDepartment(), category);
int completed = calculateCompleted(courses);
return ResultResponseDto.of(total, completed, responseDtoList);
}

public CreditResponseDto readCoursesCredit(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND));
int total = standardService.getTotal(member.getYear(), Category.ALL);
int total = standardService.getTotal(member.getYear());
return CreditResponseDto.from(total, member);
}

Expand All @@ -57,10 +57,6 @@ public ResultResponseDto<CultureResponseDto> readCultureCourses(Long memberId, D
return ResultResponseDto.of(total, completed, responseDtoList);
}

private Category getCategory(Category category) {
return category != null ? category : Category.ALL;
}

private int calculateCompleted(List<Course> courses) {
return courses.stream()
.mapToInt(Course::getCredit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public int getCultureTotal(int size, Domain domain) {
};
}

public int getTotal(Year year) {
return getTotal(year, null);
}

public int getTotal(Year year, Department department, Category category) {
int total = getTotal(year, category);
return department.isHasAdvanced() ? total : getTotal(total, category);
return department.isHasAdvanced() || category == null ? total : getTotal(total, category);
}

public int getTotal(Year year, Category category) {
private int getTotal(Year year, Category category) {
return standardRepository.findByYearAndCategory(year, category)
.map(Standard::getTotal)
.orElse(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@RequiredArgsConstructor
public enum Category {

ALL("전체"),
MAJOR_ADVANCED("1전심"),
MAJOR_OPTIONAL("1전선"),
CULTURE("교양"),
Expand Down

0 comments on commit b8dfce7

Please sign in to comment.