Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/NaviBook/backend
Browse files Browse the repository at this point in the history
  • Loading branch information
momnpa333 committed Mar 10, 2023
2 parents c9eabfe + 8f72536 commit 171e6ad
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/main/java/KNU/Navibook/server/controller/RecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public class RecordController {

@GetMapping("/api/record") // record 전체 검색
@ResponseBody
public RecordDTO allRecord(@RequestParam("page") Integer page, @RequestParam("orderBy") String orderBy) {
public RecordDTO allRecord(@RequestParam("orderBy") String orderBy) {
List<Record> records = recordService.findRecords();
List<Record> pageRecords = new ArrayList<>();

if (orderBy.equals("book")){ // bookName 오름차순 정렬
Comparator<Record> bs = Comparator.comparing(a -> a.getBook().getBookInfo().getBookName());
Expand All @@ -49,26 +48,19 @@ else if (orderBy.equals("giveDate")){ // GiveDate 내림차순 정렬
else if (orderBy.equals("user")){ // userId 오름차순 정렬
Comparator<Record> us = Comparator.comparing(a -> a.getUser().getId());
Collections.sort(records, us);
}else{ // 예외처리 해줘야 함.

}

for(int i = (page*10)-10; (records != null) && (records.size() > i) && (i < page*10); i++){
pageRecords.add(records.get(i));
}

RecordDTO recordDTO = new RecordDTO(pageRecords, records.size());
RecordDTO recordDTO = new RecordDTO(records, records.size());

return recordDTO;
}
@GetMapping("/api/record/user/{userId}") // userId로 userRecord 검색
@ResponseBody
public RecordDTO userRecord(@PathVariable("userId") String userId,
@RequestParam("page") Integer page, @RequestParam("orderBy") String orderBy)
@RequestParam("orderBy") String orderBy)
{
User user = userService.findOne(userId);
List<Record> records = recordService.findRecordByUser(user);
List<Record> pageRecords = new ArrayList<>();

if (user==null){
throw new UserNotFoundException(String.format("userId %s not found",userId));
Expand All @@ -90,21 +82,16 @@ else if (orderBy.equals("giveDate")){ // GiveDate 내림차순 정렬, 반납
Collections.reverse(records);
}

for(int i = (page*10)-10; (records != null) && (records.size() > i) && (i < page*10); i++){
pageRecords.add(records.get(i));
}
RecordDTO recordDTO = new RecordDTO(pageRecords, records.size());
RecordDTO recordDTO = new RecordDTO(records, records.size());

return recordDTO;
}
@GetMapping("/api/record/book/{bookId}") //bookId로 bookRecord 검색
@ResponseBody
public RecordDTO bookRecord(@PathVariable("bookId") Long bookId,
@RequestParam("page") Integer page)
public RecordDTO bookRecord(@PathVariable("bookId") Long bookId)
{
Book book = bookService.findOne(bookId);
List<Record> records = recordService.findRecordByBook(book);
List<Record> pageRecords = new ArrayList<>();

Comparator<Record> ts = Comparator.comparing(Record::getTakeDate);
Collections.sort(records, ts);
Expand All @@ -114,10 +101,7 @@ public RecordDTO bookRecord(@PathVariable("bookId") Long bookId,
throw new BookNotFoundException(String.format("bookId %s not found",bookId));
}

for(int i = (page*10)-10; (records != null) && (records.size() > i) && (i < page*10); i++){
pageRecords.add(records.get(i));
}
RecordDTO recordDTO = new RecordDTO(pageRecords, records.size());
RecordDTO recordDTO = new RecordDTO(records, records.size());

return recordDTO;
}
Expand Down

0 comments on commit 171e6ad

Please sign in to comment.