Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
vgnlkn committed Nov 9, 2024
1 parent 446b600 commit 40d0a78
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
8 changes: 5 additions & 3 deletions backend/activities/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# entity_id: ObjectId, // ID сущности, с которой работал пользователь (например, _id книги, автора и т.д.)
# created_at: Date // Дата создания записи

from flask import jsonify
from flask import jsonify, request
from pymongo import MongoClient


Expand All @@ -24,8 +24,10 @@ def activities():
return jsonify({"message": "Hello World!"}), 200

@self.__app.route("/activities", methods=["POST"])
def get_activities():
return jsonify({"message": "post activities!"}), 200
def insert_activity():
body = request.get_json()
print(body)
return body, 200


if __name__ == "__main__":
Expand Down
36 changes: 33 additions & 3 deletions backend/users/users.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
from flask import jsonify
# Users {
# _id: ObjectId,
# login: String, // Логин пользователя
# hash_password: String, // Хэш пароля пользователя
# created_at: Date, // Дата регистрации
# visited_at: Date, // Время последнего посещения
# name: String, // Имя
# surname: String, // Фамилия
# activities: ObjectId[],
# books: ObjectId[]
# }

from flask import jsonify, request
from pymongo import MongoClient


class UsersService:
collection_name = "users"
db_name = "library"

def __init__(self, app: any, mongo: any) -> None:
self.__app = app
self.__mongo = mongo
Expand All @@ -15,9 +30,24 @@ def get_users():
return jsonify({"message": "get user!"}), 200

@self.__app.route("/users", methods=["POST"])
def insert_users():
return jsonify({"message": "insert user!"}), 200
def insert_user():
return self.addUser(request.get_json())

def addUser(self, request_data):
if not request_data or "login" not in request_data:
return jsonify({"error": "Missing login in request data"}), 400

login = request_data["login"]
print(login)
response = {}

collection = self.__mongo[self.db_name][self.collection_name]
response = collection.find_one({"login": login})




return response, 200

if __name__ == "__main__":
pass

0 comments on commit 40d0a78

Please sign in to comment.