-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
39 deletions.
There are no files selected for viewing
36 changes: 32 additions & 4 deletions
36
src/main/java/com/spoony/spoony_server/domain/post/controller/PostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,58 @@ | ||
package com.spoony.spoony_server.domain.post.controller; | ||
|
||
import com.spoony.spoony_server.common.dto.ResponseDTO; | ||
import com.spoony.spoony_server.domain.post.dto.PostCreateDTO; | ||
import com.spoony.spoony_server.domain.post.dto.request.PostCreateRequestDTO; | ||
import com.spoony.spoony_server.domain.post.dto.response.PostResponseDTO; | ||
import com.spoony.spoony_server.domain.post.service.PostService; | ||
import com.spoony.spoony_server.infra.service.AwsFileService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/post") | ||
@RequiredArgsConstructor | ||
public class PostController { | ||
|
||
private final PostService postService; | ||
private final AwsFileService awsFileService; | ||
|
||
@GetMapping("/{postId}") | ||
public ResponseEntity<ResponseDTO<PostResponseDTO>> getPost(@PathVariable Long postId) { | ||
PostResponseDTO postResponse = postService.getPostById(postId); | ||
return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.success(postResponse)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ResponseDTO<Void>> createPost(@RequestBody PostCreateRequestDTO postCreateRequestDTO) { | ||
postService.createPost(postCreateRequestDTO); | ||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
public ResponseEntity<ResponseDTO<Void>> createPost( | ||
@RequestPart("data") PostCreateRequestDTO postCreateRequestDTO, | ||
@RequestPart("photos") List<MultipartFile> photos | ||
) throws IOException { | ||
List<String> photoUrlList = awsFileService.savePostImages(photos); | ||
|
||
PostCreateDTO updatedPostCreateDTO = new PostCreateDTO( | ||
postCreateRequestDTO.userId(), | ||
postCreateRequestDTO.title(), | ||
postCreateRequestDTO.description(), | ||
postCreateRequestDTO.placeName(), | ||
postCreateRequestDTO.placeAddress(), | ||
postCreateRequestDTO.placeRoadAddress(), | ||
postCreateRequestDTO.latitude(), | ||
postCreateRequestDTO.longitude(), | ||
postCreateRequestDTO.categoryId(), | ||
postCreateRequestDTO.menuList(), | ||
photoUrlList | ||
); | ||
|
||
postService.createPost(updatedPostCreateDTO); | ||
|
||
return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.success(null)); | ||
return ResponseEntity.ok(ResponseDTO.success(null)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/spoony/spoony_server/domain/post/dto/PostCreateDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.spoony.spoony_server.domain.post.dto; | ||
|
||
import java.util.List; | ||
|
||
public record PostCreateDTO(Long userId, | ||
String title, | ||
String description, | ||
String placeName, | ||
String placeAddress, | ||
String placeRoadAddress, | ||
Double latitude, | ||
Double longitude, | ||
Long categoryId, | ||
List<String> menuList, | ||
List<String> photoUrlList) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters