add endpoint of get feedbacks (#18697)

Co-authored-by: lizb <lizb@sugon.com>
This commit is contained in:
Ganondorf 2025-05-13 10:35:14 +08:00 committed by GitHub
parent 0fed5c1193
commit c76d763639
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 614 additions and 1 deletions

View File

@ -93,6 +93,18 @@ class MessageFeedbackApi(Resource):
return {"result": "success"} 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): class MessageSuggestedApi(Resource):
@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY, required=True)) @validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY, required=True))
def get(self, app_model: App, end_user: EndUser, message_id): 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(MessageListApi, "/messages")
api.add_resource(MessageFeedbackApi, "/messages/<uuid:message_id>/feedbacks") api.add_resource(MessageFeedbackApi, "/messages/<uuid:message_id>/feedbacks")
api.add_resource(MessageSuggestedApi, "/messages/<uuid:message_id>/suggested") api.add_resource(MessageSuggestedApi, "/messages/<uuid:message_id>/suggested")
api.add_resource(AppGetFeedbacksApi, "/app/feedbacks")

View File

@ -1237,6 +1237,21 @@ class MessageFeedback(Base):
account = db.session.query(Account).filter(Account.id == self.from_account_id).first() account = db.session.query(Account).filter(Account.id == self.from_account_id).first()
return account 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): class MessageFile(Base):
__tablename__ = "message_files" __tablename__ = "message_files"

View File

@ -177,6 +177,21 @@ class MessageService:
return feedback 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 @classmethod
def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str): def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
message = ( message = (

View File

@ -383,6 +383,69 @@ The text generation application offers non-session support and is ideal for tran
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.
### Query
<Properties>
<Property name='page' type='string' key='page'>
optionalpaginationdefault1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
optional records per page default20
</Property>
</Properties>
### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/text-to-audio' url='/text-to-audio'
method='POST' method='POST'

View File

@ -381,6 +381,69 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from
</Row> </Row>
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。
### クエリ
<Properties>
<Property name='page' type='string' key='page'>
任意ページ番号。デフォルト値1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
任意1ページあたりの件数。デフォルト値20
</Property>
</Properties>
### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/text-to-audio' url='/text-to-audio'
method='POST' method='POST'

View File

@ -355,6 +355,68 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
</Col> </Col>
</Row> </Row>
---
<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.
### Query
<Properties>
<Property name='page' type='string' key='page'>
optionalpaginationdefault1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
optional records per page default20
</Property>
</Properties>
### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
--- ---
<Heading <Heading
@ -845,4 +907,4 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
``` ```
</CodeGroup> </CodeGroup>
</Col> </Col>
</Row> </Row>

View File

@ -487,6 +487,69 @@ Chat applications support session persistence, allowing previous chat history to
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.
### Query
<Properties>
<Property name='page' type='string' key='page'>
optionalpaginationdefault1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
optional records per page default20
</Property>
</Properties>
### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'

View File

@ -487,6 +487,70 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。
### クエリ
<Properties>
<Property name='page' type='string' key='page'>
任意ページ番号。デフォルト値1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
任意1ページあたりの件数。デフォルト値20
</Property>
</Properties>
### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'

View File

@ -493,6 +493,71 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='获取APP的消息点赞和反馈'
name='#app-feedbacks'
/>
<Row>
<Col>
获取应用的终端用户反馈、点赞。
### Query
<Properties>
<Property name='page' type='string' key='page'>
选填分页默认值1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
选填每页数量默认值20
</Property>
</Properties>
### Response
- `data` (List) 返回该APP的点赞、反馈列表。
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'

View File

@ -450,6 +450,69 @@ Chat applications support session persistence, allowing previous chat history to
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.
### Query
<Properties>
<Property name='page' type='string' key='page'>
optionalpaginationdefault1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
optional records per page default20
</Property>
</Properties>
### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'

View File

@ -450,6 +450,70 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。
### クエリ
<Properties>
<Property name='page' type='string' key='page'>
任意ページ番号。デフォルト値1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
任意1ページあたりの件数。デフォルト値20
</Property>
</Properties>
### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'

View File

@ -464,6 +464,69 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
--- ---
<Heading
url='/app/feedbacks'
method='GET'
title='获取APP的消息点赞和反馈'
name='#app-feedbacks'
/>
<Row>
<Col>
获取应用的终端用户反馈、点赞。
### Query
<Properties>
<Property name='page' type='string' key='page'>
选填分页默认值1
</Property>
</Properties>
<Properties>
<Property name='limit' type='string' key='limit'>
选填每页数量默认值20
</Property>
</Properties>
### Response
- `data` (List) 返回该APP的点赞、反馈列表。
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading <Heading
url='/messages/{message_id}/suggested' url='/messages/{message_id}/suggested'
method='GET' method='GET'