From 75a2cdf11eb5f5630dfa3a5847487f29757b83a0 Mon Sep 17 00:00:00 2001 From: Salmonllama Date: Sun, 3 Dec 2023 07:17:55 -0500 Subject: [PATCH] refactor: Use UUIDs on Galleries Remove Long-based IDs and use universally unique IDs. Closed FS-27 --- .../fashionscapeapi/controller/GalleryController.java | 7 ++++--- .../io/salmonllama/fashionscapeapi/model/Gallery.java | 8 +++++--- .../fashionscapeapi/repository/GalleryRepository.java | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/salmonllama/fashionscapeapi/controller/GalleryController.java b/src/main/java/io/salmonllama/fashionscapeapi/controller/GalleryController.java index dcc764c..64a9d20 100644 --- a/src/main/java/io/salmonllama/fashionscapeapi/controller/GalleryController.java +++ b/src/main/java/io/salmonllama/fashionscapeapi/controller/GalleryController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; @RestController @RequestMapping("/api/v1/gallery") @@ -26,7 +27,7 @@ public class GalleryController { } @GetMapping("/{id}") - public ResponseEntity getGalleryById(@PathVariable(value = "id") Long galleryId) throws ResourceNotFoundException { + public ResponseEntity getGalleryById(@PathVariable(value = "id") UUID galleryId) throws ResourceNotFoundException { Gallery gallery = galleryRepository.findById(galleryId).orElseThrow(() -> new ResourceNotFoundException("Gallery not found for id :: " + galleryId)); return ResponseEntity.ok().body(gallery); @@ -54,7 +55,7 @@ public class GalleryController { } @PutMapping("/{id}") - public ResponseEntity updateGallery(@PathVariable(value = "id") Long galleryId, @Valid @RequestBody Gallery galleryDetails) throws ResourceNotFoundException { + public ResponseEntity updateGallery(@PathVariable(value = "id") UUID galleryId, @Valid @RequestBody Gallery galleryDetails) throws ResourceNotFoundException { Gallery gallery = galleryRepository.findById(galleryId).orElseThrow(() -> new ResourceNotFoundException("Gallery not found for id :: " + galleryId)); gallery @@ -70,7 +71,7 @@ public class GalleryController { } @DeleteMapping("/{id}") - public ResponseEntity> deleteGallery(@PathVariable(value = "id") Long galleryId) throws ResourceNotFoundException { + public ResponseEntity> deleteGallery(@PathVariable(value = "id") UUID galleryId) throws ResourceNotFoundException { Gallery gallery = galleryRepository.findById(galleryId).orElseThrow(() -> new ResourceNotFoundException("Gallery not found for id :: " + galleryId)); galleryRepository.delete(gallery); diff --git a/src/main/java/io/salmonllama/fashionscapeapi/model/Gallery.java b/src/main/java/io/salmonllama/fashionscapeapi/model/Gallery.java index 86c6868..1dbe881 100644 --- a/src/main/java/io/salmonllama/fashionscapeapi/model/Gallery.java +++ b/src/main/java/io/salmonllama/fashionscapeapi/model/Gallery.java @@ -2,10 +2,12 @@ package io.salmonllama.fashionscapeapi.model; import jakarta.persistence.*; +import java.util.UUID; + @Entity @Table(name = "gallery") public class Gallery { - private Long id; + private UUID id; private String serverId; private String channelId; private String tag; @@ -18,10 +20,10 @@ public class Gallery { @Id @GeneratedValue @Column(name = "id") - public Long getId() { + public UUID getId() { return id; } - public Gallery setId(Long id) { + public Gallery setId(UUID id) { this.id = id; return this; } diff --git a/src/main/java/io/salmonllama/fashionscapeapi/repository/GalleryRepository.java b/src/main/java/io/salmonllama/fashionscapeapi/repository/GalleryRepository.java index 5f10695..48be946 100644 --- a/src/main/java/io/salmonllama/fashionscapeapi/repository/GalleryRepository.java +++ b/src/main/java/io/salmonllama/fashionscapeapi/repository/GalleryRepository.java @@ -6,8 +6,9 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Optional; +import java.util.UUID; -public interface GalleryRepository extends JpaRepository { +public interface GalleryRepository extends JpaRepository { @Query(value = "SELECT g FROM gallery g WHERE g.server_id = ?1", nativeQuery = true) List findAllByServer(String serverId);