Compare commits
No commits in common. "b8e6df732c5f43c30aefd3ac7bf811292605cedc" and "13bdaf0bd20fb74b34a9a0cc4a90a9db9a6fb1c4" have entirely different histories.
b8e6df732c
...
13bdaf0bd2
@ -1,7 +1,6 @@
|
|||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
before_action :authenticate_user!
|
|
||||||
after_action :set_csrf_cookie
|
after_action :set_csrf_cookie
|
||||||
|
|
||||||
skip_before_action :verify_authenticity_token, if: :development_swagger?
|
skip_before_action :verify_authenticity_token, if: :development_swagger?
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
class Users::RegistrationsController < Devise::RegistrationsController
|
|
||||||
clear_respond_to
|
|
||||||
respond_to :json
|
|
||||||
end
|
|
@ -1,8 +0,0 @@
|
|||||||
class Users::SessionsController < Devise::SessionsController
|
|
||||||
clear_respond_to
|
|
||||||
respond_to :json
|
|
||||||
|
|
||||||
# skip_before_action :authenticate_user!, only: %i[create]
|
|
||||||
|
|
||||||
# skip_before_action :verify_authenticity_token, if: :development_swagger?
|
|
||||||
end
|
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Table name: users
|
# Table name: users
|
||||||
#
|
#
|
||||||
# id :uuid not null, primary key
|
# id :bigint not null, primary key
|
||||||
# confirmation_sent_at :datetime
|
# confirmation_sent_at :datetime
|
||||||
# confirmation_token :string
|
# confirmation_token :string
|
||||||
# confirmed_at :datetime
|
# confirmed_at :datetime
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
devise_scope :user do
|
devise_for :users
|
||||||
post 'users', to: 'users/registrations#create'
|
|
||||||
|
|
||||||
post '/users/sign_in', to: 'users/sessions#create'
|
|
||||||
delete '/users/sign_out', to: 'users/sessions#destroy'
|
|
||||||
end
|
|
||||||
|
|
||||||
mount Rswag::Ui::Engine => '/api-docs'
|
mount Rswag::Ui::Engine => '/api-docs'
|
||||||
mount Rswag::Api::Engine => '/api-docs'
|
mount Rswag::Api::Engine => '/api-docs'
|
||||||
resources :groups, only: :index
|
resources :groups, only: :index
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
class DeviseCreateUsers < ActiveRecord::Migration[8.0]
|
class DeviseCreateUsers < ActiveRecord::Migration[8.0]
|
||||||
def change
|
def change
|
||||||
create_table :users, id: :uuid do |t|
|
create_table :users do |t|
|
||||||
## Database authenticatable
|
## Database authenticatable
|
||||||
t.string :email, null: false, default: ""
|
t.string :email, null: false, default: ""
|
||||||
t.string :encrypted_password, null: false, default: ""
|
t.string :encrypted_password, null: false, default: ""
|
||||||
|
4
db/schema.rb
generated
4
db/schema.rb
generated
@ -1,3 +1,5 @@
|
|||||||
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
# This file is auto-generated from the current state of the database. Instead
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
# of editing this file, please use the migrations feature of Active Record to
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
# incrementally modify your database, and then regenerate this schema definition.
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
@ -186,7 +188,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_095753) do
|
|||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
t.string "reset_password_token"
|
t.string "reset_password_token"
|
||||||
|
@ -22,7 +22,6 @@ RSpec.describe 'expenses', type: :request do
|
|||||||
|
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,7 +44,6 @@ RSpec.describe 'expenses', type: :request do
|
|||||||
response_empty_200
|
response_empty_200
|
||||||
response_422
|
response_422
|
||||||
response_404
|
response_404
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,6 @@ RSpec.describe 'groups', type: :request do
|
|||||||
}
|
}
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,7 +26,6 @@ RSpec.describe 'guests', type: :request do
|
|||||||
}
|
}
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
|
|
||||||
post('create guest') do
|
post('create guest') do
|
||||||
@ -51,7 +50,6 @@ RSpec.describe 'guests', type: :request do
|
|||||||
|
|
||||||
response_empty_201
|
response_empty_201
|
||||||
response_422
|
response_422
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,7 +77,6 @@ RSpec.describe 'guests', type: :request do
|
|||||||
response_empty_200
|
response_empty_200
|
||||||
response_422
|
response_422
|
||||||
response_404
|
response_404
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
|
|
||||||
delete('delete guest') do
|
delete('delete guest') do
|
||||||
@ -89,7 +86,6 @@ RSpec.describe 'guests', type: :request do
|
|||||||
|
|
||||||
response_empty_200
|
response_empty_200
|
||||||
response_404
|
response_404
|
||||||
regular_api_responses
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
module Swagger
|
|
||||||
module Schema
|
|
||||||
USER = {
|
|
||||||
id: { type: :string, format: :uuid },
|
|
||||||
email: { type: :string, format: :email },
|
|
||||||
created_at: SwaggerResponseHelper::TIMESTAMP,
|
|
||||||
updated_at: SwaggerResponseHelper::TIMESTAMP
|
|
||||||
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,33 +0,0 @@
|
|||||||
require 'swagger_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'users/registrations', type: :request do
|
|
||||||
|
|
||||||
path '/users' do
|
|
||||||
post('create registration') do
|
|
||||||
tags 'Users Registrations'
|
|
||||||
consumes 'application/json'
|
|
||||||
produces 'application/json'
|
|
||||||
|
|
||||||
parameter name: :body, in: :body, schema: {
|
|
||||||
type: :object,
|
|
||||||
required: [:user],
|
|
||||||
properties: {
|
|
||||||
user: {
|
|
||||||
type: :object,
|
|
||||||
required: %i[email password password_confirmation],
|
|
||||||
properties: {
|
|
||||||
email: { type: :string, format: :email},
|
|
||||||
password: SwaggerResponseHelper::PASSWORD,
|
|
||||||
password_confirmation: SwaggerResponseHelper::PASSWORD
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response(201, 'created') do
|
|
||||||
schema type: :object, properties: Swagger::Schema::USER
|
|
||||||
xit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,47 +0,0 @@
|
|||||||
require 'swagger_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'users/sessions', type: :request do
|
|
||||||
|
|
||||||
path '/users/sign_in' do
|
|
||||||
|
|
||||||
post('create session') do
|
|
||||||
tags 'Users Sessions'
|
|
||||||
consumes 'application/json'
|
|
||||||
produces 'application/json'
|
|
||||||
|
|
||||||
parameter name: :body, in: :body, schema: {
|
|
||||||
type: :object,
|
|
||||||
required: %i[user],
|
|
||||||
properties: {
|
|
||||||
user: {
|
|
||||||
type: :object,
|
|
||||||
required: %i[email password],
|
|
||||||
properties: {
|
|
||||||
email: { type: :string, format: :email },
|
|
||||||
password: SwaggerResponseHelper::PASSWORD
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response(201, 'created') do
|
|
||||||
schema type: :object, properties: Swagger::Schema::USER
|
|
||||||
xit
|
|
||||||
end
|
|
||||||
|
|
||||||
response_401(message: 'Invalid Email or password.')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
path '/users/sign_out' do
|
|
||||||
|
|
||||||
delete('delete session') do
|
|
||||||
tags 'Users Sessions'
|
|
||||||
consumes 'application/json'
|
|
||||||
produces 'application/json'
|
|
||||||
response(204, 'Session destroyed') do
|
|
||||||
xit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require_relative './swagger_response_helper'
|
require_relative './swagger_response_helper'
|
||||||
require_relative './requests/schemas.rb'
|
|
||||||
|
|
||||||
include SwaggerResponseHelper
|
include SwaggerResponseHelper
|
||||||
|
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
module SwaggerResponseHelper
|
module SwaggerResponseHelper
|
||||||
TIMESTAMP_FORMAT = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z'
|
|
||||||
TIMESTAMP_EXAMPLE = Time.zone.now.iso8601(3)
|
|
||||||
|
|
||||||
TIMESTAMP = {type: :string,pattern: TIMESTAMP_FORMAT,example: TIMESTAMP_EXAMPLE}.freeze
|
|
||||||
PASSWORD = { type: :string, minLength: User.password_length.begin, maxLength: User.password_length.end }
|
|
||||||
|
|
||||||
|
|
||||||
def regular_api_responses
|
|
||||||
response_401
|
|
||||||
end
|
|
||||||
|
|
||||||
def response_422
|
def response_422
|
||||||
response(422, 'Validation errors in input parameters') do
|
response(422, 'Validation errors in input parameters') do
|
||||||
produces 'application/json'
|
produces 'application/json'
|
||||||
@ -44,18 +33,6 @@ module SwaggerResponseHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_401(message: nil)
|
|
||||||
response(401, 'Unauthorized') do
|
|
||||||
produces 'application/json'
|
|
||||||
schema type: :object,
|
|
||||||
required: %i[error],
|
|
||||||
properties: {
|
|
||||||
error: { type: :string, example: message || 'You need to sign in or sign up before continuing.' }
|
|
||||||
}
|
|
||||||
xit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def error_schema
|
def error_schema
|
||||||
|
Loading…
x
Reference in New Issue
Block a user