Skip to content

Commit

Permalink
Merge pull request #80 from mju-likelion/feature/db-integrity-fix-#79
Browse files Browse the repository at this point in the history
Feature/#79 DB 레코드 중복 생성 문제 수정
  • Loading branch information
Dh3356 authored Feb 25, 2024
2 parents 8e93c67 + cfd6f1f commit 7b78d60
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 271 deletions.
118 changes: 0 additions & 118 deletions src/main/java/org/mjulikelion/bagel/aspect/RateLimitAspect.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/org/mjulikelion/bagel/config/ServletInitializer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.mjulikelion.bagel.service.application.ApplicationCommandService;
import org.mjulikelion.bagel.service.application.ApplicationQueryService;
import org.mjulikelion.bagel.util.annotaion.file.introduce.IntroduceFileConstraint;
import org.mjulikelion.bagel.util.annotaion.ratelimit.RateLimit;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -27,21 +26,18 @@ public class ApplicationController {
private final ApplicationQueryService applicationQueryService;
private final ApplicationCommandService applicationCommandService;

@RateLimit
@GetMapping("/{part}")
public ResponseEntity<ResponseDto<ApplicationGetResponseData>> getApplicationByPart(
@PathVariable("part") String part) {
return this.applicationQueryService.getApplicationByPart(part);
}

@RateLimit
@PostMapping()
public ResponseEntity<ResponseDto<Void>> saveApplication(
@RequestBody @Valid ApplicationSaveDto applicationSaveDto) {
return this.applicationCommandService.saveApplication(applicationSaveDto);
}

@RateLimit
@PostMapping("/file")
public ResponseEntity<ResponseDto<FileSaveResponseData>> saveFile(
@IntroduceFileConstraint @RequestPart MultipartFile file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.mjulikelion.bagel.dto.response.apply.ApplyExistResponseData;
import org.mjulikelion.bagel.service.apply.ApplyCommandService;
import org.mjulikelion.bagel.service.apply.ApplyQueryService;
import org.mjulikelion.bagel.util.annotaion.ratelimit.RateLimit;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -26,14 +25,12 @@ public class ApplyController {
private final ApplyQueryService applyQueryService;
private final ApplyCommandService applyCommandService;

@RateLimit
@GetMapping("/exist/{studentId}")
public ResponseEntity<ResponseDto<ApplyExistResponseData>> getApplicationExist(
@PathVariable("studentId") @Pattern(regexp = APPLICATION_STUDENT_ID_PATTERN) @Valid String studentId) {
return this.applyQueryService.getApplyExist(studentId);
}

@RateLimit
@PostMapping()
public ResponseEntity<ResponseDto<Void>> saveApply(
@RequestBody @Valid ApplySaveDto applySaveDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.mjulikelion.bagel.exception.DateRangeException;
import org.mjulikelion.bagel.exception.FileStorageException;
import org.mjulikelion.bagel.exception.InvalidDataException;
import org.mjulikelion.bagel.exception.RateLimitException;
import org.mjulikelion.bagel.exception.JpaException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
Expand All @@ -24,17 +24,6 @@
@Slf4j
@RestControllerAdvice
public class ExceptionController {
//RateLimitException 예외를 처리하는 핸들러(요청이 제한된 경우)
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
@ExceptionHandler(RateLimitException.class)
public ResponseEntity<ResponseDto<Void>> handleRateLimitException(RateLimitException rateLimitException) {
log.error("RateLimitException: {}", rateLimitException.getMessage());
ErrorCode errorCode = ErrorCode.RATE_LIMIT_ERROR;
String code = errorCode.getCode();
String message = errorCode.getMessage();
return new ResponseEntity<>(ResponseDto.res(code, message), HttpStatus.TOO_MANY_REQUESTS);
}

//DateRangeException 예외를 처리하는 핸들러(날짜 범위에 맞지 않는 경우)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(DateRangeException.class)
Expand Down Expand Up @@ -157,4 +146,15 @@ public ResponseEntity<ResponseDto<Void>> handleInvalidDataException(InvalidDataE
String message = errorCode.getMessage();
return new ResponseEntity<>(ResponseDto.res(code, message), HttpStatus.BAD_REQUEST);
}

//JpaException 예외를 처리하는 핸들러(SQL 오류가 발생한 경우)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(JpaException.class)
public ResponseEntity<ResponseDto<Void>> handleJpaException(JpaException jpaException) {
log.error("SqlException: {}", jpaException.getMessage());
ErrorCode errorCode = jpaException.getErrorCode();
String code = errorCode.getCode();
String message = errorCode.getMessage() + " : " + jpaException.getMessage();
return new ResponseEntity<>(ResponseDto.res(code, message), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.mjulikelion.bagel.controller;

import org.mjulikelion.bagel.util.annotaion.ratelimit.RateLimit;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthController {
@RateLimit
@GetMapping("/health")
public String health() {
return "ok";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
@AllArgsConstructor
public enum ErrorCode {
//잘못된 요청 오류들
RATE_LIMIT_ERROR("4290", "요청이 너무 많습니다."),//요청이 너무 많음
DATE_RANGE_ERROR("4030", "지원 기간이 아닙니다."),//지원 기간이 아님
//서버 내부 오류들
INTERNAL_SERVER_ERROR("5000", "알 수 없는 서버 내부 오류."),//서버 내부 오류
FILE_STORAGE_ERROR("5001", "파일 저장에 실패하였습니다."),//파일 저장 실패
JPA_ERROR("5002", "JPA 오류가 발생하였습니다."),//SQL 오류
//잘못된 경로, 메소드 오류들
METHOD_NOT_ALLOWED_ERROR("4050", "허용되지 않은 메소드 입니다."),//허용되지 않은 메소드
NO_RESOURCE_ERROR("4040", "해당 리소스를 찾을 수 없습니다."),//리소스를 찾을 수 없음(잘못된 URI)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.mjulikelion.bagel.exception;

import org.mjulikelion.bagel.errorcode.ErrorCode;

public class JpaException extends CustomException {
public JpaException(ErrorCode errorCode, String message) {
super(errorCode, message);
}
}

This file was deleted.

This file was deleted.

16 changes: 8 additions & 8 deletions src/main/java/org/mjulikelion/bagel/model/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ public class Application {
@Column(updatable = false, unique = true, nullable = false)
private UUID id;

@Column(length = 100)
@Column(length = 100, nullable = false)
private String name;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "major_id")
@JoinColumn(name = "major_id", nullable = false)
private Major major;

@Column(name = "student_id", length = 8)
@Column(name = "student_id", length = 8, unique = true, nullable = false, updatable = false)
private String studentId;

@Column(length = 100)
@Column(length = 100, nullable = false)
private String phoneNumber;

@Column(length = 100)
@Column(length = 100, nullable = false)
private String email;

@Column(length = 10)
@Column(length = 10, nullable = false)
private String grade;

@Enumerated(EnumType.STRING)
@Column
@Column(nullable = false)
private Part part;

@Column(length = 256)
@Column(length = 256, nullable = false)
private String link;

@CreatedDate
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/mjulikelion/bagel/model/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import java.util.Date;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,7 +27,11 @@
@Entity(name = "history")
public class History {
@Id
@Column(length = 8, updatable = false, unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid2")
@Column(updatable = false, unique = true, nullable = false)
private UUID id;

@Column(length = 8, updatable = false, nullable = false)
@NotNull
private String studentId;

Expand Down
Loading

0 comments on commit 7b78d60

Please sign in to comment.