Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ API do sistema CGR da CJR.
* [Especificações](#especificações)
* [CI/CD](#ci-cd)
* [Entidades](#entidades)
* [User](#user)
* [Member](#member)
* [Team](#ream)
* [Role](#role)
* [MemberRole](#memberrole)
* [Payment](#payment)
* [Project](#project)
* [Requisições](#requisições)

<a name="specification"> </a>
Expand Down Expand Up @@ -39,6 +42,19 @@ em um terminal bash ou zsh.

Atualmente, a API conta com as seguintes entidades:

#### User

Um usuario cadastrado no sistema pode acessar os dados referente as equipes, no qaul ele esta alocado, e a sua política de benefícios no sistema. Caso o usuario seja um admin pode criar novas equipe e projetos, além de alocar membros nos projetos e núcleos da empresa.

| value | type |
|:-------------:|:-------------:|
| id | integer |
| name | string |
| email | string |
| admin | boolean |
| deleted_at | date_time |


#### Member

Um membro da empresa que será cadastrado no sistema.
Expand Down Expand Up @@ -83,6 +99,30 @@ Relação entre um membro e um cargo (e, por extensão, um time). Essas relaçõ
| entry_date | date_time |
| deleted_at | date_time |

#### Payment

Um pagamento será registrado no sistema toda vez que confirmar o pagamento de parcela, seja ela única ou mensal, mantendo assim um registro para realizar as funcionalidades do sistema.

| value | type |
|:----------: |:-----------: |
| id | integer |
| amount | integer |
| payed | boolean |
| payment_date | date |

#### Project

Um projeto no sistema vai armazenar alguns dados importante para a empresa como: nome do projeto, descrição, extrato dos pagamento já realizados e equipe responsavel pelo projeto.

| value | type |
|:----------: |:-----------: |
| id | integer |
| team_id | foreign_key |
| payment_id | foreign_key |
| name | string |
| client_info | string |
| project_info | string |
| deleted_at | date_time |

## Requisições

Expand Down Expand Up @@ -221,4 +261,93 @@ Atualiza as informações de um cargo, com base em seu `id`. Pode restaurar o ca

Atualiza o valor de `deleted_at` para o momento da requisição.


#### Project
```http
GET /projects/
GET /projects/:id
POST /projects/
PATCH/PUT /projects/:id
DELETE /projects/:id
```

##### GET /projects/

Retorna todos os projetos não apagados do sistema

* **content_type**: application/json
* **response**: project[]{ team }

##### GET /projects/:id

Retorna um projeto e a equipe responsavel com base em seu `id`, caso não esteja apagado

* **content_type**: application/json
* **response**: project[]{ team }

##### POST /projects/

Cria um projeto com um time específico no sistema.

* **body**: team_id, payment_id(opt), name, client_info, project_info
* **content_type**: application/json
* **response**: project

##### PATCH/PUT /projects/:id

Atualiza as informações de um projeto, com base em seu `id`. Pode restaurar o cargo caso tenha sido apagado.

* **body**: team_id, payment_id(opt), name, client_info, project_info, deleted_at
* **content_type**: application/json
* **response**: project

##### DELETE /projects/:id

Atualiza o valor de `deleted_at` para o momento da requisição.


#### Payments
```http
GET /payments/
GET /payments/:id
POST /payments/
PATCH/PUT /payments/:id
DELETE /payments/:id
```

##### GET /payments/

Retorna todos os pagamentos não apagados do sistema

* **content_type**: application/json
* **response**: payments[]

##### GET /payments/:id

Retorna um pagamento com base em seu `id`, caso não esteja apagado

* **content_type**: application/json
* **response**: payment[]

##### POST /payments/

Adiciona um pagamento no sistema.

* **body**: amount, payed, payment_date
* **content_type**: application/json
* **response**: payment

##### PATCH/PUT /payments/:id

Atualiza as informações de um pagamento, com base em seu `id`. Pode restaurar o cargo caso tenha sido apagado.

* **body**: amount, payed, payment_date
* **content_type**: application/json
* **response**: payment

##### DELETE /payments/:id

Atualiza o valor de `deleted_at` para o momento da requisição.


* **response**: nil
53 changes: 53 additions & 0 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class PaymentsController < ApplicationController
before_action :set_payment, only: %i[ show update destroy ]

# GET /payments
# GET /payments.json
def index
@payments = Payment.all
end

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

# POST /payments
# POST /payments.json
def create
@payment = Payment.new(payment_params)

if @payment.save
render :show, status: :created, location: @payment
else
render json: @payment.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /payments/1
# PATCH/PUT /payments/1.json
def update
if @payment.update(payment_params)
render :show, status: :ok, location: @payment
else
render json: @payment.errors, status: :unprocessable_entity
end
end

# DELETE /payments/1
# DELETE /payments/1.json
def destroy
@payment.destroy
end

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

# Only allow a list of trusted parameters through.
def payment_params
params.require(:payment).permit(:amount, :payed, :payment_date)
end
end
51 changes: 51 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class ProjectsController < ApplicationController
before_action :set_project, only: %i[ show update destroy ]

# GET /projects
def index
@projects = Project.all

render json: @projects, include: [:team]
end

# GET /projects/1
def show
render json: @project, include: [:team]
end

# POST /projects
def create
@project = Project.new(project_params)

if @project.save
render :show, status: :created, location: @project
else
render json: @project.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /projects/1
def update
if @project.update(project_params)
render :show, status: :ok, location: @project
else
render json: @project.errors, status: :unprocessable_entity
end
end

# DELETE /projects/1
def destroy
@project.destroy
end

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

# Only allow a list of trusted parameters through.
def project_params
params.require(:project).permit(:team_id, :payment_id, :name, :client_info, :project_info, :deleted_at)
end
end
2 changes: 1 addition & 1 deletion app/controllers/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def set_team

# Only allow a trusted parameter "white list" through.
def role_params
params.require(:role).permit(:name, :team_id)
params.require(:role).permit(:name, :team_id, :description)
end
end
8 changes: 4 additions & 4 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class TeamsController < ApplicationController
before_action :set_team, only: [:show, :update, :destroy]
before_action :set_team, only: [:show, :show_members, :update, :destroy]

include TeamManager

# GET /teams
def index
@teams = Team.all

render json: @teams, include: [:roles]
render json: @teams, include: [:roles, :members]
end

# GET /teams/1
def show
render json: @team, include: [:roles]
render json: @team, include: [:roles, :members]
end

# POST /teams
Expand Down Expand Up @@ -52,7 +52,7 @@ def set_team

# Only allow a trusted parameter "white list" through.
def team_params
params.require(:team).permit(:name, :initials)
params.require(:team).permit(:name, :initials, :description)
end

def roles_params
Expand Down
4 changes: 4 additions & 0 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Payment < ApplicationRecord
belongs_to :project , optional: true

end
4 changes: 4 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Project < ApplicationRecord
belongs_to :team
has_many :payments
end
10 changes: 9 additions & 1 deletion app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ class Team < ApplicationRecord

belongs_to :parent, class_name: 'Team', optional: true
has_many :children, class_name: 'Team', foreign_key: 'parent_id'

belongs_to :project , optional: true
include SoftDeletable

validates :name, uniqueness: true, presence: true

def members
members = []
self.roles.all.each do |role|
members = members + role.members.all
end
members
end
# Validar se apenas um cargo (ou nenhum) tem a flag de 'leader'
# Dica: Usar método 'validate' como:
#
Expand Down
2 changes: 2 additions & 0 deletions app/views/payments/_payment.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! payment, :id, :amount, :payed, :payment_date, :created_at, :updated_at
json.url payment_url(payment, format: :json)
1 change: 1 addition & 0 deletions app/views/payments/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @payments, partial: "payments/payment", as: :payment
1 change: 1 addition & 0 deletions app/views/payments/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "payments/payment", payment: @payment
2 changes: 2 additions & 0 deletions app/views/projects/_project.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! project, :id, :team_id, :payment_id, :name, :client_info, :project_info, :deleted_at, :created_at, :updated_at
json.url project_url(project, format: :json)
1 change: 1 addition & 0 deletions app/views/projects/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @projects, partial: "projects/project", as: :project
1 change: 1 addition & 0 deletions app/views/projects/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "projects/project", project: @project
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Rails.application.routes.draw do
resources :payments
resources :projects
resources :teams, shallow: true do
resources :roles
end
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20210929143634_create_payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePayments < ActiveRecord::Migration[6.1]
def change
create_table :payments do |t|
t.integer :amount
t.boolean :payed
t.date :payment_date

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20210929143726_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateProjects < ActiveRecord::Migration[6.1]
def change
create_table :projects do |t|
t.references :team, foreign_key: true
t.references :payment, foreign_key: true
t.string :name
t.string :client_info
t.string :project_info
t.datetime :deleted_at

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20211208134156_add_description_to_teams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDescriptionToTeams < ActiveRecord::Migration[6.1]
def change
add_column :teams, :description, :text
end
end
5 changes: 5 additions & 0 deletions db/migrate/20211208134211_add_description_to_role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDescriptionToRole < ActiveRecord::Migration[6.1]
def change
add_column :roles, :description, :text
end
end
Loading