diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/ExerciseCheckPointSpringJPA.iml b/.idea/ExerciseCheckPointSpringJPA.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/ExerciseCheckPointSpringJPA.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..0dbd425
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..6bfce0b
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://localhost:3306
+
+
+
+
+
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml
new file mode 100644
index 0000000..ce1f046
--- /dev/null
+++ b/.idea/data_source_mapping.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..63e9001
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..eda147d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..fce4815
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
new file mode 100644
index 0000000..18795a5
--- /dev/null
+++ b/.idea/sqldialects.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/helloSupermarket.iml b/helloSupermarket.iml
new file mode 100644
index 0000000..bf84dc1
--- /dev/null
+++ b/helloSupermarket.iml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/http-requests.http b/src/http-requests.http
new file mode 100644
index 0000000..ec41a1b
--- /dev/null
+++ b/src/http-requests.http
@@ -0,0 +1,5 @@
+### GET request to example server
+GET https://examples.http-client.intellij.net/get
+ ?generated-in=IntelliJ IDEA
+
+###
\ No newline at end of file
diff --git a/src/main/java/com/ironhack/helloSupermarket/HelloSupermarketApplication.java b/src/main/java/com/ironhack/helloSupermarket/HelloSupermarketApplication.java
new file mode 100644
index 0000000..bd765da
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/HelloSupermarketApplication.java
@@ -0,0 +1,13 @@
+package com.ironhack.helloSupermarket;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class HelloSupermarketApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(HelloSupermarketApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/ironhack/helloSupermarket/controller/ItemController.java b/src/main/java/com/ironhack/helloSupermarket/controller/ItemController.java
new file mode 100644
index 0000000..03bada6
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/controller/ItemController.java
@@ -0,0 +1,90 @@
+package com.ironhack.helloSupermarket.controller;
+
+import com.ironhack.helloSupermarket.enums.Category;
+import com.ironhack.helloSupermarket.model.Item;
+import com.ironhack.helloSupermarket.model.ProduceStock;
+import com.ironhack.helloSupermarket.service.ItemService;
+import jakarta.validation.Valid;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+
+import java.net.URI;
+import java.util.List;
+
+@RestController
+public class ItemController {
+ private final ItemService itemService;
+
+ public ItemController(ItemService itemService){
+ this.itemService = itemService;
+ }
+
+ //crud
+ //create
+ @PostMapping("/inventory")
+ public ResponseEntity- create(@Valid @RequestBody Item item){
+ Item createdItem = itemService.create(item);
+
+ URI location = ServletUriComponentsBuilder
+ .fromCurrentRequest()
+ .path("/{name}")
+ .buildAndExpand(createdItem.getName())
+ .toUri();
+
+ return ResponseEntity.created(location).body(createdItem);
+ }
+
+ //read
+ @GetMapping("/inventory/{id}")
+ public Item findById(@PathVariable Long id){
+ return itemService.findById(id);
+ }
+
+ //read all
+ @GetMapping("/inventory")
+ public List
- readAll (){
+ return itemService.readAll();
+ }
+
+ //update
+ @PutMapping("/inventory/{id}")
+ public Item update(@PathVariable Long id, @Valid @RequestBody Item item){
+ return itemService.update(id, item);
+ }
+
+ //delete
+ @DeleteMapping("/inventory/{id}")
+ public void delete(@PathVariable Long id){
+ itemService.delete(id);
+ }
+
+
+ //repository custom methods
+ @GetMapping("/inventory/category/{categoryString}")
+ public List
- findItemsByCategory(@PathVariable String categoryString) {
+ Category categoryEnum = Category.valueOf(categoryString.toUpperCase());
+ return itemService.findItemsByCategory(categoryEnum);
+ }
+
+ @GetMapping("/inventory/low-stock")
+ public List
- findLowStock(){
+ return itemService.findLowStock();
+ };
+
+
+ @GetMapping("/inventory/to-discount/{price}")
+ public List
- findItemsToDiscount(@PathVariable double price){
+ return itemService.findItemsToDiscount(price);
+ };
+
+ @GetMapping("inventory/alphabetically")
+ public List
- sortByName(){
+ return itemService.sortByName();
+ }
+
+ @GetMapping("/inventory/produce-stock")
+ public List getProduceStock(){
+ return itemService.getProduceStock();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ironhack/helloSupermarket/enums/Category.java b/src/main/java/com/ironhack/helloSupermarket/enums/Category.java
new file mode 100644
index 0000000..5233610
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/enums/Category.java
@@ -0,0 +1,10 @@
+package com.ironhack.helloSupermarket.enums;
+
+public enum Category {
+ PRODUCE,
+ DIARY,
+ BAKERY,
+ BEVERAGES,
+ PANTRY,
+ FROZEN
+}
diff --git a/src/main/java/com/ironhack/helloSupermarket/model/Item.java b/src/main/java/com/ironhack/helloSupermarket/model/Item.java
new file mode 100644
index 0000000..d418c85
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/model/Item.java
@@ -0,0 +1,80 @@
+package com.ironhack.helloSupermarket.model;
+
+import com.ironhack.helloSupermarket.enums.Category;
+import jakarta.persistence.*;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Positive;
+import jakarta.validation.constraints.PositiveOrZero;
+
+import java.util.UUID;
+
+@Entity
+@Table(name = "item")
+public class Item {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+
+ @NotBlank (message = "Name is required")
+ private String name;
+
+ @NotNull (message = "Category is required")
+ @Enumerated(EnumType.STRING)
+ private Category category;
+
+ @Positive (message = "Price must be bigger than 0")
+ private double price;
+
+ @PositiveOrZero (message = "Stock value cannot be negative")
+ private int stock;
+
+
+ //getters and setters
+ public Long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Category getCategory() {
+ return category;
+ }
+
+ public void setCategory(Category category) {
+ this.category = category;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ public int getStock() {
+ return stock;
+ }
+
+ public void setStock(int stock) {
+ this.stock = stock;
+ }
+
+ //constructors
+ public Item (){}
+
+ public Item(String name, Category category, double price, int stock) {
+ this.name = name;
+ this.category = category;
+ this.price = price;
+ this.stock = stock;
+ }
+}
diff --git a/src/main/java/com/ironhack/helloSupermarket/model/ProduceStock.java b/src/main/java/com/ironhack/helloSupermarket/model/ProduceStock.java
new file mode 100644
index 0000000..699edb2
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/model/ProduceStock.java
@@ -0,0 +1,27 @@
+package com.ironhack.helloSupermarket.model;
+
+public class ProduceStock {
+ private String name;
+ private int stock;
+
+ public ProduceStock(String name, int stock){
+ this.name = name;
+ this.stock = stock;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getStock() {
+ return stock;
+ }
+
+ public void setStock(int stock) {
+ this.stock = stock;
+ }
+}
diff --git a/src/main/java/com/ironhack/helloSupermarket/repository/ItemRepository.java b/src/main/java/com/ironhack/helloSupermarket/repository/ItemRepository.java
new file mode 100644
index 0000000..42abcdd
--- /dev/null
+++ b/src/main/java/com/ironhack/helloSupermarket/repository/ItemRepository.java
@@ -0,0 +1,30 @@
+package com.ironhack.helloSupermarket.repository;
+
+import com.ironhack.helloSupermarket.enums.Category;
+import com.ironhack.helloSupermarket.model.Item;
+import com.ironhack.helloSupermarket.model.ProduceStock;
+import jakarta.validation.constraints.NotNull;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.UUID;
+
+@Repository
+public interface ItemRepository extends JpaRepository
- {
+ List
- findItemsByCategory(Category category);
+ List
- findItemsByStockLessThan(int threshold);
+ List
- findItemsByPriceGreaterThan(double price);
+
+
+ //order alphabetically - JPQL
+ @Query("SELECT i FROM Item i ORDER BY i.name")
+ List
- sortByName();
+
+ //find only produce - SQL
+ @Query(value = "SELECT name, stock FROM item WHERE category='PRODUCE'", nativeQuery = true)
+ List