diff --git a/operation-api/src/main/java/org/sopt/makers/operation/web/banner/api/BannerApiController.java b/operation-api/src/main/java/org/sopt/makers/operation/web/banner/api/BannerApiController.java index f0a18646..3e950e42 100644 --- a/operation-api/src/main/java/org/sopt/makers/operation/web/banner/api/BannerApiController.java +++ b/operation-api/src/main/java/org/sopt/makers/operation/web/banner/api/BannerApiController.java @@ -3,9 +3,11 @@ import lombok.RequiredArgsConstructor; import lombok.val; +import org.sopt.makers.operation.code.success.web.BannerSuccessCode; import org.sopt.makers.operation.dto.BaseResponse; import org.sopt.makers.operation.util.ApiResponseUtil; import org.sopt.makers.operation.web.banner.dto.request.BannerRequest; +import org.sopt.makers.operation.web.banner.dto.request.BannerRequest.BannerCreate; import org.sopt.makers.operation.web.banner.service.BannerService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -15,60 +17,68 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_CREATE_BANNER; import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_DELETE_BANNER; import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_GET_BANNER_DETAIL; +import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_GET_BANNER_IMAGE_PRE_SIGNED_URL; import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_GET_EXTERNAL_BANNERS; import org.springframework.web.bind.annotation.*; -import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_CREATE_BANNER; -import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_GET_BANNER_DETAIL; -import static org.sopt.makers.operation.code.success.web.BannerSuccessCode.SUCCESS_GET_BANNER_IMAGE_PRE_SIGNED_URL; - @RestController @RequestMapping("/api/v1/banners") @RequiredArgsConstructor public class BannerApiController implements BannerApi { - private final BannerService bannerService; - @Override - @GetMapping("/{bannerId}") - public ResponseEntity> getBannerDetail( - @PathVariable("bannerId") Long bannerId - ) { - val response = bannerService.getBannerDetail(bannerId); - return ApiResponseUtil.success(SUCCESS_GET_BANNER_DETAIL, response); - } + private final BannerService bannerService; + + @Override + @GetMapping("/{bannerId}") + public ResponseEntity> getBannerDetail( + @PathVariable("bannerId") Long bannerId + ) { + val response = bannerService.getBannerDetail(bannerId); + return ApiResponseUtil.success(SUCCESS_GET_BANNER_DETAIL, response); + } - @Override - @DeleteMapping("/{bannerId}") - public ResponseEntity> deleteBanner( - @PathVariable("bannerId") Long bannerId - ) { - bannerService.deleteBanner(bannerId); - return ApiResponseUtil.success(SUCCESS_DELETE_BANNER); - } + @Override + @DeleteMapping("/{bannerId}") + public ResponseEntity> deleteBanner( + @PathVariable("bannerId") Long bannerId + ) { + bannerService.deleteBanner(bannerId); + return ApiResponseUtil.success(SUCCESS_DELETE_BANNER); + } - @Override - @GetMapping("/images") - public ResponseEntity> getExternalBanners( - @RequestParam("image_type") String imageType, - @RequestParam("location") String location - ) { - return ApiResponseUtil.success(SUCCESS_GET_EXTERNAL_BANNERS, bannerService.getExternalBanners(imageType, location)); + @Override + @GetMapping("/images") + public ResponseEntity> getExternalBanners( + @RequestParam("image_type") String imageType, + @RequestParam("location") String location + ) { + return ApiResponseUtil.success(SUCCESS_GET_EXTERNAL_BANNERS, + bannerService.getExternalBanners(imageType, location)); + } - @Override - @GetMapping("/img/pre-signed") - public ResponseEntity> getIssuedPreSignedUrlForPutImage(@RequestParam("content-name") String contentName, @RequestParam("image-type") String imageType, - @RequestParam("image-extension") String imageExtension, @RequestParam("content-type") String contentType) { - val response = bannerService.getIssuedPreSignedUrlForPutImage(contentName, imageType, imageExtension, contentType); - return ApiResponseUtil.success(SUCCESS_GET_BANNER_IMAGE_PRE_SIGNED_URL, response); - } + @Override + @GetMapping("/img/pre-signed") + public ResponseEntity> getIssuedPreSignedUrlForPutImage( + @RequestParam("content-name") String contentName, + @RequestParam("image-type") String imageType, + @RequestParam("image-extension") String imageExtension, + @RequestParam("content-type") String contentType + ) { + val response = bannerService.getIssuedPreSignedUrlForPutImage(contentName, imageType, + imageExtension, contentType); + return ApiResponseUtil.success(SUCCESS_GET_BANNER_IMAGE_PRE_SIGNED_URL, response); + } - @PostMapping - @Override - public ResponseEntity> createBanner(@RequestBody BannerRequest.BannerCreate request) { - val response = bannerService.createBanner(request); - return ApiResponseUtil.success(SUCCESS_CREATE_BANNER, response); - } + @PostMapping + @Override + public ResponseEntity> createBanner( + @RequestBody BannerRequest.BannerCreate request + ) { + val response = bannerService.createBanner(request); + return ApiResponseUtil.success(SUCCESS_CREATE_BANNER, response); + } } diff --git a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java index 3d901e8c..c58d10a7 100644 --- a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java +++ b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -66,7 +67,7 @@ void getBannerDetail() throws Exception { this.mockMvc.perform( // when get("/api/v1/banners/" + MOCK_BANNER_ID) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .principal(mock(Principal.class))) // then .andExpect(status().isOk()) @@ -93,7 +94,7 @@ void deleteBanner() throws Exception { this.mockMvc.perform( //when delete("/api/v1/banners/" + MOCK_BANNER_ID) - .contentType(MediaType.APPLICATION_JSON) + .contentType(APPLICATION_JSON) .principal(mock(Principal.class))) //then @@ -112,8 +113,8 @@ void getExternalBanners() throws Exception { this.mockMvc.perform( // when get("/api/v1/banners/images") - .contentType(MediaType.APPLICATION_JSON) - .param("platform", imageType) + .contentType(APPLICATION_JSON) + .param("image_type", imageType) .param("location", location) .principal(mock(Principal.class))) // then diff --git a/operation-common/src/main/java/org/sopt/makers/operation/code/success/web/BannerSuccessCode.java b/operation-common/src/main/java/org/sopt/makers/operation/code/success/web/BannerSuccessCode.java index 48a66599..8c2f063f 100644 --- a/operation-common/src/main/java/org/sopt/makers/operation/code/success/web/BannerSuccessCode.java +++ b/operation-common/src/main/java/org/sopt/makers/operation/code/success/web/BannerSuccessCode.java @@ -12,7 +12,7 @@ public enum BannerSuccessCode implements SuccessCode { SUCCESS_GET_BANNER_DETAIL(HttpStatus.OK, "배너 상세 정보 조회 성공"), SUCCESS_DELETE_BANNER(HttpStatus. NO_CONTENT, "배너 삭제 성공"), - SUCCESS_GET_EXTERNAL_BANNERS(HttpStatus.OK, "외부 배너 조회 성공") + SUCCESS_GET_EXTERNAL_BANNERS(HttpStatus.OK, "외부 배너 조회 성공"), SUCCESS_GET_BANNER_IMAGE_PRE_SIGNED_URL(HttpStatus.OK, "이미지 업로드 pre signed url 조회에 성공했습니다"), SUCCESS_CREATE_BANNER(HttpStatus.CREATED, "배너 생성에 성공했습니다") ;