From bbf4f932798dca159135efacbcbacfdce19d84a0 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Fri, 5 Jul 2024 19:25:13 +0200
Subject: [PATCH 01/19] feat: Add CategoryServiceTest and
CategoryControllerTest
The code changes include adding new test classes CategoryServiceTest and CategoryControllerTest. These test classes are used to test the functionality of the CategoryService and CategoryController classes respectively. The CategoryServiceTest class contains tests for the addCategory, getAllCategories, and getCategoryById methods of the CategoryService class. The CategoryControllerTest class contains tests for the getAllCategories, fetchCategoryById, and createCategory methods of the CategoryController class.
Recent user commits:
- Merge branch '36-refactor-dataset-class' into '22-integrate-api-and-frontend'
- Merge branch '22-integrate-api-and-frontend' into '36-refactor-dataset-class'
- Refactor Dataset class
- Merge branch '11-add-api-for-getting-home-page-data' into '22-integrate-api-and-frontend'
- Merge branch '37-restructure-backend-according-to-seperation-by-concerns' into '11-add-api-for-getting-home-page-data'
- refactor: finilase project structure
- Merge branch '11-add-api-for-getting-home-page-data' into '22-integrate-api-and-frontend'
- Merge branch '25-consider-moving-non-templated-html-into-static' into '11-add-api-for-getting-home-page-data'
- refactor: move static sites into static, Remove unused PageController and update main.js for page navigation
- fixed bugs:
- suppressed display of search results if nothing was found but there were previous searches
- improved display timing of search results/initial pages, which led to false displays
---
pom.xml | 8 +
.../Dataset/DatasetControllerTests.java | 305 ++++++++++++++++++
.../DataDash/Dataset/DatasetServiceTest.java | 123 +++++++
.../category/CategoryControllerTest.java | 75 +++++
.../category/CategoryServiceTest.java | 68 ++++
5 files changed, 579 insertions(+)
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetServiceTest.java
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryControllerTest.java
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryServiceTest.java
diff --git a/pom.xml b/pom.xml
index 5d76e0c..36bb031 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,14 @@
h2
runtime
+
+
+ org.mockito
+ mockito-core
+ 4.5.1
+ test
+
+
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
new file mode 100644
index 0000000..06a22fc
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
@@ -0,0 +1,305 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import de.uni_passau.fim.PADAS.group3.DataDash.Dataset.DatasetController;
+import de.uni_passau.fim.PADAS.group3.DataDash.Dataset.DatasetService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.net.URL;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.doAnswer;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+@WebMvcTest(DatasetController.class)
+public class DatasetControllerTests {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private DatasetService datasetService;
+
+ @Autowired
+ private ObjectMapper objectMapper = new ObjectMapper();
+
+ private Dataset d = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ @Test
+ void getDatasetById_whenExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"); // Assuming a
+ // constructor or
+ // builder pattern
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(get("/api/v1/datasets/id/" + id.toString()))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ void getDatasetById_whenNotExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(datasetService.getDatasetById(id)).willReturn(null);
+
+ mockMvc.perform(get("/api/v1/datasets/id/" + id))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ void createDataset() throws Exception {
+ Dataset dataset = d;
+ given(datasetService.addDataset(any(Dataset.class))).willAnswer(invocation -> invocation.getArgument(0));
+ mockMvc.perform(post("/api/v1/datasets")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(dataset)))
+ .andExpect(status().isCreated());
+ }
+
+ @Test
+ void deleteDataset_whenExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(delete("/api/v1/datasets/id/" + id.toString()))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ void deleteDataset_whenNotExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(datasetService.getDatasetById(id)).willReturn(null);
+
+ mockMvc.perform(delete("/api/v1/datasets/id/" + id))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ void upvote_whenExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ doAnswer(invocation -> {
+ dataset.upvote(); // Directly modify the dataset
+ return null;
+ }).when(datasetService).upvoteDataset(id);
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id.toString() + "/upvote"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(dataset)));
+
+ assertEquals(1, dataset.getUpvotes()); // Assuming getUpvotes() method exists and initial upvotes are 0
+ }
+
+ @Test
+ void upvote_whenNotExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(datasetService.getDatasetById(id)).willReturn(null);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/upvote"))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ void downvote_whenExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ doAnswer(invocation -> {
+ dataset.downvote(); // Directly modify the dataset
+ return null;
+ }).when(datasetService).downvoteDataset(id);
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id.toString() + "/downvote"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(dataset)));
+
+ assertEquals(-1, dataset.getUpvotes()); // Assuming getDownvotes() method exists and initial downvotes are 0
+ }
+
+ @Test
+ void downvote_whenNotExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(datasetService.getDatasetById(id)).willReturn(null);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/downvote"))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ void postMethodName_whenExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ doAnswer(invocation -> {
+ dataset.vote(3); // Directly modify the dataset
+ return null;
+ }).when(datasetService).voteDataset(id, 3);
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id.toString() + "/stars?stars=3"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(dataset)));
+
+ assertEquals(3, dataset.getRaiting()); // Assuming getVotes() method exists and initial votes are 0
+ }
+
+ @Test
+ void postMethodName_whenNotExists() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(datasetService.getDatasetById(id)).willReturn(null);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=3"))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ void postMethodName_whenInvalidStars() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=7"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void postMethodName_whenInvalidStars2() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=0"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void postMethodName_whenInvalidStars3() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=-1"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void postMethodName_whenInvalidStars4() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=6"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void postMethodName_whenInvalidStars5() throws Exception {
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+
+ given(datasetService.getDatasetById(id)).willReturn(dataset);
+
+ mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=100"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void searchDatasets_whenExists() throws Exception {
+ String keyword = "data";
+ List datasets = Arrays.asList(
+ new Dataset("Title 1", "abst", "data", "auth", null, null, Type.API, "MIT"),
+ new Dataset("Title 2", "abst", "data", "auth", null, null, Type.API, "MIT"));
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(new PageImpl<>(datasets));
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword))
+ .andExpect(status().isOk());
+ //TODO: Check output
+ }
+
+ @Test
+ void searchDatasets_whenNotExists() throws Exception {
+ String keyword = "nonexistent";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?seaarch=" + keyword))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ void searchDatasets_whenInvalidSort() throws Exception {
+ String keyword = "data";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&sort=invalid"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void searchDatasets_whenInvalidDirection() throws Exception {
+ String keyword = "data";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&direction=invalid"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void searchDatasets_whenInvalidPage() throws Exception {
+ String keyword = "data";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&page=-1"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void searchDatasets_whenInvalidSize() throws Exception {
+ String keyword = "data";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&size=-1"))
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void searchDatasets_whenInvalidSize2() throws Exception {
+ String keyword = "data";
+ given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+
+ mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&size=0"))
+ .andExpect(status().isBadRequest());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetServiceTest.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetServiceTest.java
new file mode 100644
index 0000000..98e0ff4
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetServiceTest.java
@@ -0,0 +1,123 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
+
+
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.data.domain.Pageable;
+
+import de.uni_passau.fim.PADAS.group3.DataDash.category.Category;
+import de.uni_passau.fim.PADAS.group3.DataDash.category.CategoryRepository;
+
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+class DatasetServiceTest {
+
+ @Mock
+ private dataRepository datasetRepository;
+ @Mock
+ private CategoryRepository categoryRepository;
+
+ @InjectMocks
+ private DatasetService datasetService;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void testGetDatasetById() { // Test for getDatasetById method
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset();
+ when(datasetRepository.getDatasetById(id)).thenReturn(dataset);
+ assertEquals(dataset, datasetService.getDatasetById(id));
+ }
+
+ @Test
+ void testAddDataset() { // Test for addDataset method
+ Dataset dataset = new Dataset();
+ when(datasetRepository.save(dataset)).thenReturn(dataset);
+ assertEquals(dataset, datasetService.addDataset(dataset));
+ }
+
+ @Test
+ void testVoteDataset() { // Test for voteDataset method
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset();
+ when(datasetRepository.getDatasetById(id)).thenReturn(dataset);
+ datasetService.voteDataset(id, 5);
+ verify(datasetRepository).save(dataset);
+ assertEquals(1, dataset.getVotes());
+ assertEquals(5, dataset.getRaiting());
+ }
+
+ @Test
+ void testDeleteDataset() { // Test for deleteDataset method
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset();
+ when(datasetRepository.getDatasetById(id)).thenReturn(dataset);
+ datasetService.deleteDataset(id);
+ verify(datasetRepository).delete(dataset);
+ }
+
+ @Test
+ void testUpvoteDataset() { // Test for upvoteDataset method
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset();
+ when(datasetRepository.getDatasetById(id)).thenReturn(dataset);
+ datasetService.upvoteDataset(id);
+ verify(datasetRepository).save(dataset);
+ assertEquals(1, dataset.getUpvotes());
+ }
+
+ @Test
+ void testDownvoteDataset() { // Test for downvoteDataset method
+ UUID id = UUID.randomUUID();
+ Dataset dataset = new Dataset();
+ when(datasetRepository.getDatasetById(id)).thenReturn(dataset);
+ datasetService.downvoteDataset(id);
+ verify(datasetRepository).save(dataset);
+ assertEquals(-1, dataset.getUpvotes());
+ }
+
+
+
+ @Test
+ void testSearchByOptionalCriteria() { // Test for searchByOptionalCriteria method
+ String search = "search";
+ Type type = Type.DATASET;
+ Pageable pageable = PageRequest.of(0, 10);
+ List datasets = Arrays.asList(new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"), new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"));
+ PageImpl s = new PageImpl(datasets);
+ given(datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), Optional.ofNullable(type),pageable)).willReturn(s);
+ assertEquals(s.getContent(), datasetService.searchByOptionalCriteria(search, "%",type.toString(), pageable).getContent());
+ }
+
+ @Test
+ void testSearchByOptionalCriteriaWithCategory() { // Test for searchByOptionalCriteria method
+ String search = "search";
+ Type type = Type.DATASET;
+ String category = UUID.randomUUID().toString();
+ Category cat = new Category();
+ Pageable pageable = PageRequest.of(0, 10);
+ List datasets = Arrays.asList(new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"), new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"));
+ PageImpl s = new PageImpl(datasets);
+ given(categoryRepository.getCategoryById(UUID.fromString(category))).willReturn(cat);
+ given(datasetRepository.searchByOptionalCriteriaWithCategory(Optional.ofNullable(search), cat ,Optional.ofNullable(type),pageable)).willReturn(s);
+ assertEquals(s.getContent(), datasetService.searchByOptionalCriteria(search, category,type.toString(), pageable).getContent());
+ }
+
+ // Additional tests for other methods can be added following the same pattern.
+}
\ No newline at end of file
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryControllerTest.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryControllerTest.java
new file mode 100644
index 0000000..d977563
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryControllerTest.java
@@ -0,0 +1,75 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.category;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.util.Arrays;
+import java.util.UUID;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+@WebMvcTest(CategoryController.class)
+public class CategoryControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private CategoryService categoryService;
+
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ Category category = new Category("yeet");
+
+ @Test
+ public void testGetAllCategories() throws Exception {
+ CategoryDto category1 = CategoryDtoMapper.toDto(category);
+ CategoryDto category2 = CategoryDtoMapper.toDto(category);
+ given(categoryService.getAllCategories()).willReturn(Arrays.asList(category1, category2));
+
+ mockMvc.perform(get("/api/v1/categories"))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(Arrays.asList(category1, category2))));
+ }
+
+ @Test
+ public void testFetchCategoryByIdFound() throws Exception {
+ UUID id = UUID.randomUUID();
+ CategoryDto category = CategoryDtoMapper.toDto(this.category);
+ given(categoryService.getCategoryById(id)).willReturn(category);
+
+ mockMvc.perform(get("/api/v1/categories/id/{id}", id))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(category)));
+ }
+
+ @Test
+ public void testFetchCategoryByIdNotFound() throws Exception {
+ UUID id = UUID.randomUUID();
+ given(categoryService.getCategoryById(id)).willReturn(null);
+
+ mockMvc.perform(get("/api/v1/categories/id/{id}", id))
+ .andExpect(status().isNotFound());
+ }
+
+ @Test
+ public void testCreateCategory() throws Exception {
+ CategoryDto categoryDto = CategoryDtoMapper.toDto(category);
+ mockMvc.perform(post("/api/v1/categories")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(categoryDto)))
+ .andExpect(status().isCreated());
+ // Verify that the service method was called once
+ verify(categoryService).addCategory(any(CategoryDto.class));
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryServiceTest.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryServiceTest.java
new file mode 100644
index 0000000..a06d189
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryServiceTest.java
@@ -0,0 +1,68 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.category;
+
+import static org.mockito.Mockito.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class CategoryServiceTest {
+
+ @Mock
+ private CategoryRepository categoryRepository;
+
+ @InjectMocks
+ private CategoryService categoryService;
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ public void testAddCategory() {
+ CategoryDto categoryDto = new CategoryDto("Test Category", UUID.randomUUID());
+ categoryService.addCategory(categoryDto);
+
+ verify(categoryRepository, times(1)).save(any(Category.class));
+ }
+
+ @Test
+ public void testGetAllCategories() {
+ when(categoryRepository.findAll()).thenReturn(Arrays.asList(new Category("Category 1"), new Category("Category 2")));
+
+ List categories = categoryService.getAllCategories();
+
+ assertNotNull(categories);
+ assertEquals(2, categories.size());
+ }
+
+ @Test
+ public void testGetCategoryByIdFound() {
+ UUID id = UUID.randomUUID();
+ Category category = new Category("Test Category");
+ when(categoryRepository.getCategoryById(id)).thenReturn(category);
+
+ CategoryDto result = categoryService.getCategoryById(id);
+
+ assertNotNull(result);
+ assertEquals("Test Category", result.getName());
+ }
+
+ @Test
+ public void testGetCategoryByIdNotFound() {
+ UUID id = UUID.randomUUID();
+ when(categoryRepository.getCategoryById(id)).thenReturn(null);
+
+ CategoryDto result = categoryService.getCategoryById(id);
+
+ assertNull(result);
+ }
+}
\ No newline at end of file
From aea23b0a6acd3b82268db258ab6fcbcc1cdbcce9 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 13:08:37 +0200
Subject: [PATCH 02/19] refactor: optimize imports
---
.../group3/DataDash/Dataset/DatasetControllerTests.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
index 06a22fc..634287a 100644
--- a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
@@ -1,8 +1,7 @@
package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
import com.fasterxml.jackson.databind.ObjectMapper;
-import de.uni_passau.fim.PADAS.group3.DataDash.Dataset.DatasetController;
-import de.uni_passau.fim.PADAS.group3.DataDash.Dataset.DatasetService;
+
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
@@ -10,13 +9,10 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
-import java.net.URL;
-import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
From cff7e8166e458029a8e0ec316525a18db405c291 Mon Sep 17 00:00:00 2001
From: J-Klinke
Date: Sat, 6 Jul 2024 17:11:11 +0200
Subject: [PATCH 03/19] implemented delete & back button
---
src/main/resources/static/details.css | 42 ++++++++++++++++++++++++++
src/main/resources/static/details.html | 4 +++
src/main/resources/static/details.js | 36 +++++++++++++++++++---
3 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/src/main/resources/static/details.css b/src/main/resources/static/details.css
index 86bb412..ad808bc 100644
--- a/src/main/resources/static/details.css
+++ b/src/main/resources/static/details.css
@@ -208,6 +208,48 @@ a {
}
}
+#details-btns > . {
+ float: right;
+}
+
+#delete-btn {
+ background: #861c1c;
+}
+
+/* button styling to be revisited */
+.btn {
+ padding: .5lh 1lh;
+ border: none;
+ border-radius: .5lh;
+ --btn-color: var(--fg-color);
+ background-color: var(--btn-color);
+ color: var(--text-color);
+ font-weight: bold;
+ font-size: 1rem;
+ transition: background-color 100ms, filter 200ms;
+ transition-timing-function: ease-out;
+ --drop-shadow-opacity: .5;
+ --drop-shadow-offset-y: 0;
+ --drop-shadow-blur: .25rem;
+ --drop-shadow: drop-shadow(
+ rgba(0, 0, 0, var(--drop-shadow-opacity))
+ 0 var(--drop-shadow-offset-y) var(--drop-shadow-blur)
+ );
+ filter: var(--drop-shadow);
+}
+
+.btn:focus-visible, #is-dataset:focus-visible + #is-dataset-toggle {
+ outline-offset: 2px;
+}
+
+.btn:not(:disabled):hover {
+ background-color: color-mix(in oklab, var(--btn-color) 80%, var(--bg-color));
+ --drop-shadow-opacity: .8;
+ --drop-shadow-offset-y: .25rem;
+ --drop-shadow-blur: .4rem;
+}
+
+
#nothing-found-bg {
background-position-x: calc(50% + 3cqh);
}
diff --git a/src/main/resources/static/details.html b/src/main/resources/static/details.html
index e91405e..1e867b3 100644
--- a/src/main/resources/static/details.html
+++ b/src/main/resources/static/details.html
@@ -58,6 +58,10 @@
ipsam nobis quis.
+
+
+
+
diff --git a/src/main/resources/static/details.js b/src/main/resources/static/details.js
index e770a5c..155b14d 100644
--- a/src/main/resources/static/details.js
+++ b/src/main/resources/static/details.js
@@ -13,6 +13,10 @@ const category = document.getElementById("category");
const license = document.getElementById("license");
const termsOfUse = document.getElementById("terms-of-use");
const fullDescription = document.getElementById("full-description");
+const backButton = document.getElementById("back-btn");
+const deleteButton = document.getElementById("delete-btn");
+
+let dataset = null;
const currentLocation = new URL(location.href);
if (currentLocation.searchParams.has("id")) {
@@ -22,10 +26,16 @@ if (currentLocation.searchParams.has("id")) {
if (response.ok) {
const data = await response.json();
- const dataset = new Dataset(data);
+ dataset = new Dataset(data);
console.dir(data, dataset);
const upvoteComponent = dataset.createUpvoteComponent();
+ console.log(dataset.storageGet());
+ debugger
+ if (dataset.storageGetKey("created-locally", false)) {
+ deleteButton.classList.remove("hidden");
+ }
+
title.innerText = dataset.title;
title.dataset.type = dataset.type.toLowerCase();
rating.value = dataset.rating;
@@ -41,10 +51,10 @@ if (currentLocation.searchParams.has("id")) {
month: "long",
year: "numeric",
});
- category.innerText = dataset.category.name;
- category.dataset.id = dataset.category.id;
- license.innerText = dataset.license;
- termsOfUse.href = dataset.termsOfUse;
+ //category.innerText = dataset.category.name;
+ //category.dataset.id = dataset.category.id;
+ //license.innerText = dataset.license;
+ //termsOfUse.href = dataset.termsOfUse;
fullDescription.innerText = dataset.fullDescription;
@@ -57,3 +67,19 @@ if (currentLocation.searchParams.has("id")) {
mainPage.classList.add("hidden");
notFoundPage.classList.remove("hidden");
}
+
+backButton.addEventListener("click", () => {
+ window.location.href = location.origin;
+})
+
+deleteButton.addEventListener("click", () => {
+ if (dataset != null) {
+ fetch(`${currentLocation.origin}/api/v1/datasets/id/` + dataset.id, {
+ method: 'DELETE'
+ }).then(resp => {
+ if (resp.ok) {
+ window.location.href = location.origin;
+ }
+ });
+ }
+});
From 7e08a507e4e3548f9b6358d7d84dd9249c0c006c Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 17:54:48 +0200
Subject: [PATCH 04/19] feat: Add CategoryRepositoryTests and
DataRepositoryTests
The code changes include adding new test classes CategoryRepositoryTests and DataRepositoryTests. These test classes are used to test the functionality of the CategoryRepository and DataRepository classes respectively. The CategoryRepositoryTests class contains tests for the findById, findByName, and findAll methods of the CategoryRepository class. The DataRepositoryTests class contains tests for the findByOptionalCriteria and getDatasetById methods of the DataRepository class.
---
.../DataDash/Dataset/DataRepositoryTests.java | 80 +++++++++++++++++++
.../Dataset/DatasetControllerTests.java | 51 +++++++-----
.../category/CategoryRepositoryTests.java | 56 +++++++++++++
3 files changed, 165 insertions(+), 22 deletions(-)
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DataRepositoryTests.java
create mode 100644 src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepositoryTests.java
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DataRepositoryTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DataRepositoryTests.java
new file mode 100644
index 0000000..3a8fa41
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DataRepositoryTests.java
@@ -0,0 +1,80 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@DataJpaTest
+public class DataRepositoryTests {
+
+ @Autowired
+ private dataRepository dataRepository;
+
+ @BeforeEach
+ private void clearDatabase() {
+ dataRepository.deleteAll();
+ }
+
+ @Test
+ public void testFindByOptionalCriteria() {
+ // Prepare test data
+ Dataset dataset = new Dataset("title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset);
+
+ // Execute the method under test
+ Page result = dataRepository.findByOptionalCriteria(
+ Optional.of("title"), Optional.empty(), Optional.empty(), Optional.empty(),
+ Optional.empty(), Optional.empty(), Optional.empty(), PageRequest.of(0, 10));
+
+ // Assertions
+ assertThat(result.getContent()).hasSize(1);
+ assertThat(result.getContent().get(0).getTitle()).isEqualTo("title");
+ }
+ @Test
+ public void searchByOptionalCriteria() {
+ Dataset dataset1 = new Dataset("water", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset1);
+ Dataset dataset = new Dataset("title1", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset);
+ dataset = new Dataset("title1", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset);
+
+ Page result = dataRepository.searchByOptionalCriteria(
+ Optional.of("water"), Optional.empty(), PageRequest.of(0, 10));
+
+ assertThat(result.getContent()).hasSize(1);
+ assertThat(result.getContent().get(0).getTitle()).isEqualTo("water");
+ }
+ @Test
+ public void searchByOptionalCriteriaMulti() {
+ Dataset dataset1 = new Dataset("title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset1);
+ Dataset dataset = new Dataset("title1", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset);
+ dataset = new Dataset("title1", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataRepository.save(dataset);
+
+ Page result = dataRepository.searchByOptionalCriteria(
+ Optional.of("title%"), Optional.empty(), PageRequest.of(0, 10));
+
+ assertThat(result.getContent()).hasSize(3);
+ }
+
+ @Test
+ public void getDatasetById() {
+ Dataset dataset = new Dataset("title", "abst", "desc", "auth", null, null, Type.API, "MIT");
+ dataset = dataRepository.save(dataset);
+
+ Dataset result = dataRepository.getDatasetById(dataset.getId());
+
+ assertThat(result).isNotNull();
+ assertThat(result.getTitle()).isEqualTo("title");
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
index 634287a..8a3c7d9 100644
--- a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
@@ -45,9 +45,7 @@ public class DatasetControllerTests {
@Test
void getDatasetById_whenExists() throws Exception {
UUID id = UUID.randomUUID();
- Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT"); // Assuming a
- // constructor or
- // builder pattern
+ Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
given(datasetService.getDatasetById(id)).willReturn(dataset);
mockMvc.perform(get("/api/v1/datasets/id/" + id.toString()))
@@ -233,68 +231,77 @@ public class DatasetControllerTests {
@Test
void searchDatasets_whenExists() throws Exception {
- String keyword = "data";
+ String keyword = "title%";
List datasets = Arrays.asList(
- new Dataset("Title 1", "abst", "data", "auth", null, null, Type.API, "MIT"),
- new Dataset("Title 2", "abst", "data", "auth", null, null, Type.API, "MIT"));
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(new PageImpl<>(datasets));
+ new Dataset("Title 1", "abst", "data", "auth", null, null, Type.API, "MIT"));
+ // new Dataset("Title 2", "abst", "data", "auth", null, null, Type.API, "MIT"));
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword))
- .andExpect(status().isOk());
- //TODO: Check output
+ Page page = new PageImpl<>(datasets);
+ given(datasetService.searchByOptionalCriteria(keyword, "%", "%",
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(page);
+ String s = objectMapper.writeValueAsString(page);
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword))
+ .andExpect(status().isOk())
+ .andExpect(content().json(s));
}
@Test
void searchDatasets_whenNotExists() throws Exception {
String keyword = "nonexistent";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?seaarch=" + keyword))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword))
.andExpect(status().isOk());
}
@Test
void searchDatasets_whenInvalidSort() throws Exception {
String keyword = "data";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&sort=invalid"))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword + "&sort=invalid"))
.andExpect(status().isBadRequest());
}
@Test
void searchDatasets_whenInvalidDirection() throws Exception {
String keyword = "data";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&direction=invalid"))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword + "&direction=invalid"))
.andExpect(status().isBadRequest());
}
@Test
void searchDatasets_whenInvalidPage() throws Exception {
String keyword = "data";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&page=-1"))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword + "&page=-1"))
.andExpect(status().isBadRequest());
}
@Test
void searchDatasets_whenInvalidSize() throws Exception {
String keyword = "data";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&size=-1"))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword + "&size=-1"))
.andExpect(status().isBadRequest());
}
@Test
void searchDatasets_whenInvalidSize2() throws Exception {
String keyword = "data";
- given(datasetService.searchByOptionalCriteria(keyword,null,null,PageRequest.of(0,20,Sort.by(Sort.Direction.DESC,"upvotes")))).willReturn(Page.empty());
+ given(datasetService.searchByOptionalCriteria(keyword, null, null,
+ PageRequest.of(0, 20, Sort.by(Sort.Direction.DESC, "upvotes")))).willReturn(Page.empty());
- mockMvc.perform(get("/api/v1/datasets/search?searach=" + keyword + "&size=0"))
+ mockMvc.perform(get("/api/v1/datasets/search?search=" + keyword + "&size=0"))
.andExpect(status().isBadRequest());
}
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepositoryTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepositoryTests.java
new file mode 100644
index 0000000..2330d6c
--- /dev/null
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepositoryTests.java
@@ -0,0 +1,56 @@
+package de.uni_passau.fim.PADAS.group3.DataDash.category;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@DataJpaTest
+public class CategoryRepositoryTests {
+
+ @Autowired
+ private CategoryRepository categoryRepository;
+
+ private Category savedCategory;
+
+ @BeforeEach
+ public void setup() {
+ // Setup data for each test
+ Category category = new Category();
+ category.setName("Test Category");
+ // Assuming Category class has a setName method and an ID that is auto-generated
+ savedCategory = categoryRepository.save(category);
+ }
+
+ @Test
+ public void whenFindById_thenReturnCategory() {
+ Optional foundCategory = categoryRepository.findById(savedCategory.getId());
+ assertThat(foundCategory).isPresent();
+ assertThat(foundCategory.get().getId()).isEqualTo(savedCategory.getId());
+ }
+
+ @Test
+ public void whenFindByName_thenReturnCategoryList() {
+ List categories = categoryRepository.findByName("Test Category");
+ assertThat(categories).hasSize(1);
+ assertThat(categories.get(0).getName()).isEqualTo("Test Category");
+ }
+
+ @Test
+ public void whenFindAll_thenReturnAllCategories() {
+ List categories = categoryRepository.findAll();
+ assertThat(categories).isNotEmpty();
+ }
+
+ @Test
+ public void whenGetCategoryById_thenReturnCategory() {
+ Category foundCategory = categoryRepository.getCategoryById(savedCategory.getId());
+ assertThat(foundCategory).isNotNull();
+ assertThat(foundCategory.getId()).isEqualTo(savedCategory.getId());
+ }
+}
\ No newline at end of file
From 603517d1872e3761e9b6ebdb73daff18a3b28876 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 17:57:52 +0200
Subject: [PATCH 05/19] feat: Remove unused methods in dataRepository and
CategoryRepository
---
.../DataDash/Dataset/dataRepository.java | 26 -------------------
.../DataDash/category/CategoryRepository.java | 2 +-
2 files changed, 1 insertion(+), 27 deletions(-)
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
index c896552..65cfd0e 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
@@ -17,32 +17,6 @@ public interface dataRepository extends JpaRepository {
Dataset getDatasetById(UUID id);
- List findByTitle(String title);
-
- List findByTitleLike(String title);
-
- List findByAuthorLike(String author);
-
- List findByType(Type type);
-
- List findByAuthor(String author);
-
- List findByAbstLike(String abst);
-
- List findByDescriptionLike(String description);
-
- List findByRaitingGreaterThan(float raiting);
-
- List findByVotesGreaterThan(int votes);
-
- List findByDateAfter(Date date);
-
- List findByDateBefore(Date date);
-
- List findByCategorie(Category categorie);
-
- List findByDateBetween(Date date1, Date date2);
-
@SuppressWarnings("null")
Page findAll(Pageable pageable);
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepository.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepository.java
index acde965..38e84c6 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepository.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryRepository.java
@@ -17,4 +17,4 @@ public interface CategoryRepository extends JpaRepository{
@SuppressWarnings("null")
Optional findById(UUID id);
-}
+}
\ No newline at end of file
From 1effb09cdba3740ea7541dab98d580ed4c0b6af2 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 18:03:27 +0200
Subject: [PATCH 06/19] feat: Update dataset voting logic to allow for zero
stars
---
.../fim/PADAS/group3/DataDash/Dataset/DatasetController.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 1d1ef41..1fe09b6 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
@@ -70,7 +70,7 @@ public class DatasetController {
if (datasetService.getDatasetById(id) == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- if (!(stars > 0 && stars < 6)) {
+ if (!(stars >= 0 && stars < 6)) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
datasetService.voteDataset(id, stars);
From 69afb590d48abb7d91d51ba2313789cf22d11e6c Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 18:26:54 +0200
Subject: [PATCH 07/19] chore: Remove unused imports in DatasetController,
DatasetService, and dataRepository
---
.../fim/PADAS/group3/DataDash/Dataset/DatasetController.java | 2 --
.../fim/PADAS/group3/DataDash/Dataset/DatasetService.java | 1 -
.../fim/PADAS/group3/DataDash/Dataset/dataRepository.java | 2 --
3 files changed, 5 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 b118dab..a844374 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
@@ -15,8 +15,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;
-
@EnableSpringDataWebSupport(pageSerializationMode = PageSerializationMode.VIA_DTO)
@RestController
@RequestMapping("/api/v1/datasets")
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 93d1388..52e6ef6 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
@@ -1,7 +1,6 @@
package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
import java.time.LocalDate;
-import java.util.List;
import java.util.Optional;
import java.util.UUID;
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
index 65cfd0e..b983df2 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/dataRepository.java
@@ -1,9 +1,7 @@
package de.uni_passau.fim.PADAS.group3.DataDash.Dataset;
-import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import java.sql.Date;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
From c0ad1ca8482bfaef2c969f225f7db4076fd6a573 Mon Sep 17 00:00:00 2001
From: J-Klinke
Date: Sat, 6 Jul 2024 18:28:07 +0200
Subject: [PATCH 08/19] rating is implemented, updates the stars and prohibits
voting more than once
---
src/main/resources/static/details.css | 11 +++++++
src/main/resources/static/details.html | 1 +
src/main/resources/static/details.js | 42 ++++++++++++++++++++++++--
src/main/resources/static/main.js | 2 +-
4 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/static/details.css b/src/main/resources/static/details.css
index ad808bc..416a76d 100644
--- a/src/main/resources/static/details.css
+++ b/src/main/resources/static/details.css
@@ -79,6 +79,17 @@ h1 {
grid-column: 1 / 3;
}
+#rating-input {
+ mask-image: url("stars.svg");
+ -webkit-mask-image: url("stars.svg");
+ mask-size: contain;
+ mask-mode: alpha;
+ width: 5lh;
+ height: 1lh;
+ margin-inline: .5ch;
+ background: linear-gradient(to right, yellow 33%, black 33%);
+}
+
#rating {
color: color-mix(in oklab, var(--text-color) 80%, black);
color: transparent;
diff --git a/src/main/resources/static/details.html b/src/main/resources/static/details.html
index 1e867b3..ff27926 100644
--- a/src/main/resources/static/details.html
+++ b/src/main/resources/static/details.html
@@ -24,6 +24,7 @@
Title
4
+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Perspiciatis recusandae laborum odio corrupti voluptas quisquam dicta, quibusdam ipsum qui exercitationem.
https://example.com/dataset
diff --git a/src/main/resources/static/details.js b/src/main/resources/static/details.js
index 155b14d..52cfa34 100644
--- a/src/main/resources/static/details.js
+++ b/src/main/resources/static/details.js
@@ -17,6 +17,8 @@ const backButton = document.getElementById("back-btn");
const deleteButton = document.getElementById("delete-btn");
let dataset = null;
+let currentRating = 0;
+let isRated = false;
const currentLocation = new URL(location.href);
if (currentLocation.searchParams.has("id")) {
@@ -35,11 +37,13 @@ if (currentLocation.searchParams.has("id")) {
if (dataset.storageGetKey("created-locally", false)) {
deleteButton.classList.remove("hidden");
}
+ isRated = dataset.storageGetKey("is-rated", false)
+
title.innerText = dataset.title;
title.dataset.type = dataset.type.toLowerCase();
rating.value = dataset.rating;
- ratingText.innerText = dataset.rating;
+ ratingText.innerText = parseFloat(dataset.rating).toFixed(1);
shortDescription.innerText = dataset.shortDescription;
url.href = dataset.url;
url.innerText = dataset.url;
@@ -51,7 +55,7 @@ if (currentLocation.searchParams.has("id")) {
month: "long",
year: "numeric",
});
- //category.innerText = dataset.category.name;
+ //category.innerText = dataset.category.name; // TODO: uncomment
//category.dataset.id = dataset.category.id;
//license.innerText = dataset.license;
//termsOfUse.href = dataset.termsOfUse;
@@ -83,3 +87,37 @@ deleteButton.addEventListener("click", () => {
});
}
});
+
+rating.addEventListener("mousemove", (event) => {
+ if (!isRated) {
+ let bounds = rating.getBoundingClientRect();
+ currentRating = Math.round(((event.clientX - bounds.left) / bounds.width) * 5);
+ console.log(currentRating);
+ rating.value = currentRating;
+ }
+
+});
+
+rating.addEventListener("mouseleave", () => {
+ rating.value = dataset.rating;
+});
+
+rating.addEventListener("click", () => {
+ if (!isRated) {
+ fetch(`${currentLocation.origin}/api/v1/datasets/id/` + dataset.id + "/stars?stars=" + currentRating, {
+ method: 'PUT'
+ }).then(resp => {
+ if (resp.ok) {
+ dataset.storageSetKey("is-rated", true);
+ isRated = true;
+ fetch(`${currentLocation.origin}/api/v1/datasets/id/` + dataset.id)
+ .then(resp => resp.json())
+ .then((data) => {
+ dataset = new Dataset(data);
+ ratingText.innerText = parseFloat(dataset.rating).toFixed(1);
+ rating.value = dataset.rating;
+ });
+ }
+ });
+ }
+})
diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js
index ad98c3b..d58c423 100644
--- a/src/main/resources/static/main.js
+++ b/src/main/resources/static/main.js
@@ -1,4 +1,4 @@
-import { DATASET_ENDPOINT, getBaseURL } from "./constants.js";
+import { DATASET_ENDPOINT, getBaseURL } from "./constants.js"
import { fetchQuery } from "./contentUtility.js";
import Dataset from "./dataset.js";
From b87fafe36065182c77bf0f30dd73fa3d67947cb1 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 18:41:03 +0200
Subject: [PATCH 09/19] link to exmple site
---
src/main/resources/data.sql | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 5f7c01b..9e1e6c8 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -11,11 +11,11 @@ INSERT INTO category (id, name) VALUES
-- Insert sample data into dataset
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');
+('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://example.com'),
+('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://example.com'),
+('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://example.com'),
+('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://example.com'),
+('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://example.com');
-- Insert 10 more sample data into dataset
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'),
From f1cb3c1af07c2714a67af85bc8197b914f27b758 Mon Sep 17 00:00:00 2001
From: J-Klinke
Date: Sat, 6 Jul 2024 19:28:12 +0200
Subject: [PATCH 10/19] minor styling changes
---
src/main/resources/static/details.css | 7 +++++--
src/main/resources/static/details.js | 8 ++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/main/resources/static/details.css b/src/main/resources/static/details.css
index 416a76d..92d1372 100644
--- a/src/main/resources/static/details.css
+++ b/src/main/resources/static/details.css
@@ -219,8 +219,11 @@ a {
}
}
-#details-btns > . {
- float: right;
+#details-btns {
+ grid-column: 1 / 4;
+ justify-content: end;
+ gap: 1rem;
+ display: flex;
}
#delete-btn {
diff --git a/src/main/resources/static/details.js b/src/main/resources/static/details.js
index 52cfa34..4f530a2 100644
--- a/src/main/resources/static/details.js
+++ b/src/main/resources/static/details.js
@@ -55,10 +55,10 @@ if (currentLocation.searchParams.has("id")) {
month: "long",
year: "numeric",
});
- //category.innerText = dataset.category.name; // TODO: uncomment
- //category.dataset.id = dataset.category.id;
- //license.innerText = dataset.license;
- //termsOfUse.href = dataset.termsOfUse;
+ category.innerText = dataset.category.name;
+ category.dataset.id = dataset.category.id;
+ license.innerText = dataset.license;
+ termsOfUse.href = dataset.termsOfUse;
fullDescription.innerText = dataset.fullDescription;
From 448bc30f03e15d00f76f7291472be70746100e1a Mon Sep 17 00:00:00 2001
From: J-Klinke
Date: Sat, 6 Jul 2024 19:40:35 +0200
Subject: [PATCH 11/19] found & fixed minor bug: sorting by stars now works
---
.../uni_passau/fim/PADAS/group3/DataDash/Dataset/Dataset.java | 2 +-
src/main/resources/static/index.html | 4 ++--
2 files changed, 3 insertions(+), 3 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 8a269c9..36796e3 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
@@ -52,7 +52,7 @@ public class Dataset {
private String licence;
- private static final List sortable = Arrays.asList("author", "title", "upvotes", "date");
+ private static final List sortable = Arrays.asList("author", "title", "upvotes", "raiting", "date");
@ManyToOne
private Category categorie;
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
index 46da537..88979c4 100644
--- a/src/main/resources/static/index.html
+++ b/src/main/resources/static/index.html
@@ -45,8 +45,8 @@
-
-
+
+
From 54977ce95b8b74ab595918e9f5ce5158ec7fedc5 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 19:52:54 +0200
Subject: [PATCH 12/19] chore: generate moor data
---
src/main/resources/data.sql | 46 ++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 5f7c01b..18c7216 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -11,6 +11,7 @@ INSERT INTO category (id, name) VALUES
-- Insert sample data into dataset
INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence, terms_of_use) VALUES
+<<<<<<< Updated upstream
('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'),
@@ -18,6 +19,13 @@ INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, auth
('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, 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://example.com'),
+('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://example.com'),
+('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://example.com'),
+('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://example.com'),
+('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://example.com'),
+>>>>>>> Stashed changes
('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'),
@@ -27,4 +35,40 @@ INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, auth
('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
+('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'),
+('2023-01-16', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174115', 'Abstract 16', 'Author 16', 'Description 16', 'Title 16', 'http://example.com/16', 'API', 'MIT', 'http://zip.com'),
+('2023-01-17', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174116', 'Abstract 17', 'Author 17', 'Description 17', 'Title 17', 'http://example.com/17', 'DATASET', 'MIT', 'http://zip.com'),
+('2023-01-18', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174117', 'Abstract 18', 'Author 18', 'Description 18', 'Title 18', 'http://example.com/18', 'API', 'MIT', 'http://zip.com'),
+('2023-01-19', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174118', 'Abstract 19', 'Author 19', 'Description 19', 'Title 19', 'http://example.com/19', 'DATASET', 'MIT', 'http://zip.com'),
+('2023-01-20', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174119', 'Abstract 20', 'Author 20', 'Description 20', 'Title 20', 'http://example.com/20', 'API', 'MIT', 'http://zip.com'),
+('2023-01-21', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174120', 'Abstract 21', 'Author 21', 'Description 21', 'Title 21', 'http://example.com/21', 'DATASET', 'MIT', 'http://zip.com'),
+('2023-01-22', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174121', 'Abstract 22', 'Author 22', 'Description 22', 'Title 22', 'http://example.com/22', 'API', 'MIT', 'http://zip.com'),
+('2023-01-23', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174122', 'Abstract 23', 'Author 23', 'Description 23', 'Title 23', 'http://example.com/23', 'DATASET', 'MIT', 'http://zip.com'),
+('2023-01-24', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174123', 'Abstract 24', 'Author 24', 'Description 24', 'Title 24', 'http://example.com/24', 'API', 'MIT', 'http://zip.com'),
+('2023-01-25', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174124', 'Abstract 25', 'Author 25', 'Description 25', 'Title 25', 'http://example.com/25', 'DATASET', 'MIT', 'http://zip.com'),
+('2023-01-27', 4.3, 95, 115, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174126', 'Abstract 27', 'Author 27', 'Description 27', 'Title 27', 'http://example.com/27', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-01-28', 4.7, 160, 180, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174127', 'Abstract 28', 'Author 28', 'Description 28', 'Title 28', 'http://example.com/28', 'API', 'GPL', 'http://zip.com'),
+('2023-01-29', 4.4, 110, 130, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174128', 'Abstract 29', 'Author 29', 'Description 29', 'Title 29', 'http://example.com/29', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-01-30', 4.8, 190, 210, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174129', 'Abstract 30', 'Author 30', 'Description 30', 'Title 30', 'http://example.com/30', 'API', 'GPL', 'http://zip.com'),
+('2023-01-31', 4.5, 100, 120, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174130', 'Abstract 31', 'Author 31', 'Description 31', 'Title 31', 'http://example.com/31', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-01', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174131', 'Abstract 32', 'Author 32', 'Description 32', 'Title 32', 'http://example.com/32', 'API', 'GPL', 'http://zip.com'),
+('2023-02-02', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174132', 'Abstract 33', 'Author 33', 'Description 33', 'Title 33', 'http://example.com/33', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-03', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174133', 'Abstract 34', 'Author 34', 'Description 34', 'Title 34', 'http://example.com/34', 'API', 'GPL', 'http://zip.com'),
+('2023-02-04', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174134', 'Abstract 35', 'Author 35', 'Description 35', 'Title 35', 'http://example.com/35', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-05', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174135', 'Abstract 36', 'Author 36', 'Description 36', 'Title 36', 'http://example.com/36', 'API', 'GPL', 'http://zip.com'),
+('2023-02-06', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174136', 'Abstract 37', 'Author 37', 'Description 37', 'Title 37', 'http://example.com/37', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-07', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174137', 'Abstract 38', 'Author 38', 'Description 38', 'Title 38', 'http://example.com/38', 'API', 'GPL', 'http://zip.com'),
+('2023-02-08', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174138', 'Abstract 39', 'Author 39', 'Description 39', 'Title 39', 'http://example.com/39', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-09', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174139', 'Abstract 40', 'Author 40', 'Description 40', 'Title 40', 'http://example.com/40', 'API', 'GPL', 'http://zip.com');
+-- Insert more sample data into dataset
+INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence, terms_of_use) VALUES
+('2023-02-10', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174140', 'Abstract 41', 'Author 41', 'Description 41', 'Title 41', 'http://example.com/41', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-11', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174141', 'Abstract 42', 'Author 42', 'Description 42', 'Title 42', 'http://example.com/42', 'API', 'GPL', 'http://zip.com'),
+('2023-02-12', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174002', '123e4567-e89b-12d3-a456-426614174142', 'Abstract 43', 'Author 43', 'Description 43', 'Title 43', 'http://example.com/43', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-13', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174003', '123e4567-e89b-12d3-a456-426614174143', 'Abstract 44', 'Author 44', 'Description 44', 'Title 44', 'http://example.com/44', 'API', 'GPL', 'http://zip.com'),
+('2023-02-14', 4.2, 80, 100, '123e4567-e89b-12d3-a456-426614174004', '123e4567-e89b-12d3-a456-426614174144', 'Abstract 45', 'Author 45', 'Description 45', 'Title 45', 'http://example.com/45', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-15', 4.6, 120, 140, '123e4567-e89b-12d3-a456-426614174005', '123e4567-e89b-12d3-a456-426614174145', 'Abstract 46', 'Author 46', 'Description 46', 'Title 46', 'http://example.com/46', 'API', 'GPL', 'http://zip.com'),
+('2023-02-16', 4.8, 180, 200, '123e4567-e89b-12d3-a456-426614174006', '123e4567-e89b-12d3-a456-426614174146', 'Abstract 47', 'Author 47', 'Description 47', 'Title 47', 'http://example.com/47', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-17', 4.3, 90, 110, '123e4567-e89b-12d3-a456-426614174007', '123e4567-e89b-12d3-a456-426614174147', 'Abstract 48', 'Author 48', 'Description 48', 'Title 48', 'http://example.com/48', 'API', 'GPL', 'http://zip.com'),
+('2023-02-18', 4.7, 150, 170, '123e4567-e89b-12d3-a456-426614174000', '123e4567-e89b-12d3-a456-426614174148', 'Abstract 49', 'Author 49', 'Description 49', 'Title 49', 'http://example.com/49', 'DATASET', 'GPL', 'http://zip.com'),
+('2023-02-19', 4.9, 200, 220, '123e4567-e89b-12d3-a456-426614174001', '123e4567-e89b-12d3-a456-426614174149', 'Abstract 50', 'Author 50', 'Description 50', 'Title 50', 'http://example.com/50', 'API', 'GPL', 'http://zip.com');
\ No newline at end of file
From e8de33cdcb7295fdd3853abe83699d70cb67b98e Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 19:54:59 +0200
Subject: [PATCH 13/19] chore: Remove unused imports and fix data.sql conflicts
---
src/main/resources/data.sql | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 18c7216..7fbfc2e 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -11,21 +11,11 @@ INSERT INTO category (id, name) VALUES
-- Insert sample data into dataset
INSERT INTO dataset (date, raiting, upvotes, votes, categorie_id, id, abst, author, description, title, url, type, licence, terms_of_use) VALUES
-<<<<<<< Updated upstream
-('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, 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://example.com'),
('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://example.com'),
('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://example.com'),
('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://example.com'),
('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://example.com'),
->>>>>>> Stashed changes
('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'),
From 9a6260d1bd509e6d51d2d038c3ab1c35b5aa70b8 Mon Sep 17 00:00:00 2001
From: J-Klinke
Date: Sat, 6 Jul 2024 20:04:39 +0200
Subject: [PATCH 14/19] bugfix: pagination works again
---
src/main/resources/static/contentUtility.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/static/contentUtility.js b/src/main/resources/static/contentUtility.js
index 6854b66..ceb91ac 100644
--- a/src/main/resources/static/contentUtility.js
+++ b/src/main/resources/static/contentUtility.js
@@ -9,7 +9,7 @@ export async function fetchQuery(fetchString, clearResults) {
const data = await response.json();
parseContent(data.content, clearResults);
- lastQuery.totalPages = data.totalPages;
+ lastQuery.totalPages = data.page.totalPages;
if (clearResults) {
lastQuery.currentPage = 0;
}
From b2aabecce14fe0b4985c6f027c93c771f6482a10 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 20:41:31 +0200
Subject: [PATCH 15/19] chore: Update Spring Boot version to 3.3.1 in pom.xml &
remove unused dependency
---
pom.xml | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 36bb031..78fe176 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.3.0
+ 3.3.1
de.uni-passau.fim.PADAS.group3
@@ -57,13 +57,6 @@
runtime
-
- org.mockito
- mockito-core
- 4.5.1
- test
-
-
From e84ecd18bd032727471e6e243352d15ee690fb27 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 20:47:12 +0200
Subject: [PATCH 16/19] feat: Remove invalid stars validation in
DatasetControllerTests becaurse giving 0 stars sould be an option
---
.../DataDash/Dataset/DatasetControllerTests.java | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
index 8a3c7d9..87bb850 100644
--- a/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
+++ b/src/test/java/de/uni_passau/fim/PADAS/group3/DataDash/Dataset/DatasetControllerTests.java
@@ -185,17 +185,6 @@ public class DatasetControllerTests {
.andExpect(status().isBadRequest());
}
- @Test
- void postMethodName_whenInvalidStars2() throws Exception {
- UUID id = UUID.randomUUID();
- Dataset dataset = new Dataset("Title", "abst", "desc", "auth", null, null, Type.API, "MIT");
-
- given(datasetService.getDatasetById(id)).willReturn(dataset);
-
- mockMvc.perform(put("/api/v1/datasets/id/" + id + "/stars?stars=0"))
- .andExpect(status().isBadRequest());
- }
-
@Test
void postMethodName_whenInvalidStars3() throws Exception {
UUID id = UUID.randomUUID();
From ba6257059d5c405260da9e84d8ad05c3679d93c7 Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 21:11:27 +0200
Subject: [PATCH 17/19] Refactor DatasetService and CategoryService for better
code organization and encapsulation
---
.../group3/DataDash/Dataset/DatasetService.java | 16 ++++++++--------
.../DataDash/category/CategoryService.java | 8 ++++----
2 files changed, 12 insertions(+), 12 deletions(-)
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 52e6ef6..757739e 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
@@ -17,44 +17,44 @@ public class DatasetService {
private dataRepository datasetRepository;
private CategoryRepository categoryRepository;
- public DatasetService(dataRepository datasetRepository, CategoryRepository categoryRepository) {
+ DatasetService(dataRepository datasetRepository, CategoryRepository categoryRepository) {
this.datasetRepository = datasetRepository;
this.categoryRepository = categoryRepository;
}
- public Dataset getDatasetById(UUID id) {
+ Dataset getDatasetById(UUID id) {
return datasetRepository.getDatasetById(id);
}
- public Dataset addDataset(Dataset dataset) {
+ Dataset addDataset(Dataset dataset) {
dataset.setDate(LocalDate.now());
return datasetRepository.save(dataset);
}
- public void voteDataset(UUID id, int vote) {
+ void voteDataset(UUID id, int vote) {
Dataset dataset = datasetRepository.getDatasetById(id);
dataset.vote(vote);
datasetRepository.save(dataset);
}
- public void deleteDataset(UUID id) {
+ void deleteDataset(UUID id) {
Dataset dataset = datasetRepository.getDatasetById(id);
datasetRepository.delete(dataset);
}
- public void upvoteDataset(UUID id) {
+ void upvoteDataset(UUID id) {
Dataset dataset = datasetRepository.getDatasetById(id);
dataset.upvote();
datasetRepository.save(dataset);
}
- public void downvoteDataset(UUID id) {
+ void downvoteDataset(UUID id) {
Dataset dataset = datasetRepository.getDatasetById(id);
dataset.downvote();
datasetRepository.save(dataset);
}
- public Page searchByOptionalCriteria(String search, String categories, String type, Pageable pageable) {
+ Page searchByOptionalCriteria(String search, String categories, String type, Pageable pageable) {
Category category = categories.equals("%") ? null
: categoryRepository.getCategoryById(UUID.fromString(categories));
Type t = type.equals("%") ? null : Type.valueOf(type);
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
index 3e2698f..6065620 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
@@ -8,22 +8,22 @@ import java.util.UUID;
public class CategoryService {
private CategoryRepository categoryRepository;
- public CategoryService(CategoryRepository categoryRepository) {
+ CategoryService(CategoryRepository categoryRepository) {
this.categoryRepository = categoryRepository;
}
- public void addCategory(CategoryDto category) {
+ void addCategory(CategoryDto category) {
Category cat = new Category(category.getName());
categoryRepository.save(cat);
}
- public List getAllCategories() {
+ List getAllCategories() {
List tmp = categoryRepository.findAll();
List s = tmp.stream().map(CategoryDtoMapper::toDto).toList();
return s;
}
- public CategoryDto getCategoryById(UUID id) {
+ CategoryDto getCategoryById(UUID id) {
Category c = categoryRepository.getCategoryById(id);
if (c == null) {
return null;
From 146eb0e8f588fbc4517d1a8803882a9f6773c64f Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 21:59:22 +0200
Subject: [PATCH 18/19] chore: Refactor CategoryController and CategoryService
to return created category
---
.../PADAS/group3/DataDash/category/CategoryController.java | 4 ++--
.../fim/PADAS/group3/DataDash/category/CategoryService.java | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryController.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryController.java
index 3ce13b0..f68be67 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryController.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryController.java
@@ -37,8 +37,8 @@ public class CategoryController {
}
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
- public void createCategory(@RequestBody CategoryDto dto) {
- categoryService.addCategory(dto);
+ public Category createCategory(@RequestBody CategoryDto dto) {
+ return categoryService.addCategory(dto);
}
diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
index 6065620..ced75f3 100644
--- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
+++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/category/CategoryService.java
@@ -12,9 +12,9 @@ public class CategoryService {
this.categoryRepository = categoryRepository;
}
- void addCategory(CategoryDto category) {
+ Category addCategory(CategoryDto category) {
Category cat = new Category(category.getName());
- categoryRepository.save(cat);
+ return categoryRepository.save(cat);
}
List getAllCategories() {
From fd0a62ea51924df903f4cac37f90a8c97496704f Mon Sep 17 00:00:00 2001
From: Erik Foris
Date: Sat, 6 Jul 2024 22:11:12 +0200
Subject: [PATCH 19/19] chore: Remove unused Thymeleaf dependency in pom.xml
---
pom.xml | 5 -----
1 file changed, 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index 78fe176..cdd484e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,11 +22,6 @@
org.springframework.boot
spring-boot-starter-data-jpa
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
-
org.springframework.boot