GithubHelp home page GithubHelp logo

dtluther / product-rating-exercise Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petra-living/product-rating-exercise

0.0 1.0 0.0 123 KB

Dockerfile 1.34% Ruby 97.32% HTML 0.73% Shell 0.61%

product-rating-exercise's Introduction

README

API Calls

  • GET /product: returns all products in order highest rating on average (those with no reviews come last)
  • GET /product/:id: returns a single product
  • GET /product/:id/reviews: returns all reviews for a specific product as a JSON array, sorted by most recent and then highest rated
  • POST /product/:id/reviews: creates a review for a specific product
    • params:
      • author: string (REQUIRED)
      • rating: integer between 1 and 5 (REQUIRED)
      • headline: string less than 120 chars (REQUIRED)
      • body: text (optional)
    • Example photo of a this API call on Postman: Example Post Request

Original Prompt

Please fork this repository and use it to solve the following problem: given a simple product catalog API, add the ability to rate products, to see product ratings, and to list products by rating.

This repository provides a starting point for a Ruby on Rails implementation. You are welcome to use a different toolset if you prefer, please see below.

Setup

To start working on this codebase, do the following:

  1. Ensure that you have an up-to-date installation of Docker.
  2. $ docker-compose build
  3. $ docker-compose run --rm api rake db:create db:migrate db:seed
  4. $ docker-compose up

You should now be able to list products at http://localhost:3000/product

The initial api consists of just two operations:

  • GET /product: returns all products as a JSON array.
  • GET /product/:id: returns a single product.

The problem

Please create two new endpoints:

  1. Create a review for a given product that has the following properties:
    • The author of the review, requied.
    • Star rating between 1 and 5 (inclusive), required.
    • The headline text of the review, required.
    • The body text.
  2. List all reviews for a given product, with the following parameters:
    • Sort by either star rating or date, optional.
    • Sort in ascending or descending order, optional.
    • The default sort order should be by date descending (i.e., most recent review first).

Also, please modify the GET /product call, used to return all products, to return the most highly rated products first.

To use something other than Rails

You are welcome to implement this in a language/toolkit of your choice. You will need to replace the basic functionality implemented in this project template, which is:

  1. A table with the following schema (or equivalent if not using a relational database)
    CREATE TABLE products (
     id uuid DEFAULT gen_random_uuid() primary key,
     name text not null,
     description character varying,
     created_at timestamp(6) without time zone NOT NULL,
     updated_at timestamp(6) without time zone NOT NULL
    );
    CREATE UNIQUE INDEX index_products_on_name ON products(name);
  2. The initial API as described above, returning the rows of this table as JSON.

You can get started by running the docker-compose commands listed under Setup above to create the database, schema, and some sample data in the products table, and then replacing the api service in docker-compose.yaml with your own implementation.

product-rating-exercise's People

Contributors

dtluther avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.