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

Product CRUD #3

Merged
merged 3 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
insert and select all from products
  • Loading branch information
Visnicio committed Jul 8, 2022
commit 362943b3f08118e4962571b351d1c6be8c4d7dfe
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.watchbeans.watchbeans.controllers;

import java.util.List;

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

import com.watchbeans.watchbeans.models.Product;
import com.watchbeans.watchbeans.repositories.ProductRepository;


import org.springframework.web.bind.annotation.RequestMapping;

@RestController
Expand All @@ -11,9 +19,22 @@ public class ProductController {
public ProductController() {
}

@Autowired
private ProductRepository productRepository;

@RequestMapping(value = "/helloWorld", method = RequestMethod.GET)
public String helloWorld(){
return "Estamos no ar mesmo?";
}

@RequestMapping(value = "/criar", method = RequestMethod.POST)
public Product createProduct(@RequestBody Product product) {
return productRepository.save(product);
}

@RequestMapping(value = "/listar", method = RequestMethod.GET)
public List<Product> listProducts() {
return productRepository.findAll();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.watchbeans.watchbeans.models;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "produto")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cod_produto")
private Long id;

@Column(name = "nome_produto", nullable = false)
private String name;

@Column(name = "preco_produto", nullable = false)
private Float price;

@Column(name = "modelo_produto", nullable = false)
private String model;

@Column(name = "cod_venda", nullable = true)
private Integer sale_id;


public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return this.name;
}

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

public Float getPrice() {
return this.price;
}

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

public String getModel() {
return this.model;
}

public void setModel(String model) {
this.model = model;
}

public Integer getSale_id() {
return this.sale_id;
}

public void setSale_id(Integer sale_id) {
this.sale_id = sale_id;
}

@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Product)) {
return false;
}
Product product = (Product) o;
return Objects.equals(id, product.id) && Objects.equals(name, product.name) && Objects.equals(price, product.price) && Objects.equals(model, product.model) && Objects.equals(sale_id, product.sale_id);
}

@Override
public int hashCode() {
return Objects.hash(id, name, price, model);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ManagerRepository extends JpaRepository<Manager, Long>{
//public Professor login(String matricula, String senha);

//Aluno save(Aluno aluno);
//uma classe que é temporaria para mandar os dados para o banco
//uma classe que é temporaria para mandar os dados para o banco S é a classe temp e a T é a classe que esta no banco
//<S extends T> S save(S name);
// <newAluno extends Aluno> newAluno save(newAluno aluno);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.watchbeans.watchbeans.repositories;

import javax.persistence.Lob;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.watchbeans.watchbeans.models.Product;

@Repository
public interface ProductRepository extends JpaRepository<Product, Long>{

<newProduct extends Product> newProduct save(newProduct product);
}