Skip to content

Commit

Permalink
Merge pull request #224 from Review-zip/refactor/#223-image-upload
Browse files Browse the repository at this point in the history
[Refactor] image upload 토큰 인증 추가
  • Loading branch information
yoondaeng authored Feb 15, 2024
2 parents a226e5b + cb4e236 commit b4a6ff2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.ReviewZIP.domain.image;

import com.example.ReviewZIP.domain.image.dto.response.UploadImageResponseDto;
import com.example.ReviewZIP.domain.image.dto.response.ImageResponseDto;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -9,8 +9,8 @@
@Component
public class ImageConverter {

public static UploadImageResponseDto toUploadImageDto(List<Images> imagesList) {
public static ImageResponseDto toUploadImageDto(List<Images> imagesList) {
List<Long> imageIds = imagesList.stream().map(Images::getId).collect(Collectors.toList());
return new UploadImageResponseDto(imageIds);
return new ImageResponseDto(imageIds);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.example.ReviewZIP.domain.image;

import com.example.ReviewZIP.domain.image.dto.response.UploadImageResponseDto;
import com.example.ReviewZIP.domain.image.dto.response.ImageResponseDto;
import com.example.ReviewZIP.domain.user.UsersService;
import com.example.ReviewZIP.global.response.ApiResponse;
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.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -17,16 +21,18 @@
@RequestMapping("/v1/images")
public class ImagesController {
private final ImagesService imageService;
private final UsersService usersService;

@PostMapping("/users/{userId}")
@Operation(summary = "이미지 업로드 API", description = "UploadImageResponseDto 사용")
@PostMapping(path = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "파일 업로드 API", description = "UploadImageResponseDto 사용")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE402", description = "이미지 업로드 실패",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<UploadImageResponseDto> uploadImage(@PathVariable(name="userId") Long userId, @RequestParam("fileList") List<MultipartFile> fileList){
public ApiResponse<ImageResponseDto> uploadImage(@AuthenticationPrincipal UserDetails user, @RequestParam("fileList") List<MultipartFile> fileList){
Long userId = usersService.getUserId(user);
List<Images> imageList = imageService.uploadImage(fileList, userId);
UploadImageResponseDto imageResponseDto = ImageConverter.toUploadImageDto(imageList);
ImageResponseDto imageResponseDto = ImageConverter.toUploadImageDto(imageList);
return ApiResponse.onSuccess(imageResponseDto);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UploadImageResponseDto {
public class ImageResponseDto {
public List<Long> imageIds;
}

0 comments on commit b4a6ff2

Please sign in to comment.