profileShare

rasmusjy / tasteprint

Read-only snapshot

No repository description.

main default branch 169 files Expires Sep 13, 2026, 9:06 AM
TastingController.java 2,157 bytes
1 package com.tasteprint.tasting;
2
3 import java.util.UUID;
4
5 import jakarta.validation.Valid;
6
7 import org.springframework.http.HttpStatus;
8 import org.springframework.security.core.annotation.AuthenticationPrincipal;
9 import org.springframework.web.bind.annotation.DeleteMapping;
10 import org.springframework.web.bind.annotation.GetMapping;
11 import org.springframework.web.bind.annotation.PathVariable;
12 import org.springframework.web.bind.annotation.PostMapping;
13 import org.springframework.web.bind.annotation.PutMapping;
14 import org.springframework.web.bind.annotation.RequestBody;
15 import org.springframework.web.bind.annotation.RequestMapping;
16 import org.springframework.web.bind.annotation.RequestParam;
17 import org.springframework.web.bind.annotation.ResponseStatus;
18 import org.springframework.web.bind.annotation.RestController;
19
20 import com.tasteprint.account.AuthenticatedUser;
21
22 @RestController
23 @RequestMapping("/api/v1/tastings")
24 class TastingController {
25
26 private final TastingService tastings;
27
28 TastingController(TastingService tastings) {
29 this.tastings = tastings;
30 }
31
32 @GetMapping
33 TastingPage list(@AuthenticationPrincipal AuthenticatedUser user,
34 @RequestParam(defaultValue = "0") int page,
35 @RequestParam(defaultValue = "20") int size) {
36 return tastings.page(user.id(), page, size);
37 }
38
39 @PostMapping
40 @ResponseStatus(HttpStatus.CREATED)
41 TastingView record(@AuthenticationPrincipal AuthenticatedUser user,
42 @Valid @RequestBody SaveTastingRequest request) {
43 return tastings.record(user.id(), request);
44 }
45
46 @PutMapping("/{tastingId}")
47 TastingView update(@AuthenticationPrincipal AuthenticatedUser user,
48 @PathVariable UUID tastingId,
49 @Valid @RequestBody SaveTastingRequest request) {
50 return tastings.update(user.id(), tastingId, request);
51 }
52
53 @DeleteMapping("/{tastingId}")
54 @ResponseStatus(HttpStatus.NO_CONTENT)
55 void delete(@AuthenticationPrincipal AuthenticatedUser user, @PathVariable UUID tastingId) {
56 tastings.delete(user.id(), tastingId);
57 }
58 }
59