Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: create 코드 수정 #64

Merged
merged 1 commit into from
Jan 8, 2024
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 @@ -20,8 +20,10 @@
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.net.URI;
import java.util.List;

@Tag(name = "ClubPost API", description = "동아리/학회 관련 API입니다.")
Expand Down Expand Up @@ -72,11 +74,11 @@ public ResponseEntity<?> createClubPost(@CurrentUser UserPrincipal userPrincipal
@Valid @RequestPart ClubPostReq clubPostReq,
@RequestPart("images") List<MultipartFile> images) throws IOException {
Long clubPostId = clubPostService.createClubPost(userPrincipal.getId(), clubPostReq, images);
ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(clubPostId)
.build();
return ResponseEntity.ok(apiResponse);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(clubPostId)
.toUri();
return ResponseEntity.created(location).build();
}

// 글 수정하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class IdeaPostService {
private final RedisTemplate<String, String> redisTemplate;

@Transactional
public ResponseEntity<?> resisterIdea(UserPrincipal userPrincipal, ResisterIdeaReq resisterIdeaReq){
public Long resisterIdea(UserPrincipal userPrincipal, ResisterIdeaReq resisterIdeaReq){
User user = userRepository.findById(userPrincipal.getId()).get();
IdeaPost ideapost = IdeaPost.builder()
.title(resisterIdeaReq.getTitle())
Expand All @@ -54,13 +54,7 @@ public ResponseEntity<?> resisterIdea(UserPrincipal userPrincipal, ResisterIdeaR

ideaPostRepository.save(ideapost);

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(ideapost.getId())
.message("아이디어를 만들었어요!")
.build();

return ResponseEntity.ok(apiResponse);
return ideapost.getId();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;

@RequiredArgsConstructor
@RestController
Expand All @@ -38,7 +41,13 @@ public class IdeaPostController {
ResponseEntity<?> resisterIdea(@Parameter(description = "Access Token을 입력해주세요.", required = true)
@CurrentUser UserPrincipal userPrincipal,
@Valid @RequestBody ResisterIdeaReq resisterIdeaReq){
return ideaPostService.resisterIdea(userPrincipal, resisterIdeaReq);

Long id = ideaPostService.resisterIdea(userPrincipal, resisterIdeaReq);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(id)
.toUri();
return ResponseEntity.created(location).build();
}

@Operation(summary = "글 전체 조회", description = "아이디어의 글을 정렬하여 조회한다.")
Expand Down