diff --git a/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/PostController.java b/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/PostController.java index 2758881..1a7aed8 100644 --- a/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/PostController.java +++ b/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/PostController.java @@ -28,7 +28,7 @@ public PostController(PostService postService) { @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity postSave( @RequestPart("post") PostSaveReqDto postSaveReqDto, - @RequestPart("imgUrl") MultipartFile imgUrl, + @RequestPart(value = "imgUrl", required = false) MultipartFile imgUrl, Principal principal) throws IOException { postService.postSave(postSaveReqDto, imgUrl, principal); return new ResponseEntity<>("Successful Post Save", HttpStatus.CREATED); diff --git a/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/response/PostInfoResDto.java b/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/response/PostInfoResDto.java index 16f8600..019c970 100644 --- a/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/response/PostInfoResDto.java +++ b/src/main/java/net/skhu/likelion12thteam03be/post/api/dto/response/PostInfoResDto.java @@ -12,6 +12,7 @@ @Builder public record PostInfoResDto( Long postId, + String nickname, String title, String content, String imgUrl, @@ -26,6 +27,7 @@ public record PostInfoResDto( public static PostInfoResDto from(Post post) { return PostInfoResDto.builder() .postId(post.getPostId()) + .nickname(post.getUser().getNickname()) .title(post.getTitle()) .content(post.getContent()) .location(post.getLocation()) diff --git a/src/main/java/net/skhu/likelion12thteam03be/post/application/PostService.java b/src/main/java/net/skhu/likelion12thteam03be/post/application/PostService.java index dc6fdda..f49ad24 100644 --- a/src/main/java/net/skhu/likelion12thteam03be/post/application/PostService.java +++ b/src/main/java/net/skhu/likelion12thteam03be/post/application/PostService.java @@ -41,11 +41,17 @@ public class PostService { private final UserRepository userRepository; @Transactional - public void postSave(PostSaveReqDto postSaveReqDto, @RequestPart(required = false) MultipartFile multipartFile, Principal principal) throws IOException { + public void postSave(PostSaveReqDto postSaveReqDto, @RequestPart(required = false) MultipartFile multipartFile, Principal principal) { String loginId = principal.getName(); - String imgUrl = s3Service.upload(multipartFile, "post"); - +// String imgUrl = s3Service.upload(multipartFile, "post"); + String imgUrl = null; + try { + imgUrl = (multipartFile == null) ? s3Service.upload(multipartFile, "post") : null; + } catch (IOException e) { + imgUrl = null; + } + User user = userRepository.findByLoginId(loginId) .orElseThrow(() -> new IllegalArgumentException("해당 유저가 존재하지 않습니다. loginId = " + loginId)); diff --git a/src/main/java/net/skhu/likelion12thteam03be/post/domain/Post.java b/src/main/java/net/skhu/likelion12thteam03be/post/domain/Post.java index 4783ba2..0011bbc 100644 --- a/src/main/java/net/skhu/likelion12thteam03be/post/domain/Post.java +++ b/src/main/java/net/skhu/likelion12thteam03be/post/domain/Post.java @@ -1,5 +1,6 @@ package net.skhu.likelion12thteam03be.post.domain; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -52,7 +53,8 @@ public class Post extends Time { private User user; @Builder - public Post(String title, String content, Location location, Integer time, Integer price, Category category, List moods, String imgUrl, User user) { + public Post(User user, String title, String content, Location location, Integer time, Integer price, Category category, List moods, String imgUrl) { + this.user = user; this.title = title; this.content = content; this.location = location; @@ -61,7 +63,6 @@ public Post(String title, String content, Location location, Integer time, Integ this.category = category; this.moods = moods; this.imgUrl = imgUrl; - this.user = user; } public void update(Location location, Category category, PostUpdateReqDto postUpdateReqDto, List moods, String imgUrl) {