rails_simple_api

所属分类:Leetcode/题库
开发工具:Ruby
文件大小:40KB
下载次数:0
上传日期:2022-06-23 05:33:19
上 传 者sh-1993
说明:  Rails API,过去的工作面试挑战
(Rails API, past job interview challenge)

文件列表:
.dockerignore (4667, 2022-06-23)
.ruby-version (11, 2022-06-23)
Dockerfile (490, 2022-06-23)
Gemfile (1435, 2022-06-23)
Gemfile.lock (3961, 2022-06-23)
Rakefile (227, 2022-06-23)
app (0, 2022-06-23)
app\channels (0, 2022-06-23)
app\channels\application_cable (0, 2022-06-23)
app\channels\application_cable\channel.rb (79, 2022-06-23)
app\channels\application_cable\connection.rb (85, 2022-06-23)
app\controllers (0, 2022-06-23)
app\controllers\application_controller.rb (97, 2022-06-23)
app\controllers\concerns (0, 2022-06-23)
app\controllers\concerns\.keep (0, 2022-06-23)
app\controllers\products_controller.rb (903, 2022-06-23)
app\jobs (0, 2022-06-23)
app\jobs\application_job.rb (269, 2022-06-23)
app\mailers (0, 2022-06-23)
app\mailers\application_mailer.rb (102, 2022-06-23)
app\models (0, 2022-06-23)
app\models\application_record.rb (78, 2022-06-23)
app\models\concerns (0, 2022-06-23)
app\models\concerns\.keep (0, 2022-06-23)
app\models\product.rb (769, 2022-06-23)
app\views (0, 2022-06-23)
app\views\layouts (0, 2022-06-23)
app\views\layouts\mailer.html.erb (229, 2022-06-23)
app\views\layouts\mailer.text.erb (13, 2022-06-23)
bin (0, 2022-06-23)
bin\bundle (2945, 2022-06-23)
bin\rails (264, 2022-06-23)
bin\rake (213, 2022-06-23)
bin\setup (1008, 2022-06-23)
bin\spring (507, 2022-06-23)
config.ru (130, 2022-06-23)
config (0, 2022-06-23)
... ...

# Rails Simple API Build a REST API service for a warehouse platform. The basic functionality is to add and show product information as well as list all the products in the system. Each product has the following structure: - *id*: the unique ID of the product - *name*: the name of the product - *description*: the description of the product - *vendor*: the product vendor name - *price*: the price of the product, represented as a non-negative integer denoting cents - *currency*: the currency of the product (either EUR or USD) - *stock*: the number of the product items in the warehouse - *image_url*: the URL of the product image - *sku*: the product stock-keeping unit (SKU) The REST service must expose the **/products** endpoint, which allows for managing the collection of products in the following way: **POST** request to **/products**: - Validates de following conditions: - *name* is set - The length of *name* is not more than 40 characters - The length of *vendor* (if provided) is not more than 100 characters - *price* is set - *price* is an integer - *currency* is set - *currency* is USD or EUR - *stock* is set - *stock* is an integer - If any of the above requirements fail, the server should return the response code 422. Otherwise, in the case of a successful request, the server should return the response code 201 and the product information in JSON format. - Returns response in JSON format only **GET** request to **/products**: - Returns response in JSON if JSON format is requested: requested header contains **"Accept":"application/json"** - Returns response in XML if XML format is requested: requested header contains **"Accept":"application/xml"** - **Products should be ordered by id**. - The HTTP response code should be 200. **GET** request to **/product/:id** - Returns response in JSON if JSON format is requested: requested header contains **"Accept":"application/json"** - Returns response in XML if XML format is requested: requested header contains **"Accept":"application/XML"** - If the product with the given id does not exist, then the response code should be 404. Otherwise, the response code should be 200. ## Software Instructions - Ruby version: 2.7.1 - Rails version: 6.0.2 - Default port: 8000 ## Execution ### Requirements - docker-compose v 1.29.2+ Usage of docker requires some changes in the system, like adding the user to the docker group ### Running the server ``` docker-compose build docker-compose run web rake db:create docker-compose run web rake db:migrate docker-compose up ``` ### Seeding the database ``` docker-compose run web rake db:seed ``` ### Cleaning the database ``` docker-compose run web rake db:drop docker-compose run web rake db:create docker-compose run web rake db:migrate ``` ### Stoping docker After shutting down the rails `ctrl + c`: ``` docker-compose down ``` ### Using the API Require tools [Insomnia](https://insomnia.rest/download) This project was created using this instructions: [Docker Docs: Quickstart, composer and rails](https://docs.docker.com/samples/rails/)

近期下载者

相关文件


收藏者