Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 4 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
96 changes: 96 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>daw2a</groupId>
<artifactId>ApiCervezas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ApiCervezas</name>
<description>ApiCervezas</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>6.2.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
13 changes: 13 additions & 0 deletions src/main/java/daw2a/kata_cervezas/KataCervezasApplication.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
53 changes: 53 additions & 0 deletions src/main/java/daw2a/kata_cervezas/controllers/BeerController.java
Original file line number Diff line number Diff line change
@@ -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<Beer> 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<Beer> getBeersByAbv(@RequestParam Float minAbv) {
return beerService.findBeersWithAbvGreaterThan(minAbv);
}

//segun nombre
@GetMapping("/search")
public List<Beer> searchBeersByName(@RequestParam String name) {
return beerService.findBeersByNameContaining(name);
}
}
Original file line number Diff line number Diff line change
@@ -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<Brewery> getAllBreweries() {
return breweryService.getAllBreweries();
}

@GetMapping("/{id}")
public ResponseEntity<Brewery> getBreweryById(@PathVariable Long id) {
Brewery brewery = breweryService.getBreweryById(id);
return ResponseEntity.ok(brewery);
}

@PostMapping
public ResponseEntity<Brewery> createBrewery(@RequestBody Brewery brewery) {
Brewery newBrewery = breweryService.createBrewery(brewery);
return ResponseEntity.ok(newBrewery);
}

@PutMapping("/{id}")
public ResponseEntity<Brewery> 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<Brewery> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Category> getAllCategories() {
return categoryService.getAllCategories();
}

@GetMapping("/{id}")
public ResponseEntity<Category> getCategoryById(@PathVariable Long id) {
Category category = categoryService.getCategoryById(id);
return ResponseEntity.ok(category);
}

@PostMapping
public ResponseEntity<Category> createCategory(@RequestBody Category category) {
Category newCategory = categoryService.createCategory(category);
return ResponseEntity.ok(newCategory);
}

@PutMapping("/{id}")
public ResponseEntity<Category> 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());
}
}
}
56 changes: 56 additions & 0 deletions src/main/java/daw2a/kata_cervezas/controllers/StyleController.java
Original file line number Diff line number Diff line change
@@ -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<Style> getAllStyles() {
return styleService.getAllStyles();
}

@GetMapping("/{id}")
public ResponseEntity<Style> getStyleById(@PathVariable Long id) {
Style style = styleService.getStyleById(id);
return ResponseEntity.ok(style);
}

@PostMapping
public ResponseEntity<Style> createStyle(@RequestBody Style style) {
Style newStyle = styleService.createStyle(style);
return ResponseEntity.ok(newStyle);
}

@PutMapping("/{id}")
public ResponseEntity<Style> updateStyle(@PathVariable Long id, @RequestBody Style styleDetails) {
Style updatedStyle = styleService.updateStyle(id, styleDetails);
return ResponseEntity.ok(updatedStyle);
}

@DeleteMapping("/{id}")
public ResponseEntity<?> deleteStyle(@PathVariable Long id) {
styleService.deleteStyle(id);
return ResponseEntity.ok().build();
}

//por nombre
@GetMapping("/search")
public List<Style> searchStyles(@RequestParam String name) {
return styleService.findStylesByName(name);
}
}
Loading