feat: Use UUIDs in Outfit
Reworked the outfit model, repository, and controller to use UUIDs instead of String IDs. Closes FS-29
This commit is contained in:
parent
b55f7c0cfa
commit
5c0a24e08f
@ -3,6 +3,7 @@ package io.salmonllama.fashionscapeapi.controller;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -27,7 +28,7 @@ public class OutfitController {
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Outfit> getOutfitById(@PathVariable(value = "id") String outfitId) throws ResourceNotFoundException {
|
||||
public ResponseEntity<Outfit> getOutfitById(@PathVariable(value = "id") UUID outfitId) throws ResourceNotFoundException {
|
||||
Outfit outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||
|
||||
return ResponseEntity.ok().body(outfit);
|
||||
@ -48,7 +49,7 @@ public class OutfitController {
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Outfit> updateOutfit(@PathVariable(value = "id") String outfitId, @Valid @RequestBody Outfit outfitDetails) throws ResourceNotFoundException {
|
||||
public ResponseEntity<Outfit> updateOutfit(@PathVariable(value = "id") UUID outfitId, @Valid @RequestBody Outfit outfitDetails) throws ResourceNotFoundException {
|
||||
Outfit outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||
|
||||
outfit
|
||||
@ -70,7 +71,7 @@ public class OutfitController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Map<String, Boolean>> deleteOutfit(@PathVariable(value = "id") String outfitId) throws ResourceNotFoundException {
|
||||
public ResponseEntity<Map<String, Boolean>> deleteOutfit(@PathVariable(value = "id") UUID outfitId) throws ResourceNotFoundException {
|
||||
Outfit outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||
|
||||
outfitRepository.delete(outfit);
|
||||
|
@ -1,13 +1,14 @@
|
||||
package io.salmonllama.fashionscapeapi.model;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "outfit")
|
||||
public class Outfit {
|
||||
private String id;
|
||||
private UUID id;
|
||||
private String link;
|
||||
private String submitter;
|
||||
private String tag;
|
||||
@ -25,11 +26,12 @@ public class Outfit {
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
public String getId() {
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public Outfit setId(String id) {
|
||||
public Outfit setId(UUID id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ import org.springframework.stereotype.Repository;
|
||||
import io.salmonllama.fashionscapeapi.model.Outfit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Repository
|
||||
public interface OutfitRepository extends JpaRepository<Outfit, String> {
|
||||
public interface OutfitRepository extends JpaRepository<Outfit, UUID> {
|
||||
@Query(value = "SELECT o FROM outfit o ORDER BY random() LIMIT 1", nativeQuery = true)
|
||||
Outfit findRandomOutfit();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user