diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/CategoryController.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/CategoryController.java index 5f725a3..69a162e 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/CategoryController.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/CategoryController.java @@ -3,12 +3,15 @@ import java.util.List; import java.util.UUID; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import de.uni_passau.fim.PADAS.group3.DataDash.model.CategoryDto; import de.uni_passau.fim.PADAS.group3.DataDash.model.CategoryService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -29,14 +32,17 @@ public class CategoryController { } @GetMapping("/id/{id}") - public CategoryDto getMethodName(@PathVariable("id") UUID id) { - return categoryService.getCategoryById(id); + public ResponseEntity fetchCategoryById(@PathVariable("id") UUID id) { + CategoryDto category = categoryService.getCategoryById(id); + if(category == null) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + return new ResponseEntity<>(category, HttpStatus.OK); } - + @ResponseStatus(HttpStatus.CREATED) @PostMapping - public String postMethodName(@RequestBody CategoryDto dto) { + public void createCategory(@RequestBody CategoryDto dto) { categoryService.addCategory(dto); - return null; } diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/CategoryService.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/CategoryService.java index ba36dc0..d975497 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/CategoryService.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/CategoryService.java @@ -4,7 +4,6 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; - @Service public class CategoryService { private CategoryRepository categoryRepository; @@ -25,8 +24,11 @@ public class CategoryService { } public CategoryDto getCategoryById(UUID id) { - return CategoryDtoMapper.toDto(categoryRepository.getCategoryById(id)); + Category c = categoryRepository.getCategoryById(id); + if (c == null) { + return null; + } + return CategoryDtoMapper.toDto(c); } - }