반응형
POSTMAN을 이용하여 테스트 진행(검색: postman)
https://www.postman.com/downloads/
처음으로 인텔리 J 실행시 에러 처리
에러 내용
Process 'command 'C:/Program Files/Java/jdk1.8.0_291/bin/java.exe'' finished with non-zero exit value 1
https://www.inflearn.com/questions/69450
컨트롤러 코드
package org.example.controller;
import lombok.AllArgsConstructor;
import org.example.model.TodoEntity;
import org.example.model.TodoRequest;
import org.example.model.TodoResponse;
import org.example.service.TodoService;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@CrossOrigin
@AllArgsConstructor
@RestController
@RequestMapping("/")
public class TodoController {
private final TodoService service;
@PostMapping
public ResponseEntity<TodoResponse> create(@RequestBody TodoRequest request) {
System.out.println("CREATE");
if (ObjectUtils.isEmpty(request.getTitle())){
return ResponseEntity.badRequest().build();
}
if (ObjectUtils.isEmpty(request.getOrder())){
request.setOrder(0L);
}
if (ObjectUtils.isEmpty(request.getCompleted())){
request.setCompleted(false);
}
TodoEntity result = this.service.add(request);
return ResponseEntity.ok(new TodoResponse(result));
}
@GetMapping("{id}")
public ResponseEntity<TodoResponse> readOne(@PathVariable Long id) {
System.out.println("READ ONE");
TodoEntity result = this.service.searchById(id);
return ResponseEntity.ok(new TodoResponse(result));
}
@GetMapping
public ResponseEntity<List<TodoResponse>> readAll() {
System.out.println("READ ALL");
List<TodoEntity> list = this.service.searchAll();
List<TodoResponse> responses = list.stream().map(TodoResponse::new).collect(Collectors.toList());
return ResponseEntity.ok(responses);
}
@PatchMapping("{id}")
public ResponseEntity<TodoResponse> update(@PathVariable Long id, @RequestBody TodoRequest request) {
System.out.println("UPDATE");
TodoEntity result = this.service.updateById(id, request);
return ResponseEntity.ok(new TodoResponse(result));
}
@DeleteMapping("{id}")
public ResponseEntity<?> deleteOne(@PathVariable Long id){
System.out.println("DELETE");
this.service.deleteById(id);
return ResponseEntity.ok().build();
}
@DeleteMapping
public ResponseEntity<?> deleteAll() {
System.out.println("DELETE ALL");
this.service.deleteAll();
return ResponseEntity.ok().build();
}
}
main 코드
package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TodoServerApplication {
public static void main(String[] args) {
// System.out.println("Hello Todo!");
SpringApplication.run(TodoServerApplication.class, args);
}
}
포스트 맨을 이용하여 확인
로그가 찍히는 것을 확인
todolist 확인
Reference Specs for Todo-Backend (todobackend.com)
페이지에서 확인
Todo-Backend client (todobackend.com)
밑줄친 곳에 본인의 서버 정보를 입력(포트번호)
로그 확인
반응형
'IntelliJ' 카테고리의 다른 글
인텔리제이로 리펙터링 하기 (0) | 2021.06.05 |
---|---|
테스트 코드 작성 (0) | 2021.06.05 |
TodoList 구현 (서비스 코드 구현) (0) | 2021.05.30 |
TodoList 구현 (repository 구현) (0) | 2021.05.30 |
TodoList 구현 (모델) (0) | 2021.05.30 |