Generate user model, document some endpoints (missing email verification)
This commit is contained in:
parent
ed7207d707
commit
b8e6df732c
4
app/controllers/users/registrations_controller.rb
Normal file
4
app/controllers/users/registrations_controller.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
|
clear_respond_to
|
||||||
|
respond_to :json
|
||||||
|
end
|
8
app/controllers/users/sessions_controller.rb
Normal file
8
app/controllers/users/sessions_controller.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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 :bigint not null, primary key
|
# id :uuid 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,7 +1,13 @@
|
|||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
devise_for :users
|
devise_scope :user do
|
||||||
|
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 do |t|
|
create_table :users, id: :uuid 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,5 +1,3 @@
|
|||||||
# 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.
|
||||||
@ -188,7 +186,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", force: :cascade do |t|
|
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, 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,6 +22,7 @@ RSpec.describe 'expenses', type: :request do
|
|||||||
|
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
|
regular_api_responses
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ 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,6 +28,7 @@ RSpec.describe 'groups', type: :request do
|
|||||||
}
|
}
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
|
regular_api_responses
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,6 +26,7 @@ RSpec.describe 'guests', type: :request do
|
|||||||
}
|
}
|
||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
|
regular_api_responses
|
||||||
end
|
end
|
||||||
|
|
||||||
post('create guest') do
|
post('create guest') do
|
||||||
@ -50,6 +51,7 @@ RSpec.describe 'guests', type: :request do
|
|||||||
|
|
||||||
response_empty_201
|
response_empty_201
|
||||||
response_422
|
response_422
|
||||||
|
regular_api_responses
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ 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
|
||||||
@ -86,6 +89,7 @@ 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
|
||||||
|
11
spec/requests/schemas.rb
Normal file
11
spec/requests/schemas.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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
|
33
spec/requests/users/registrations_spec.rb
Normal file
33
spec/requests/users/registrations_spec.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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
|
47
spec/requests/users/sessions_spec.rb
Normal file
47
spec/requests/users/sessions_spec.rb
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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,6 +4,7 @@
|
|||||||
|
|
||||||
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,6 +1,17 @@
|
|||||||
# 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'
|
||||||
@ -33,6 +44,18 @@ 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