forked from java-lesson-cbnu/android-lesson-06
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDataEndpoint.java
More file actions
42 lines (35 loc) · 1.93 KB
/
UserDataEndpoint.java
File metadata and controls
42 lines (35 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package kr.easw.lesson06.controller;
import kr.easw.lesson06.model.dto.RemoveUserDto;
import kr.easw.lesson06.service.UserDataService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
// @RestController 어노테이션을 사용하여 이 클래스가 REST 컨트롤러임을 선언합니다.
@RestController
// @RequestMapping 어노테이션을 사용하여 이 클래스의 기반 엔드포인트를 /api/v1/data로 설정합니다.
@RequestMapping("/api/v1/user")
// final로 지정된 모든 필드를 파라미터로 가지는 생성자를 생성합니다.
@RequiredArgsConstructor
public class UserDataEndpoint {
// 원래대로라면 리스트를 통해 JSON에서 사용할 수 있는 형태로 변환해야 하지만, 이번 실습에서는 건너뜁니다.
private final UserDataService userDataService;
@GetMapping("/list")
public List<String> listUsers() {
throw new RuntimeException("이곳에 유저 목록을 반환하는 코드를 작성하십시오.");
return userDataService.userList();
}
// 원래대로라면 리스트를 통해 JSON에서 사용할 수 있는 형태로 변환해야 하지만, 이번 실습에서는 건너뜁니다.
@PostMapping("/remove")
public ResponseEntity<String> removeUser() {
throw new RuntimeException("이곳에 유저를 삭제하는 코드를 작성하십시오.");
public ResponseEntity<String> removeUser(@RequestBody RemoveUserDto removeUser) {
userDataService.deleteUser(removeUser.getUserId());
return ResponseEntity.ok().body(removeUser.getUserId());
}
}
}