From bf9b411c9bc8f6e6b04cb12ead0ad4d956fb4a04 Mon Sep 17 00:00:00 2001 From: Erik Foris Date: Fri, 5 Jul 2024 19:31:19 +0200 Subject: [PATCH 1/5] chore: Remove unused DatasetController endpoint and method --- .../DataDash/Dataset/DatasetController.java | 20 --------- .../DataDash/Dataset/DatasetService.java | 44 ------------------- 2 files changed, 64 deletions(-) diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetController.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetController.java index 8665acb..1d1ef41 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetController.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetController.java @@ -14,8 +14,6 @@ import java.util.UUID; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import de.uni_passau.fim.PADAS.group3.DataDash.category.Category; - @RestController @RequestMapping("/api/v1/datasets") @EnableSpringDataWebSupport @@ -79,24 +77,6 @@ public class DatasetController { return new ResponseEntity<>(datasetService.getDatasetById(id), HttpStatus.OK); } - @GetMapping - public Page getDatasetsByDateAfter(@RequestParam(value = "author", required = false) String author, - @RequestParam(value = "title", required = false) String title, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "abst", required = false) String abst, - @RequestParam(value = "type", required = false) Type type, - @RequestParam(value = "min-rating", required = false) Float rating, - @RequestParam(value = "page", required = false, defaultValue = "0") int page, - @RequestParam(value = "size", required = false, defaultValue = "20") int size, - @RequestParam(value = "sort", required = false, defaultValue = "upvotes") String sort, - @RequestParam(value = "direction", required = false, defaultValue = "desc") String direction, - @RequestParam(value = "category", required = false) Category category) { - Pageable pageable = PageRequest.of(page, size, - Sort.by(Sort.Direction.fromString(direction), sort)); - return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, rating, category, - pageable); - } - @GetMapping("/search") public ResponseEntity> search( @RequestParam(value = "search", required = false, defaultValue = "%") String search, diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetService.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetService.java index 7762f31..93d1388 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetService.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetService.java @@ -23,10 +23,6 @@ public class DatasetService { this.categoryRepository = categoryRepository; } - public List getAllDatasets() { - return datasetRepository.findAll(); - } - public Dataset getDatasetById(UUID id) { return datasetRepository.getDatasetById(id); } @@ -36,10 +32,6 @@ public class DatasetService { return datasetRepository.save(dataset); } - public void updateDatasetTitle(UUID id, String title) { - datasetRepository.getDatasetById(id).setTitle(title); - } - public void voteDataset(UUID id, int vote) { Dataset dataset = datasetRepository.getDatasetById(id); dataset.vote(vote); @@ -51,34 +43,6 @@ public class DatasetService { datasetRepository.delete(dataset); } - public List getDatasetsByTitle(String title) { - return datasetRepository.findByTitle(title); - } - - public List getDatasetsByTitleLike(String title) { - return datasetRepository.findByTitleLike(title); - } - - public List findByDescriptionLike(String description) { - return datasetRepository.findByDescriptionLike(description); - } - - public List getDatasetsByAuthorLike(String author) { - return datasetRepository.findByAuthorLike(author); - } - - public List getDatasetsByType(Type type) { - return datasetRepository.findByType(type); - } - - public List getDatasetsByAbstLike(String abst) { - return datasetRepository.findByAbstLike(abst); - } - - public List getDatasetsByRaitingGreaterThan(float raiting) { - return datasetRepository.findByRaitingGreaterThan(raiting); - } - public void upvoteDataset(UUID id) { Dataset dataset = datasetRepository.getDatasetById(id); dataset.upvote(); @@ -91,14 +55,6 @@ public class DatasetService { datasetRepository.save(dataset); } - public Page getDatasetsByOptionalCriteria(String title, String description, String author, String abst, - Type type, Float raiting, Category category, Pageable pageable) { - return datasetRepository.findByOptionalCriteria(Optional.ofNullable(title), Optional.ofNullable(description), - Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type), - Optional.ofNullable(category), - Optional.ofNullable(raiting), pageable); - } - public Page searchByOptionalCriteria(String search, String categories, String type, Pageable pageable) { Category category = categories.equals("%") ? null : categoryRepository.getCategoryById(UUID.fromString(categories)); From 464cf104f9c315c80966fb7c75c6ef34f3d5a33e Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Sat, 6 Jul 2024 13:31:30 +0200 Subject: [PATCH 2/5] datasets now redirect to their details pages. also implemented 'button' look and feel for the datasets --- src/main/resources/static/dataset.js | 10 +++++++++- src/main/resources/static/main.css | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/dataset.js b/src/main/resources/static/dataset.js index 1c5d40a..cc654e1 100644 --- a/src/main/resources/static/dataset.js +++ b/src/main/resources/static/dataset.js @@ -104,7 +104,15 @@ export default class Dataset { return null; } - clone.querySelector(".dataset").dataset.id = this.#id; + let datasetContainer = clone.querySelector(".dataset"); + datasetContainer.dataset.id = this.#id; + datasetContainer.addEventListener("click", event => { + if (!event.target.classList.contains("btn")) { + let detailsPage = new URL("/details.html", location.origin); + detailsPage.searchParams.append("id", this.#id); + window.location.href = detailsPage.toString(); + } + }) clone.querySelector(".dataset-title").innerText = this.#title; clone.querySelector(".dataset-description").innerText = this.#description; clone.querySelector(".upvote-count").innerText = this.#upvotes; diff --git a/src/main/resources/static/main.css b/src/main/resources/static/main.css index 8a0b141..ae3eb64 100644 --- a/src/main/resources/static/main.css +++ b/src/main/resources/static/main.css @@ -109,6 +109,11 @@ header { align-items: center; justify-content: space-between; box-sizing: border-box; + cursor: pointer; +} + +.dataset:hover { + filter: brightness(1.2); } .upvote { From c9211a0b0010c0b824f7fd41a53b3c2dfde53cca Mon Sep 17 00:00:00 2001 From: Erik Foris Date: Sat, 6 Jul 2024 13:36:45 +0200 Subject: [PATCH 3/5] chore: Update dataset table schema and Dataset class to accominate terms of use --- .../group3/DataDash/Dataset/Dataset.java | 12 +++++++ src/main/resources/data.sql | 34 +++++++++---------- src/main/resources/schema.sql | 2 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/Dataset.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/Dataset.java index c8ed4e3..8a269c9 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/Dataset.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/Dataset.java @@ -10,6 +10,7 @@ import de.uni_passau.fim.PADAS.group3.DataDash.category.Category; import java.sql.Date; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -46,6 +47,9 @@ public class Dataset { private URL url; + @Column(name = "terms_of_use") + private URL termsOfUse; + private String licence; private static final List sortable = Arrays.asList("author", "title", "upvotes", "date"); @@ -121,6 +125,10 @@ public class Dataset { return url; } + public URL getTermsOfUse() { + return termsOfUse; + } + public String getLicence() { return licence; } @@ -152,6 +160,10 @@ public class Dataset { public void setUrl(URL url) { this.url = url; } + + public void setTermsOfUse(URL termsOfUse) { + this.termsOfUse = termsOfUse; + } public void setTitle(String title) { this.title = title.substring(0, Math.min(title.length(), 50)); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 51257a9..5f7c01b 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -10,21 +10,21 @@ INSERT INTO category (id, name) VALUES ('123e4567-e89b-12d3-a456-426614174002', 'Health'); -- Insert sample data into dataset -INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence) VALUES -('2023-01-01', 4.5, 100, 120, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174100', 'Abstract 1', 'Author 1', 'Description 1', 'Title 1', 'http://example.com/1', 'API', 'MIT'), -('2023-01-02', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174101', 'Abstract 2', 'Author 2', 'Description 2', 'Title 2', 'http://example.com/2', 'DATASET', 'MIT'), -('2023-01-03', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174102', 'Abstract 3', 'Author 3', 'Description 3', 'Title 3', 'http://example.com/3', 'API', 'MIT'), -('2023-01-04', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174103', 'Abstract 4', 'Author 4', 'Description 4', 'Title 4', 'http://example.com/4', 'DATASET', 'MIT'), -('2023-01-05', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174104', 'Abstract 5', 'Author 5', 'Description 5', 'Title 5', 'http://example.com/5', 'API', 'MIT'); +INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence, terms_of_use) VALUES +('2023-01-01', 4.5, 100, 120, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174100', 'Abstract 1', 'Author 1', 'Description 1', 'Title 1', 'http://example.com/1', 'API', 'MIT', 'http://url.de'), +('2023-01-02', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174101', 'Abstract 2', 'Author 2', 'Description 2', 'Title 2', 'http://example.com/2', 'DATASET', 'MIT', 'http://url.de'), +('2023-01-03', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174102', 'Abstract 3', 'Author 3', 'Description 3', 'Title 3', 'http://example.com/3', 'API', 'MIT', 'http://url.de'), +('2023-01-04', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174103', 'Abstract 4', 'Author 4', 'Description 4', 'Title 4', 'http://example.com/4', 'DATASET', 'MIT', 'http://url.de'), +('2023-01-05', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174104', 'Abstract 5', 'Author 5', 'Description 5', 'Title 5', 'http://example.com/5', 'API', 'MIT', 'http://url.de'); -- Insert 10 more sample data into dataset -INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence) VALUES -('2023-01-06', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174105', 'Abstract 6', 'Author 6', 'Description 6', 'Title 6', 'http://example.com/6', 'API', 'MIT'), -('2023-01-07', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174106', 'Abstract 7', 'Author 7', 'Description 7', 'Title 7', 'http://example.com/7', 'DATASET', 'MIT'), -('2023-01-08', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174107', 'Abstract 8', 'Author 8', 'Description 8', 'Title 8', 'http://example.com/8', 'API', 'MIT'), -('2023-01-09', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174108', 'Abstract 9', 'Author 9', 'Description 9', 'Title 9', 'http://example.com/9', 'DATASET', 'MIT'), -('2023-01-10', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174109', 'Abstract 10', 'Author 10', 'Description 10', 'Title 10', 'http://example.com/10', 'API', 'MIT'), -('2023-11-11', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174110', 'Abstract 11', 'Author 11', 'Description 11', 'Title 11', 'http://example.com/11', 'DATASET', 'MIT'), -('2023-09-12', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174111', 'Abstract 12', 'Author 12', 'Description 12', 'Title 12', 'http://example.com/12', 'API', 'MIT'), -('2023-03-13', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174112', 'Abstract 13', 'Author 13', 'Description 13', 'Title 13', 'http://example.com/13', 'DATASET', 'MIT'), -('2021-01-14', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174113', 'Abstract 14', 'Author 14', 'Description 14', 'Title 14', 'http://example.com/14', 'API', 'MIT'), -('2024-01-15', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174114', 'Abstract 15', 'Author 15', 'Description 15', 'Title 15', 'http://example.com/15', 'DATASET', 'MIT'); \ No newline at end of file +INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence, terms_of_use) VALUES +('2023-01-06', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174105', 'Abstract 6', 'Author 6', 'Description 6', 'Title 6', 'http://example.com/6', 'API', 'MIT', 'http://zip.com'), +('2023-01-07', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174106', 'Abstract 7', 'Author 7', 'Description 7', 'Title 7', 'http://example.com/7', 'DATASET', 'MIT', 'http://zip.com'), +('2023-01-08', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174107', 'Abstract 8', 'Author 8', 'Description 8', 'Title 8', 'http://example.com/8', 'API', 'MIT', 'http://zip.com'), +('2023-01-09', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174108', 'Abstract 9', 'Author 9', 'Description 9', 'Title 9', 'http://example.com/9', 'DATASET', 'MIT', 'http://zip.com'), +('2023-01-10', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174109', 'Abstract 10', 'Author 10', 'Description 10', 'Title 10', 'http://example.com/10', 'API', 'MIT', 'http://zip.com'), +('2023-11-11', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174110', 'Abstract 11', 'Author 11', 'Description 11', 'Title 11', 'http://example.com/11', 'DATASET', 'MIT', 'http://zip.com'), +('2023-09-12', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174111', 'Abstract 12', 'Author 12', 'Description 12', 'Title 12', 'http://example.com/12', 'API', 'MIT', 'http://zip.com'), +('2023-03-13', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174112', 'Abstract 13', 'Author 13', 'Description 13', 'Title 13', 'http://example.com/13', 'DATASET', 'MIT', 'http://zip.com'), +('2021-01-14', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174113', 'Abstract 14', 'Author 14', 'Description 14', 'Title 14', 'http://example.com/14', 'API', 'MIT', 'http://zip.com'), +('2024-01-15', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174114', 'Abstract 15', 'Author 15', 'Description 15', 'Title 15', 'http://example.com/15', 'DATASET', 'MIT', 'http://zip.com'); \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 0385a13..d61125c 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -3,5 +3,5 @@ DROP TABLE IF EXISTS category; create table category (id uuid not null, name varchar(255), primary key (id)); -create table dataset (date date, raiting float(24) not null, upvotes integer not null, votes integer not null, categorie_id uuid, id uuid not null, abst varchar(255), author varchar(255), description varchar(255), title varchar(255), url varchar(255), type enum ('API','DATASET'), licence varchar(255), primary key (id)); +create table dataset (date date, raiting float(24) not null, upvotes integer not null, votes integer not null, categorie_id uuid, id uuid not null, abst varchar(255), author varchar(255), description varchar(200000), title varchar(255), url varchar(2048), terms_of_use varchar(2048), type enum ('API','DATASET'), licence varchar(255), primary key (id)); alter table if exists dataset add constraint FKq6qwq6u473f89h71s7rf97ruy foreign key (categorie_id) references category; From 4e19a24833cf512f8b824e7bf3d9ec3f213f368d Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Sat, 6 Jul 2024 14:26:57 +0200 Subject: [PATCH 4/5] local authorship is now stored --- src/main/resources/static/add.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/resources/static/add.js b/src/main/resources/static/add.js index 280eb67..c1f11cb 100644 --- a/src/main/resources/static/add.js +++ b/src/main/resources/static/add.js @@ -1,3 +1,5 @@ +import Dataset from "./dataset.js"; + const form = document.forms[0]; const { title: titleEntry, @@ -23,7 +25,7 @@ const validationListener = () => { fullDescriptionEntry, ].forEach(input => input.addEventListener("input", validationListener)); -form.addEventListener("submit", e => { +form.addEventListener("submit", async e => { e.preventDefault(); if (!form.reportValidity()) return; @@ -43,17 +45,20 @@ form.addEventListener("submit", e => { // Don't allow several requests to be sent at the same time addBtn.disabled = true; - fetch("/api/v1/datasets", { + let response = await fetch("/api/v1/datasets", { method: "POST", body: JSON.stringify(newContent), headers: { "Content-Type": "application/json;charset=utf-8" } - }).then(response => { - if (response.status == 200) { - location.assign("/"); - } else { - addBtn.disabled = !form.checkValidity(); - } + }); + let data = await response.json(); + let dataset = new Dataset(data); + dataset.storageSetKey("createdLocally", true); + if (response.status == 200) { + location.assign("/"); + } else { + addBtn.disabled = !form.checkValidity(); + } }); From 8b5ac69e3c4629ed936b46cb5ddb22e3dc0cd132 Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Sat, 6 Jul 2024 14:44:10 +0200 Subject: [PATCH 5/5] changed key name added cancelbtn eventlistener --- src/main/resources/static/add.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/add.js b/src/main/resources/static/add.js index c1f11cb..53292ad 100644 --- a/src/main/resources/static/add.js +++ b/src/main/resources/static/add.js @@ -25,6 +25,10 @@ const validationListener = () => { fullDescriptionEntry, ].forEach(input => input.addEventListener("input", validationListener)); +cancelBtn.addEventListener("click", () => { + window.location.href = location.origin; +}) + form.addEventListener("submit", async e => { e.preventDefault(); if (!form.reportValidity()) return; @@ -55,8 +59,8 @@ form.addEventListener("submit", async e => { }); let data = await response.json(); let dataset = new Dataset(data); - dataset.storageSetKey("createdLocally", true); - if (response.status == 200) { + dataset.storageSetKey("created-locally", true); + if (response.ok) { location.assign("/"); } else { addBtn.disabled = !form.checkValidity();