From a44b452a58dbae3673e2fc254d2c81bc199e6138 Mon Sep 17 00:00:00 2001 From: Mauriciofearauj Date: Thu, 23 May 2024 20:32:34 -0300 Subject: [PATCH] tabela de estoque --- backend/app/helpers/estoques_helper.rb | 2 + backend/app/models/estoque.rb | 2 + backend/app/models/user.rb | 1 + backend/app/views/estoques/_estoque.html.erb | 2 + .../app/views/estoques/_estoque.json.jbuilder | 2 + backend/app/views/estoques/_form.html.erb | 17 +++++++ backend/app/views/estoques/edit.html.erb | 10 ++++ backend/app/views/estoques/index.html.erb | 14 ++++++ .../app/views/estoques/index.json.jbuilder | 1 + backend/app/views/estoques/new.html.erb | 9 ++++ backend/app/views/estoques/show.html.erb | 10 ++++ backend/app/views/estoques/show.json.jbuilder | 1 + backend/config/routes.rb | 1 + .../migrate/20240523232810_create_estoques.rb | 8 ++++ backend/db/schema.rb | 14 +++++- .../controllers/estoques_controller_test.rb | 48 +++++++++++++++++++ backend/test/fixtures/estoques.yml | 11 +++++ backend/test/models/estoque_test.rb | 7 +++ backend/test/system/estoques_test.rb | 39 +++++++++++++++ 19 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 backend/app/helpers/estoques_helper.rb create mode 100644 backend/app/models/estoque.rb create mode 100644 backend/app/views/estoques/_estoque.html.erb create mode 100644 backend/app/views/estoques/_estoque.json.jbuilder create mode 100644 backend/app/views/estoques/_form.html.erb create mode 100644 backend/app/views/estoques/edit.html.erb create mode 100644 backend/app/views/estoques/index.html.erb create mode 100644 backend/app/views/estoques/index.json.jbuilder create mode 100644 backend/app/views/estoques/new.html.erb create mode 100644 backend/app/views/estoques/show.html.erb create mode 100644 backend/app/views/estoques/show.json.jbuilder create mode 100644 backend/db/migrate/20240523232810_create_estoques.rb create mode 100644 backend/test/controllers/estoques_controller_test.rb create mode 100644 backend/test/fixtures/estoques.yml create mode 100644 backend/test/models/estoque_test.rb create mode 100644 backend/test/system/estoques_test.rb diff --git a/backend/app/helpers/estoques_helper.rb b/backend/app/helpers/estoques_helper.rb new file mode 100644 index 0000000..f309b49 --- /dev/null +++ b/backend/app/helpers/estoques_helper.rb @@ -0,0 +1,2 @@ +module EstoquesHelper +end diff --git a/backend/app/models/estoque.rb b/backend/app/models/estoque.rb new file mode 100644 index 0000000..05074cd --- /dev/null +++ b/backend/app/models/estoque.rb @@ -0,0 +1,2 @@ +class Estoque < ApplicationRecord +end diff --git a/backend/app/models/user.rb b/backend/app/models/user.rb index fa04170..fd6ad00 100644 --- a/backend/app/models/user.rb +++ b/backend/app/models/user.rb @@ -1,3 +1,4 @@ class User < ApplicationRecord belongs_to :cargo + has_many :estoques end diff --git a/backend/app/views/estoques/_estoque.html.erb b/backend/app/views/estoques/_estoque.html.erb new file mode 100644 index 0000000..cd5f9d7 --- /dev/null +++ b/backend/app/views/estoques/_estoque.html.erb @@ -0,0 +1,2 @@ +
+
diff --git a/backend/app/views/estoques/_estoque.json.jbuilder b/backend/app/views/estoques/_estoque.json.jbuilder new file mode 100644 index 0000000..c3683d7 --- /dev/null +++ b/backend/app/views/estoques/_estoque.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! estoque, :id, :created_at, :updated_at +json.url estoque_url(estoque, format: :json) diff --git a/backend/app/views/estoques/_form.html.erb b/backend/app/views/estoques/_form.html.erb new file mode 100644 index 0000000..d3093c7 --- /dev/null +++ b/backend/app/views/estoques/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_with(model: estoque) do |form| %> + <% if estoque.errors.any? %> +
+

<%= pluralize(estoque.errors.count, "error") %> prohibited this estoque from being saved:

+ + +
+ <% end %> + +
+ <%= form.submit %> +
+<% end %> diff --git a/backend/app/views/estoques/edit.html.erb b/backend/app/views/estoques/edit.html.erb new file mode 100644 index 0000000..c08645a --- /dev/null +++ b/backend/app/views/estoques/edit.html.erb @@ -0,0 +1,10 @@ +

Editing estoque

+ +<%= render "form", estoque: @estoque %> + +
+ +
+ <%= link_to "Show this estoque", @estoque %> | + <%= link_to "Back to estoques", estoques_path %> +
diff --git a/backend/app/views/estoques/index.html.erb b/backend/app/views/estoques/index.html.erb new file mode 100644 index 0000000..f1b37c0 --- /dev/null +++ b/backend/app/views/estoques/index.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

Estoques

+ +
+ <% @estoques.each do |estoque| %> + <%= render estoque %> +

+ <%= link_to "Show this estoque", estoque %> +

+ <% end %> +
+ +<%= link_to "New estoque", new_estoque_path %> diff --git a/backend/app/views/estoques/index.json.jbuilder b/backend/app/views/estoques/index.json.jbuilder new file mode 100644 index 0000000..8006a74 --- /dev/null +++ b/backend/app/views/estoques/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @estoques, partial: "estoques/estoque", as: :estoque diff --git a/backend/app/views/estoques/new.html.erb b/backend/app/views/estoques/new.html.erb new file mode 100644 index 0000000..8c05172 --- /dev/null +++ b/backend/app/views/estoques/new.html.erb @@ -0,0 +1,9 @@ +

New estoque

+ +<%= render "form", estoque: @estoque %> + +
+ +
+ <%= link_to "Back to estoques", estoques_path %> +
diff --git a/backend/app/views/estoques/show.html.erb b/backend/app/views/estoques/show.html.erb new file mode 100644 index 0000000..fdcdad9 --- /dev/null +++ b/backend/app/views/estoques/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @estoque %> + +
+ <%= link_to "Edit this estoque", edit_estoque_path(@estoque) %> | + <%= link_to "Back to estoques", estoques_path %> + + <%= button_to "Destroy this estoque", @estoque, method: :delete %> +
diff --git a/backend/app/views/estoques/show.json.jbuilder b/backend/app/views/estoques/show.json.jbuilder new file mode 100644 index 0000000..1cc0c4e --- /dev/null +++ b/backend/app/views/estoques/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "estoques/estoque", estoque: @estoque diff --git a/backend/config/routes.rb b/backend/config/routes.rb index 621d76e..70d984b 100644 --- a/backend/config/routes.rb +++ b/backend/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :estoques resources :cargos resources :users # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/backend/db/migrate/20240523232810_create_estoques.rb b/backend/db/migrate/20240523232810_create_estoques.rb new file mode 100644 index 0000000..6a52f69 --- /dev/null +++ b/backend/db/migrate/20240523232810_create_estoques.rb @@ -0,0 +1,8 @@ +class CreateEstoques < ActiveRecord::Migration[7.1] + def change + create_table :estoques do |t| + + t.timestamps + end + end +end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index fd261d0..b4e28ca 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_21_013908) do +ActiveRecord::Schema[7.1].define(version: 2024_05_23_231320) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,17 @@ t.datetime "updated_at", null: false end + create_table "estoques", force: :cascade do |t| + t.string "nomeitem" + t.integer "quantidade" + t.boolean "disponibilidade" + t.string "descricaoitem" + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_estoques_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "nome" t.string "matricula" @@ -31,5 +42,6 @@ t.index ["cargo_id"], name: "index_users_on_cargo_id" end + add_foreign_key "estoques", "users" add_foreign_key "users", "cargos" end diff --git a/backend/test/controllers/estoques_controller_test.rb b/backend/test/controllers/estoques_controller_test.rb new file mode 100644 index 0000000..69e76f7 --- /dev/null +++ b/backend/test/controllers/estoques_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class EstoquesControllerTest < ActionDispatch::IntegrationTest + setup do + @estoque = estoques(:one) + end + + test "should get index" do + get estoques_url + assert_response :success + end + + test "should get new" do + get new_estoque_url + assert_response :success + end + + test "should create estoque" do + assert_difference("Estoque.count") do + post estoques_url, params: { estoque: { } } + end + + assert_redirected_to estoque_url(Estoque.last) + end + + test "should show estoque" do + get estoque_url(@estoque) + assert_response :success + end + + test "should get edit" do + get edit_estoque_url(@estoque) + assert_response :success + end + + test "should update estoque" do + patch estoque_url(@estoque), params: { estoque: { } } + assert_redirected_to estoque_url(@estoque) + end + + test "should destroy estoque" do + assert_difference("Estoque.count", -1) do + delete estoque_url(@estoque) + end + + assert_redirected_to estoques_url + end +end diff --git a/backend/test/fixtures/estoques.yml b/backend/test/fixtures/estoques.yml new file mode 100644 index 0000000..d7a3329 --- /dev/null +++ b/backend/test/fixtures/estoques.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/backend/test/models/estoque_test.rb b/backend/test/models/estoque_test.rb new file mode 100644 index 0000000..6080816 --- /dev/null +++ b/backend/test/models/estoque_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class EstoqueTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/backend/test/system/estoques_test.rb b/backend/test/system/estoques_test.rb new file mode 100644 index 0000000..4e88e0b --- /dev/null +++ b/backend/test/system/estoques_test.rb @@ -0,0 +1,39 @@ +require "application_system_test_case" + +class EstoquesTest < ApplicationSystemTestCase + setup do + @estoque = estoques(:one) + end + + test "visiting the index" do + visit estoques_url + assert_selector "h1", text: "Estoques" + end + + test "should create estoque" do + visit estoques_url + click_on "New estoque" + + click_on "Create Estoque" + + assert_text "Estoque was successfully created" + click_on "Back" + end + + test "should update Estoque" do + visit estoque_url(@estoque) + click_on "Edit this estoque", match: :first + + click_on "Update Estoque" + + assert_text "Estoque was successfully updated" + click_on "Back" + end + + test "should destroy Estoque" do + visit estoque_url(@estoque) + click_on "Destroy this estoque", match: :first + + assert_text "Estoque was successfully destroyed" + end +end