Skip to content

Commit

Permalink
feat: 유저 API 응답 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
woosung1223 committed Jun 30, 2024
1 parent 7e2893a commit c22cd30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package slvtwn.khu.toyouserver.common;

// TODO: 효율적인 예외처리 Wrapping 과정에 대해 고민
public record ToyouResponse<T>(String code, T data) {

public static <T> ToyouResponse<T> success(T data) {
return new ToyouResponse<>("SUCCESS", data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package slvtwn.khu.toyouserver.user.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import slvtwn.khu.toyouserver.common.ToyouResponse;
import slvtwn.khu.toyouserver.user.dto.UserResponse;
import slvtwn.khu.toyouserver.user.service.UserService;

@RequiredArgsConstructor
@RestController
public class UserController {

private final UserService userService;

@GetMapping("/users/{userId}")
public ToyouResponse<UserResponse> findUser(@PathVariable Long userId) {
UserResponse userResponse = userService.findUser(userId);

return ToyouResponse.success(userResponse);
}
}

0 comments on commit c22cd30

Please sign in to comment.