增加了api功能:
创建API文档页面 :新建了 status/templates/status/api_docs.html 模板文件,包含:
- API认证方式说明
- 所有API端点的详细说明(POST /api/checkin/、GET /api/services/、GET /api/services/{id}/history/、GET /api/status-summary/)
- 每个端点的请求体和响应体示例
- 状态码和检测类型的说明
This commit is contained in:
@@ -43,6 +43,27 @@ class Service(models.Model):
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.host})"
|
||||
|
||||
def get_latest_status(self):
|
||||
"""获取最新状态"""
|
||||
latest_record = self.records.first()
|
||||
if latest_record:
|
||||
return latest_record.status
|
||||
return 'UNKNOWN'
|
||||
|
||||
def get_latest_check_time(self):
|
||||
"""获取最新检测时间"""
|
||||
latest_record = self.records.first()
|
||||
if latest_record:
|
||||
return latest_record.checked_at
|
||||
return None
|
||||
|
||||
def get_latest_response_time(self):
|
||||
"""获取最新响应时间"""
|
||||
latest_record = self.records.first()
|
||||
if latest_record:
|
||||
return latest_record.response_time
|
||||
return None
|
||||
|
||||
class Meta:
|
||||
verbose_name = '服务'
|
||||
verbose_name_plural = '服务'
|
||||
|
||||
Reference in New Issue
Block a user