현재 구현할 기능
현재 상황
MockHttpServletRequest:
HTTP Method = GET
Request URI = /v1/users
Parameters = {page=[1], size=[10]}
Headers = [Content-Type:"application/json;charset=UTF-8"]
Body = null
Session Attrs = {}
Handler:
Type = com.example.projectPrac.v1.user.controller.UserController
Method = com.example.projectPrac.v1.user.controller.UserController#getUsers(int, int)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = org.springframework.web.HttpMediaTypeNotAcceptableException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 406
Error message = null
Headers = []
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
@GetMapping
public ResponseEntity getUsers(@Positive @RequestParam int page,
@Positive @RequestParam int size){
Page<User> users = userService.findUsers(page-1, size);
List<UserDto.Response> data = mapper.usersToUsersResponseDtos(users.getContent());
return new ResponseEntity(new MultiResponseDto(data, users), HttpStatus.OK);
}
현재 사용하고 있는 DTO 들에 Getter를 확인
@Getter // 추가
public class MultiResponseDto<T> {
private List<T> data;
private PageInfo pageInfo;
public MultiResponseDto(List<T> data, Page page){
this.data = data;
this.pageInfo = new PageInfo(page.getNumber()+1, page.getSize(),
page.getTotalElements(), page.getTotalPages());
}
@Getter // 추가
private class PageInfo{
private int page;
private int size;
private long totalElements;
private int totalPages;
PageInfo(int page, int size, long totalElements, int totalPages){
this.page = page;
this.size = size;
this.totalElements = totalElements;
this.totalPages = totalPages;
}
}
}