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
Prev Previous commit
commit para alteração de branch
  • Loading branch information
Visnicio committed Jul 11, 2022
commit 789fe806bb4a24a970f799288f87a9143559e3eb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 = "venda")
public class Sale {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cod_venda")
private Long id;

@Column(name = "cod_produto", nullable = false)
private Long product_id;


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

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

public Long getProduct_id() {
return this.product_id;
}

public void setProduct_id(Long product_id) {
this.product_id = product_id;
}


@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Sale)) {
return false;
}
Sale sale = (Sale) o;
return Objects.equals(id, sale.id) && Objects.equals(product_id, sale.product_id);
}

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


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

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.watchbeans.watchbeans.models.Sale;

public interface SaleRepository extends JpaRepository<Sale, Long>{

//TODO - create the insert and update methods

<newSale extends Sale> newSale save(newSale sale);


//essa lógica talvez nao seja aplicada como "adicionar produto" pois só altera o valor da venda sem ter conjunto com o valor do produto, e nem aplica o código da venda ao produto
//talvez dê de fazer isso pelo front onde ele faz uma requisição da venda para atualizar o preco e no produto para atualizar o cod_venda
//mas o melhor seria fazer aqui.
//escrever a lógica da venda
@Modifying
@Transactional
@Query(value = "UPDATE venda SET valor_venda = :newPrice WHERE cod_venda = :id", nativeQuery = true)
public void updatePrice(@Param("newPrice")Float price, @Param("id")Long id);



}