diff --git a/Gemfile b/Gemfile index e3178da..0cd5a55 100644 --- a/Gemfile +++ b/Gemfile @@ -12,17 +12,6 @@ gem "pg", "~> 1.1" # Use the Puma web server [https://github.com/puma/puma] gem "puma", "~> 5.0" -# Build JSON APIs with ease [https://github.com/rails/jbuilder] -# gem "jbuilder" - -# Use Redis adapter to run Action Cable in production -# gem "redis", "~> 4.0" - -# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] -# gem "kredis" - -# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] -# gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] @@ -30,11 +19,6 @@ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false -# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] -# gem "image_processing", "~> 1.2" - -# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible -# gem "rack-cors" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem @@ -42,7 +26,6 @@ group :development, :test do end group :development do - # Speed up commands on slow machines / big apps [https://github.com/rails/spring] - # gem "spring" + end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb new file mode 100644 index 0000000..b6b853c --- /dev/null +++ b/app/controllers/clients_controller.rb @@ -0,0 +1,2 @@ +class ClientsController < ApplicationController +end diff --git a/app/controllers/corporate_clients_controller.rb b/app/controllers/corporate_clients_controller.rb new file mode 100644 index 0000000..f3bb064 --- /dev/null +++ b/app/controllers/corporate_clients_controller.rb @@ -0,0 +1,11 @@ +class CorporateClientsController < ApplicationController + def index + @corporate_clients = CorporateClient.all + render json: @corporate_clients + end + + def show + @corporate_client = CorporateClient.find(params[:id]) + render json: @corporate_client + end +end diff --git a/app/controllers/individual_clients_controller.rb b/app/controllers/individual_clients_controller.rb new file mode 100644 index 0000000..4c0fe93 --- /dev/null +++ b/app/controllers/individual_clients_controller.rb @@ -0,0 +1,11 @@ +class IndividualClientsController < ApplicationController + def index + @individual_clients = IndividualClient.all + render json: @individual_clients + end + + def show + @individual_client = IndividualClient.find(params[:id]) + render json: @individual_client + end +end diff --git a/app/models/client.rb b/app/models/client.rb new file mode 100644 index 0000000..45b2363 --- /dev/null +++ b/app/models/client.rb @@ -0,0 +1,2 @@ +class Client < ApplicationRecord +end diff --git a/app/models/corporateClient.rb b/app/models/corporateClient.rb new file mode 100644 index 0000000..04afaba --- /dev/null +++ b/app/models/corporateClient.rb @@ -0,0 +1,9 @@ +class CorporateClient < Client + validates :legal_name, presence: true + validates :trade_name, presence: true + validates :cnpj, presence: true, uniqueness: true + validates :ie, presence: true + validates :foundation_date, presence: true + validates :has_partnership, inclusion: { in: [true, false] } + validates :how_find_us, presence: false +end diff --git a/app/models/individualClient.rb b/app/models/individualClient.rb new file mode 100644 index 0000000..0b65895 --- /dev/null +++ b/app/models/individualClient.rb @@ -0,0 +1,8 @@ +class IndividualClient < Client + validates :first_name, presence: true + validates :nickname, presence: false + validates :cpf, presence: true, uniqueness: true + validates :rg, presence: true + validates :birth_date, presence: true + validates :how_find_us, presence: false +end diff --git a/config/routes.rb b/config/routes.rb index 4da4d5e..f1baaac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do + resources :corporate_clients, only: [:index, :show] + resources :individual_clients, only: [:index, :show] resources :addresses, only: [:index, :show] end diff --git a/db/migrate/20241008044353_create_addresses.rb b/db/migrate/20241008044353_create_addresses.rb index 67684f4..e0973cc 100644 --- a/db/migrate/20241008044353_create_addresses.rb +++ b/db/migrate/20241008044353_create_addresses.rb @@ -1,5 +1,5 @@ class CreateAddresses < ActiveRecord::Migration[7.0] - def create_table + def change create_table :addresses do |t| t.integer :address_type t.string :street_name diff --git a/db/migrate/20241017031706_create_clients.rb b/db/migrate/20241017031706_create_clients.rb new file mode 100644 index 0000000..813d192 --- /dev/null +++ b/db/migrate/20241017031706_create_clients.rb @@ -0,0 +1,21 @@ +class CreateClients < ActiveRecord::Migration[7.0] + def change + create_table :clients do |t| + t.string :type + t.string :first_name + t.string :how_find_us + t.string :nickname + t.string :cpf + t.string :rg + t.date :birth_date + t.string :legal_name + t.string :trade_name + t.string :cnpj + t.string :ie + t.date :foundation_date + t.boolean :has_partnership + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 624b5a6..b17b80e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_10_09_033130) do +ActiveRecord::Schema[7.0].define(version: 2024_10_17_031706) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,4 +30,22 @@ t.datetime "updated_at", null: false end + create_table "clients", force: :cascade do |t| + t.string "type" + t.string "first_name" + t.string "how_find_us" + t.string "nickname" + t.string "cpf" + t.string "rg" + t.date "birth_date" + t.string "legal_name" + t.string "trade_name" + t.string "cnpj" + t.string "ie" + t.date "foundation_date" + t.boolean "has_partnership" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/test/controllers/corporate_clients_controller_test.rb b/test/controllers/corporate_clients_controller_test.rb new file mode 100644 index 0000000..2c69504 --- /dev/null +++ b/test/controllers/corporate_clients_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CorporateClientsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/individual_clients_controller_test.rb b/test/controllers/individual_clients_controller_test.rb new file mode 100644 index 0000000..e0a37f2 --- /dev/null +++ b/test/controllers/individual_clients_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class IndividualClientsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/clients.yml b/test/fixtures/clients.yml new file mode 100644 index 0000000..1f06e29 --- /dev/null +++ b/test/fixtures/clients.yml @@ -0,0 +1,31 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + type: + first_name: MyString + how_find_us: MyString + nickname: MyString + cpf: MyString + rg: MyString + birth_date: 2024-10-17 + legal_name: MyString + trade_name: MyString + cnpj: MyString + ie: MyString + foundation_date: 2024-10-17 + has_partnership: false + +two: + type: + first_name: MyString + how_find_us: MyString + nickname: MyString + cpf: MyString + rg: MyString + birth_date: 2024-10-17 + legal_name: MyString + trade_name: MyString + cnpj: MyString + ie: MyString + foundation_date: 2024-10-17 + has_partnership: false diff --git a/test/models/client_test.rb b/test/models/client_test.rb new file mode 100644 index 0000000..c3c6d6c --- /dev/null +++ b/test/models/client_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ClientTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end