Coder Social home page Coder Social logo

databases-fullstack-project's Introduction

Todo List Manager

Enpoints

POST /login – login

Request

{
  "username": "string",
  "password": "string"
}

Response

{
  "id": "number",
  "username": "string"
}, 200

DELETE /logout – logout

Response

  • HTTP 204 No Content

POST /register - register

Request

{
  "username": "string",
  "password": "string"
}

Response

{
  "id": "number",
  "username": "string"
}, 201

databases-fullstack-project's People

Contributors

biggujo avatar elcaramel avatar cs31ivank avatar qoqik avatar

Watchers

 avatar

databases-fullstack-project's Issues

Add groups resource

Each group has tasks and users

Important notes:

  • if a user is not in /groups/:id/users, reject access to /groups/:id/tasks;
  • if a user is not in groups/:id/users, reject access to this route to the user;
  • other users cannot join other users (a user only can join/leave the group if he and only he wants to)

Model:

  • name of the group;
  • array of Users model;
  • array of tasks like in Tasks controller and Tasks model;
  • timestamps (created_at, updated_at)

Routes:

  • GET /groups – get all groups (array of groups);
  • POST /groups – create new group;
  • GET /groups/:id – get one group:

Schema of response of GET /groups/:id:

{
  "name": "string",
  "members": 123
}
  • PUT /groups/:id – update group

Accepted data to PUT /groups/:id:

{
"name": "string",
}

  • POST /groups/:groupid/users – add new user to the group (user joins). Works only if userid == current_user.id;

Accepted data to POST /groups/:groupid/users:

{
"id": 12345,
}

  • DELETE /groups/:groupid/users/:userid – remove a user from the group (user leaves). Works only if userid == current_user.id;

  • ALL /groups/:id/tasks – GET, POST, PUT like in tasks controller etc.

Add subtasks for tasks on backend

Subtasks:

  • subtasks has the same scheme as the tasks;
  • Task model has many Tasks;
  • make work possible with the following routes:
    • private tasks of the user:
      • GET /api/tasks/:id/subtasks - get all subtasks;
      • POST /api/tasks/:id/subtasks - add a subtask;
      • PUT /api/tasks/:taskid/subtasks/:subtaskid - update a subtask;
      • DELETE /api/tasks/:taskid/subtasks/:subtaskid - delete a subtask;
    • group tasks:
      • GET /api/groups/:groupid/tasks/:id/subtasks - get all subtasks;
      • POST /api/groups/:groupid/tasks/:id/subtasks - add a subtask;
      • PUT /api/groups/:groupid/tasks/:taskid/subtasks/:subtaskid - update a subtask;
      • DELETE /api/groups/:groupid/tasks/:taskid/subtasks/:subtaskid - delete a subtask

Hint: maybe I've made a mistake in routes here, but the main point must be clear

Implement a query object for tasks

Set of methods:

  • sort by name (ascending, descending);
  • sort by deadline (ascending, descending);
  • filter by actual status: only completed/only in progress/only overdue tasks (it means deadline has passed, but the task is still in progress);
  • filter by date range (e.g. tasks between 2024-03-02 12:00 and 2024-04-05 12:00);
  • pagination

Hint: dates can be compared as plain strings (e.g. of a query: "deadline >= 2024-03-02 12:00 and deadline <= 2024-04-05 12:00")

Steps to implement:

  • create folder backend/query;
  • create file backend/query/tasks_query.py;
  • implement a class TasksQuery:
    • constructor accepts an object of initial scope of data;
    • methods (better to make private, but not essential):
      • like in Rails last homework

How to use this class:

  • in tasks_controller.py in def index() write something like this (it is not tested to work, though):
def index():
  user_id = session.get("id")
  if user_id is None:
      return {'message': 'Unauthorized'}, 401

  parameters = request.args
  initial_scope = Task.query_user_tasks(user_id).all()

  query_object = new TasksQuery(initial_scope) # idk if it works. It is just a pseudocode
  scoped_data = query_object.call(parameters)

  return jsonify(json_list=[i.serialize for i in scoped_data])

How to test:

Authorisation request:
Image

Create tasks request:
Image

Update task:
Image

Main request to test queries:
Image


Example of Query Object class in Rails:

# frozen_string_literal: true

class ServiceSubcategoryQuery
  attr_accessor :initial_scope

  def initialize(initial_scope)
    @initial_scope = initial_scope
  end

  def call(params)
    scoped = @initial_scope

    scoped = filter_by_name(scoped, params)
    scoped = filter_by_domain(scoped, params)
    sort_by_categories_amount(scoped, params)
  end

  private

  def filter_by_name(scoped, params)
    query = params[:query]

    scoped.where("categoryname ILIKE ?", "%#{query}%")
  end

  def filter_by_domain(scoped, params)
    domain = params[:domain]

    is_domain_empty = domain == "" || domain.nil?

    return scoped if is_domain_empty

    scoped.where(servicedomain_id: domain.to_i)
  end

  def sort_by_categories_amount(scoped, params)
    sort_order = params[:sort_by_services_amount] == "ascending" ? "ASC" : "DESC"

    scoped.left_joins(:services)
          .group("servicesubcategories.id")
          .order("COUNT(services.id) #{sort_order}")
  end
end

Add header

  • links: home, todo (route : /todo), sign up (/signup), sign in (/signin)

Backend: Add Task resource

  • router – /api/tasks (see example in the project with users);
  • REST API CRUD operations;
  • fields: id, text, is_completed, created_at, updated_at. All fields are nullable=false;
  • validation (see user_schemas.py);

All points must work

Fix header

  • remove "About" from the header;
  • remove About page from the application (from the /frontend/pages folder etc.);
  • Add to header "All Groups", "My Groups" links

Image

Add MVC

  • error handler decorators;
  • MVC pattern implementation;
  • schema validations;
  • add persist data from MySQL to mysql-data folder

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.