diff --git a/src/main/java/KNU/Navibook/server/controller/BookController.java b/src/main/java/KNU/Navibook/server/controller/BookController.java index b590930..d3bfee6 100644 --- a/src/main/java/KNU/Navibook/server/controller/BookController.java +++ b/src/main/java/KNU/Navibook/server/controller/BookController.java @@ -101,7 +101,7 @@ public Book bookAddPosition(@RequestBody Map requestData) { return book; } //bookid에 맞는 book 없으면 404 - //userid에 맞는 user 없으면 404 + //userid에 맞는 user 없으면 404 // 관리자 조건 추가 해야 할 듯? @PostMapping("/api/book/borrow") @ResponseBody public Book bookBorrow(@RequestBody Map requestData) { @@ -140,7 +140,7 @@ public Book bookBorrow(@RequestBody Map requestData) { } //bookid에 맞는 book 없으면 404 //userid에 맞는 user 없으면 404 - @PostMapping("/api/book/return") + @PostMapping("/api/book/return") // 관리자 조건 추가해야 할 듯? @ResponseBody public Book bookReturn(@RequestBody Map requestData) { String userId =(String) requestData.get("userId"); @@ -168,7 +168,8 @@ public Book bookReturn(@RequestBody Map requestData) { book.setSelfFloor(null); LocalDate nowDate = LocalDate.now(ZoneId.of("Asia/Seoul")); // 반납 현재 날짜 입력 - Record record = recordService.findRecord(book); + List records = recordService.findRecordByBook(book); // 그 책의 관련 된 Record 전부를 가져옴. + Record record = records.get(records.size()-1); // 그 후 레코드의 마지막 값 가져오기 why? 그 레코드의 giveDate 만 바꿔줘야 하니까 record.setGiveDate(nowDate.toString()); bookService.saveBook(book); diff --git a/src/main/java/KNU/Navibook/server/controller/RecordController.java b/src/main/java/KNU/Navibook/server/controller/RecordController.java index 525bbc5..b4b63a6 100644 --- a/src/main/java/KNU/Navibook/server/controller/RecordController.java +++ b/src/main/java/KNU/Navibook/server/controller/RecordController.java @@ -1,14 +1,40 @@ package KNU.Navibook.server.controller; +import KNU.Navibook.server.domain.Record; +import KNU.Navibook.server.domain.User; import KNU.Navibook.server.service.RecordService; +import KNU.Navibook.server.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.*; @Controller public class RecordController { @Autowired RecordService recordService; + @Autowired + UserService userService; + + @GetMapping("/api/record/user/{userId}") + @ResponseBody + public List userRecord(@PathVariable("userId") String userId, + @RequestParam("page") Integer page)//, @RequestParam("orederBy") 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); + + for(int i = (page*10)-10; records != null && records.size() >= i && i <= page*10; i++){ + pageRecords.add(records.get(i)); + } + return pageRecords; + } } diff --git a/src/main/java/KNU/Navibook/server/repository/RecordRepository.java b/src/main/java/KNU/Navibook/server/repository/RecordRepository.java index 0bd1b9a..3c8b067 100644 --- a/src/main/java/KNU/Navibook/server/repository/RecordRepository.java +++ b/src/main/java/KNU/Navibook/server/repository/RecordRepository.java @@ -2,11 +2,15 @@ import KNU.Navibook.server.domain.Book; import KNU.Navibook.server.domain.Record; +import KNU.Navibook.server.domain.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface RecordRepository extends JpaRepository { Record findByid(Long id); - Record findBybook(Book book); // Book으로 Record찾기 + List findBybook(Book book); // Book으로 Record찾기 + List findByuser(User user); } \ No newline at end of file diff --git a/src/main/java/KNU/Navibook/server/service/RecordService.java b/src/main/java/KNU/Navibook/server/service/RecordService.java index 516d608..3898cc8 100644 --- a/src/main/java/KNU/Navibook/server/service/RecordService.java +++ b/src/main/java/KNU/Navibook/server/service/RecordService.java @@ -2,6 +2,7 @@ import KNU.Navibook.server.domain.Book; import KNU.Navibook.server.domain.Record; +import KNU.Navibook.server.domain.User; import KNU.Navibook.server.repository.RecordRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,7 +17,8 @@ public class RecordService { public List findRecords(){ return recordRepository.findAll(); } - public Record findRecord(Book book) { return recordRepository.findBybook(book);} // 책으로 Record찾기. + public List findRecordByBook(Book book) { return recordRepository.findBybook(book);} // 책으로 Record찾기. + public List findRecordByUser(User user) { return recordRepository.findByuser(user);} // 유저로 Record찾기. public Record saveRecord(Record record){ return recordRepository.save(record); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index abae897..803d22e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,10 +1,10 @@ spring.datasource.driverClassName=org.mariadb.jdbc.Driver -spring.datasource.url=jdbc:mariadb://navi.cibnganlxeh6.ap-northeast-2.rds.amazonaws.com:3306/navi +#spring.datasource.url=jdbc:mariadb://navi.cibnganlxeh6.ap-northeast-2.rds.amazonaws.com:3306/navi spring.datasource.username=root -spring.datasource.password=navi1234 +#spring.datasource.password=navi1234 spring.mvc.hiddenmethod.filter.enabled=true -spring.jpa.hibernate.ddl-auto = update +spring.jpa.hibernate.ddl-auto = create -#spring.datasource.url=jdbc:mariadb://localhost:3306/navi -#spring.datasource.password=root +spring.datasource.url=jdbc:mariadb://localhost:3306/navi +spring.datasource.password=root diff --git a/src/navi.dll b/src/navi.dll index 144e874..3548c50 100644 --- a/src/navi.dll +++ b/src/navi.dll @@ -128,4 +128,34 @@ INSERT INTO book VALUES ( '95', '3', TRUE,'11','3' ); INSERT INTO book VALUES ( '96', '3', TRUE,'8','3' ); INSERT INTO book VALUES ( '97', '1', TRUE,'1','1' ); INSERT INTO book VALUES ( '98', '3', TRUE,'3','3' ); -INSERT INTO book VALUES ( '99', '2', TRUE,'14','2' ); \ No newline at end of file +INSERT INTO book VALUES ( '99', '2', TRUE,'14','2' ); +INSERT INTO record VALUES ( '1', '2022-02-09', '2022-02-01', '13', 'park12'); +INSERT INTO record VALUES ( '2', '2022-02-09', '2022-02-01', '14', 'park12'); +INSERT INTO record VALUES ( '3', '2022-02-06', '2022-02-01', '11', 'gwon01'); +INSERT INTO record VALUES ( '4', '2022-02-03', '2022-02-01', '10', 'park12'); +INSERT INTO record VALUES ( '5', '2022-02-05', '2022-02-01', '3', 'kim01'); +INSERT INTO record VALUES ( '6', '2022-02-04', '2022-02-01', '4', 'kim01'); +INSERT INTO record VALUES ( '7', '2022-02-09', '2022-02-01', '6', 'park12'); +INSERT INTO record VALUES ( '8', '2022-02-10', '2022-02-01', '7', 'kim01'); +INSERT INTO record VALUES ( '9', '2022-02-12', '2022-02-01', '8', 'park12'); +INSERT INTO record VALUES ( '10', '2022-02-11', '2022-02-03', '10', 'kim01'); +INSERT INTO record VALUES ( '11', '2022-02-13', '2022-02-07', '20', 'park12'); +INSERT INTO record VALUES ( '12', '2022-02-14', '2022-02-07', '19', 'gwon01'); +INSERT INTO record VALUES ( '13', '2022-02-13', '2022-02-08', '18', 'park12'); +INSERT INTO record VALUES ( '14', '2022-02-22', '2022-02-09', '17', 'gwon01'); +INSERT INTO record VALUES ( '15', '2022-02-09', '2022-02-10', '30', 'gwon01'); +INSERT INTO record VALUES ( '16', '2022-02-09', '2022-02-11', '25', 'park12'); +INSERT INTO record VALUES ( '17', '2022-02-09', '2022-02-12', '24', 'gwon01'); +INSERT INTO record VALUES ( '18', '2022-02-09', '2022-02-13', '23', 'park12'); +INSERT INTO record VALUES ( '19', '2022-02-09', '2022-02-15', '22', 'gwon01'); +INSERT INTO record VALUES ( '20', '2022-02-09', '2022-02-16', '40', 'park12'); +INSERT INTO record VALUES ( '21', '2022-02-09', '2022-02-17', '41', 'gwon01'); +INSERT INTO record VALUES ( '22', '2022-03-03', '2022-03-01', '52', 'park12'); +INSERT INTO record VALUES ( '23', '2022-03-05', '2022-03-03', '56', 'kim01'); +INSERT INTO record VALUES ( '24', '2022-03-10', '2022-03-05', '53', 'park12'); +INSERT INTO record VALUES ( '25', '2022-03-12', '2022-03-10', '54', 'kim01'); +INSERT INTO record VALUES ( '26', '2022-03-13', '2022-03-11', '55', 'park12'); +INSERT INTO record VALUES ( '27', '2022-03-14', '2022-03-12', '64', 'kim01'); +INSERT INTO record VALUES ( '28', '2022-03-15', '2022-03-14', '62', 'kim01'); +INSERT INTO record VALUES ( '29', '2022-03-16', '2022-03-16', '61', 'park12'); +INSERT INTO record VALUES ( '30', '2022-03-17', '2022-03-13', '66', 'kim01'); \ No newline at end of file