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

[refactor] 여행 TODO 생성 API 리팩터링 #39

Merged
merged 3 commits into from
Jan 9, 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 @@ -8,19 +8,21 @@
import org.doorip.trip.service.TodoService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@RequiredArgsConstructor
@RequestMapping("/api/todos")
@RequestMapping("/api/trips")
@Controller
public class TodoApiController {
private final TodoService todoService;

@PostMapping
public ResponseEntity<ApiResponse<?>> createTripTodo(@RequestBody final TodoCreateRequest request) {
todoService.createTripTodo(request);
@PostMapping("/{tripId}/todos")
public ResponseEntity<ApiResponse<?>> createTripTodo(@PathVariable final Long tripId,
@RequestBody final TodoCreateRequest request) {
todoService.createTripTodo(tripId, request);
return ApiResponseUtil.success(SuccessMessage.CREATED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;

public record TodoCreateRequest(
Long tripId,
String title,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDate endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class TodoService {
private final ParticipantRepository participantRepository;
private final TodoRepository todoRepository;

public void createTripTodo(TodoCreateRequest request) {
public void createTripTodo(Long tripId, TodoCreateRequest request) {
validateAllocators(request.allocators());
Trip findTrip = getTrip(request.tripId());
Trip findTrip = getTrip(tripId);
Todo todo = createTodo(request, findTrip);
createAllocators(request.allocators(), todo);
todoRepository.save(todo);
Expand Down