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
Next Next commit
product crud
  • Loading branch information
Visnicio committed Jul 10, 2022
commit d5bc25e7e22b791f42f281b7c8359d663f7933a5
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
6 changes: 6 additions & 0 deletions watchbeansAPI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>


<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.watchbeans.watchbeans.controllers;

import java.security.Principal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.neo4j.Neo4jProperties.Authentication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.watchbeans.watchbeans.repositories.ManagerRepository;
Expand All @@ -15,7 +18,7 @@


@RestController
@RequestMapping("/manager")
@RequestMapping("/gerente")
@CrossOrigin(origins = "*")
public class ManagerController {

Expand All @@ -35,11 +38,18 @@ public String login(@RequestBody Manager manager) {
}
}

@RequestMapping(value = "/findAll", method = RequestMethod.GET)
@RequestMapping(value = "/listar", method = RequestMethod.GET)
public List<Manager> findAll() {
return this.managerRepository.findAll();
}

@RequestMapping(value = "/usuario_logado", method = RequestMethod.GET)
@ResponseBody
public String getCurrentUserId(Principal principal) {
return principal.getName();
}


// @RequestMapping(value = "/login", method = RequestMethod.POST)
// public @ResponseBody Professor login(@RequestBody Professor professor){
// Professor professorLogin = professorRepository.login(professor.getMatricula(), professor.getSenha());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
@RequestMapping("/produtos")
@RequestMapping("/produto")
public class ProductController {

public ProductController() {
Expand All @@ -37,4 +37,21 @@ public List<Product> listProducts() {
return productRepository.findAll();
}

@RequestMapping(value = "/listar/{id}", method = RequestMethod.GET)
public Product findProduct(@PathVariable("id") Long id) {
return productRepository.findProduct(id);
}

@RequestMapping(value = "/atualizar_preco", method = RequestMethod.PUT)
public String updateProduct(@RequestBody Product product) {
productRepository.updatePrice(product.getPrice(), product.getId());
return "Atualizado com sucesso";
}

@RequestMapping(value = "/deletar", method = RequestMethod.DELETE)
public String deleteProduct(@RequestBody Product product) {
productRepository.deleteProduct(product.getId());
return "Deletado com sucesso";
}

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

import javax.persistence.Lob;
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 org.springframework.stereotype.Repository;

import com.watchbeans.watchbeans.models.Product;
Expand All @@ -11,4 +14,17 @@
public interface ProductRepository extends JpaRepository<Product, Long>{

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

@Modifying
@Transactional
@Query(value = "UPDATE produto SET preco_produto = :newPrice WHERE cod_produto = :id", nativeQuery = true)
public void updatePrice(@Param("newPrice")Float price, @Param("id")Long id);

@Modifying
@Transactional
@Query(value = "DELETE FROM produto WHERE cod_produto = :id", nativeQuery = true)
public void deleteProduct(@Param("id")Long id);

@Query(value = "SELECT * FROM produto WHERE cod_produto = :id", nativeQuery = true)
public Product findProduct(@Param("id")Long id);
}
3 changes: 3 additions & 0 deletions watchbeansAPI/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update

security.basic.enable: false
security.ignored=