The task is to implement a service that stores users and the segments they belong to (creating, modifying, deleting segments, as well as adding and removing users from segments).
Full task description is available at this link.
- The service must provide an HTTP API with JSON format for both sending requests and receiving results.
- Development language: Golang.
- Any frameworks and libraries can be used.
- Relational DBMS: MySQL or PostgreSQL.
- Use of docker and docker-compose for setting up and deploying the dev environment.
$ git clone https://github.com/ptoshiko/avito_assignment.git
$ cd avito_assignment
$ make runmake testdb
make tMethod for creating a segment. Accepts a segment slug (name).
Request Example
curl -X POST -H "Content-Type: application/json" -d '{
"seg_name": "AVITO_DISCOUNT_50"
}' http://localhost:8080/segment/create
Response
{
"message":"Segment created successfully"
}Method for deleting a segment. Accepts a segment slug (name).
Request Example
curl -X DELETE -H "Content-Type: application/json" -d '{
"seg_name": "AVITO_DISCOUNT_30"
}' http://localhost:8080/segment/delete
Response
{
"message": "Segment deleted successfully"
}Method for adding a user to a segment. Accepts a list of segment slugs (names) to add to the user, a list of segment slugs (names) to remove from the user, and a user ID.
A request is considered valid if:
- Segments from the addition list are present in the segments table
- Segments from the removal list belong to the user
- One of the lists can be empty In other cases, the request is considered invalid.
Request Example
curl -X PATCH -H "Content-Type: application/json" -d '{
"user_id": 1,
"segments_to_add": ["AVITO_VOICE_MESSAGES"],
"segments_to_remove": ["AVITO_PERFORMANCE_VAS"]
}' http://localhost:8080/user/1
Response
{
"message": "User segments updated successfully"
}Method for retrieving active segments of a user. Takes a user ID as input.
curl -X GET http://localhost:8080/user/1
Response
{
[{"seg_id":1,"seg_name":"AVITO_DISCOUNT_30"},{"seg_id":3,"seg_name":"AVITO_VOICE_MESSAGES"}]
}