上传文件至 /
This commit is contained in:
69
Poll.py
Normal file
69
Poll.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from ProjectCfg import DOMAIN
|
||||
from .CallServer import _make_request
|
||||
from typing import List,Any,Optional,Dict
|
||||
|
||||
###==========================投票功能============================
|
||||
def GetPoll(poll_id: str, Authorization: str) -> dict:
|
||||
"""获取投票"""
|
||||
url = f"{DOMAIN}/polls/{poll_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('GET', url, headers)
|
||||
|
||||
def PostPoll(Authorization: str, title: Optional[str] = None, description: Optional[str] = None, ended_at: Optional[str] = None, is_anonymous: Optional[bool] = None, questions: Optional[List[Dict[str, Any]]] = None) -> dict:
|
||||
"""创建投票"""
|
||||
body = {
|
||||
"title": title,
|
||||
"description": description,
|
||||
"ended_at": ended_at,
|
||||
"is_anonymous": is_anonymous,
|
||||
"questions": questions,
|
||||
}
|
||||
url = f"{DOMAIN}/polls"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def DeletePoll(Authorization: str, poll_id: str) -> dict:
|
||||
"""删除投票"""
|
||||
url = f"{DOMAIN}/polls/{poll_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
||||
|
||||
def AnswerPoll(Authorization: str, poll_id: str, answer: Dict[str, Any]) -> dict:
|
||||
"""回答投票"""
|
||||
body = {"answer": answer}
|
||||
url = f"{DOMAIN}/polls/{poll_id}/answer"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('POST', url, headers, request_body=body, normal_codes=[201])
|
||||
|
||||
def DeletePollAnswer(Authorization: str, poll_id: str) -> dict:
|
||||
"""删除投票回答"""
|
||||
url = f"{DOMAIN}/polls/{poll_id}/answer"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('DELETE', url, headers, normal_codes=[204])
|
||||
|
||||
def GetPollFeedback(Authorization: str, poll_id: str, offset: int = 0, take: int = 20) -> dict:
|
||||
"""获取投票反馈"""
|
||||
url = f"{DOMAIN}/polls/{poll_id}/feedback"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
params = {'offset': offset, 'take': take}
|
||||
return _make_request('GET', url, headers, params=params)
|
||||
|
||||
def GetMyPolls(Authorization: str, pub: Optional[str] = None, active: bool = False, offset: int = 0, take: int = 20) -> dict:
|
||||
"""获取我的投票"""
|
||||
url = f"{DOMAIN}/polls/me"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
params = {'offset': offset, 'take': take, 'pub': pub, 'active': active}
|
||||
return _make_request('GET', url, headers, params=params)
|
||||
|
||||
def PatchPoll(Authorization: str, poll_id: str, title: Optional[str] = None, description: Optional[str] = None, ended_at: Optional[str] = None, is_anonymous: Optional[bool] = None, questions: Optional[List[Dict[str, Any]]] = None) -> dict:
|
||||
"""修改投票"""
|
||||
body = {
|
||||
"title": title,
|
||||
"description": description,
|
||||
"ended_at": ended_at,
|
||||
"is_anonymous": is_anonymous,
|
||||
"questions": questions,
|
||||
}
|
||||
url = f"{DOMAIN}/polls/{poll_id}"
|
||||
headers = {'accept': 'application/json', 'Authorization': Authorization}
|
||||
return _make_request('PATCH', url, headers, request_body=body, normal_codes=[201])
|
Reference in New Issue
Block a user