refactor(server): decouple services and improve architecture
- Introduce interfaces for all major services (JWT, PostAI, Comment, Message, Notification, QRCodeLogin, Upload, Vote, etc.) to support dependency inversion. - Move query parameters from `internal/dto` to a new `internal/query` package to separate request payloads from data transfer objects. - Refactor `internal/router` to use embedded `RouterDeps` for cleaner dependency management. - Decouple handlers from repositories by injecting services instead of direct repository access, ensuring proper layering. - Improve database initialization by moving it from `internal/model` to `internal/database`. - Optimize message decryption by implementing a more efficient `BatchDecrypt` method in `MessageEncryptor` using a worker pool. - Enhance error handling and security by implementing fail-fast checks for encryption key length during startup. - Clean up unused code, including the `avatar` package and several unused DTOs.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package dto
|
||||
package dto
|
||||
|
||||
import (
|
||||
"with_you/internal/model"
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
// CreateReportRequest 创建举报请求
|
||||
type CreateReportRequest struct {
|
||||
TargetType string `json:"target_type" binding:"required,oneof=post comment message"`
|
||||
TargetID string `json:"target_id" binding:"required"`
|
||||
Reason string `json:"reason" binding:"required,oneof=spam inappropriate harassment misinformation other"`
|
||||
Description string `json:"description" binding:"max=500"`
|
||||
TargetType string `json:"target_type" binding:"required,oneof=post comment message"`
|
||||
TargetID string `json:"target_id" binding:"required"`
|
||||
Reason string `json:"reason" binding:"required,oneof=spam inappropriate harassment misinformation other"`
|
||||
Description string `json:"description" binding:"max=500"`
|
||||
}
|
||||
|
||||
// ReportResponse 举报响应
|
||||
@@ -26,89 +26,77 @@ type ReportResponse struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// AdminReportListQuery 管理端举报列表查询参数
|
||||
type AdminReportListQuery struct {
|
||||
Page int `form:"page" binding:"min=1"`
|
||||
PageSize int `form:"page_size" binding:"min=1,max=100"`
|
||||
TargetType string `form:"target_type" binding:"omitempty,oneof=post comment message"`
|
||||
Status string `form:"status" binding:"omitempty,oneof=pending processing resolved rejected"`
|
||||
StartDate string `form:"start_date" binding:"omitempty"`
|
||||
EndDate string `form:"end_date" binding:"omitempty"`
|
||||
Keyword string `form:"keyword" binding:"omitempty"`
|
||||
}
|
||||
|
||||
// AdminReportListResponse 管理端举报列表响应
|
||||
type AdminReportListResponse struct {
|
||||
ID string `json:"id"`
|
||||
ReporterID string `json:"reporter_id"`
|
||||
ID string `json:"id"`
|
||||
ReporterID string `json:"reporter_id"`
|
||||
Reporter *UserResponse `json:"reporter,omitempty"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID string `json:"target_id"`
|
||||
Reason string `json:"reason"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Status string `json:"status"`
|
||||
HandledBy *string `json:"handled_by,omitempty"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID string `json:"target_id"`
|
||||
Reason string `json:"reason"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Status string `json:"status"`
|
||||
HandledBy *string `json:"handled_by,omitempty"`
|
||||
Handler *UserResponse `json:"handler,omitempty"`
|
||||
HandledAt *string `json:"handled_at,omitempty"`
|
||||
Result *string `json:"result,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
HandledAt *string `json:"handled_at,omitempty"`
|
||||
Result *string `json:"result,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// AdminReportDetailResponse 管理端举报详情响应
|
||||
type AdminReportDetailResponse struct {
|
||||
ID string `json:"id"`
|
||||
ReporterID string `json:"reporter_id"`
|
||||
ID string `json:"id"`
|
||||
ReporterID string `json:"reporter_id"`
|
||||
Reporter *UserResponse `json:"reporter"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID string `json:"target_id"`
|
||||
Reason string `json:"reason"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Status string `json:"status"`
|
||||
HandledBy *string `json:"handled_by,omitempty"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID string `json:"target_id"`
|
||||
Reason string `json:"reason"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Status string `json:"status"`
|
||||
HandledBy *string `json:"handled_by,omitempty"`
|
||||
Handler *UserResponse `json:"handler,omitempty"`
|
||||
HandledAt *string `json:"handled_at,omitempty"`
|
||||
Result *string `json:"result,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
||||
HandledAt *string `json:"handled_at,omitempty"`
|
||||
Result *string `json:"result,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
||||
// 被举报内容详情
|
||||
TargetContent *ReportTargetContent `json:"target_content,omitempty"`
|
||||
}
|
||||
|
||||
// ReportTargetContent 被举报内容详情
|
||||
type ReportTargetContent struct {
|
||||
Type string `json:"type"` // post, comment, message
|
||||
ID string `json:"id"`
|
||||
Author *UserResponse `json:"author,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Title string `json:"title,omitempty"` // 帖子标题
|
||||
Images []string `json:"images,omitempty"` // 图片列表
|
||||
Status string `json:"status,omitempty"` // 内容状态
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
Type string `json:"type"` // post, comment, message
|
||||
ID string `json:"id"`
|
||||
Author *UserResponse `json:"author,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Title string `json:"title,omitempty"` // 帖子标题
|
||||
Images []string `json:"images,omitempty"` // 图片列表
|
||||
Status string `json:"status,omitempty"` // 内容状态
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
}
|
||||
|
||||
// HandleReportRequest 处理举报请求
|
||||
type HandleReportRequest struct {
|
||||
Action string `json:"action" binding:"required,oneof=approve reject"` // approve: 确认违规, reject: 驳回
|
||||
Result string `json:"result" binding:"max=500"` // 处理结果说明
|
||||
Result string `json:"result" binding:"max=500"` // 处理结果说明
|
||||
}
|
||||
|
||||
// BatchHandleReportRequest 批量处理举报请求
|
||||
type BatchHandleReportRequest struct {
|
||||
IDs []string `json:"ids" binding:"required,min=1,max=100"`
|
||||
Action string `json:"action" binding:"required,oneof=approve reject"`
|
||||
Result string `json:"result" binding:"max=500"`
|
||||
Result string `json:"result" binding:"max=500"`
|
||||
}
|
||||
|
||||
// AdminBatchHandleResponse 批量处理响应
|
||||
type AdminBatchHandleResponse struct {
|
||||
SuccessCount int `json:"success_count"`
|
||||
FailedCount int `json:"failed_count"`
|
||||
FailedIDs []string `json:"failed_ids,omitempty"`
|
||||
FailedCount int `json:"failed_count"`
|
||||
FailedIDs []string `json:"failed_ids,omitempty"`
|
||||
}
|
||||
|
||||
// ==================== 转换函数 ====================
|
||||
|
||||
|
||||
// ConvertReportToResponse 将 Report 模型转换为响应
|
||||
func ConvertReportToResponse(report *model.Report) *ReportResponse {
|
||||
return &ReportResponse{
|
||||
@@ -180,4 +168,4 @@ func ConvertReportToAdminDetailResponse(report *model.Report, reporter *model.Us
|
||||
resp.HandledAt = &handledAt
|
||||
}
|
||||
return resp
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user