From 9cfb77d0293cc1896ab0853f54364e952a1d2206 Mon Sep 17 00:00:00 2001 From: Quentin Guillemin Date: Thu, 14 Mar 2024 11:23:20 +0100 Subject: [PATCH] feat!: add UUID --- package.json | 2 ++ .../fr/recia/collabsoft/db/entity/File.java | 6 ++++++ .../collabsoft/service/db/FileService.java | 2 ++ src/main/webapp/src/types/fileType.ts | 1 + .../recia/collabsoft/test/DatabaseUtils.java | 13 +++++++------ yarn.lock | 18 ++++++++++++++++++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d7b38008..9949b3c6 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@types/lodash.isempty": "^4", "@types/lodash.throttle": "^4", "@types/node": "^20", + "@types/uuid": "^9", "@types/xml2js": "^0", "@uportal/open-id-connect": "^1.40.2", "@vitejs/plugin-vue": "^5.0.4", @@ -74,6 +75,7 @@ "sass": "^1.71.1", "standard-version": "^9.5.0", "typescript": "~5.4.2", + "uuid": "^9.0.1", "vite": "^5.1.5", "vite-plugin-vuetify": "^2.0.3", "vitest": "^1.3.1", diff --git a/src/main/java/fr/recia/collabsoft/db/entity/File.java b/src/main/java/fr/recia/collabsoft/db/entity/File.java index 675fb8f4..54f81ba7 100644 --- a/src/main/java/fr/recia/collabsoft/db/entity/File.java +++ b/src/main/java/fr/recia/collabsoft/db/entity/File.java @@ -16,6 +16,7 @@ package fr.recia.collabsoft.db.entity; import lombok.AllArgsConstructor; +import lombok.Generated; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -38,6 +39,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Objects; +import java.util.UUID; @Entity @Getter @@ -55,6 +57,10 @@ public class File implements Serializable { @ToString.Include private Long id; + @Column(name = "uuid", nullable = false) + @ToString.Include + private String uuid; + @Column(name = "title", nullable = false) @ToString.Include private String title; diff --git a/src/main/java/fr/recia/collabsoft/service/db/FileService.java b/src/main/java/fr/recia/collabsoft/service/db/FileService.java index e2b625e2..b647bb11 100644 --- a/src/main/java/fr/recia/collabsoft/service/db/FileService.java +++ b/src/main/java/fr/recia/collabsoft/service/db/FileService.java @@ -35,6 +35,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.UUID; @Slf4j @Service @@ -118,6 +119,7 @@ public File saveFile(JsonFileBody body) { if (associatedApp == null) return null; File file = new File(); + file.setUuid(UUID.randomUUID().toString()); file.setTitle(body.getTitle()); file.setDescription(body.getDescription()); file.setBlob(body.getBlob().getBytes()); diff --git a/src/main/webapp/src/types/fileType.ts b/src/main/webapp/src/types/fileType.ts index a69c1483..d3ed2c42 100644 --- a/src/main/webapp/src/types/fileType.ts +++ b/src/main/webapp/src/types/fileType.ts @@ -5,6 +5,7 @@ import type { User } from '@/types/userType.ts'; export type File = { id: number; + uuid: string; title: string; description: string | null; blob: any; diff --git a/src/test/java/fr/recia/collabsoft/test/DatabaseUtils.java b/src/test/java/fr/recia/collabsoft/test/DatabaseUtils.java index 90fdcc5a..40024da9 100644 --- a/src/test/java/fr/recia/collabsoft/test/DatabaseUtils.java +++ b/src/test/java/fr/recia/collabsoft/test/DatabaseUtils.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.List; +import java.util.UUID; public class DatabaseUtils { @@ -141,27 +142,27 @@ public void initDatabase() { userRepository.saveAllAndFlush(List.of(user1, user2, user3)); final File file1 = new File( - file1Id, "file1", null, "".getBytes(), user1, null, user1, null, + file1Id, UUID.randomUUID().toString(), "file1", null, "".getBytes(), user1, null, user1, null, associatedApp1, false ); final File file2 = new File( - file2Id, "file2", null, "".getBytes(), user1, null, user1, null, + file2Id, UUID.randomUUID().toString(), "file2", null, "".getBytes(), user1, null, user1, null, associatedApp1, false ); final File file3 = new File( - file3Id, "file3", null, "".getBytes(), user2, null, user2, null, + file3Id, UUID.randomUUID().toString(), "file3", null, "".getBytes(), user2, null, user2, null, associatedApp1, false ); final File file4 = new File( - file4Id, "file4", null, "".getBytes(), user2, null, user2, null, + file4Id, UUID.randomUUID().toString(), "file4", null, "".getBytes(), user2, null, user2, null, associatedApp1, true ); final File file5 = new File( - file5Id, "file5", null, "".getBytes(), user3, null, user3, null, + file5Id, UUID.randomUUID().toString(), "file5", null, "".getBytes(), user3, null, user3, null, associatedApp1, false ); final File file6 = new File( - file6Id, "file6", null, "".getBytes(), user3, null, user3, null, + file6Id, UUID.randomUUID().toString(), "file6", null, "".getBytes(), user3, null, user3, null, associatedApp1, false ); fileRepository.saveAllAndFlush(List.of(file1, file2, file3, file4, file5, file6)); diff --git a/yarn.lock b/yarn.lock index f8326d46..471eba7a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1128,6 +1128,13 @@ __metadata: languageName: node linkType: hard +"@types/uuid@npm:^9": + version: 9.0.8 + resolution: "@types/uuid@npm:9.0.8" + checksum: 10/b8c60b7ba8250356b5088302583d1704a4e1a13558d143c549c408bf8920535602ffc12394ede77f8a8083511b023704bc66d1345792714002bfa261b17c5275 + languageName: node + linkType: hard + "@types/web-bluetooth@npm:^0.0.20": version: 0.0.20 resolution: "@types/web-bluetooth@npm:0.0.20" @@ -2143,6 +2150,7 @@ __metadata: "@types/lodash.isempty": "npm:^4" "@types/lodash.throttle": "npm:^4" "@types/node": "npm:^20" + "@types/uuid": "npm:^9" "@types/xml2js": "npm:^0" "@uportal/open-id-connect": "npm:^1.40.2" "@vitejs/plugin-vue": "npm:^5.0.4" @@ -2171,6 +2179,7 @@ __metadata: sass: "npm:^1.71.1" standard-version: "npm:^9.5.0" typescript: "npm:~5.4.2" + uuid: "npm:^9.0.1" vite: "npm:^5.1.5" vite-plugin-vuetify: "npm:^2.0.3" vitest: "npm:^1.3.1" @@ -6750,6 +6759,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:^9.0.1": + version: 9.0.1 + resolution: "uuid@npm:9.0.1" + bin: + uuid: dist/bin/uuid + checksum: 10/9d0b6adb72b736e36f2b1b53da0d559125ba3e39d913b6072f6f033e0c87835b414f0836b45bcfaf2bdf698f92297fea1c3cc19b0b258bc182c9c43cc0fab9f2 + languageName: node + linkType: hard + "validate-npm-package-license@npm:^3.0.1": version: 3.0.4 resolution: "validate-npm-package-license@npm:3.0.4"