Skip to content

Commit

Permalink
Merge pull request #53 from Leets-Official/feature/#52-post-image-upl…
Browse files Browse the repository at this point in the history
…oad-api

Feature: 단일 이미지 업로드 API
  • Loading branch information
codingmy authored Nov 9, 2024
2 parents 3657820 + 5c7eee6 commit cf1ff00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package land.leets.Carrot.domain.post.controller;

import static land.leets.Carrot.domain.user.controller.ResponseMessage.IMAGE_UPLOAD_SUCCESS;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import land.leets.Carrot.domain.apply.dto.response.GetAppliedListResponse;
import land.leets.Carrot.domain.career.service.WorkTypeService;
import land.leets.Carrot.domain.image.service.S3ImageService;
import land.leets.Carrot.domain.post.dto.request.GetPostedPostRequest;
import land.leets.Carrot.domain.post.dto.request.PostPostImageRequest;
import land.leets.Carrot.domain.post.dto.request.PostPostRequest;
import land.leets.Carrot.domain.post.dto.response.PostAImageUrlResponse;
import land.leets.Carrot.domain.post.dto.response.PostImageUrlResponse;
import land.leets.Carrot.domain.post.dto.response.PostResponse;
import land.leets.Carrot.domain.post.dto.response.PostedPostResponse;
import land.leets.Carrot.domain.post.dto.response.ShortPostResponse;
import land.leets.Carrot.domain.post.dto.response.WorkTypeResponse;
import land.leets.Carrot.domain.post.service.PostService;
import land.leets.Carrot.global.auth.annotation.CurrentUser;
import land.leets.Carrot.global.common.response.ResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -23,8 +30,10 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "PostController", description = "게시글 관련 controller")
Expand All @@ -33,6 +42,7 @@
public class PostController {
private final PostService postService;
private final WorkTypeService workTypeService;
private final S3ImageService s3ImageService;

@PostMapping
public ResponseEntity<Void> postNewPost(@RequestBody @Valid PostPostRequest requestBody) {
Expand Down Expand Up @@ -90,6 +100,20 @@ public ResponseEntity<PostImageUrlResponse> postPostImages(@RequestPart PostPost
return ResponseEntity.ok(postService.getImageUrlList(requestBody));
}

//게시글 복수 이미지 업로드 API미작동시 이미지 업로드 단일 API 대용 구현
@PostMapping("/upload-post-image")
@Operation(summary = "게시글 단일 이미지 업로드")
public ResponseEntity<ResponseDto<PostAImageUrlResponse>> uploadProfileImage(
@RequestParam("image") MultipartFile image,
@Parameter(hidden = true) @CurrentUser Long userId) {
String imageUrl = s3ImageService.uploadImage(image, "post-images");

return ResponseEntity.ok(
ResponseDto.response(IMAGE_UPLOAD_SUCCESS.getCode(),
IMAGE_UPLOAD_SUCCESS.getMessage(), new PostAImageUrlResponse(imageUrl))
);
}

@GetMapping("/post/applied/{userId}")
public ResponseEntity<ResponseDto<GetAppliedListResponse>> getAppliedList(
@PathVariable Long userId){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package land.leets.Carrot.domain.post.dto.response;

public record PostAImageUrlResponse(
String imageUrl
) {
}

0 comments on commit cf1ff00

Please sign in to comment.