Skip to content

Commit

Permalink
임시 저장 수정 API 추가 및 응답 리팩토링 완료 (#211)
Browse files Browse the repository at this point in the history
* feat : 공유페이지 임시저장을 위한 'updatePending' 메서드 추가 (#210)

* refactor : 멀티파트 포함하는 저장, 임시저장 API 추가 및 응답 리팩토링 (#210)
  • Loading branch information
dpdmstjs authored Oct 26, 2023
1 parent 9698703 commit dd478b6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.javajober.spaceWall.controller;

import com.javajober.core.exception.ApiStatus;
import com.javajober.core.security.JwtTokenizer;
import com.javajober.core.util.file.FileImageService;
import com.javajober.core.message.SuccessMessage;
import com.javajober.core.util.ApiUtils;
import com.javajober.core.util.response.ApiResponse;
import com.javajober.spaceWall.domain.FlagType;
import com.javajober.spaceWall.filedto.SpaceWallSaveRequest;
import com.javajober.spaceWall.dto.response.SpaceWallSaveResponse;
import com.javajober.spaceWall.filedto.SpaceWallUpdateRequest;
import com.javajober.spaceWall.service.FileUploadService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -33,7 +32,7 @@ public FileUploadController(final FileImageService fileImageService, final FileU
}

@PostMapping(path = "/wall/file", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> save(@RequestPart(value = "data") final SpaceWallSaveRequest spaceWallSaveRequest,
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> save(@RequestPart(value = "data") final SpaceWallSaveRequest spaceWallSaveRequest,
@RequestPart(value = "fileName") List<MultipartFile> files,
@RequestPart(value = "backgroundImgURL", required = false) MultipartFile backgroundImgURL,
@RequestPart(value = "wallInfoImgURL", required = false) MultipartFile wallInfoImgURL,
Expand All @@ -45,11 +44,27 @@ public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> save(@Request
fileImageService.checkImageFileSize(backgroundImgURL, wallInfoImgURL, styleImgURL);
SpaceWallSaveResponse data = fileUploadService.save(memberId, spaceWallSaveRequest, FlagType.SAVED, files, backgroundImgURL, wallInfoImgURL, styleImgURL);

return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_SAVE_SUCCESS, data));
return ApiResponse.response(ApiStatus.OK, "공유페이지 저장이 완료되었습니다.", data);
}

@PostMapping(path = "wall-temporary/file", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> savePending(@RequestPart(value = "data") final SpaceWallSaveRequest spaceWallSaveRequest,
@RequestPart(value = "fileName") List<MultipartFile> files,
@RequestPart(value = "backgroundImgURL", required = false) MultipartFile backgroundImgURL,
@RequestPart(value = "wallInfoImgURL", required = false) MultipartFile wallInfoImgURL,
@RequestPart(value = "styleImgURL", required = false) MultipartFile styleImgURL,
@RequestHeader("Authorization") String token) {

Long memberId = jwtTokenizer.getUserIdFromToken(token);
fileImageService.validatePdfFile(files);
fileImageService.checkImageFileSize(backgroundImgURL, wallInfoImgURL, styleImgURL);
SpaceWallSaveResponse data = fileUploadService.save(memberId, spaceWallSaveRequest, FlagType.PENDING, files, backgroundImgURL, wallInfoImgURL, styleImgURL);

return ApiResponse.response(ApiStatus.OK, "공유페이지 임시저장이 완료되었습니다.", data);
}

@PutMapping(path = "/wall/file", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> update(@RequestPart(value = "data") final SpaceWallUpdateRequest spaceWallRequest,
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> update(@RequestPart(value = "data") final SpaceWallUpdateRequest spaceWallRequest,
@RequestPart(value = "fileName") List<MultipartFile> files,
@RequestPart(value = "backgroundImgURL", required = false) MultipartFile backgroundImgURL,
@RequestPart(value = "wallInfoImgURL", required = false) MultipartFile wallInfoImgURL,
Expand All @@ -61,7 +76,22 @@ public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> update(@Reque
fileImageService.checkImageFileSize(backgroundImgURL, wallInfoImgURL, styleImgURL);
SpaceWallSaveResponse data = fileUploadService.update(memberId, spaceWallRequest, FlagType.SAVED, files, backgroundImgURL, wallInfoImgURL, styleImgURL);

return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.CREATE_SUCCESS, data));
return ApiResponse.response(ApiStatus.OK, "공유페이지 수정이 완료되었습니다.", data);
}

@PutMapping(path = "wall-temporary/file", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> updatePending(@RequestPart(value = "data") final SpaceWallUpdateRequest spaceWallRequest,
@RequestPart(value = "fileName") List<MultipartFile> files,
@RequestPart(value = "backgroundImgURL", required = false) MultipartFile backgroundImgURL,
@RequestPart(value = "wallInfoImgURL", required = false) MultipartFile wallInfoImgURL,
@RequestPart(value = "styleImgURL", required = false) MultipartFile styleImgURL,
@RequestHeader("Authorization") String token){

Long memberId = jwtTokenizer.getUserIdFromToken(token);
fileImageService.validatePdfFile(files);
fileImageService.checkImageFileSize(backgroundImgURL, wallInfoImgURL, styleImgURL);
SpaceWallSaveResponse data = fileUploadService.update(memberId, spaceWallRequest, FlagType.PENDING, files, backgroundImgURL, wallInfoImgURL, styleImgURL);

return ApiResponse.response(ApiStatus.OK, "공유페이지 임시저장이 완료되었습니다.", data);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.javajober.spaceWall.controller;

import com.javajober.core.message.SuccessMessage;
import com.javajober.core.security.JwtTokenizer;
import com.javajober.core.util.response.ApiResponse;
import com.javajober.core.util.ApiUtils;
import com.javajober.core.exception.ApiStatus;
import com.javajober.spaceWall.domain.FlagType;
import com.javajober.spaceWall.dto.request.IsPublicUpdateRequest;
Expand All @@ -16,7 +14,6 @@
import com.javajober.spaceWall.service.SpaceWallFindService;
import com.javajober.spaceWall.service.SpaceWallService;
import com.javajober.spaceWall.service.SpaceWallTemporaryService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -102,31 +99,41 @@ public ResponseEntity<ApiResponse.Response<DuplicateURLResponse>> hasDuplicateSh
}

@PutMapping("/wall")
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> update(@RequestHeader("Authorization") String token, @RequestBody final SpaceWallStringUpdateRequest spaceWallUpdateRequest){
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> update(@RequestHeader("Authorization") String token, @RequestBody final SpaceWallStringUpdateRequest spaceWallUpdateRequest){

Long memberId = jwtTokenizer.getUserIdFromToken(token);

SpaceWallSaveResponse data = spaceWallService.update(memberId, spaceWallUpdateRequest, FlagType.SAVED);

return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.CREATE_SUCCESS, data));
return ApiResponse.response(ApiStatus.OK, "공유페이지 수정이 완료되었습니다.", data);
}

@DeleteMapping("/wall-temporary/{spaceId}")
public ResponseEntity<ApiResponse.MessageResponse> deleteTemporary(@PathVariable Long spaceId, @RequestHeader("Authorization") String token) {
@PutMapping(path = "/wall-temporary")
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> updatePending(@RequestHeader("Authorization") String token, @RequestBody final SpaceWallStringUpdateRequest spaceWallUpdateRequest) {

Long memberId = jwtTokenizer.getUserIdFromToken(token);
spaceWallTemporaryService.delete(memberId, spaceId);

return ApiResponse.messageResponse(ApiStatus.OK, "공유페이지 임시 저장 삭제를 성공했습니다.");
SpaceWallSaveResponse data = spaceWallService.update(memberId, spaceWallUpdateRequest, FlagType.PENDING);

return ApiResponse.response(ApiStatus.OK, "공유페이지 임시저장이 완료되었습니다.", data);
}

@PutMapping("/wall/public")
public ResponseEntity<ApiResponse.MessageResponse> updateIsPublic(@RequestBody IsPublicUpdateRequest isPublicUpdateRequest,
@RequestHeader("Authorization") String token) {
@RequestHeader("Authorization") String token) {

Long memberId = jwtTokenizer.getUserIdFromToken(token);
spaceWallService.updateIsPublic(isPublicUpdateRequest, memberId);

return ApiResponse.messageResponse(ApiStatus.OK, "외부 공개 여부가 업데이트 되었습니다.");
}

@DeleteMapping("/wall-temporary/{spaceId}")
public ResponseEntity<ApiResponse.MessageResponse> deleteTemporary(@PathVariable Long spaceId, @RequestHeader("Authorization") String token) {

Long memberId = jwtTokenizer.getUserIdFromToken(token);
spaceWallTemporaryService.delete(memberId, spaceId);

return ApiResponse.messageResponse(ApiStatus.OK, "공유페이지 임시 저장 삭제를 성공했습니다.");
}
}

0 comments on commit dd478b6

Please sign in to comment.