Skip to content

Commit

Permalink
Merge pull request #59 from Leets-Official/refactor/#57/스웨거-로깅
Browse files Browse the repository at this point in the history
Refactor # 59 스웨거 파일 업로딩 추가
  • Loading branch information
hyxklee authored Oct 24, 2024
2 parents 59e3f28 + 78a4e9e commit 81b4e9e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import leets.weeth.domain.account.application.usecase.ReceiptUseCase;
import leets.weeth.global.common.response.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -17,7 +18,7 @@ public class ReceiptAdminController {

private final ReceiptUseCase receiptUseCase;

@PostMapping
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<Void> save(@RequestPart @Valid ReceiptDTO.Save dto, @RequestPart(required = false) List<MultipartFile> images) {
receiptUseCase.save(dto, images);
return CommonResponse.createSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import leets.weeth.domain.user.application.exception.UserNotMatchException;
import leets.weeth.global.common.response.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -22,15 +23,15 @@ public class NoticeAdminController {

private final NoticeUsecase noticeUsecase;

@PostMapping
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> save(@RequestPart @Valid NoticeDTO.Save dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@Parameter(hidden = true) @CurrentUser Long userId) {
noticeUsecase.save(dto, files, userId);
return CommonResponse.createSuccess(NOTICE_CREATED_SUCCESS.getMessage());
}

@PatchMapping("/{noticeId}")
@PatchMapping(value = "/{noticeId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> update(@PathVariable Long noticeId,
@RequestPart @Valid NoticeDTO.Update dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import leets.weeth.domain.user.application.exception.UserNotMatchException;
import leets.weeth.global.common.response.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -21,7 +22,7 @@ public class PostController {

private final PostUsecase postUsecase;

@PostMapping
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> save(@RequestPart @Valid PostDTO.Save dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@CurrentUser Long userId) {
Expand All @@ -39,7 +40,7 @@ public CommonResponse<PostDTO.Response> findPost(@PathVariable Long postId) {
return CommonResponse.createSuccess(postUsecase.findPost(postId));
}

@PatchMapping("/{postId}")
@PatchMapping(value = "/{postId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> update(@PathVariable Long postId,
@RequestPart @Valid PostDTO.Update dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package leets.weeth.global.config.swagger;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import java.lang.reflect.Type;

@Component
public class OctetStreamReadMsgConverter extends AbstractJackson2HttpMessageConverter {
@Autowired
public OctetStreamReadMsgConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

// 기존 application/octet-stream 타입을 쓰기로 다루는 메시지 컨버터가 이미 존재 (ByteArrayHttpMessageConverter)
// 따라서 해당 컨버터는 쓰기 작업에는 이용하면 안됨
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package leets.weeth.global.config;
package leets.weeth.global.config.swagger;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
Expand Down

0 comments on commit 81b4e9e

Please sign in to comment.