Skip to content

Commit

Permalink
merge code from server
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jan 2, 2024
1 parent 869b13f commit 6ff046a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
22 changes: 8 additions & 14 deletions server/model/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,17 @@ class ChatGroup(Base):
)


def _default(value):
if isinstance(value, db.Model):
return value.__dict__
elif isinstance(value, Decimal):
return int(value)
elif isinstance(value, datetime):
return value.strftime("%Y-%m-%d %H:%M:%S")
elif isinstance(value, time):
return value.isoformat()
return str(value)


class CustomJsonProvider(DefaultJSONProvider):
default = _default
@staticmethod
def default(value):
if isinstance(value, db.Model):
return value.__dict__
elif isinstance(value, datetime):
return value.strftime("%Y-%m-%d %H:%M:%S")
return str(value)


app.json_provider_class = CustomJsonProvide
app.json_provider_class = CustomJsonProvider
app.json = CustomJsonProvider(app)


Expand Down
3 changes: 3 additions & 0 deletions server/model/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def get_team_list_by_user_id(user_id, page=1, size=100):
Team.status == 0,
)
)
total = query.count()
if total == 0:
return [], 0
return query_one_page(query, page, size), total


Expand Down
2 changes: 1 addition & 1 deletion server/model/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy import and_, or_

from .schema import User
from .schema import User, db


def get_user_by_id(user_id):
Expand Down
2 changes: 1 addition & 1 deletion server/routes/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from app import app
from flask import Blueprint, abort, jsonify, redirect, request
from flask import Blueprint, jsonify, session
from model.team import get_team_list_by_user_id, is_team_admin
from model.user import get_user_by_id
from utils.auth import authenticated
Expand Down
2 changes: 1 addition & 1 deletion server/utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def register(code: str) -> str | None:
)

db.session.add(new_user)
db.session.commit()
db.session.flush()

new_bind_user = BindUser(
id=ObjID.new_id(),
Expand Down

0 comments on commit 6ff046a

Please sign in to comment.