feat: init sms-server-cli SDK
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+142
@@ -0,0 +1,142 @@
|
||||
package smscli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 用户接口
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
// CreateTemplate 创建短信模板。
|
||||
// POST /api/sms/template
|
||||
func (c *Client) CreateTemplate(ctx context.Context, req CreateTemplateReq) (SmsTemplate, error) {
|
||||
return post[SmsTemplate](c, ctx, "/api/sms/template", req)
|
||||
}
|
||||
|
||||
// ListTemplates 获取当前用户的模板列表(分页)。
|
||||
// GET /api/sms/template/list
|
||||
func (c *Client) ListTemplates(ctx context.Context, q PaginationQuery) (PaginationResult[SmsTemplate], error) {
|
||||
params := paginationParams(q)
|
||||
return get[PaginationResult[SmsTemplate]](c, ctx, "/api/sms/template/list", buildQuery(params))
|
||||
}
|
||||
|
||||
// GetTemplate 获取指定模板详情。
|
||||
// GET /api/sms/template/:id
|
||||
func (c *Client) GetTemplate(ctx context.Context, id uint) (SmsTemplate, error) {
|
||||
return get[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/template/%d", id), nil)
|
||||
}
|
||||
|
||||
// UpdateTemplate 更新指定模板。
|
||||
// PUT /api/sms/template/:id
|
||||
func (c *Client) UpdateTemplate(ctx context.Context, id uint, req UpdateTemplateReq) (SmsTemplate, error) {
|
||||
return put[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/template/%d", id), req)
|
||||
}
|
||||
|
||||
// DeleteTemplate 删除指定模板。
|
||||
// DELETE /api/sms/template/:id
|
||||
func (c *Client) DeleteTemplate(ctx context.Context, id uint) error {
|
||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/template/%d", id))
|
||||
return err
|
||||
}
|
||||
|
||||
// SubmitTemplate 提交模板进入审核。
|
||||
// POST /api/sms/template/:id/submit
|
||||
func (c *Client) SubmitTemplate(ctx context.Context, id uint) error {
|
||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/template/%d/submit", id), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// ListRecommendedTemplates 获取推荐模板列表(分页)。
|
||||
// GET /api/sms/template/recommended
|
||||
func (c *Client) ListRecommendedTemplates(ctx context.Context, q PaginationQuery) (PaginationResult[SmsRecommendedTemplate], error) {
|
||||
params := paginationParams(q)
|
||||
return get[PaginationResult[SmsRecommendedTemplate]](c, ctx, "/api/sms/template/recommended", buildQuery(params))
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────
|
||||
// 管理员接口
|
||||
// ──────────────────────────────────────────────
|
||||
|
||||
// AdminListTemplates 管理员获取模板列表,可按 UserID、Status 筛选。
|
||||
// GET /api/sms/admin/template/list
|
||||
func (c *Client) AdminListTemplates(ctx context.Context, q TemplateListQuery) (PaginationResult[SmsTemplate], error) {
|
||||
params := mergeParams(paginationParams(q.PaginationQuery), map[string]interface{}{
|
||||
"user_id": q.UserID,
|
||||
"status": q.Status,
|
||||
})
|
||||
return get[PaginationResult[SmsTemplate]](c, ctx, "/api/sms/admin/template/list", buildQuery(params))
|
||||
}
|
||||
|
||||
// AdminListRecommendedTemplates 管理员获取推荐模板列表(分页)。
|
||||
// GET /api/sms/admin/template/recommended
|
||||
func (c *Client) AdminListRecommendedTemplates(ctx context.Context, q PaginationQuery) (PaginationResult[SmsRecommendedTemplate], error) {
|
||||
params := paginationParams(q)
|
||||
return get[PaginationResult[SmsRecommendedTemplate]](c, ctx, "/api/sms/admin/template/recommended", buildQuery(params))
|
||||
}
|
||||
|
||||
// AdminGetTemplate 管理员获取指定模板详情。
|
||||
// GET /api/sms/admin/template/:id
|
||||
func (c *Client) AdminGetTemplate(ctx context.Context, id uint) (SmsTemplate, error) {
|
||||
return get[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d", id), nil)
|
||||
}
|
||||
|
||||
// AdminCreateTemplate 管理员创建模板(可指定 UserID)。
|
||||
// POST /api/sms/admin/template
|
||||
func (c *Client) AdminCreateTemplate(ctx context.Context, req AdminCreateTemplateReq) (SmsTemplate, error) {
|
||||
return post[SmsTemplate](c, ctx, "/api/sms/admin/template", req)
|
||||
}
|
||||
|
||||
// AdminUpdateTemplate 管理员更新指定模板。
|
||||
// PUT /api/sms/admin/template/:id
|
||||
func (c *Client) AdminUpdateTemplate(ctx context.Context, id uint, req AdminUpdateTemplateReq) (SmsTemplate, error) {
|
||||
return put[SmsTemplate](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d", id), req)
|
||||
}
|
||||
|
||||
// AdminDeleteTemplate 管理员删除指定模板。
|
||||
// DELETE /api/sms/admin/template/:id
|
||||
func (c *Client) AdminDeleteTemplate(ctx context.Context, id uint) error {
|
||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d", id))
|
||||
return err
|
||||
}
|
||||
|
||||
// AdminSubmitTemplate 管理员提交模板进入审核。
|
||||
// POST /api/sms/admin/template/:id/submit
|
||||
func (c *Client) AdminSubmitTemplate(ctx context.Context, id uint) error {
|
||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d/submit", id), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// ApproveTemplate 管理员审核通过模板。
|
||||
// POST /api/sms/admin/template/:id/approve
|
||||
func (c *Client) ApproveTemplate(ctx context.Context, id uint) error {
|
||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d/approve", id), nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// RejectTemplate 管理员驳回模板,需提供驳回原因。
|
||||
// POST /api/sms/admin/template/:id/reject
|
||||
func (c *Client) RejectTemplate(ctx context.Context, id uint, req RejectReq) error {
|
||||
_, err := post[any](c, ctx, fmt.Sprintf("/api/sms/admin/template/%d/reject", id), req)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateRecommendedTemplate 管理员创建推荐模板。
|
||||
// POST /api/sms/admin/template/recommended
|
||||
func (c *Client) CreateRecommendedTemplate(ctx context.Context, req CreateRecommendedTemplateReq) (SmsRecommendedTemplate, error) {
|
||||
return post[SmsRecommendedTemplate](c, ctx, "/api/sms/admin/template/recommended", req)
|
||||
}
|
||||
|
||||
// UpdateRecommendedTemplate 管理员更新推荐模板。
|
||||
// PUT /api/sms/admin/template/recommended/:id
|
||||
func (c *Client) UpdateRecommendedTemplate(ctx context.Context, id uint, req UpdateRecommendedTemplateReq) (SmsRecommendedTemplate, error) {
|
||||
return put[SmsRecommendedTemplate](c, ctx, fmt.Sprintf("/api/sms/admin/template/recommended/%d", id), req)
|
||||
}
|
||||
|
||||
// DeleteRecommendedTemplate 管理员删除推荐模板。
|
||||
// DELETE /api/sms/admin/template/recommended/:id
|
||||
func (c *Client) DeleteRecommendedTemplate(ctx context.Context, id uint) error {
|
||||
_, err := del[any](c, ctx, fmt.Sprintf("/api/sms/admin/template/recommended/%d", id))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user