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/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/README.md b/README.md index 3a2112b..c68a9dc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/um2scOsx) > **Note** > Si alguien quiere usar docker, docker-compose, adelante. > Pero ahora mismo no es nuestro objetivo. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d6aedfa --- /dev/null +++ b/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + daw2a + ApiCervezas + 0.0.1-SNAPSHOT + ApiCervezas + ApiCervezas + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.h2database + h2 + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot + 3.3.4 + + + jakarta.validation + jakarta.validation-api + + + org.springframework.security + spring-security-crypto + 6.2.0 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/daw2a/kata_cervezas/KataCervezasApplication.java b/src/main/java/daw2a/kata_cervezas/KataCervezasApplication.java new file mode 100644 index 0000000..3b7677f --- /dev/null +++ b/src/main/java/daw2a/kata_cervezas/KataCervezasApplication.java @@ -0,0 +1,13 @@ +package daw2a.kata_cervezas; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class KataCervezasApplication { + + public static void main(String[] args) { + SpringApplication.run(KataCervezasApplication.class, args); + } + +} diff --git a/src/main/java/daw2a/kata_cervezas/controllers/BeerController.java b/src/main/java/daw2a/kata_cervezas/controllers/BeerController.java new file mode 100644 index 0000000..8395b2b --- /dev/null +++ b/src/main/java/daw2a/kata_cervezas/controllers/BeerController.java @@ -0,0 +1,53 @@ +package daw2a.kata_cervezas.controllers; + +import daw2a.kata_cervezas.entities.Beer; +import daw2a.kata_cervezas.services.BeerService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/beers") +@RequiredArgsConstructor +public class BeerController { + private final BeerService beerService; + + @GetMapping + public List getAllBeers() { + return beerService.getAllBeers(); + } + + @GetMapping("/{id}") + public Beer getBeerById(@PathVariable Long id) { + return beerService.getBeerById(id); + } + + @PostMapping + public Beer createBeer(@RequestBody Beer beer) { + return beerService.saveBeer(beer); + } + + @PutMapping("/{id}") + public Beer updateBeer(@PathVariable Long id, @RequestBody Beer beer) { + beer.setId(id); + return beerService.saveBeer(beer); + } + + @DeleteMapping("/{id}") + public void deleteBeer(@PathVariable Long id) { + beerService.deleteBeer(id); + } + + //segun volumen de alcohol + @GetMapping("/abv") + public List getBeersByAbv(@RequestParam Float minAbv) { + return beerService.findBeersWithAbvGreaterThan(minAbv); + } + + //segun nombre + @GetMapping("/search") + public List searchBeersByName(@RequestParam String name) { + return beerService.findBeersByNameContaining(name); + } +} \ No newline at end of file diff --git a/src/main/java/daw2a/kata_cervezas/controllers/BreweryController.java b/src/main/java/daw2a/kata_cervezas/controllers/BreweryController.java new file mode 100644 index 0000000..ca9a053 --- /dev/null +++ b/src/main/java/daw2a/kata_cervezas/controllers/BreweryController.java @@ -0,0 +1,64 @@ +package daw2a.kata_cervezas.controllers; + +import daw2a.kata_cervezas.entities.Brewery; +import daw2a.kata_cervezas.services.BreweryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/breweries") +public class BreweryController { + + private final BreweryService breweryService; + + @Autowired + public BreweryController(BreweryService breweryService) { + this.breweryService = breweryService; + } + + // CRUD endpoints + @GetMapping + public List getAllBreweries() { + return breweryService.getAllBreweries(); + } + + @GetMapping("/{id}") + public ResponseEntity getBreweryById(@PathVariable Long id) { + Brewery brewery = breweryService.getBreweryById(id); + return ResponseEntity.ok(brewery); + } + + @PostMapping + public ResponseEntity createBrewery(@RequestBody Brewery brewery) { + Brewery newBrewery = breweryService.createBrewery(brewery); + return ResponseEntity.ok(newBrewery); + } + + @PutMapping("/{id}") + public ResponseEntity updateBrewery(@PathVariable Long id, @RequestBody Brewery breweryDetails) { + Brewery updatedBrewery = breweryService.updateBrewery(id, breweryDetails); + return ResponseEntity.ok(updatedBrewery); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteBrewery(@PathVariable Long id) { + breweryService.deleteBrewery(id); + return ResponseEntity.ok().build(); + } + + // por nombre y por ciudad + @GetMapping("/search") + public List searchBreweries(@RequestParam(required = false) String name, + @RequestParam(required = false) String city) { + if (name != null && !name.isEmpty()) { + return breweryService.findBreweriesByName(name); + } else if (city != null && !city.isEmpty()) { + return breweryService.findBreweriesByCity(city); + } else { + return breweryService.getAllBreweries(); + } + } +} diff --git a/src/main/java/daw2a/kata_cervezas/controllers/CategoryController.java b/src/main/java/daw2a/kata_cervezas/controllers/CategoryController.java new file mode 100644 index 0000000..18ba979 --- /dev/null +++ b/src/main/java/daw2a/kata_cervezas/controllers/CategoryController.java @@ -0,0 +1,60 @@ +package daw2a.kata_cervezas.controllers; + +import daw2a.kata_cervezas.entities.Category; +import daw2a.kata_cervezas.services.CategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import java.util.List; + +@RestController +@RequestMapping("/categories") +public class CategoryController { + + private final CategoryService categoryService; + + @Autowired + public CategoryController(CategoryService categoryService) { + this.categoryService = categoryService; + } + + // CRUD endpoints + @GetMapping + public List getAllCategories() { + return categoryService.getAllCategories(); + } + + @GetMapping("/{id}") + public ResponseEntity getCategoryById(@PathVariable Long id) { + Category category = categoryService.getCategoryById(id); + return ResponseEntity.ok(category); + } + + @PostMapping + public ResponseEntity createCategory(@RequestBody Category category) { + Category newCategory = categoryService.createCategory(category); + return ResponseEntity.ok(newCategory); + } + + @PutMapping("/{id}") + public ResponseEntity updateCategory(@PathVariable Long id, @RequestBody Category categoryDetails) { + Category updatedCategory = categoryService.updateCategory(id, categoryDetails); + return ResponseEntity.ok(updatedCategory); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteCategory(@PathVariable Long id) { + categoryService.deleteCategory(id); + return ResponseEntity.ok().build(); + } + + // por nombre o todar las categorias + @GetMapping("/search") + public ResponseEntity searchCategories(@RequestParam(required = false) String name) { + if (name != null && !name.isEmpty()) { + return ResponseEntity.ok(categoryService.findCategoriesByName(name)); + } else { + return ResponseEntity.ok(categoryService.getAllCategories()); + } + } +} diff --git a/src/main/java/daw2a/kata_cervezas/controllers/StyleController.java b/src/main/java/daw2a/kata_cervezas/controllers/StyleController.java new file mode 100644 index 0000000..62ea279 --- /dev/null +++ b/src/main/java/daw2a/kata_cervezas/controllers/StyleController.java @@ -0,0 +1,56 @@ +package daw2a.kata_cervezas.controllers; +import daw2a.kata_cervezas.entities.Style; +import daw2a.kata_cervezas.services.StyleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/styles") +public class StyleController { + + private final StyleService styleService; + + @Autowired + public StyleController(StyleService styleService) { + this.styleService = styleService; + } + + // CRUD endpoints + @GetMapping + public List