Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -40,13 +41,18 @@ public class PostController {
@ApiErrorCodeExample(ErrorStatus.class)
public ResponseEntity<PostResponseDto> createPost(
@RequestPart("dto") String dtoJson,
@RequestPart("images") List<MultipartFile> images) {
@RequestPart("images") List<MultipartFile> images,
HttpServletRequest request) {

if (images == null || images.size() != 2) {
throw new IllegalArgumentException("이미지는 반드시 2개 업로드해야 합니다.");
}

System.out.println(images.size());
HttpSession session = request.getSession(false);
User user = (User) session.getAttribute("user");
if (user == null) {
throw new GeneralException(ErrorStatus._UNAUTHORIZED, "로그인한 유저가 없습니다.");
}

PostRequestDto dto;

Expand All @@ -57,7 +63,7 @@ public ResponseEntity<PostResponseDto> createPost(
throw new RuntimeException("JSON 파싱 실패", e);
}

PostResponseDto response = postService.createPost(dto, images);
PostResponseDto response = postService.createPost(dto, images, user);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class PostRequestDto {
private Long userId;
// private Long userId;
private String title;
private String content;
private String place;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public class PostService {
private final PinRepository pinRepository;

@Transactional
public PostResponseDto createPost(PostRequestDto dto, List<MultipartFile> images) {
public PostResponseDto createPost(PostRequestDto dto, List<MultipartFile> images, User user) {
try {
User user = userRepository.findById(dto.getUserId())
.orElseThrow(() -> new GeneralException(ErrorStatus._NOT_FOUND, "해당 유저를 찾을 수 없습니다."));

Pin pin = Pin.builder()
.latitude(dto.getLatitude())
Expand Down