Skip to content

Commit

Permalink
manejo de excepciones
Browse files Browse the repository at this point in the history
  • Loading branch information
Elemma00 committed Jun 17, 2024
1 parent b50a937 commit 998be3e
Show file tree
Hide file tree
Showing 24 changed files with 916 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.emma.curso.springboot.di.factura.springboot_difactura;

import java.util.Arrays;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

import com.emma.curso.springboot.di.factura.springboot_difactura.models.Item;
import com.emma.curso.springboot.di.factura.springboot_difactura.models.Product;

@Configuration
@PropertySource(value = "classpath:data.properties", encoding = "UTF-8")
public class AppConfig {

@Bean
List<Item> itemsInvoice() {
Product p1 = new Product("Cámara Sony", 800);
Product p2 = new Product("Bicicleta Bianchi 26", 1200);
List<Item> items = Arrays.asList(new Item(p1, 2), new Item(p2, 4));
return items;
}

@Bean
@Primary
List<Item> itemsInvoiceOficina() {
Product p1 = new Product("Monitor Asus 24", 700);
Product p2 = new Product("Notebook Razer", 2400);
Product p3 = new Product("Impresora HP", 800);
Product p4 = new Product("Escritorio Oficina", 900);
List<Item> items = Arrays.asList(new Item(p1, 2), new Item(p2, 4), new Item(p3, 1), new Item(p4, 1));
return items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.emma.curso.springboot.di.factura.springboot_difactura.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.emma.curso.springboot.di.factura.springboot_difactura.models.Invoice;

@RestController
@RequestMapping("/invoices")
public class InvoiceController {

@Autowired
private Invoice invoice;

@GetMapping("/show")
public Invoice show(){
return invoice;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.emma.curso.springboot.di.factura.springboot_difactura.models;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Component
@RequestScope
@JsonIgnoreProperties({"targetSource", "advisors"})
public class Client {

@Value("${client.name}")
private String name;

@Value("${client.lastname}")
private String lastname;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Component
@RequestScope
@JsonIgnoreProperties({"targetSource", "advisors"})
public class Invoice {

@Autowired
private Client client;

@Value("${invoice.description.office}")
private String descripcion;

@Autowired
private List<Item> items;

public Client getClient() {
Expand All @@ -37,4 +47,8 @@ public void setItems(List<Item> items) {
this.items = items;
}

public int getTotal(){
return items.stream().mapToInt(Item::getImporte).sum();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ public class Item {

private Product product;
private Integer quantity;


public Item() {
}

public Item(Product product, Integer quantity) {
this.product = product;
this.quantity = quantity;
}

public Product getProduct() {
return product;
}

public void setProduct(Product product) {
this.product = product;
}

public Integer getQuantity() {
return quantity;
}

public void setQuantity(Integer quantity) {
this.quantity = quantity;
}


public int getImporte(){
return quantity * product.getPrice();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
package com.emma.curso.springboot.di.factura.springboot_difactura.models;


public class Product {

private String name;
private Integer price;

public Product() {
}

public Product(String name, Integer price) {
this.name = name;
this.price = price;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getPrice() {
return price;
}

public void setPrice(Integer price) {
this.price = price;
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
spring.application.name=springboot-difactura
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.force=true
spring.messages.encoding=UTF-8
4 changes: 4 additions & 0 deletions springboot-difactura/src/main/resources/data.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
client.name=Emmanuel
client.lastname=Faúndez
invoice.description=Factura de Deporte
invoice.description.office= Factura de Oficina
33 changes: 33 additions & 0 deletions springboot-error/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
19 changes: 19 additions & 0 deletions springboot-error/.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
#
# https://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.7/apache-maven-3.9.7-bin.zip
Loading

0 comments on commit 998be3e

Please sign in to comment.