fe43b9bdce
- 将README从英文翻译为中文 - 添加详细的API参考文档,包括所有管理接口和枚举值说明 - 补充安装、快速开始、认证方式等使用指南 refactor(client): 优化客户端代码结构并添加详细注释 - 为所有API方法添加中文注释和使用说明 - 改进Client结构体和Option配置的设计 - 统一错误处理和响应结构的文档说明
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package emailcli
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// ListAuditPending 分页查询待人工审核的邮件。
|
|
//
|
|
// GET /api/v1/audits/pending?page=&page_size=&user_id=&account_id=&keyword= ServiceAuth
|
|
func (c *Client) ListAuditPending(ctx context.Context, q AuditPendingQuery) (*PaginationResult[MailLog], error) {
|
|
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
|
"user_id": q.UserID,
|
|
"account_id": q.AccountID,
|
|
"keyword": q.Keyword,
|
|
})
|
|
return get[*PaginationResult[MailLog]](c, ctx, "/api/v1/audits/pending", buildQuery(params))
|
|
}
|
|
|
|
// GetAuditPendingDetail 获取待审核邮件的完整详情(含正文)。
|
|
//
|
|
// GET /api/v1/audits/pending/{id} ServiceAuth
|
|
func (c *Client) GetAuditPendingDetail(ctx context.Context, id uint) (*MailLogDetail, error) {
|
|
return get[*MailLogDetail](c, ctx, fmt.Sprintf("/api/v1/audits/pending/%d", id), nil)
|
|
}
|
|
|
|
// ApproveAudit 审核通过单封邮件,通过后邮件立即入队发送。
|
|
//
|
|
// POST /api/v1/audits/{id}/approve ServiceAuth
|
|
func (c *Client) ApproveAudit(ctx context.Context, id uint) error {
|
|
_, err := post[any](c, ctx, fmt.Sprintf("/api/v1/audits/%d/approve", id), nil)
|
|
return err
|
|
}
|
|
|
|
// RejectAudit 审核驳回单封邮件,被驳回的邮件会退还配额。
|
|
//
|
|
// POST /api/v1/audits/{id}/reject ServiceAuth
|
|
func (c *Client) RejectAudit(ctx context.Context, id uint, req AuditRejectReq) error {
|
|
_, err := post[any](c, ctx, fmt.Sprintf("/api/v1/audits/%d/reject", id), req)
|
|
return err
|
|
}
|
|
|
|
// BatchApproveAudit 批量通过。MailLogIDs 至少 1 个。
|
|
//
|
|
// POST /api/v1/audits/batch/approve ServiceAuth
|
|
func (c *Client) BatchApproveAudit(ctx context.Context, req BatchAuditApproveReq) error {
|
|
_, err := post[any](c, ctx, "/api/v1/audits/batch/approve", req)
|
|
return err
|
|
}
|
|
|
|
// BatchRejectAudit 批量驳回。建议填写 RejectReason 方便溯源。
|
|
//
|
|
// POST /api/v1/audits/batch/reject ServiceAuth
|
|
func (c *Client) BatchRejectAudit(ctx context.Context, req BatchAuditRejectReq) error {
|
|
_, err := post[any](c, ctx, "/api/v1/audits/batch/reject", req)
|
|
return err
|
|
}
|
|
|
|
// ListAuditLogs 分页查询审核历史记录。
|
|
//
|
|
// GET /api/v1/audits/logs?page=&page_size=&audit_type=&action=&user_id=&start_date=&end_date= ServiceAuth
|
|
func (c *Client) ListAuditLogs(ctx context.Context, q AuditLogQuery) (*PaginationResult[MailAudit], error) {
|
|
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
|
"audit_type": q.AuditType,
|
|
"action": q.Action,
|
|
"user_id": q.UserID,
|
|
"start_date": q.StartDate,
|
|
"end_date": q.EndDate,
|
|
})
|
|
return get[*PaginationResult[MailAudit]](c, ctx, "/api/v1/audits/logs", buildQuery(params))
|
|
}
|
|
|
|
// GetAuditStats 审核概览统计:待审核数量、今日自动/人工通过/驳回分布。
|
|
//
|
|
// GET /api/v1/audits/stats ServiceAuth
|
|
func (c *Client) GetAuditStats(ctx context.Context) (*AuditStats, error) {
|
|
return get[*AuditStats](c, ctx, "/api/v1/audits/stats", nil)
|
|
}
|