Skip to content

Commit

Permalink
BE: [feature] 시험 등록, 세션입장, 학생정보 입력 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
HOJEONGKIMM committed Nov 10, 2024
1 parent 53d65d4 commit 6902f8a
Show file tree
Hide file tree
Showing 39 changed files with 375 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/2024-2-SCS4031-4tune_2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/Eyesee.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
21 changes: 21 additions & 0 deletions .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/backend/Eyesee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-security'

// 랜덤 코드 생성
implementation 'org.apache.commons:commons-lang3:3.12.0'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ public enum BaseResponseCode {
// Exam Errors
NOT_FOUND_EXAM("E0001", HttpStatus.NOT_FOUND, "시험을 찾을 수 없습니다."),
NOT_FOUND_EXAM_CODE("E0002", HttpStatus.NOT_FOUND, "시험 코드를 찾을 수 없습니다."),

// Exam Errors
EXAM_NOT_FOUND("E0001", HttpStatus.NOT_FOUND, "시험을 찾을 수 없습니다."),
SESSION_NOT_FOUND("E0002", HttpStatus.NOT_FOUND, "세션을 찾을 수 없습니다."),
EXAM_ALREADY_EXISTS("E0003", HttpStatus.CONFLICT, "이미 존재하는 시험입니다."),
INVALID_EXAM_STATUS("E0004", HttpStatus.BAD_REQUEST, "유효하지 않은 시험 상태입니다."),
EXAM_ACCESS_DENIED("E0005", HttpStatus.FORBIDDEN, "시험에 접근할 권한이 없습니다."),
NOT_FOUND_SESSION("E0003", HttpStatus.NOT_FOUND, "세션을 찾을 수 없습니다."),
EXAM_ALREADY_EXISTS("E0004", HttpStatus.CONFLICT, "이미 존재하는 시험입니다."),
INVALID_EXAM_STATUS("E0005", HttpStatus.BAD_REQUEST, "유효하지 않은 시험 상태입니다."),
EXAM_ACCESS_DENIED("E0006", HttpStatus.FORBIDDEN, "시험에 접근할 권한이 없습니다."),

// 기타 추가 오류 코드 ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.fortune.eyesee.common.exception.BaseException;
import com.fortune.eyesee.common.response.BaseResponse;
import com.fortune.eyesee.common.response.BaseResponseCode;
import com.fortune.eyesee.dto.ExamCodeRequestDTO;
import com.fortune.eyesee.dto.ExamResponseDTO;
import com.fortune.eyesee.dto.UserDetailResponseDTO;
import com.fortune.eyesee.dto.UserListResponseDTO;
import com.fortune.eyesee.dto.*;
import com.fortune.eyesee.enums.ExamStatus;
import com.fortune.eyesee.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,7 +12,10 @@
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/exams")
Expand Down Expand Up @@ -58,6 +58,35 @@ public class ExamController {
// return ResponseEntity.ok(new BaseResponse<>(examList));
// }

// 시험 등록
// @PostMapping
// public ResponseEntity<BaseResponse<ExamResponseDTO>> registerExam(@RequestBody ExamRequestDTO examRequestDTO, HttpSession session) {
// Integer adminId = (Integer) session.getAttribute("adminId");
// if (adminId == null) {
// // 로그인되지 않은 경우 예외처리
// throw new BaseException(BaseResponseCode.UNAUTHORIZED);
// }
//
// // 시험 생성 및 랜덤 코드 생성
// ExamResponseDTO response = examService.registerExam(adminId, examRequestDTO);
// return ResponseEntity.ok(new BaseResponse<>(response, "시험 등록에 성공했습니다."));
// }
@PostMapping
public ResponseEntity<BaseResponse<Map<String, String>>> registerExam(@RequestBody ExamRequestDTO examRequestDTO, HttpSession session) {
Integer adminId = (Integer) session.getAttribute("adminId");
if (adminId == null) {
throw new BaseException(BaseResponseCode.UNAUTHORIZED);
}

ExamResponseDTO response = examService.registerExam(adminId, examRequestDTO);

// examRandomCode만 포함된 응답 생성
Map<String, String> responseData = new HashMap<>();
responseData.put("examRandomCode", response.getExamRandomCode());

return ResponseEntity.ok(new BaseResponse<>(responseData, "시험 등록에 성공했습니다."));
}

// "before" 상태의 Exam 리스트 조회
@GetMapping("/before")
public ResponseEntity<BaseResponse<List<ExamResponseDTO>>> getBeforeExams() {
Expand Down Expand Up @@ -127,4 +156,4 @@ public ResponseEntity<BaseResponse<UserDetailResponseDTO>> getUserDetailByExamId
UserDetailResponseDTO response = examService.getUserDetailByExamIdAndUserId(examId, userId);
return ResponseEntity.ok(new BaseResponse<>(response, "학생 상세 정보 조회 성공"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.fortune.eyesee.controller;

import com.fortune.eyesee.common.response.BaseResponse;
import com.fortune.eyesee.dto.ExamCodeRequestDTO;
import com.fortune.eyesee.dto.UserInfoRequestDTO;
import com.fortune.eyesee.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sessions")
public class SessionController {

private final SessionService sessionService;

@Autowired
public SessionController(SessionService sessionService) {
this.sessionService = sessionService;
}

// 시험 세션 입장
@PostMapping("/join")
public ResponseEntity<BaseResponse<String>> joinExam(@RequestBody ExamCodeRequestDTO examCodeRequestDTO) {
sessionService.joinExamSession(examCodeRequestDTO.getExamCode());
return ResponseEntity.ok(new BaseResponse<>("시험 세션 입장에 성공했습니다."));
}

// 사용자 정보 입력
@PostMapping("/student")
public ResponseEntity<BaseResponse<String>> addUserInfo(@RequestBody UserInfoRequestDTO userInfoRequestDTO) {
sessionService.addUserInfo(userInfoRequestDTO);
return ResponseEntity.ok(new BaseResponse<>("사용자 정보 입력에 성공했습니다."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fortune.eyesee.dto;

import lombok.Data;

import java.time.LocalDate;
import java.time.LocalTime;

@Data
public class ExamRequestDTO {
private String examName;
private String examSemester;
private Integer examStudentNumber;
private String examLocation;
private LocalDate examDate;
private LocalTime examStartTime;
private Integer examDuration;
private Integer examQuestionNumber;
private Integer examTotalScore;
private String examNotice;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

package com.fortune.eyesee.dto;

import lombok.Data;

@Data
public class UserInfoRequestDTO {
private String name; // 사용자 이름
private String department; // 학과
private Integer userNum; // 학번
private Integer seatNum; // 좌석 번호
}
Loading

0 comments on commit 6902f8a

Please sign in to comment.