{
"username": "string",
"password": "string"
}
{
"id": "number",
"username": "string"
}, 200
- HTTP 204 No Content
{
"username": "string",
"password": "string"
}
{
"id": "number",
"username": "string"
}, 201
{
"username": "string",
"password": "string"
}
{
"id": "number",
"username": "string"
}, 200
{
"username": "string",
"password": "string"
}
{
"id": "number",
"username": "string"
}, 201
Each group has tasks and users
Important notes:
/groups/:id/users
, reject access to /groups/:id/tasks
;groups/:id/users
, reject access to this route to the user;Model:
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 groupAccepted 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.
Subtasks:
Task
model has many
Tasks
;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;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 subtaskHint: maybe I've made a mistake in routes here, but the main point must be clear
Set of methods:
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:
How to use this class:
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:
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
Done:
Photo: https://www.shutterstock.com/image-photo/close-womans-hands-writing-spiral-600nw-525439534.jpg
/api/tasks
(see example in the project with users);nullable=false
;All points must work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.