Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

Commit

Permalink
Adicionado as classes de Venda e Produto (Consertos).
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcalbuquerque committed May 22, 2019
1 parent c8663e2 commit fe5a0ab
Show file tree
Hide file tree
Showing 113 changed files with 570 additions and 13 deletions.
1 change: 1 addition & 0 deletions deliveryLanches/.gitignore → .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
idea/*

# Ignore all logfiles and tempfiles.
/log/*
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion deliveryLanches/Gemfile.lock → Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.142.2)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
spring (2.0.2)
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions app/assets/javascripts/produtos.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/vendas.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/produtos.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the produtos controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
84 changes: 84 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
body {
background-color: #fff;
color: #333;
margin: 33px;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;

&:visited {
color: #666;
}

&:hover {
color: #fff;
background-color: #000;
}
}

th {
padding-bottom: 5px;
}

td {
padding: 0 5px 7px;
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px 7px 0;
margin-bottom: 20px;
background-color: #f0f0f0;

h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px -7px 0;
background-color: #c00;
color: #fff;
}

ul li {
font-size: 12px;
list-style: square;
}
}

label {
display: block;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/vendas.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Vendas controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/produtos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ProdutosController < ApplicationController
before_action :set_produto, only: [:show, :edit, :update, :destroy]

# GET /produtos
# GET /produtos.json
def index
@produtos = Produto.all
end

# GET /produtos/1
# GET /produtos/1.json
def show
end

# GET /produtos/new
def new
@produto = Produto.new
end

# GET /produtos/1/edit
def edit
end

# POST /produtos
# POST /produtos.json
def create
@produto = Produto.new(produto_params)

respond_to do |format|
if @produto.save
format.html { redirect_to @produto, notice: 'Produto was successfully created.' }
format.json { render :show, status: :created, location: @produto }
else
format.html { render :new }
format.json { render json: @produto.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /produtos/1
# PATCH/PUT /produtos/1.json
def update
respond_to do |format|
if @produto.update(produto_params)
format.html { redirect_to @produto, notice: 'Produto was successfully updated.' }
format.json { render :show, status: :ok, location: @produto }
else
format.html { render :edit }
format.json { render json: @produto.errors, status: :unprocessable_entity }
end
end
end

# DELETE /produtos/1
# DELETE /produtos/1.json
def destroy
@produto.destroy
respond_to do |format|
format.html { redirect_to produtos_url, notice: 'Produto was successfully destroyed.' }
format.json { head :no_content }
end
end

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

# Never trust parameters from the scary internet, only allow the white list through.
def produto_params
params.require(:produto).permit(:id, :descricao, :precoCompra, :precoVenda)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def set_venda

# Never trust parameters from the scary internet, only allow the white list through.
def venda_params
params.require(:venda).permit(:id, :valorTotal)
params.require(:venda).permit(:id, :quantidade, :valorTotal)
end
end
2 changes: 2 additions & 0 deletions app/helpers/produtos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProdutosHelper
end
2 changes: 2 additions & 0 deletions app/helpers/vendas_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VendasHelper
end
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions app/models/produto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Produto < ApplicationRecord
validates :descricao, presence: { message: 'É um campo obrigatório' }
validates :descricao, length: { minimum: 2, message: ' tem menos de 2 caracteres' }
validates :descricao, length: { maximum: 100, message: ' tem mais de 100 caracteres' }
end
4 changes: 1 addition & 3 deletions deliveryLanches/app/models/venda.rb → app/models/venda.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Venda < ApplicationRecord

belongs_to :Produto
belongs_to :produto
#Entrará Cliente belongs_to :Cliente

validates :valorVenda, presence: { message: 'É um campo obrigatório' }
validates :valorVenda, numericality: { message: 'É um campo apenas numérico' }
validates :valorVenda, numericality: { greater_than_or_equal_to: 0, message: 'Deve ser maior ou igual a zero' }

end
37 changes: 37 additions & 0 deletions app/views/produtos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_with(model: produto, local: true) do |form| %>
<% if produto.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(produto.errors.count, "error") %> prohibited this produto from being saved:</h2>

<ul>
<% produto.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :id %>
<%= form.number_field :id, id: :produto_id %>
</div>

<div class="field">
<%= form.label :descricao %>
<%= form.text_field :descricao, id: :produto_descricao %>
</div>

<div class="field">
<%= form.label :precoCompra %>
<%= form.text_field :precoCompra, id: :produto_precoCompra %>
</div>

<div class="field">
<%= form.label :precoVenda %>
<%= form.text_field :precoVenda, id: :produto_precoVenda %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/produtos/_produto.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! produto, :id, :id, :descricao, :precoCompra, :precoVenda, :created_at, :updated_at
json.url produto_url(produto, format: :json)
6 changes: 6 additions & 0 deletions app/views/produtos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Produto</h1>

<%= render 'form', produto: @produto %>

<%= link_to 'Show', @produto %> |
<%= link_to 'Back', produtos_path %>
33 changes: 33 additions & 0 deletions app/views/produtos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<p id="notice"><%= notice %></p>

<h1>Produtos</h1>

<table>
<thead>
<tr>
<th>Id</th>
<th>Descricao</th>
<th>Precocompra</th>
<th>Precovenda</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @produtos.each do |produto| %>
<tr>
<td><%= produto.id %></td>
<td><%= produto.descricao %></td>
<td><%= produto.precoCompra %></td>
<td><%= produto.precoVenda %></td>
<td><%= link_to 'Show', produto %></td>
<td><%= link_to 'Edit', edit_produto_path(produto) %></td>
<td><%= link_to 'Destroy', produto, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Produto', new_produto_path %>
1 change: 1 addition & 0 deletions app/views/produtos/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @produtos, partial: "produtos/produto", as: :produto
5 changes: 5 additions & 0 deletions app/views/produtos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New Produto</h1>

<%= render 'form', produto: @produto %>

<%= link_to 'Back', produtos_path %>
24 changes: 24 additions & 0 deletions app/views/produtos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Id:</strong>
<%= @produto.id %>
</p>

<p>
<strong>Descricao:</strong>
<%= @produto.descricao %>
</p>

<p>
<strong>Precocompra:</strong>
<%= @produto.precoCompra %>
</p>

<p>
<strong>Precovenda:</strong>
<%= @produto.precoVenda %>
</p>

<%= link_to 'Edit', edit_produto_path(@produto) %> |
<%= link_to 'Back', produtos_path %>
1 change: 1 addition & 0 deletions app/views/produtos/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "produtos/produto", produto: @produto
32 changes: 32 additions & 0 deletions app/views/vendas/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_with(model: venda, local: true) do |form| %>
<% if venda.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(venda.errors.count, "error") %> prohibited this venda from being saved:</h2>

<ul>
<% venda.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :id %>
<%= form.number_field :id, id: :venda_id %>
</div>

<div class="field">
<%= form.label :quantidade %>
<%= form.number_field :quantidade, id: :venda_quantidade %>
</div>

<div class="field">
<%= form.label :valorTotal %>
<%= form.text_field :valorTotal, id: :venda_valorTotal %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/vendas/_venda.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! venda, :id, :id, :quantidade, :valorTotal, :created_at, :updated_at
json.url venda_url(venda, format: :json)
6 changes: 6 additions & 0 deletions app/views/vendas/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Venda</h1>

<%= render 'form', venda: @venda %>

<%= link_to 'Show', @venda %> |
<%= link_to 'Back', vendas_path %>
Loading

0 comments on commit fe5a0ab

Please sign in to comment.