From f2ed69f6f8578ca429b486826d1f954d4c252b24 Mon Sep 17 00:00:00 2001 From: vokarl Date: Fri, 16 Aug 2024 14:43:28 +0200 Subject: [PATCH] refactoring --- .idea/compiler.xml | 1 + .../src/main/java/org/example/backend/Product.java | 2 +- .../java/org/example/backend/ProductController.java | 6 ++---- .../java/org/example/backend/ProductRepository.java | 2 ++ .../java/org/example/backend/ProductService.java | 7 +++---- .../org/example/backend/BackendApplicationTest.java | 13 ------------- frontend/src/componets/ProductList.tsx | 2 +- 7 files changed, 10 insertions(+), 23 deletions(-) delete mode 100644 backend/src/test/java/org/example/backend/BackendApplicationTest.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c86ed3f..66bc19f 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + diff --git a/backend/src/main/java/org/example/backend/Product.java b/backend/src/main/java/org/example/backend/Product.java index b290558..bab9ee3 100644 --- a/backend/src/main/java/org/example/backend/Product.java +++ b/backend/src/main/java/org/example/backend/Product.java @@ -3,6 +3,6 @@ public record Product( String id, String name, - int ammount + int amount ) { } diff --git a/backend/src/main/java/org/example/backend/ProductController.java b/backend/src/main/java/org/example/backend/ProductController.java index 7cc978b..880073e 100644 --- a/backend/src/main/java/org/example/backend/ProductController.java +++ b/backend/src/main/java/org/example/backend/ProductController.java @@ -1,19 +1,17 @@ package org.example.backend; +import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; - +@RequiredArgsConstructor @RestController @RequestMapping("/api/products") public class ProductController { private final ProductService productService; - public ProductController(ProductService productService) { - this.productService = productService; - } @GetMapping public List getAllGroceries() { return productService.findAllGroceries(); diff --git a/backend/src/main/java/org/example/backend/ProductRepository.java b/backend/src/main/java/org/example/backend/ProductRepository.java index 15aa29b..6c1b23c 100644 --- a/backend/src/main/java/org/example/backend/ProductRepository.java +++ b/backend/src/main/java/org/example/backend/ProductRepository.java @@ -1,7 +1,9 @@ package org.example.backend; import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; +@Repository public interface ProductRepository extends MongoRepository { } diff --git a/backend/src/main/java/org/example/backend/ProductService.java b/backend/src/main/java/org/example/backend/ProductService.java index 83de4f2..7434024 100644 --- a/backend/src/main/java/org/example/backend/ProductService.java +++ b/backend/src/main/java/org/example/backend/ProductService.java @@ -1,18 +1,17 @@ package org.example.backend; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; - +@RequiredArgsConstructor @Service public class ProductService { private final ProductRepository productRepository; - public ProductService(ProductRepository productRepository) { - this.productRepository = productRepository; - } + public List findAllGroceries(){ return productRepository.findAll(); } diff --git a/backend/src/test/java/org/example/backend/BackendApplicationTest.java b/backend/src/test/java/org/example/backend/BackendApplicationTest.java deleted file mode 100644 index 8c1aac8..0000000 --- a/backend/src/test/java/org/example/backend/BackendApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.example.backend; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class TodoBackendApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/frontend/src/componets/ProductList.tsx b/frontend/src/componets/ProductList.tsx index 5ae6063..a4d6a01 100644 --- a/frontend/src/componets/ProductList.tsx +++ b/frontend/src/componets/ProductList.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import axios from 'axios'; import { Product } from '../models/product.tsx';