Merged in feature/FS-29-uuids (pull request #7)
feat: Use UUIDs in Outfit
This commit is contained in:
commit
25ace1be3f
@ -3,6 +3,7 @@ package io.salmonllama.fashionscapeapi.controller;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -27,7 +28,7 @@ public class OutfitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@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));
|
Outfit outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||||
|
|
||||||
return ResponseEntity.ok().body(outfit);
|
return ResponseEntity.ok().body(outfit);
|
||||||
@ -48,7 +49,7 @@ public class OutfitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@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 outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||||
|
|
||||||
outfit
|
outfit
|
||||||
@ -70,7 +71,7 @@ public class OutfitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@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));
|
Outfit outfit = outfitRepository.findById(outfitId).orElseThrow(() -> new ResourceNotFoundException("Outfit not found for id :: " + outfitId));
|
||||||
|
|
||||||
outfitRepository.delete(outfit);
|
outfitRepository.delete(outfit);
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package io.salmonllama.fashionscapeapi.model;
|
package io.salmonllama.fashionscapeapi.model;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "outfit")
|
@Table(name = "outfit")
|
||||||
public class Outfit {
|
public class Outfit {
|
||||||
private String id;
|
private UUID id;
|
||||||
private String link;
|
private String link;
|
||||||
private String submitter;
|
private String submitter;
|
||||||
private String tag;
|
private String tag;
|
||||||
@ -25,11 +26,12 @@ public class Outfit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
@Column(name = "id", nullable = false, unique = true)
|
@Column(name = "id", nullable = false, unique = true)
|
||||||
public String getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
public Outfit setId(String id) {
|
public Outfit setId(UUID id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ import org.springframework.stereotype.Repository;
|
|||||||
import io.salmonllama.fashionscapeapi.model.Outfit;
|
import io.salmonllama.fashionscapeapi.model.Outfit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Repository
|
@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)
|
@Query(value = "SELECT o FROM outfit o ORDER BY random() LIMIT 1", nativeQuery = true)
|
||||||
Outfit findRandomOutfit();
|
Outfit findRandomOutfit();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user