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

Fix: 디렉토리 경로 수정 #24

Merged
merged 1 commit into from
May 7, 2024
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
Expand Up @@ -10,6 +10,8 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ice/spot/domain/BoardingRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ice/spot/domain/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class Image {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "origin_name")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ice.spot.domain;
package ice.spot.domain.type;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ice/spot/dto/global/ExceptionDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ice.spot.dto.global;

import ice.spot.exeption.ErrorCode;
import ice.spot.exception.ErrorCode;

public record ExceptionDto(
Integer code,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ice/spot/dto/global/ResponseDto.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ice.spot.exeption;
package ice.spot.exception;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ice.spot.exeption;
package ice.spot.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ice.spot.exeption;
package ice.spot.exception;

import ice.spot.dto.global.ResponseDto;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ice/spot/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/ice/spot/service/BoardingRecordService.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 10 additions & 21 deletions src/main/java/ice/spot/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/main/java/ice/spot/util/HeaderUtil.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down