Backend for android app for SPbU dorms forum
(!) I really advise you to use Postman
Authentication works by passing a special Token in the header of every HTTP-request, like so:
Authentication: "Token <paste user auth-token>"
To get this token user should be registered, and then get it by requesting. Here is the pipeline of registering:
- api/auth/users/
POST-request, containing email, username, password (all mistakes in fields would be printed back) \ - New user created, but email activation is needed, so look into console if mock activation(by default) or open mailbox and copy the activation code.
- api/auth/activate/
POST-request, containing "email" and "activation_code" fields(str and int).
!ATTENTION! codes expire after 5 minutes, you can send new ones by POST-request with "email" and <"resend": true> fields.
(IF YOU FEEL TOO LAZY, THEN JUST EDIT USER FIELD is_active IN DB) - api/auth/token/login/
POST-request, containing username and password, answer will contain "auth-token", that you should paste into requests headers.
(These are routes from server url)
- api/sales/
- GET - prints all posts (permissions: Everyone)
(args: all=(true/false), user_id=(id of user), search=(substring)) - POST - creates new post (fields: title, price, description, is_published) (permissions: Authenticated)
- GET - prints all posts (permissions: Everyone)
- api/sales/<int: post_id>
- GET - print single post (permissions: Authenticated)
- PUT, PATCH, DELETE - recreate, updates, deletes single post (permissions: Post Author or Admin)
(!ATTENTION!) to delete picture from post send request with "images_to_delete": [1, 2, 3, ...] (integers, id of pictures you need to delete)
- api/user/<int: user_id>
- GET - print user info (permissions: Authenticated)
- PUT, PATCH, DELETE - recreate, updates, deletes user account (permissions: Post Author or Admin)
- api/image/salecard/<int: salecard_photo_id>
- GET - shows picture, attached to some salecard, with id = salecard_photo_id (permissions: Everyone)
- api/image/user/<int: user_id>
- GET - shows picture, attached to user profile (permissions: Everyone)
- api/comments/<int: post_id>
- GET - shows all comments of salecard (permissions: Authenticated)
- POST - creates a new comment (fields: content) (permissions: Authenticated)
- api/categories/
- GET - shows all categories (permissions: Authenticated)
- admin/
- Django regular admin panel
- Install requirements
poetry install --with dev- Create file «.env» in vunkpunk/vunkpunk, then paste this variable in it:
SECRET_KEY="secret key(ask our dev team)"(EXTRA) if you try working with real smtp, then add this
EMAIL_HOST = "smtp host (I suggest using mailtrap to mock smtp)"
EMAIL_PORT = <integer>
EMAIL_HOST_USER = "smtp username"
EMAIL_HOST_PASSWORD = "yeah, you guessed it, smtp user password"(EXTRA ENDED)
- Execute migrations
python vunkpunk/manage.py migrate- Run test server
python vunkpunk/manage.py runserver- (OPTIONAL) create admin account
python vunkpunk/manage.py createsuperuser