add endpoint of get feedbacks (#18697)
Co-authored-by: lizb <lizb@sugon.com>
This commit is contained in:
parent
0fed5c1193
commit
c76d763639
12 changed files with 614 additions and 1 deletions
|
|
@ -93,6 +93,18 @@ class MessageFeedbackApi(Resource):
|
|||
return {"result": "success"}
|
||||
|
||||
|
||||
class AppGetFeedbacksApi(Resource):
|
||||
@validate_app_token
|
||||
def get(self, app_model: App):
|
||||
"""Get All Feedbacks of an app"""
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument("page", type=int, default=1, location="args")
|
||||
parser.add_argument("limit", type=int_range(1, 101), required=False, default=20, location="args")
|
||||
args = parser.parse_args()
|
||||
feedbacks = MessageService.get_all_messages_feedbacks(app_model, page=args["page"], limit=args["limit"])
|
||||
return {"data": feedbacks}
|
||||
|
||||
|
||||
class MessageSuggestedApi(Resource):
|
||||
@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY, required=True))
|
||||
def get(self, app_model: App, end_user: EndUser, message_id):
|
||||
|
|
@ -119,3 +131,4 @@ class MessageSuggestedApi(Resource):
|
|||
api.add_resource(MessageListApi, "/messages")
|
||||
api.add_resource(MessageFeedbackApi, "/messages/<uuid:message_id>/feedbacks")
|
||||
api.add_resource(MessageSuggestedApi, "/messages/<uuid:message_id>/suggested")
|
||||
api.add_resource(AppGetFeedbacksApi, "/app/feedbacks")
|
||||
|
|
|
|||
|
|
@ -1237,6 +1237,21 @@ class MessageFeedback(Base):
|
|||
account = db.session.query(Account).filter(Account.id == self.from_account_id).first()
|
||||
return account
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": str(self.id),
|
||||
"app_id": str(self.app_id),
|
||||
"conversation_id": str(self.conversation_id),
|
||||
"message_id": str(self.message_id),
|
||||
"rating": self.rating,
|
||||
"content": self.content,
|
||||
"from_source": self.from_source,
|
||||
"from_end_user_id": str(self.from_end_user_id) if self.from_end_user_id else None,
|
||||
"from_account_id": str(self.from_account_id) if self.from_account_id else None,
|
||||
"created_at": self.created_at.isoformat(),
|
||||
"updated_at": self.updated_at.isoformat(),
|
||||
}
|
||||
|
||||
|
||||
class MessageFile(Base):
|
||||
__tablename__ = "message_files"
|
||||
|
|
|
|||
|
|
@ -177,6 +177,21 @@ class MessageService:
|
|||
|
||||
return feedback
|
||||
|
||||
@classmethod
|
||||
def get_all_messages_feedbacks(cls, app_model: App, page: int, limit: int):
|
||||
"""Get all feedbacks of an app"""
|
||||
offset = (page - 1) * limit
|
||||
feedbacks = (
|
||||
db.session.query(MessageFeedback)
|
||||
.filter(MessageFeedback.app_id == app_model.id)
|
||||
.order_by(MessageFeedback.created_at.desc(), MessageFeedback.id.desc())
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.all()
|
||||
)
|
||||
|
||||
return [record.to_dict() for record in feedbacks]
|
||||
|
||||
@classmethod
|
||||
def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
|
||||
message = (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue