diff --git a/src/main/java/ice/spot/controller/BoardingRecordController.java b/src/main/java/ice/spot/controller/BoardingRecordController.java index 03e3a1b..82c107a 100644 --- a/src/main/java/ice/spot/controller/BoardingRecordController.java +++ b/src/main/java/ice/spot/controller/BoardingRecordController.java @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; + @Slf4j @RestController @RequiredArgsConstructor @@ -20,11 +22,11 @@ public class BoardingRecordController { private final BoardingRecordService boardingRecordService; @PostMapping("/boarding-record") - public ResponseDto saveBoardingRecord( + public ResponseDto saveBoardingRecord ( @UserId Long userId, @RequestPart(value = "image", required = false) MultipartFile multipartFile, @RequestPart(value = "dto") BoardingRecordRequest boardingRecordRequest - ) { + ) throws IOException { Long imageId = imageService.saveImage(multipartFile); return ResponseDto.created(boardingRecordService diff --git a/src/main/java/ice/spot/domain/BoardingRecord.java b/src/main/java/ice/spot/domain/BoardingRecord.java index 8667ca0..10346e0 100644 --- a/src/main/java/ice/spot/domain/BoardingRecord.java +++ b/src/main/java/ice/spot/domain/BoardingRecord.java @@ -27,11 +27,11 @@ public class BoardingRecord { private User user; @OneToOne - @JoinColumn(name = "parking_lot_id", referencedColumnName = "id") + @JoinColumn(name = "parking_lot_id") private ParkingLot parkingLot; @OneToOne - @JoinColumn(name = "image_id", referencedColumnName = "id") + @JoinColumn(name = "image_id") private Image image; @Builder diff --git a/src/main/java/ice/spot/domain/Image.java b/src/main/java/ice/spot/domain/Image.java index 3c23ab9..71c246e 100644 --- a/src/main/java/ice/spot/domain/Image.java +++ b/src/main/java/ice/spot/domain/Image.java @@ -14,6 +14,7 @@ public class Image { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") private Long id; @Column(name = "origin_name") diff --git a/src/main/java/ice/spot/domain/ParkingLotResult.java b/src/main/java/ice/spot/domain/type/ParkingLotResult.java similarity index 93% rename from src/main/java/ice/spot/domain/ParkingLotResult.java rename to src/main/java/ice/spot/domain/type/ParkingLotResult.java index 3c299a2..ec48743 100644 --- a/src/main/java/ice/spot/domain/ParkingLotResult.java +++ b/src/main/java/ice/spot/domain/type/ParkingLotResult.java @@ -1,4 +1,4 @@ -package ice.spot.domain; +package ice.spot.domain.type; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/ice/spot/dto/global/ExceptionDto.java b/src/main/java/ice/spot/dto/global/ExceptionDto.java index 7017212..949fce8 100644 --- a/src/main/java/ice/spot/dto/global/ExceptionDto.java +++ b/src/main/java/ice/spot/dto/global/ExceptionDto.java @@ -1,6 +1,6 @@ package ice.spot.dto.global; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; public record ExceptionDto( Integer code, diff --git a/src/main/java/ice/spot/dto/global/ResponseDto.java b/src/main/java/ice/spot/dto/global/ResponseDto.java index 939e0d6..5460f8b 100644 --- a/src/main/java/ice/spot/dto/global/ResponseDto.java +++ b/src/main/java/ice/spot/dto/global/ResponseDto.java @@ -1,7 +1,7 @@ package ice.spot.dto.global; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotNull; import net.minidev.json.annotate.JsonIgnore; diff --git a/src/main/java/ice/spot/exeption/CommonException.java b/src/main/java/ice/spot/exception/CommonException.java similarity index 90% rename from src/main/java/ice/spot/exeption/CommonException.java rename to src/main/java/ice/spot/exception/CommonException.java index 427c4c6..c7dd9c7 100644 --- a/src/main/java/ice/spot/exeption/CommonException.java +++ b/src/main/java/ice/spot/exception/CommonException.java @@ -1,4 +1,4 @@ -package ice.spot.exeption; +package ice.spot.exception; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/ice/spot/exeption/ErrorCode.java b/src/main/java/ice/spot/exception/ErrorCode.java similarity index 98% rename from src/main/java/ice/spot/exeption/ErrorCode.java rename to src/main/java/ice/spot/exception/ErrorCode.java index 2df9bd6..39304df 100644 --- a/src/main/java/ice/spot/exeption/ErrorCode.java +++ b/src/main/java/ice/spot/exception/ErrorCode.java @@ -1,4 +1,4 @@ -package ice.spot.exeption; +package ice.spot.exception; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/ice/spot/exeption/GlobalExceptionHandler.java b/src/main/java/ice/spot/exception/GlobalExceptionHandler.java similarity index 98% rename from src/main/java/ice/spot/exeption/GlobalExceptionHandler.java rename to src/main/java/ice/spot/exception/GlobalExceptionHandler.java index e8e105a..2689cf5 100644 --- a/src/main/java/ice/spot/exeption/GlobalExceptionHandler.java +++ b/src/main/java/ice/spot/exception/GlobalExceptionHandler.java @@ -1,4 +1,4 @@ -package ice.spot.exeption; +package ice.spot.exception; import ice.spot.dto.global.ResponseDto; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/ice/spot/interceptor/pre/UserIdArgumentResolver.java b/src/main/java/ice/spot/interceptor/pre/UserIdArgumentResolver.java index 46670bb..dbe4a7f 100644 --- a/src/main/java/ice/spot/interceptor/pre/UserIdArgumentResolver.java +++ b/src/main/java/ice/spot/interceptor/pre/UserIdArgumentResolver.java @@ -1,8 +1,8 @@ package ice.spot.interceptor.pre; import ice.spot.annotation.UserId; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Component; import org.springframework.web.bind.support.WebDataBinderFactory; diff --git a/src/main/java/ice/spot/security/filter/JwtAuthenticationFilter.java b/src/main/java/ice/spot/security/filter/JwtAuthenticationFilter.java index b4626e6..c898030 100644 --- a/src/main/java/ice/spot/security/filter/JwtAuthenticationFilter.java +++ b/src/main/java/ice/spot/security/filter/JwtAuthenticationFilter.java @@ -2,8 +2,8 @@ import ice.spot.constant.Constants; import ice.spot.dto.type.ERole; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import ice.spot.security.info.JwtUserInfo; import ice.spot.security.provider.JwtAuthenticationManager; import ice.spot.util.HeaderUtil; diff --git a/src/main/java/ice/spot/security/filter/JwtExceptionFilter.java b/src/main/java/ice/spot/security/filter/JwtExceptionFilter.java index 7a8cdb0..217b985 100644 --- a/src/main/java/ice/spot/security/filter/JwtExceptionFilter.java +++ b/src/main/java/ice/spot/security/filter/JwtExceptionFilter.java @@ -1,8 +1,8 @@ package ice.spot.security.filter; import ice.spot.constant.Constants; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.MalformedJwtException; diff --git a/src/main/java/ice/spot/security/handler/exception/CustomAccessDeniedHandler.java b/src/main/java/ice/spot/security/handler/exception/CustomAccessDeniedHandler.java index fa25844..b061379 100644 --- a/src/main/java/ice/spot/security/handler/exception/CustomAccessDeniedHandler.java +++ b/src/main/java/ice/spot/security/handler/exception/CustomAccessDeniedHandler.java @@ -1,6 +1,6 @@ package ice.spot.security.handler.exception; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; import ice.spot.security.info.AuthenticationResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/main/java/ice/spot/security/handler/exception/CustomAuthenticationEntryPointHandler.java b/src/main/java/ice/spot/security/handler/exception/CustomAuthenticationEntryPointHandler.java index df9e2af..54f4c0e 100644 --- a/src/main/java/ice/spot/security/handler/exception/CustomAuthenticationEntryPointHandler.java +++ b/src/main/java/ice/spot/security/handler/exception/CustomAuthenticationEntryPointHandler.java @@ -1,6 +1,6 @@ package ice.spot.security.handler.exception; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; import ice.spot.security.info.AuthenticationResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/src/main/java/ice/spot/security/handler/login/Oauth2FailureHandler.java b/src/main/java/ice/spot/security/handler/login/Oauth2FailureHandler.java index b9d2b5c..55b9d9a 100644 --- a/src/main/java/ice/spot/security/handler/login/Oauth2FailureHandler.java +++ b/src/main/java/ice/spot/security/handler/login/Oauth2FailureHandler.java @@ -1,6 +1,6 @@ package ice.spot.security.handler.login; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; import ice.spot.security.info.AuthenticationResponse; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; diff --git a/src/main/java/ice/spot/security/handler/logout/CustomLogoutResultHandler.java b/src/main/java/ice/spot/security/handler/logout/CustomLogoutResultHandler.java index 9b2cf4b..17c9924 100644 --- a/src/main/java/ice/spot/security/handler/logout/CustomLogoutResultHandler.java +++ b/src/main/java/ice/spot/security/handler/logout/CustomLogoutResultHandler.java @@ -1,6 +1,6 @@ package ice.spot.security.handler.logout; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; import ice.spot.security.info.AuthenticationResponse; import ice.spot.util.CookieUtil; import jakarta.servlet.ServletException; diff --git a/src/main/java/ice/spot/security/info/AuthenticationResponse.java b/src/main/java/ice/spot/security/info/AuthenticationResponse.java index 01d9076..44300f7 100644 --- a/src/main/java/ice/spot/security/info/AuthenticationResponse.java +++ b/src/main/java/ice/spot/security/info/AuthenticationResponse.java @@ -3,7 +3,7 @@ import ice.spot.constant.Constants; import ice.spot.dto.global.ExceptionDto; import ice.spot.dto.response.JwtTokenDto; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.ErrorCode; import ice.spot.util.CookieUtil; import jakarta.servlet.http.HttpServletResponse; import net.minidev.json.JSONValue; diff --git a/src/main/java/ice/spot/security/service/CustomUserDetailService.java b/src/main/java/ice/spot/security/service/CustomUserDetailService.java index 91ff7f5..94c8cfd 100644 --- a/src/main/java/ice/spot/security/service/CustomUserDetailService.java +++ b/src/main/java/ice/spot/security/service/CustomUserDetailService.java @@ -1,7 +1,7 @@ package ice.spot.security.service; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import ice.spot.repository.UserRepository; import ice.spot.security.info.UserPrincipal; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/ice/spot/service/AuthService.java b/src/main/java/ice/spot/service/AuthService.java index 0483a9e..e4a89bc 100644 --- a/src/main/java/ice/spot/service/AuthService.java +++ b/src/main/java/ice/spot/service/AuthService.java @@ -2,8 +2,8 @@ import ice.spot.domain.User; import ice.spot.dto.request.OauthSignUpDto; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import ice.spot.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/ice/spot/service/BoardingRecordService.java b/src/main/java/ice/spot/service/BoardingRecordService.java index 834de05..268f65f 100644 --- a/src/main/java/ice/spot/service/BoardingRecordService.java +++ b/src/main/java/ice/spot/service/BoardingRecordService.java @@ -1,26 +1,23 @@ package ice.spot.service; -import ice.spot.annotation.UserId; import ice.spot.domain.BoardingRecord; import ice.spot.domain.Image; import ice.spot.domain.ParkingLot; import ice.spot.domain.User; import ice.spot.dto.boardingrecord.request.BoardingRecordRequest; import ice.spot.dto.boardingrecord.response.BoardingRecordResponse; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import ice.spot.repository.BoardingRecordRepository; import ice.spot.repository.ImageRepository; import ice.spot.repository.ParkingLotRepository; import ice.spot.repository.UserRepository; -import ice.spot.security.service.CustomOauth2UserDetailService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.reactive.function.client.WebClient; -import java.util.IllformedLocaleException; import java.util.List; @Slf4j diff --git a/src/main/java/ice/spot/service/ImageService.java b/src/main/java/ice/spot/service/ImageService.java index 4a9df83..ea6ad90 100644 --- a/src/main/java/ice/spot/service/ImageService.java +++ b/src/main/java/ice/spot/service/ImageService.java @@ -4,12 +4,11 @@ import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectMetadata; import ice.spot.domain.Image; -import ice.spot.domain.ParkingLotResult; +import ice.spot.domain.type.ParkingLotResult; import ice.spot.dto.image.request.ImageCheckRequest; import ice.spot.dto.image.response.ImageResponse; -import ice.spot.dto.image.request.ImageSaveRequest; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import ice.spot.repository.ImageRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -35,24 +34,20 @@ public class ImageService { private final WebClient webClient; @Transactional - public Long saveImage(MultipartFile multipartFile) { + public Long saveImage(MultipartFile multipartFile) throws IOException { String originalName = multipartFile.getOriginalFilename(); Image image = new Image(originalName); String filename = image.getStoredName(); - try { - ObjectMetadata objectMetadata = new ObjectMetadata(); - objectMetadata.setContentType(multipartFile.getContentType()); - objectMetadata.setContentLength(multipartFile.getInputStream().available()); - - amazonS3Client.putObject(bucketName, filename, multipartFile.getInputStream(), objectMetadata); + ObjectMetadata objectMetadata = new ObjectMetadata(); + objectMetadata.setContentType(multipartFile.getContentType()); + objectMetadata.setContentLength(multipartFile.getInputStream().available()); - String accessUrl = amazonS3Client.getUrl(bucketName, filename).toString(); - image.setAccessUrl(accessUrl); - } catch(IOException e) { + amazonS3Client.putObject(bucketName, filename, multipartFile.getInputStream(), objectMetadata); - } + String accessUrl = amazonS3Client.getUrl(bucketName, filename).toString(); + image.setAccessUrl(accessUrl); ParkingLotResult parkingLotResult = checkImage(new ImageCheckRequest(image.getImageUrl())); if(parkingLotResult == ParkingLotResult.CORRECT_PARKING_LOT) { @@ -99,10 +94,4 @@ public ParkingLotResult checkImage(ImageCheckRequest imageCheckRequest) { return ParkingLotResult.NOT_FOUND_KICKBOARD; } } - - @Transactional - public void deleteImage() { - Image image = imageRepository.findById(2L).orElseThrow(); - imageRepository.delete(image); - } } \ No newline at end of file diff --git a/src/main/java/ice/spot/util/HeaderUtil.java b/src/main/java/ice/spot/util/HeaderUtil.java index 4484455..9b4cc54 100644 --- a/src/main/java/ice/spot/util/HeaderUtil.java +++ b/src/main/java/ice/spot/util/HeaderUtil.java @@ -1,7 +1,7 @@ package ice.spot.util; -import ice.spot.exeption.CommonException; -import ice.spot.exeption.ErrorCode; +import ice.spot.exception.CommonException; +import ice.spot.exception.ErrorCode; import jakarta.servlet.http.HttpServletRequest; import org.springframework.util.StringUtils;