-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCirculationDeskController.java
More file actions
58 lines (48 loc) · 2.37 KB
/
Copy pathCirculationDeskController.java
File metadata and controls
58 lines (48 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package example.borrow.infrastructure;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.UUID;
import example.borrow.application.CirculationDesk;
import example.borrow.application.HoldInformation;
import example.borrow.domain.Book;
import example.borrow.domain.Hold;
import example.borrow.domain.Patron.PatronId;
import example.useraccount.UserAccount;
import example.useraccount.web.Authenticated;
import lombok.RequiredArgsConstructor;
@RestController
@RequiredArgsConstructor
public class CirculationDeskController {
private final CirculationDesk circulationDesk;
@PostMapping("/borrow/holds")
ResponseEntity<HoldInformation> holdBook(@RequestBody HoldRequest request, @Authenticated UserAccount userAccount) {
var command = new Hold.PlaceHold(new Book.Barcode(request.barcode()), LocalDate.now(), new PatronId(userAccount.email()));
var holdDto = circulationDesk.placeHold(command);
return ResponseEntity.ok(holdDto);
}
@PostMapping("/borrow/holds/{id}/checkout")
ResponseEntity<HoldInformation> checkoutBook(@PathVariable("id") UUID holdId, @Authenticated UserAccount userAccount) {
var command = new Hold.Checkout(new Hold.HoldId(holdId), LocalDate.now(), new PatronId(userAccount.email()));
var hold = circulationDesk.checkout(command);
return ResponseEntity.ok(hold);
}
@PostMapping("/borrow/holds/{id}/checkin")
ResponseEntity<HoldInformation> checkinBook(@PathVariable("id") UUID holdId, @Authenticated UserAccount userAccount) {
var command = new Hold.Checkin(new Hold.HoldId(holdId), LocalDate.now(), new PatronId(userAccount.email()));
var hold = circulationDesk.checkin(command);
return ResponseEntity.ok(hold);
}
@GetMapping("/borrow/holds/{id}")
ResponseEntity<HoldInformation> viewSingleHold(@PathVariable("id") UUID holdId) {
return circulationDesk.locate(holdId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
record HoldRequest(String barcode) {
}
}