Skip to content

Commit d2fe811

Browse files
committed
feat: Refactor nested document class names in airport and hotel models
1 parent 3a940a9 commit d2fe811

File tree

4 files changed

+98
-20
lines changed

4 files changed

+98
-20
lines changed

README.md

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,21 @@ Open the `config/couchbase.yml` file and update the connection string, username,
5252

5353
```yml
5454
common: &common
55+
bucket: travel-sample
56+
connection_string: <%= ENV['DB_CONN_STR'] %>
57+
username: <%= ENV['DB_USERNAME'] %>
58+
password: <%= ENV['DB_PASSWORD'] %>
59+
60+
development:
5561
connection_string: couchbase://localhost
5662
username: Administrator
5763
password: password
5864

59-
development:
65+
test:
6066
<<: *common
61-
bucket: travel-sample
6267

63-
test:
68+
production:
6469
<<: *common
65-
bucket: travel-sample
6670
```
6771
6872
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
@@ -97,11 +101,11 @@ docker run -p 3000:3000 ruby-couchbase-orm-quickstart -e DB_CONN_STR=<connection
97101

98102
Once the application starts, you can see the details of the application on the terminal.
99103

100-
Show Image
104+
![Application Start](./public/application_start.png)
101105

102106
The application will run on the port specified by Rails on your local machine (eg: http://localhost:3000). You will find the interactive Swagger documentation of the API if you go to the URL in your browser. Swagger documentation is used in this demo to showcase the different API endpoints and how they can be invoked. More details on the Swagger documentation can be found in the appendix.
103107

104-
Show Image
108+
![Swagger Documentation](./public/swagger_documentation.png)
105109

106110
## Running The Tests
107111

@@ -119,26 +123,100 @@ bundle exec rspec test/integration
119123

120124
For this quickstart, we use three collections, airport, airline and routes that contain sample airports, airlines and airline routes respectively. The route collection connects the airports and airlines as seen in the figure below. We use these connections in the quickstart to generate airports that are directly connected and airlines connecting to a destination airport. Note that these are just examples to highlight how you can use SQL++ queries to join the collections.
121125

122-
![Data Model](image_link)
123-
124-
## Extending API by Adding New Entity
125-
126-
If you would like to add another entity to the APIs, these are the steps to follow:
127-
128-
1. Create a new model: Create a new model for the entity in the `app/models` folder. This model should contain the schema for the entity.
129-
2. Create the new route: In Rails, you can create a new route by adding a new resource in the `config/routes.rb` file. This file should contain the logic for the new entity's CRUD operations.
130-
3. Create the new controller: Create a new controller for the entity in the `app/controllers` folder. This controller should contain the logic for the new entity's CRUD operations.
131-
4. Add the integration tests: Add integration tests for the new entity in the `test/integration` folder. This ensures that the new entity's CRUD operations are tested. The test file should be named `<entity>_spec.rb`.
132-
133-
Following these steps ensures a systematic and organized approach to expanding the API functionality with a new entity.
126+
![Data Model](./public/travel_sample_data_model.png)
127+
128+
## Extending API by Adding a New Entity
129+
130+
If you would like to add another entity to the APIs, follow these steps:
131+
132+
1. Create a new model:
133+
- Create a new model file for the entity in the `app/models` folder.
134+
- Define the schema for the entity using the appropriate attributes and validations.
135+
- Example: `app/models/customer.rb`
136+
137+
2. Create the new routes:
138+
- Open the `config/routes.rb` file.
139+
- Add new routes for the entity's CRUD operations using the `resources` method.
140+
- Example:
141+
```ruby
142+
namespace :api do
143+
namespace :v1 do
144+
resources :customers
145+
end
146+
end
147+
```
148+
149+
3. Create the new controller:
150+
- Create a new controller file for the entity in the `app/controllers/api/v1` folder.
151+
- Implement the necessary CRUD actions (index, show, create, update, destroy) in the controller.
152+
- Example: `app/controllers/api/v1/customers_controller.rb`
153+
154+
4. Add Swagger documentation:
155+
- Open the `spec/requests/api/v1/customers_spec.rb` file.
156+
- Define the Swagger documentation for the new entity's API endpoints using RSpec and the `rswag` gem.
157+
- Specify the request and response parameters, headers, and schemas for each endpoint.
158+
- Example:
159+
```ruby
160+
require 'swagger_helper'
161+
162+
describe 'Customers API', type: :request do
163+
path '/api/v1/customers' do
164+
get 'Retrieves all customers' do
165+
tags 'Customers'
166+
produces 'application/json'
167+
168+
response '200', 'customers retrieved' do
169+
schema type: :array,
170+
items: {
171+
type: :object,
172+
properties: {
173+
id: { type: :integer },
174+
name: { type: :string },
175+
email: { type: :string }
176+
},
177+
required: ['id', 'name', 'email']
178+
}
179+
180+
run_test!
181+
end
182+
end
183+
end
184+
end
185+
```
186+
187+
5. Add integration tests:
188+
- Create a new integration test file for the entity in the `test/integration` folder.
189+
- Write integration tests to cover the CRUD operations of the new entity.
190+
- Example: `test/integration/customers_spec.rb`
191+
```ruby
192+
require 'rails_helper'
193+
194+
RSpec.describe 'Customers API', type: :request do
195+
describe 'GET /api/v1/customers' do
196+
# Add tests for retrieving customers
197+
end
198+
199+
describe 'POST /api/v1/customers' do
200+
# Add tests for creating a customer
201+
end
202+
203+
# Add more tests for other CRUD operations
204+
end
205+
```
206+
207+
6. Run tests and verify:
208+
- Run the integration tests using the command `bundle exec rspec test/integration`.
209+
- Ensure that all tests pass and the new entity's CRUD operations are working as expected.
210+
211+
By following these steps, you can systematically extend the API functionality with a new entity while maintaining a well-structured and tested codebase.
134212

135213
## Running Self-Managed Couchbase Cluster
136214

137215
If you are running this quickstart with a self-managed Couchbase cluster, you need to load the travel-sample data bucket in your cluster and generate the credentials for the bucket by creating a user.
138216

139-
You need to update the connection string and the credentials in the `dev.env` file in the root folder.
217+
You need to update the connection string and the credentials in the `couchbase.yml` file in the `config` folder.
140218

141-
Note: Couchbase Server must be installed and running prior to running this app.
219+
Note: Couchbase Server must be installed and running before running this app.
142220

143221
## Swagger Documentation
144222

public/application_start.png

218 KB
Loading

public/swagger_documentation.png

1.25 MB
Loading
66.7 KB
Loading

0 commit comments

Comments
 (0)