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
19 changes: 1 addition & 18 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,20 @@ 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 ]

# 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
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"

end

2 changes: 2 additions & 0 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ClientsController < ApplicationController
end
11 changes: 11 additions & 0 deletions app/controllers/corporate_clients_controller.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions app/controllers/individual_clients_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Client < ApplicationRecord
end
9 changes: 9 additions & 0 deletions app/models/corporateClient.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions app/models/individualClient.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/migrate/20241008044353_create_addresses.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20241017031706_create_clients.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion db/schema.rb

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

7 changes: 7 additions & 0 deletions test/controllers/corporate_clients_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class CorporateClientsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/controllers/individual_clients_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class IndividualClientsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
31 changes: 31 additions & 0 deletions test/fixtures/clients.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/models/client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class ClientTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end