diff --git a/kbazaar/makefile b/kbazaar/makefile index 0d7055e..1830174 100644 --- a/kbazaar/makefile +++ b/kbazaar/makefile @@ -7,6 +7,9 @@ clean: run: ./gradlew bootRun +format: + ./gradlew spotlessApply + health: curl -X GET http://localhost:8080/api/v1/health diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/KBazaarApplication.java b/kbazaar/src/main/java/com/kampus/kbazaar/KBazaarApplication.java index 93eb929..ba8823b 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/KBazaarApplication.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/KBazaarApplication.java @@ -6,8 +6,7 @@ @SpringBootApplication public class KBazaarApplication { - public static void main(String[] args) { - SpringApplication.run(KBazaarApplication.class, args); - } - + public static void main(String[] args) { + SpringApplication.run(KBazaarApplication.class, args); + } } diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java index 2eba151..70902cb 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/Cart.java @@ -3,7 +3,6 @@ import com.kampus.kbazaar.product.Product; import lombok.Data; - @Data public class Cart { private int userID; diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java index ba99ab7..9332d36 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/cart/CartController.java @@ -4,33 +4,38 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - @RestController @RequestMapping("/api/v1") public class CartController { - public static Cart[] carts = new Cart[]{ - new Cart(1, new Product[]{ - new Product("sku1", "product1", 100, 1), - }), - new Cart(2, new Product[]{ - new Product("sku2", "product2", 200, 2), - }), - new Cart(3, new Product[]{ - new Product("sku3", "product3", 300, 3), - }), - }; - + public static Cart[] carts = + new Cart[] { + new Cart( + 1, + new Product[] { + new Product("sku1", "product1", 100, 1), + }), + new Cart( + 2, + new Product[] { + new Product("sku2", "product2", 200, 2), + }), + new Cart( + 3, + new Product[] { + new Product("sku3", "product3", 300, 3), + }), + }; @PostMapping("/carts/{id}/additems") - public ResponseEntity addProductToCart(@PathVariable String id, @RequestBody Product[] products) { - Cart cart = new Cart(1, new Product[]{ - new Product("sku1", "product1", 100, 1), - }); + public ResponseEntity addProductToCart( + @PathVariable String id, @RequestBody Product[] products) { + Cart cart = + new Cart( + 1, + new Product[] { + new Product("sku1", "product1", 100, 1), + }); return ResponseEntity.ok(cart); } - } diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/health/HealthController.java b/kbazaar/src/main/java/com/kampus/kbazaar/health/HealthController.java index b533854..b826a99 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/health/HealthController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/health/HealthController.java @@ -12,4 +12,4 @@ public class HealthController { public String health() { return "{ \"status\": \"alive\" }"; } -} \ No newline at end of file +} diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/product/Product.java b/kbazaar/src/main/java/com/kampus/kbazaar/product/Product.java index 2334876..b9f37fa 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/product/Product.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/product/Product.java @@ -5,18 +5,17 @@ @Data public class Product { private String name; - private String sku; + private String sku; - private double price; - private int quantity; + private double price; + private int quantity; - public Product() { - } + public Product() {} - public Product(String sku, String name, double price, int quantity) { - this.name = name; - this.price = price; - this.sku = sku; - this.quantity = quantity; - } + public Product(String sku, String name, double price, int quantity) { + this.name = name; + this.price = price; + this.sku = sku; + this.quantity = quantity; + } } diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/product/ProductController.java b/kbazaar/src/main/java/com/kampus/kbazaar/product/ProductController.java index 8e19949..e3a7563 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/product/ProductController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/product/ProductController.java @@ -6,15 +6,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - @RestController @RequestMapping("/api/v1") public class ProductController { - public static Product[] productsDB = new Product[] { - new Product("sku1", "Product 1", 100.0, 10), - new Product("sku2", "Product 2", 200.0, 20), - new Product("sku3", "Product 3", 300.0, 30) - }; + public static Product[] productsDB = + new Product[] { + new Product("sku1", "Product 1", 100.0, 10), + new Product("sku2", "Product 2", 200.0, 20), + new Product("sku3", "Product 3", 300.0, 30) + }; @GetMapping("/products") public ResponseEntity getProducts() { diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/user/UserController.java b/kbazaar/src/main/java/com/kampus/kbazaar/user/UserController.java index d28237f..f2f2ceb 100644 --- a/kbazaar/src/main/java/com/kampus/kbazaar/user/UserController.java +++ b/kbazaar/src/main/java/com/kampus/kbazaar/user/UserController.java @@ -1,6 +1,5 @@ package com.kampus.kbazaar.user; - import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -9,10 +8,11 @@ @RestController @RequestMapping("/api/v1") public class UserController { - private User[] users = new User[]{ - new User(1, "John Doe", "john@mailsy.com"), - new User(2, "Jane Doe", "jane@mailsy.com"), -}; + private User[] users = + new User[] { + new User(1, "John Doe", "john@mailsy.com"), + new User(2, "Jane Doe", "jane@mailsy.com"), + }; @GetMapping("/users") public User[] getAllUsers() { @@ -27,7 +27,7 @@ public User getUserById(@PathVariable String id) { return user; } } -// how to return ? {"message": "User not found"} + // how to return ? {"message": "User not found"} return null; } } diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationTests.java b/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationTests.java index a98bb71..72850ff 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationTests.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/KBazaarApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class KBazaarApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/architecture/DependencyRuleTest.java b/kbazaar/src/test/java/com/kampus/kbazaar/architecture/DependencyRuleTest.java index 3452a2b..6937eb6 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/architecture/DependencyRuleTest.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/architecture/DependencyRuleTest.java @@ -1,5 +1,7 @@ package com.kampus.kbazaar.architecture; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + import com.tngtech.archunit.core.importer.ImportOption; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; @@ -8,24 +10,30 @@ import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RestController; -import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; - -@AnalyzeClasses(packages = "com.kampus.kbazaar", importOptions = ImportOption.DoNotIncludeTests.class) +@AnalyzeClasses( + packages = "com.kampus.kbazaar", + importOptions = ImportOption.DoNotIncludeTests.class) public class DependencyRuleTest { @ArchTest static final ArchRule service_should_access_by_controller = - classes().that() + classes() + .that() .areAnnotatedWith(Service.class) - .should().onlyBeAccessed().byClassesThat() + .should() + .onlyBeAccessed() + .byClassesThat() .areAnnotatedWith(RestController.class) .allowEmptyShould(true); @ArchTest static final ArchRule repository_should_access_by_service = - classes().that() + classes() + .that() .areAnnotatedWith(Repository.class) - .should().onlyBeAccessed().byClassesThat() + .should() + .onlyBeAccessed() + .byClassesThat() .areAnnotatedWith(Service.class) .allowEmptyShould(true); -} \ No newline at end of file +} diff --git a/kbazaar/src/test/java/com/kampus/kbazaar/architecture/NamingRuleTest.java b/kbazaar/src/test/java/com/kampus/kbazaar/architecture/NamingRuleTest.java index 6b53992..278e262 100644 --- a/kbazaar/src/test/java/com/kampus/kbazaar/architecture/NamingRuleTest.java +++ b/kbazaar/src/test/java/com/kampus/kbazaar/architecture/NamingRuleTest.java @@ -1,5 +1,7 @@ package com.kampus.kbazaar.architecture; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + import com.tngtech.archunit.core.importer.ImportOption; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; @@ -8,27 +10,33 @@ import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RestController; -import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; - -@AnalyzeClasses(packages = "com.kampus.kbazaar", importOptions = ImportOption.DoNotIncludeTests.class) +@AnalyzeClasses( + packages = "com.kampus.kbazaar", + importOptions = ImportOption.DoNotIncludeTests.class) public class NamingRuleTest { @ArchTest static ArchRule rest_controller_naming_should_ending_with_controller = classes() - .that().areAnnotatedWith(RestController.class) - .should().haveSimpleNameEndingWith("Controller"); + .that() + .areAnnotatedWith(RestController.class) + .should() + .haveSimpleNameEndingWith("Controller"); @ArchTest static ArchRule repository_naming_should_ending_repository = classes() - .that().areAnnotatedWith(Repository.class) - .should().haveSimpleNameEndingWith("Repository") + .that() + .areAnnotatedWith(Repository.class) + .should() + .haveSimpleNameEndingWith("Repository") .allowEmptyShould(true); @ArchTest static ArchRule service_naming_should_ending_service = classes() - .that().areAnnotatedWith(Service.class) - .should().haveSimpleNameEndingWith("Service") + .that() + .areAnnotatedWith(Service.class) + .should() + .haveSimpleNameEndingWith("Service") .allowEmptyShould(true); }