Skip to content

Commit

Permalink
edit dll, bookController
Browse files Browse the repository at this point in the history
  • Loading branch information
tfer2442 committed Feb 9, 2023
1 parent 3d32f39 commit 44ca350
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Book bookAddPosition(@RequestBody Map<String, Object> requestData) {
return book;
}
//bookid에 맞는 book 없으면 404
//userid에 맞는 user 없으면 404
//userid에 맞는 user 없으면 404 // 관리자 조건 추가 해야 할 듯?
@PostMapping("/api/book/borrow")
@ResponseBody
public Book bookBorrow(@RequestBody Map<String, Object> requestData) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public Book bookBorrow(@RequestBody Map<String, Object> requestData) {
}
//bookid에 맞는 book 없으면 404
//userid에 맞는 user 없으면 404
@PostMapping("/api/book/return")
@PostMapping("/api/book/return") // 관리자 조건 추가해야 할 듯?
@ResponseBody
public Book bookReturn(@RequestBody Map<String, Object> requestData) {
String userId =(String) requestData.get("userId");
Expand Down Expand Up @@ -168,7 +168,8 @@ public Book bookReturn(@RequestBody Map<String, Object> requestData) {
book.setSelfFloor(null);

LocalDate nowDate = LocalDate.now(ZoneId.of("Asia/Seoul")); // 반납 현재 날짜 입력
Record record = recordService.findRecord(book);
List<Record> records = recordService.findRecordByBook(book); // 그 책의 관련 된 Record 전부를 가져옴.
Record record = records.get(records.size()-1); // 그 후 레코드의 마지막 값 가져오기 why? 그 레코드의 giveDate 만 바꿔줘야 하니까
record.setGiveDate(nowDate.toString());

bookService.saveBook(book);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/KNU/Navibook/server/controller/RecordController.java
Original file line number Diff line number Diff line change
@@ -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<Record> userRecord(@PathVariable("userId") String userId,
@RequestParam("page") Integer page)//, @RequestParam("orederBy") 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);

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

return pageRecords;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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, Long> {
Record findByid(Long id);
Record findBybook(Book book); // Book으로 Record찾기
List<Record> findBybook(Book book); // Book으로 Record찾기
List<Record> findByuser(User user);
}
4 changes: 3 additions & 1 deletion src/main/java/KNU/Navibook/server/service/RecordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +17,8 @@ public class RecordService {
public List<Record> findRecords(){
return recordRepository.findAll();
}
public Record findRecord(Book book) { return recordRepository.findBybook(book);} // 책으로 Record찾기.
public List<Record> findRecordByBook(Book book) { return recordRepository.findBybook(book);} // 책으로 Record찾기.
public List<Record> findRecordByUser(User user) { return recordRepository.findByuser(user);} // 유저로 Record찾기.
public Record saveRecord(Record record){
return recordRepository.save(record);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
32 changes: 31 additions & 1 deletion src/navi.dll
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
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');

0 comments on commit 44ca350

Please sign in to comment.