Git Product home page Git Product logo

good_night's Introduction

Requirement

  • ruby 3.1.3
  • bundler
  • docker-compose(To run mysql container)

Get Started

Switch to the desired branch

We use main branch as demo.

$ git switch main

Install required softwares

ruby 3.1.3

$ sudo apt install rbenv(for ubuntu)
$ brew install rbenv ruby-build(for MacOS)
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc #depend on which sh you choose
$ source ~/.bashrc
$ rbenv install 3.1.3

bundler

$ RBENV_VERSION=3.1.3 gem install bundler

docker-compose / mysql 5.6

In this project we provide docker-compose.yml to install mysql.

$ sudo apt install docker-compose
$ docker-compose up -d
$ docker ps #to check if mysql is running successfully

install gems

$ bundle install

env settings

If docker-compose runs well, the database.yml settings fit mysql, no need to change.

create rails database

$ bundle exec rake db:create
$ bundle exec rake db:migrate

run rails

# You need to set binding if you connect from other machine
$ bundle exec rails s

RSpec

To run the RSpec locally, follow the steps below:

create rails database for test env

$ RAILS_ENV=test bundle exec rake db:create
$ RAILS_ENV=test bundle exec rake db:migrate

execute rspec

$ bundle exec rspec spec

API document

Users

Follow user

  • URL: {base_url}/users/:user_id/follow

  • Method: POST

  • Body:

    • follower_id: user id that you want to follow.
  • Response:

    {
        "followed_users": [
            {
                "id": 1,
                "name": "Columbus Zulauf Esq.",
                "created_at": "2023-08-03T11:32:24.638Z",
                "updated_at": "2023-08-03T11:32:24.638Z"
            }
        ]
    }
  • Error:

    { "error_code": "FOLLOWER_NOT_FOUND" }
    http status error_code description
    404 FOLLOWER_NOT_FOUND The follower_id is not a valid user id
    409 FOLLOWER_ALREADY_EXISTS This user is already followed the follower

Unfollow user

  • URL: {base_url}/users/:user_id/unfollow

  • Method: POST

  • Body:

    • follower_id: user id that you want to unfollow.
  • Response:

    {
        "followed_users": [
            {
                "id": 1,
                "name": "Columbus Zulauf Esq.",
                "created_at": "2023-08-03T11:32:24.638Z",
                "updated_at": "2023-08-03T11:32:24.638Z"
            }
        ]
    }
  • Error:

    { "error_code": "USER_NOT_FOLLOWED" }
    http status error_code description
    404 USER_NOT_FOLLOWED The follower is not followed yet

User clock in

  • URL: {base_url}/users/:user_id/clock_in

  • Method: POST

  • Body: N/A

  • Response:

    {
        "clocks": [
            {
                "id": 5,
                "user_id": 1,
                "clock_in": "2023-08-03T19:14:40.000Z",
                "clock_out": null,
                "duration": null
            },
            {
                "id": 4,
                "user_id": 1,
                "clock_in": "2023-08-03T18:59:28.000Z",
                "clock_out": "2023-08-03T19:14:28.000Z",
                "duration": 900
            },
            {
                "id": 3,
                "user_id": 1,
                "clock_in": "2023-08-03T18:46:44.000Z",
                "clock_out": "2023-08-03T18:47:08.000Z",
                "duration": 24
            }
        ]
    }
  • Error:

    { "error_code": "ACTIVE_CLOCK_EXISTS" }
    http status error_code description
    400 ACTIVE_CLOCK_EXISTS User has a active clock not clock out yet

User clock out

  • URL: {base_url}/users/:user_id/clock_out

  • Method: PUT

  • Body: N/A

  • Response:

    {
        "clocks": [
            {
                "id": 5,
                "user_id": 1,
                "clock_in": "2023-08-03T19:14:40.000Z",
                "clock_out": "2023-08-03T19:16:43.000Z",
                "duration": 123
            },
            {
                "id": 4,
                "user_id": 1,
                "clock_in": "2023-08-03T18:59:28.000Z",
                "clock_out": "2023-08-03T19:14:28.000Z",
                "duration": 900
            },
            {
                "id": 3,
                "user_id": 1,
                "clock_in": "2023-08-03T18:46:44.000Z",
                "clock_out": "2023-08-03T18:47:08.000Z",
                "duration": 24
            }
        ]
    }
  • Error:

    { "error_code": "NO_ACTIVE_CLOCK" }
    http status error_code description
    400 NO_ACTIVE_CLOCK User has not clocked in yet

User followers records

  • URL: {base_url}/users/:user_id/followers_records
  • Method: GET
  • Parameters: N/A
  • Response:
    {
        "followers_records": [
            {
                "user_id": 1,
                "user_name": "Columbus Zulauf Esq.",
                "clock_in": "2023-08-03T18:59:28.000Z",
                "clock_out": "2023-08-03T19:14:28.000Z",
                "duration": 900
            },
            {
                "user_id": 1,
                "user_name": "Columbus Zulauf Esq.",
                "clock_in": "2023-08-03T18:42:03.000Z",
                "clock_out": "2023-08-03T18:46:23.000Z",
                "duration": 260
            },
            {
                "user_id": 1,
                "user_name": "Columbus Zulauf Esq.",
                "clock_in": "2023-08-03T19:14:40.000Z",
                "clock_out": "2023-08-03T19:16:43.000Z",
                "duration": 123
            },
            {
                "user_id": 1,
                "user_name": "Columbus Zulauf Esq.",
                "clock_in": "2023-08-03T18:46:44.000Z",
                "clock_out": "2023-08-03T18:47:08.000Z",
                "duration": 24
            },
            {
                "user_id": 1,
                "user_name": "Columbus Zulauf Esq.",
                "clock_in": "2023-08-03T17:07:11.000Z",
                "clock_out": "2023-08-03T17:07:33.000Z",
                "duration": 22
            }
        ]
    }
  • Error: N/A

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.