Skip to content
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

feat : 엑셀 파일로 과거 시간표 추가하기 #1153

Merged
Show file tree
Hide file tree
Changes from 3 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,36 @@
package in.koreatech.koin.domain.graduation.controller;

import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import in.koreatech.koin.global.auth.Auth;
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.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "(Normal) Graduation: 졸업학점 계산기", description = "졸업학점 계산기 정보를 관리한다")
public interface GraduationApi {
@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 = "엑셀 성적 정보 업로드")
@SecurityRequirement(name = "Jwt Authentication")
@PostMapping("/graduation/excel/upload")
ResponseEntity<String> uploadStudentGradeExcelFile(
@RequestParam(value = "file") MultipartFile file,
@Auth(permit = {STUDENT}) Integer userId
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package in.koreatech.koin.domain.graduation.controller;

import java.io.IOException;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import in.koreatech.koin.domain.graduation.service.GraduationService;
import in.koreatech.koin.domain.user.model.UserType;
import in.koreatech.koin.global.auth.Auth;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class GraduationController implements GraduationApi {

private final GraduationService graduationService;

@PostMapping("/graduation/excel/upload")
public ResponseEntity<String> uploadStudentGradeExcelFile(
@RequestParam(value = "file") MultipartFile file,
@Auth(permit = {UserType.STUDENT}) Integer userId
) {
try {
graduationService.readStudentGradeExcelFile(file, userId);
return ResponseEntity.ok("파일이 성공적으로 업로드되었습니다.");
} catch (IOException e) {
return ResponseEntity.badRequest().build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package in.koreatech.koin.domain.graduation.dto;

public record ExcelStudentData(
Soundbar91 marked this conversation as resolved.
Show resolved Hide resolved
Soundbar91 marked this conversation as resolved.
Show resolved Hide resolved
String excelYear,
String excelSemester,
String excelCode,
String excelClassTitle,
String excelLectureClass,
String excelProfessor,
String excelCourseType,
String excelCredit,
String excelGrade,
String excelRetakeStatus
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package in.koreatech.koin.domain.graduation.exception;

import in.koreatech.koin.global.exception.DataNotFoundException;

public class CatalogNotFoundException extends DataNotFoundException {

private static final String DEFAULT_MESSAGE = "존재하지 않는 대학 요람입니다.";

protected CatalogNotFoundException(String message) {
super(message);
}

protected CatalogNotFoundException(String message, String detail) {
super(message, detail);
}

public static CatalogNotFoundException withDetail(String detail) {
return new CatalogNotFoundException(DEFAULT_MESSAGE, detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package in.koreatech.koin.domain.graduation.exception;

import in.koreatech.koin.global.exception.DataNotFoundException;

public class CourseTypeNotFoundException extends DataNotFoundException {

private static final String DEFAULT_MESSAGE = "존재하지 않는 이수 구분입니다.";

protected CourseTypeNotFoundException(String message) {
super(message);
}

protected CourseTypeNotFoundException(String message, String detail) {
super(message, detail);
}

public static CourseTypeNotFoundException withDetail(String detail) {
return new CourseTypeNotFoundException(DEFAULT_MESSAGE, detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package in.koreatech.koin.domain.graduation.exception;

import in.koreatech.koin.global.exception.DataNotFoundException;

public class DepartmentNotFoundException extends DataNotFoundException {

private static final String DEFAULT_MESSAGE = "존재하지 않는 학과입니다.";

protected DepartmentNotFoundException(String message) {
super(message);
}

protected DepartmentNotFoundException(String message, String detail) {
super(message, detail);
}

public static DepartmentNotFoundException withDetail(String detail) {
return new DepartmentNotFoundException(DEFAULT_MESSAGE, detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package in.koreatech.koin.domain.graduation.exception;

import in.koreatech.koin.global.exception.DataNotFoundException;

public class ExcelFileCheckException extends DataNotFoundException {
private static final String DEFAULT_MESSAGE = "엑셀 파일 형식이 아닙니다.";

public ExcelFileCheckException(String message) {
super(message);
}

public ExcelFileCheckException(String message, String detail) {
super(message, detail);
}

public static ExcelFileCheckException withDetail(String detail) {
return new ExcelFileCheckException(DEFAULT_MESSAGE, detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package in.koreatech.koin.domain.graduation.exception;

import in.koreatech.koin.global.exception.DataNotFoundException;

public class ExcelFileNotFoundException extends DataNotFoundException {
private static final String DEFAULT_MESSAGE = "엑셀 파일을 찾을 수 없습니다.";

public ExcelFileNotFoundException(String message) {
super(message);
}

public ExcelFileNotFoundException(String message, String detail) {
super(message, detail);
}

public static ExcelFileNotFoundException withDetail(String detail) {
return new ExcelFileNotFoundException(DEFAULT_MESSAGE, detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.Optional;

import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.graduation.exception.CatalogNotFoundException;
import in.koreatech.koin.domain.graduation.model.Catalog;
import in.koreatech.koin.domain.graduation.model.Department;

public interface CatalogRepository extends Repository<Catalog, Integer> {
Optional<Catalog> findByYearAndDepartmentAndCode(String year, Department department, String code);

default Catalog getByYearAndDepartmentAndCode(String year, Department department, String code) {
return findByYearAndDepartmentAndCode(year, department, code)
.orElseThrow(() -> CatalogNotFoundException.withDetail(
"year: " + year + ", department: " + department + ", code: " + code));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.Optional;

import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.graduation.exception.CourseTypeNotFoundException;
import in.koreatech.koin.domain.graduation.model.CourseType;

public interface CourseTypeRepository extends Repository<CourseType, Integer> {

CourseType save(CourseType courseType);

Optional<CourseType> findById(Integer id);

Optional<CourseType> findByName(String name);

default CourseType getCourseTypeById(Integer id) {
return findById(id)
.orElseThrow(() -> CourseTypeNotFoundException.withDetail("course_type_id: " + id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package in.koreatech.koin.domain.graduation.repository;

import java.util.Optional;

import org.springframework.data.repository.Repository;

import in.koreatech.koin.domain.graduation.exception.DepartmentNotFoundException;
import in.koreatech.koin.domain.graduation.model.Department;

public interface DepartmentRepository extends Repository<Department, Integer> {
Optional<Department> findByName(String name);

default Department getByName(String name) {
return findByName(name)
.orElseThrow(() -> DepartmentNotFoundException.withDetail("name: " + name));
}
}
Loading
Loading