-
Notifications
You must be signed in to change notification settings - Fork 2
feat : 강의 목록 조회(학기별) #192
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
Merged
Merged
feat : 강의 목록 조회(학기별) #192
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
570c24c
feat : Lecture 클래스 생성
dradnats1012 0bdccf4
feat : LectureApi 클래스 생성
dradnats1012 0b27996
feat : LectureController 클래스 생성
dradnats1012 8b0a4df
feat : LectureRepository 클래스 생성
dradnats1012 93fef7e
feat : LectureResponse DTO 생성
dradnats1012 77b7b06
feat : LectureService 클래스 생성
dradnats1012 e33c659
feat : LectureApiTest 테스트 생성 후 통과
dradnats1012 bcaf267
refactor : 리뷰 반영
dradnats1012 f8bf260
refactor : classTime 반환타입 Integer[]로 변경
dradnats1012 8e5252d
refactor : 리뷰 반영
dradnats1012 373ab24
refactor : Integer[]배열 List<Long>으로 변경
dradnats1012 6d184a5
refactor : TimeTable로 네이밍 변경
dradnats1012 81caf95
refactor : 리뷰 반영
dradnats1012 159a087
refactor : test param 방식 변경
dradnats1012 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
32 changes: 32 additions & 0 deletions
32
src/main/java/in/koreatech/koin/domain/timetable/controller/TimetableApi.java
This file contains hidden or 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,32 @@ | ||
| package in.koreatech.koin.domain.timetable.controller; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| import in.koreatech.koin.domain.timetable.dto.LectureResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
|
||
| @Tag(name = "(Normal) Lecture: 시간표", description = "시간표 정보를 관리한다") | ||
| public interface TimetableApi { | ||
|
|
||
| @ApiResponses( | ||
| value = { | ||
| @ApiResponse(responseCode = "200"), | ||
| @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))), | ||
| } | ||
| ) | ||
| @Operation(summary = "강의 목록 조회") | ||
| @GetMapping("/lectures") | ||
| ResponseEntity<List<LectureResponse>> getLecture( | ||
| String semesterDate | ||
| ); | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/in/koreatech/koin/domain/timetable/controller/TimetableController.java
This file contains hidden or 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,27 @@ | ||
| package in.koreatech.koin.domain.timetable.controller; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import in.koreatech.koin.domain.timetable.dto.LectureResponse; | ||
| import in.koreatech.koin.domain.timetable.service.TimetableService; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class TimetableController implements TimetableApi { | ||
|
|
||
| private final TimetableService timetableService; | ||
|
|
||
| @GetMapping("/lectures") | ||
| public ResponseEntity<List<LectureResponse>> getLecture( | ||
| @RequestParam(name = "semester_date") String semester | ||
| ) { | ||
| List<LectureResponse> lectures = timetableService.getLecturesBySemester(semester); | ||
| return ResponseEntity.ok(lectures); | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
src/main/java/in/koreatech/koin/domain/timetable/dto/LectureResponse.java
This file contains hidden or 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,75 @@ | ||
| package in.koreatech.koin.domain.timetable.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import in.koreatech.koin.domain.timetable.model.Lecture; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(value = SnakeCaseStrategy.class) | ||
| public record LectureResponse( | ||
|
|
||
| @Schema(name = "과목 코드", example = "ARB244") | ||
| String code, | ||
|
|
||
| @Schema(name = "과목 이름", example = "건축구조의 이해 및 실습") | ||
| String name, | ||
|
|
||
| @Schema(name = "대상 학년", example = "3") | ||
| String grades, | ||
|
|
||
| @Schema(name = "분반", example = "01") | ||
| String lectureClass, | ||
|
|
||
| @Schema(name = "수강 인원", example = "25") | ||
| String regularNumber, | ||
|
|
||
| @Schema(name = "학부", example = "디자인ㆍ건축공학부") | ||
| String department, | ||
|
|
||
| @Schema(name = "대상", example = "디자 1 건축") | ||
| String target, | ||
|
|
||
| @Schema(name = "강의 교수", example = "이돈우") | ||
| String professor, | ||
|
|
||
| @Schema(name = "영어 수업인지", example = "N") | ||
| String isEnglish, | ||
|
|
||
| @Schema(name = "설계 학점", example = "0") | ||
| String designScore, | ||
|
|
||
| @Schema(name = "이러닝인지", example = "Y") | ||
| String isElearning, | ||
|
|
||
| @Schema(name = "강의 시간", example = "[200,201,202,203,204,205,206,207]") | ||
| List<Long> classTime | ||
| ) { | ||
| public static LectureResponse from(Lecture lecture) { | ||
| return new LectureResponse( | ||
| lecture.getCode(), | ||
| lecture.getName(), | ||
| lecture.getGrades(), | ||
| lecture.getLectureClass(), | ||
| lecture.getRegularNumber(), | ||
| lecture.getDepartment(), | ||
| lecture.getTarget(), | ||
| lecture.getProfessor(), | ||
| lecture.getIsEnglish(), | ||
| lecture.getDesignScore(), | ||
| lecture.getIsElearning(), | ||
| toListClassTime(lecture.getClassTime()) | ||
| ); | ||
| } | ||
|
|
||
| public static List<Long> toListClassTime(String classTime) { | ||
| classTime = classTime.substring(1, classTime.length() - 1); | ||
| List<String> numbers = List.of(classTime.split(",")); | ||
|
|
||
| return numbers.stream() | ||
| .map(Long::parseLong) | ||
| .toList(); | ||
|
Comment on lines
+71
to
+73
Collaborator
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. Astream 👍 |
||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/main/java/in/koreatech/koin/domain/timetable/exception/SemesterNotFoundException.java
This file contains hidden or 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,17 @@ | ||
| package in.koreatech.koin.domain.timetable.exception; | ||
|
|
||
| import in.koreatech.koin.global.exception.DataNotFoundException; | ||
|
|
||
| public class SemesterNotFoundException extends DataNotFoundException { | ||
|
|
||
| private static final String DEFAULT_MESSAGE = "존재하지 않는 학기입니다."; | ||
|
|
||
| public SemesterNotFoundException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public static SemesterNotFoundException withDetail(String detail) { | ||
| String message = String.format("%s %s", DEFAULT_MESSAGE, detail); | ||
| return new SemesterNotFoundException(message); | ||
| } | ||
| } |
112 changes: 112 additions & 0 deletions
112
src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java
This file contains hidden or 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,112 @@ | ||
| package in.koreatech.koin.domain.timetable.model; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @Table(name = "lectures") | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Lecture { | ||
|
|
||
| @Id | ||
| @Column(name = "id", nullable = false) | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "semester_date", nullable = false) | ||
| private String semester; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "code", nullable = false) | ||
| private String code; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "name", nullable = false) | ||
| private String name; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "grades", nullable = false) | ||
| private String grades; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "class", nullable = false) | ||
| private String lectureClass; | ||
|
|
||
| @Size(max = 255) | ||
| @Column(name = "regular_number") | ||
| private String regularNumber; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "department", nullable = false) | ||
| private String department; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "target", nullable = false) | ||
| private String target; | ||
|
|
||
| @Size(max = 255) | ||
| @Column(name = "professor") | ||
| private String professor; | ||
|
|
||
| @Size(max = 255) | ||
| @Column(name = "is_english") | ||
| private String isEnglish; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "design_score", nullable = false) | ||
| private String designScore; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "is_elearning", nullable = false) | ||
| private String isElearning; | ||
|
|
||
| @Size(max = 255) | ||
| @NotNull | ||
| @Column(name = "class_time", nullable = false) | ||
| private String classTime; | ||
|
|
||
| @Builder | ||
| private Lecture( | ||
| String code, String semester, | ||
| String name, String grades, String lectureClass, | ||
| String regularNumber, String department, | ||
| String target, String professor, | ||
| String isEnglish, String designScore, | ||
| String isElearning, String classTime | ||
| ) { | ||
| this.code = code; | ||
| this.semester = semester; | ||
| this.name = name; | ||
| this.grades = grades; | ||
| this.lectureClass = lectureClass; | ||
| this.regularNumber = regularNumber; | ||
| this.department = department; | ||
| this.target = target; | ||
| this.professor = professor; | ||
| this.isEnglish = isEnglish; | ||
| this.designScore = designScore; | ||
| this.isElearning = isElearning; | ||
| this.classTime = classTime; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/in/koreatech/koin/domain/timetable/repository/LectureRepository.java
This file contains hidden or 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,14 @@ | ||
| package in.koreatech.koin.domain.timetable.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.data.repository.Repository; | ||
|
|
||
| import in.koreatech.koin.domain.timetable.model.Lecture; | ||
|
|
||
| public interface LectureRepository extends Repository<Lecture, Long> { | ||
|
|
||
| List<Lecture> findBySemester(String semesterDate); | ||
|
|
||
| Lecture save(Lecture lecture); | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java/in/koreatech/koin/domain/timetable/service/TimetableService.java
This file contains hidden or 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,30 @@ | ||
| package in.koreatech.koin.domain.timetable.service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import in.koreatech.koin.domain.timetable.dto.LectureResponse; | ||
| import in.koreatech.koin.domain.timetable.exception.SemesterNotFoundException; | ||
| import in.koreatech.koin.domain.timetable.model.Lecture; | ||
| import in.koreatech.koin.domain.timetable.repository.LectureRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class TimetableService { | ||
|
|
||
| private final LectureRepository lectureRepository; | ||
|
|
||
| public List<LectureResponse> getLecturesBySemester(String semester) { | ||
| List<Lecture> lectures = lectureRepository.findBySemester(semester); | ||
| if (lectures.isEmpty()) { | ||
| throw SemesterNotFoundException.withDetail(semester); | ||
| } | ||
| return lectures.stream() | ||
| .map(LectureResponse::from) | ||
| .toList(); | ||
| } | ||
| } |
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.
A
static import 👍