diff --git a/src/main/java/KNU/Navibook/server/controller/RecordController.java b/src/main/java/KNU/Navibook/server/controller/RecordController.java index b4b63a6..8934a9a 100644 --- a/src/main/java/KNU/Navibook/server/controller/RecordController.java +++ b/src/main/java/KNU/Navibook/server/controller/RecordController.java @@ -20,16 +20,26 @@ public class RecordController { @GetMapping("/api/record/user/{userId}") @ResponseBody public List userRecord(@PathVariable("userId") String userId, - @RequestParam("page") Integer page)//, @RequestParam("orederBy") String orderBy) + @RequestParam("page") Integer page, @RequestParam("orderBy") String orderBy) { User user = userService.findOne(userId); List records = recordService.findRecordByUser(user); List pageRecords = new ArrayList<>(); -// Comparator cp = Comparator.comparing(Record::getGiveDate); -// Collections.sort(records, cp); + if (orderBy.equals("book")){ // bookName 오름차순 정렬 + Comparator bs = Comparator.comparing(a -> a.getBook().getBookInfo().getBookName()); + Collections.sort(records, bs); + } + else if (orderBy.equals("takeDate")){ // TakeDate 오름차순 정렬 + Comparator ts = Comparator.comparing(Record::getTakeDate); + Collections.sort(records, ts); + } + else if (orderBy.equals("giveDate")){ // GiveDate 오름차순 정렬 + Comparator gs = Comparator.comparing(Record::getGiveDate); + Collections.sort(records, gs); + } - for(int i = (page*10)-10; records != null && records.size() >= i && i <= page*10; i++){ + for(int i = (page*10)-10; (records != null) && (records.size() > i) && (i < page*10); i++){ pageRecords.add(records.get(i)); }