diff --git a/lesson_16/api/api_app/src/main/java/com/codedifferently/lesson16/web/PatronsController.java b/lesson_16/api/api_app/src/main/java/com/codedifferently/lesson16/web/PatronsController.java deleted file mode 100644 index 5f424143..00000000 --- a/lesson_16/api/api_app/src/main/java/com/codedifferently/lesson16/web/PatronsController.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.codedifferently.lesson16.web; - -import com.codedifferently.lesson16.library.Library; -import com.codedifferently.lesson16.library.LibraryGuest; -import com.codedifferently.lesson16.library.exceptions.MediaItemCheckedOutException; -import jakarta.validation.Valid; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/patrons") -public class PatronsController { - - private final Library library; - private final Map patronMap; - - public PatronsController(Library library) { - this.library = library; - this.patronMap = new HashMap<>(); - } - - @GetMapping - public ResponseEntity> getPatrons() { - Collection patrons = library.getPatrons(); - return ResponseEntity.ok(patrons); - } - - @PostMapping - public ResponseEntity createPatron(@Valid @RequestBody PatronsRequest request) { - LibraryGuest guest = PatronsRequest.asLibraryGuest(request); - library.addLibraryGuest(guest); - return ResponseEntity.status(HttpStatus.CREATED).build(); - } - - @GetMapping("/{id}") - public ResponseEntity getPatronById(@PathVariable UUID id) { - LibraryGuest patron = patronMap.get(id); - if (patron != null) { - return ResponseEntity.ok(patron); - } else { - return ResponseEntity.notFound().build(); - } - } - - @DeleteMapping("/{id}") - public ResponseEntity removePatron(@PathVariable UUID id) { - try { - library.removeLibraryGuest(id); - return ResponseEntity.noContent().build(); - } catch (MediaItemCheckedOutException e) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } catch (Exception e) { - return ResponseEntity.notFound().build(); - } - } -}