Commit 8d32a1ca authored by Eliss-good's avatar Eliss-good
Browse files

update

parent dfb30c47
......@@ -15,7 +15,7 @@ class ApprovedCustomerSchema(ma.SQLAlchemyAutoSchema):
include_relationships = True
exclude = ['connect_adv']
connect_customer = ma.Nested(CustomersSchema(exclude=('connect_com', 'customer_approve', 'id', )))
connect_customer = ma.Nested(CustomersSchema(exclude=( 'customer_approve', 'id', )))
class CoordinateSchema(ma.SQLAlchemyAutoSchema):
......
......@@ -15,7 +15,7 @@ class CoommunityAdvSchema(ma.SQLAlchemyAutoSchema):
load_instance = True
include_relationships = True
connect_reposted_by = ma.Nested(CustomersSchema(exclude=('comm_adv_reposted_by_customers','connect_com', )))
connect_reposted_by = ma.Nested(CustomersSchema(exclude=('comm_adv_reposted_by_customers', )))
connect_adv_id = ma.Nested(AdvertisementSchema(only=('connect_coordinates', 'adv_id_tagsadv', 'time_create',
'wait_size_users', 'id', 'adv_name', )))
......@@ -29,7 +29,7 @@ class CommunitySchema(ma.SQLAlchemyAutoSchema):
comm_adv_comm_id_community = ma.List(ma.Nested(CoommunityAdvSchema(exclude=('connect_community_id',) )))
community_cus = ma.List(ma.Nested(CustomersSchema()))
connect_customer = ma.Nested(CustomersSchema(exclude=('connect_com', 'customer_approve', 'id',)))
connect_customer = ma.Nested(CustomersSchema(exclude=( 'customer_approve', 'id',)))
def _base_query():
......
......@@ -35,3 +35,13 @@ def all_users():
return api_all_users.dump(data_query)
def filter_users(user_id=None):
data_query = _base_query()
if user_id is not None:
data_query = data_query.filter(Users.id == user_id)
api_all_users = UsersSchema()
return api_all_users.dump(data_query)
from web_setting import flask_app, db
from models.all_models import Advertisement, Users, Employer, Customers, TagsUsers, ClickHistory, CommunityAdv
from models.all_models import Advertisement, Users, Employer, Customers, TagsUsers, ClickHistory, CommunityAdv, CustomersCommunity
from werkzeug.security import generate_password_hash, check_password_hash
from routers.all_dataclasses import EntryDate, TagsIndex, RepostEvent
from routers.all_dataclasses import EntryDate, TagsIndex, RepostEvent, CustCommunity
from typing import List
......@@ -52,6 +52,12 @@ def add_new_click(NewClick: TagsIndex):
db.session.commit()
def add_new_connect_community(new_connect: CustCommunity):
comm_customers = CustomersCommunity(customers_id=new_connect.customers_id, community_id=new_connect.community_id)
db.session.add(comm_customers)
db.session.commit()
def create_advertisement(adv_info):
new_advertisement = Advertisement(
new_adv_name=adv_info.adv_name,
......
......@@ -115,16 +115,28 @@ class Customers(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
connect_users = db.relationship('Users', backref='users_cus', uselist=False)
community_id = db.Column(db.Integer, db.ForeignKey('community.id'))
connect_com = db.relationship('Community', backref='community_cus')
def __init__(self, coords, user_id, points_amount = 0):
self.user_id = user_id
self.coordinates = coords
self.points = points_amount
def __repr__(self):
return f"Customers name:'{self.connect_com}'"
return f"Customers name:'{self.connect_users}'"
class CustomersCommunity(db.Model):
__tablename__ = 'cust_community'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
customers_id = db.Column(db.Integer, db.ForeignKey('customers.id'))
connect_cust = db.relationship('Customers', backref='customers_comm')
community_id = db.Column(db.Integer, db.ForeignKey('community.id'))
connect_com = db.relationship('Community', backref='community_cus')
def __int__(self, customers_id, community_id):
self.community_id = community_id
self.customers_id = customers_id
class СoordinatesEvent(db.Model):
......
......@@ -15,7 +15,7 @@ class EmployersView(ModelView):
class CustomerView(ModelView):
form_columns = ['connect_users', 'connect_com', 'coordinates', 'points']
form_columns = ['connect_users', 'coordinates', 'points']
class CoordinatEventView(ModelView):
......
......@@ -31,3 +31,8 @@ class RepostEvent(BaseModel):
adv_id: int
is_repost: bool
community_id: int
class CustCommunity(BaseModel):
status: str
community_id: int
customers_id: int
from web_setting import flask_app, cross_origin
from api.api_users import all_users
from api.api_users import all_users, filter_users
from api.api_customers import all_customers, filter_customers
from buisness_logic.insert_models import add_new_users
from buisness_logic.insert_models import add_new_connect_community
from buisness_logic.delete_model import delete_con_community
from routers.all_dataclasses import CustCommunity
from pydantic import BaseModel, constr
from typing import Optional
from flask import jsonify, request
@flask_app.route('/api/users', methods=["GET"])
def users():
@flask_app.route('/api/users/', methods=["GET"])
@flask_app.route('/api/users/<int:user_id>', methods=["GET"])
def users(user_id=None):
if user_id is not None:
result = filter_users(user_id)
result = all_users()
return jsonify(result)
......@@ -21,6 +27,18 @@ def customers():
return jsonify(result)
@flask_app.route('/api/customers/community', methods=["POST"])
def customers_community():
res = CustCommunity(**request.get_json())
if res.status == 'delete':
delete_con_community(res)
elif res.status == 'insert':
add_new_connect_community(res)
return jsonify('sex')
#return jsonify(filter_users(res))
@flask_app.route('/api/customers/filter/login/<string:login>/', methods=["GET"])
@flask_app.route('/api/customers/filter/user_id/<int:user_id>/', methods=["GET"])
def cust_filter(login=None, user_id=None):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment