Skip to content

Commit

Permalink
edit userRecordAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
tfer2442 committed Feb 9, 2023
1 parent 44ca350 commit 56412f3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/KNU/Navibook/server/controller/RecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@ public class RecordController {
@GetMapping("/api/record/user/{userId}")
@ResponseBody
public List<Record> 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<Record> records = recordService.findRecordByUser(user);
List<Record> pageRecords = new ArrayList<>();

// Comparator<Record> cp = Comparator.comparing(Record::getGiveDate);
// Collections.sort(records, cp);
if (orderBy.equals("book")){ // bookName 오름차순 정렬
Comparator<Record> bs = Comparator.comparing(a -> a.getBook().getBookInfo().getBookName());
Collections.sort(records, bs);
}
else if (orderBy.equals("takeDate")){ // TakeDate 오름차순 정렬
Comparator<Record> ts = Comparator.comparing(Record::getTakeDate);
Collections.sort(records, ts);
}
else if (orderBy.equals("giveDate")){ // GiveDate 오름차순 정렬
Comparator<Record> 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));
}

Expand Down

0 comments on commit 56412f3

Please sign in to comment.