Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FGA0138-MDS-Ajax/2024.1-POLLUX
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzer0 committed Jun 13, 2024
2 parents 8982165 + aa21b83 commit 06bd7e1
Show file tree
Hide file tree
Showing 23 changed files with 349 additions and 2 deletions.
70 changes: 70 additions & 0 deletions backend/app/controllers/eventos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class EventosController < ApplicationController
before_action :set_evento, only: %i[ show edit update destroy ]

# GET /eventos or /eventos.json
def index
@eventos = Evento.all
end

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

# GET /eventos/new
def new
@evento = Evento.new
end

# GET /eventos/1/edit
def edit
end

# POST /eventos or /eventos.json
def create
@evento = Evento.new(evento_params)

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

# PATCH/PUT /eventos/1 or /eventos/1.json
def update
respond_to do |format|
if @evento.update(evento_params)
format.html { redirect_to evento_url(@evento), notice: "Evento was successfully updated." }
format.json { render :show, status: :ok, location: @evento }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @evento.errors, status: :unprocessable_entity }
end
end
end

# DELETE /eventos/1 or /eventos/1.json
def destroy
@evento.destroy!

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

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

# Only allow a list of trusted parameters through.
def evento_params
params.require(:evento).permit(:nome, :data, :HoraInicio, :HoraTermino, :user_id)
end
end
2 changes: 2 additions & 0 deletions backend/app/helpers/eventos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module EventosHelper
end
3 changes: 3 additions & 0 deletions backend/app/models/evento.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Evento < ApplicationRecord
belongs_to :user
end
2 changes: 1 addition & 1 deletion backend/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class User < ApplicationRecord
belongs_to :cargo
has_many :estoques
has_many :tarefas
has_many :eventos
has_many :documentos
has_many :reunioes_usuarios
has_many :reuniaos, through: :reunioes_usuarios
Expand Down
2 changes: 2 additions & 0 deletions backend/app/views/eventos/_evento.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="<%= dom_id evento %>">
</div>
2 changes: 2 additions & 0 deletions backend/app/views/eventos/_evento.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! evento, :id, :created_at, :updated_at
json.url evento_url(evento, format: :json)
17 changes: 17 additions & 0 deletions backend/app/views/eventos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(model: evento) do |form| %>
<% if evento.errors.any? %>
<div style="color: red">
<h2><%= pluralize(evento.errors.count, "error") %> prohibited this evento from being saved:</h2>

<ul>
<% evento.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.submit %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions backend/app/views/eventos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing evento</h1>

<%= render "form", evento: @evento %>

<br>

<div>
<%= link_to "Show this evento", @evento %> |
<%= link_to "Back to eventos", eventos_path %>
</div>
14 changes: 14 additions & 0 deletions backend/app/views/eventos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Eventos</h1>

<div id="eventos">
<% @eventos.each do |evento| %>
<%= render evento %>
<p>
<%= link_to "Show this evento", evento %>
</p>
<% end %>
</div>

<%= link_to "New evento", new_evento_path %>
1 change: 1 addition & 0 deletions backend/app/views/eventos/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @eventos, partial: "eventos/evento", as: :evento
9 changes: 9 additions & 0 deletions backend/app/views/eventos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New evento</h1>

<%= render "form", evento: @evento %>

<br>

<div>
<%= link_to "Back to eventos", eventos_path %>
</div>
10 changes: 10 additions & 0 deletions backend/app/views/eventos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @evento %>

<div>
<%= link_to "Edit this evento", edit_evento_path(@evento) %> |
<%= link_to "Back to eventos", eventos_path %>

<%= button_to "Destroy this evento", @evento, method: :delete %>
</div>
1 change: 1 addition & 0 deletions backend/app/views/eventos/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "eventos/evento", evento: @evento
1 change: 1 addition & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :eventos
resources :reuniaos
resources :storages
resources :documentos
Expand Down
13 changes: 13 additions & 0 deletions backend/db/migrate/20240613205914_create_eventos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateEventos < ActiveRecord::Migration[7.1]
def change
create_table :eventos do |t|
t.string :nome
t.string :data
t.string :HoraInicio
t.string :HoraTermino
t.references :user, null: false, foreign_key: true

t.timestamps
end
end
end
14 changes: 13 additions & 1 deletion backend/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions backend/docs/PolluxEndpoints/CreateEvento.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: CreateEvento
type: http
seq: 2
}

post {
url: http://localhost/3000/eventos
body: none
auth: none
}
48 changes: 48 additions & 0 deletions backend/test/controllers/eventos_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class EventosControllerTest < ActionDispatch::IntegrationTest
setup do
@evento = eventos(:one)
end

test "should get index" do
get eventos_url
assert_response :success
end

test "should get new" do
get new_evento_url
assert_response :success
end

test "should create evento" do
assert_difference("Evento.count") do
post eventos_url, params: { evento: { } }
end

assert_redirected_to evento_url(Evento.last)
end

test "should show evento" do
get evento_url(@evento)
assert_response :success
end

test "should get edit" do
get edit_evento_url(@evento)
assert_response :success
end

test "should update evento" do
patch evento_url(@evento), params: { evento: { } }
assert_redirected_to evento_url(@evento)
end

test "should destroy evento" do
assert_difference("Evento.count", -1) do
delete evento_url(@evento)
end

assert_redirected_to eventos_url
end
end
19 changes: 19 additions & 0 deletions backend/test/fixtures/eventos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
nome: MyString
string: MyString
data: MyString
string: MyString
HoraInicio: MyString
HoraTermino: MyString
user: one

two:
nome: MyString
string: MyString
data: MyString
string: MyString
HoraInicio: MyString
HoraTermino: MyString
user: two
7 changes: 7 additions & 0 deletions backend/test/models/evento_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class EventoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
39 changes: 39 additions & 0 deletions backend/test/system/eventos_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "application_system_test_case"

class EventosTest < ApplicationSystemTestCase
setup do
@evento = eventos(:one)
end

test "visiting the index" do
visit eventos_url
assert_selector "h1", text: "Eventos"
end

test "should create evento" do
visit eventos_url
click_on "New evento"

click_on "Create Evento"

assert_text "Evento was successfully created"
click_on "Back"
end

test "should update Evento" do
visit evento_url(@evento)
click_on "Edit this evento", match: :first

click_on "Update Evento"

assert_text "Evento was successfully updated"
click_on "Back"
end

test "should destroy Evento" do
visit evento_url(@evento)
click_on "Destroy this evento", match: :first

assert_text "Evento was successfully destroyed"
end
end
4 changes: 4 additions & 0 deletions view/src/constants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ export default {
document: {
base: '/documents',
single: (id) => `/documents/${id}`,
},
event: {
base: '/eventos',
single: (id) => `/eventos/${id}`,
}
}
Loading

0 comments on commit 06bd7e1

Please sign in to comment.