Skip to content

Commit

Permalink
Merge pull request #3 from adrianrbp/2-companyservice-shift-management
Browse files Browse the repository at this point in the history
company service shift management
  • Loading branch information
adrianrbp authored Aug 6, 2024
2 parents 40cc4f4 + 14938ad commit a250003
Show file tree
Hide file tree
Showing 55 changed files with 2,489 additions and 215 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/vue-container/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"formatOnPaste": true,
"quickSuggestions": {
"strings": "on"
}
},
"defaultFormatter": "esbenp.prettier-vscode"
},
"tailwindCSS": {
"includeLanguages": {
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: test

on: push

jobs:
backend:
name: 'Rails API Tests'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3.4'

- name: Install dependencies
run: |
cd backend
bundle install
- name: Run Rails tests
run: |
cd backend
bin/rails test
frontend:
name: 'Vue Frontend Tests'
runs-on: ubuntu-latest
needs: backend # Ensure frontend tests run after backend tests
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '21'

- name: Install dependencies
run: |
cd frontend
yarn install
- name: Run Jest tests
run: |
cd frontend
yarn test:unit
# - name: Start Rails server
# run: |
# cd backend
# bin/rails server -e test & # Run the server in the background

# - name: Wait for Rails server to be ready
# run: |
# until curl -s http://localhost:3000 > /dev/null; do
# echo "Waiting for Rails server..."
# sleep 2
# done

end-to-end:
name: 'End to End Tests'
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.45.1-jammy
needs: [backend, frontend]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install dependencies
run: |
cd frontend
yarn install
# - name: Install Playwright Browsers
# run: npx playwright install --with-deps

- name: Run Playwright tests
run: |
cd frontend
yarn test:e2e
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
## Monitoring Schedule

### Resumen
- Contexto:
- Coordinar los turnos de guardia para cada servicio monitoreado por semana

- Sistema que permite:
- Indicar la **disponibilidad de tiempo en la semana** de cada ingeniero del equipo
- **Asignar a ingenieros a turnos** de monitoreo de servicios.
- Visualizar los turnos asignados
#### Features
1. Gestión de Turnos:
- Facilita la visualización de los turnos asignados
- Asegura que la información sobre las horas sin asignar sea clara y accesible.
2. Gestión de Disponibilidad:
- Permite a los ingenieros
1. Seleccionar el servicio y la semana,
2. Visualizar su disponibilidad
3. Marcar su disponibilidad.
### Modo de uso:
1. Los ingenieros se reunen para organizar su disponibilidad y turnos
2. Se revisa los turnos indicados por el servicio de empresa para esa semana
3. Se pasa a consultar a cada ingeniero (segun el servicio que le toca esa semana) su disponibilidad para esa semana. Al finalizar se presiona en "Guardar".
4. Se regresa a revisar los turnos asignados automaticamente para la semana segun el servicio.

### Componentes
#### Endpoints - Gestion de Turnos (Shifts)
- 1st Dropdown (Services)
- /api/company_services
- 2nd Dropdown (Weeks)
- /api/company_services/:id/weeks
- Engineers Table
- /api/company_services/:id/engineers?week=YYYY-WW
- Shifts Table
- /api/company_services/:id/shifts?week=YYYY-WW
#### Endpoints - Gestion de Disponibilidad (Availability)
- Los de gestion de turnos para el filtrado y llenado de semana
- Updates Engineer Availability
- /api/company_services/:id/engineers/availability
- week
- availability (array)
- engineer_id
- time_blocks (array)
- day
- start_time
- end_time
- available


#### Modelos
1. Servicios monitoreados
- Bloques de 1h
- Horario establecido (grupo de bloques)
2. Semana
3. Engineer
4. Turno (bloques de 1 hora)
5. Asignacion (Relacion Ingeniero - Hora)

#### Arquitectura Frontend (Grafica Figma)
- View
- Components
- provider: useShiftManagement
- CompanyServiceApi.ts
#### Arquitectura Backend (Grafica Figma)

### Ejecución
#### Ambiente de desarrollo
- Se ha usado Devcontainer y docker-compose para facilitar el desarrollo usando contenedores y vscode
- https://code.visualstudio.com/docs/devcontainers/containers

- Pasos para ejecutar:
- Tener instalado la extension Devcontainer en vscode
- Abrir el proyecto en vscode
- Ejecutar el contenedor Rails API Container:
- abrir command palette: ctrl + shift + p
- Seleccionar: Reopen in container
- Seleccionar: "Rails API Container"
- Dentro ejecutar: `rails s`
- Ejecutar el contenedor Vue Container:
- abrir command palette: ctrl + shift + p
- Seleccionar: Reopen in container
- Seleccionar: "Vue Container"
- Dentro ejecutar: `yarn dev`
- navegar a 0.0.0.0:8080 para empezar a usar la app
- Ejecutar tests e2e:
```bash
# Conectarse a contenedor de playwright
docker exec -it monit-playwright /bin/bash
# ejectuar tests
yarn test:e2e
```


#### Alternativa:
- usar directamente docker-compose up desde la ruta base
```bash
docker-compose -f .devcontainer/docker-compose.yml up
# verificar los servicios
```

- navegar a 0.0.0.0:8080 para empezar a usar la app
11 changes: 11 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# IDE and Editor directories
.idea/
.vscode/
*.sublime-workspace
*.sublime-project
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
53 changes: 53 additions & 0 deletions backend/app/controllers/company_services_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class CompanyServicesController < ApplicationController
before_action :set_company_service, only: %i[ show update destroy ]

# GET /company_services
# GET /company_services.json
def index
@company_services = CompanyService.all
end

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

# POST /company_services
# POST /company_services.json
def create
@company_service = CompanyService.new(company_service_params)

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

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

# DELETE /company_services/1
# DELETE /company_services/1.json
def destroy
@company_service.destroy!
end

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

# Only allow a list of trusted parameters through.
def company_service_params
params.require(:company_service).permit(:name, :contract_start_date, :contract_end_date)
end
end
13 changes: 13 additions & 0 deletions backend/app/models/company_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# == Schema Information
#
# Table name: company_services
#
# id :bigint not null, primary key
# name :string
# contract_start_date :datetime
# contract_end_date :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
class CompanyService < ApplicationRecord
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! company_service, :id, :name, :contract_start_date, :contract_end_date, :created_at, :updated_at
json.url company_service_url(company_service, format: :json)
6 changes: 6 additions & 0 deletions backend/app/views/company_services/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
json.data do
json.array! @company_services, partial: "company_services/company_service", as: :company_service
end

json.status 200
json.statusText "OK"
1 change: 1 addition & 0 deletions backend/app/views/company_services/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "company_services/company_service", company_service: @company_service
1 change: 1 addition & 0 deletions backend/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.hosts << "rails"
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded any time
Expand Down
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 :company_services
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down
11 changes: 11 additions & 0 deletions backend/db/migrate/20240802031906_create_company_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateCompanyServices < ActiveRecord::Migration[7.1]
def change
create_table :company_services do |t|
t.string :name
t.datetime :contract_start_date
t.datetime :contract_end_date

t.timestamps
end
end
end
25 changes: 25 additions & 0 deletions backend/db/schema.rb

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

18 changes: 9 additions & 9 deletions backend/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
require 'faker'

10.times do
company_service = CompanyService.create(
name: Faker::Company.unique.name,
contract_start_date: Faker::Date.backward(days: 30),
contract_end_date: Faker::Date.forward(days: 30)
)
end
18 changes: 18 additions & 0 deletions backend/spec/factories/company_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: company_services
#
# id :bigint not null, primary key
# name :string
# contract_start_date :datetime
# contract_end_date :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :company_service do
name { "MyString" }
contract_start_date { "2024-08-02 03:19:06" }
contract_end_date { "2024-08-02 03:19:06" }
end
end
Loading

0 comments on commit a250003

Please sign in to comment.