Skip to content
Merged
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
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
);
}
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);
}
}
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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

static import 👍

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

stream 👍

}
}
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 src/main/java/in/koreatech/koin/domain/timetable/model/Lecture.java
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;
}
}
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);
}
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();
}
}
Loading