Skip to content

Commit

Permalink
adição da tabela de estoque
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricio-araujoo committed May 23, 2024
1 parent 088293b commit cd44a83
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
5 changes: 5 additions & 0 deletions backend/app/controllers/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'bcrypt'
def CriaUser(nome,matricula,email,senha,cargo)
hash = BCrypt::Password.create(senha)
User.create(nome: nome,matricula: matricula,email: email,senha: hash,cargo_id: cargo.id)
end
70 changes: 70 additions & 0 deletions backend/app/controllers/estoques_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class EstoquesController < ApplicationController
before_action :set_estoque, only: %i[ show edit update destroy ]

# GET /estoques or /estoques.json
def index
@estoques = Estoque.all
end

# GET /estoques/1 or /estoques/1.json
def show
end

# GET /estoques/new
def new
@estoque = Estoque.new
end

# GET /estoques/1/edit
def edit
end

# POST /estoques or /estoques.json
def create
@estoque = Estoque.new(estoque_params)

respond_to do |format|
if @estoque.save
format.html { redirect_to estoque_url(@estoque), notice: "Estoque was successfully created." }
format.json { render :show, status: :created, location: @estoque }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @estoque.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /estoques/1 or /estoques/1.json
def update
respond_to do |format|
if @estoque.update(estoque_params)
format.html { redirect_to estoque_url(@estoque), notice: "Estoque was successfully updated." }
format.json { render :show, status: :ok, location: @estoque }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @estoque.errors, status: :unprocessable_entity }
end
end
end

# DELETE /estoques/1 or /estoques/1.json
def destroy
@estoque.destroy!

respond_to do |format|
format.html { redirect_to estoques_url, notice: "Estoque was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_estoque
@estoque = Estoque.find(params[:id])
end

# Only allow a list of trusted parameters through.
def estoque_params
params.fetch(:estoque, {})
end
end
5 changes: 4 additions & 1 deletion backend/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def destroy
format.json { head :no_content }
end
end

def CriaUser(nome,matricula,email,senha,cargo)
hash = BCrypt::Password.create(senha)
User.create(nome: nome,matricula: matricula,email: email,senha: hash,cargo_id: cargo.id)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
Expand Down

0 comments on commit cd44a83

Please sign in to comment.