Skip to content

Commit

Permalink
fix: imgUrl ์˜ค๋ฅ˜
Browse files Browse the repository at this point in the history
  • Loading branch information
firefox1234123 committed Aug 6, 2024
1 parent 6971798 commit a65d461
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PostController(PostService postService) {
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Builder
public record PostInfoResDto(
Long postId,
String nickname,
String title,
String content,
String imgUrl,
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Mood> moods, String imgUrl, User user) {
public Post(User user, String title, String content, Location location, Integer time, Integer price, Category category, List<Mood> moods, String imgUrl) {
this.user = user;
this.title = title;
this.content = content;
this.location = location;
Expand All @@ -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<Mood> moods, String imgUrl) {
Expand Down

0 comments on commit a65d461

Please sign in to comment.