refactor: upgrade to Go 1.26 and modernize code idioms
- Replace `interface{}` with `any` type alias across all packages
- Use built-in `min()`/`max()` for parameter clamping
- Use `slices.SortFunc`, `slices.Min`, `slices.Max` for cleaner code
- Use `strings.Cut()` for simpler string parsing in auth middleware
- Use `errors.Is()` for proper error comparison in handlers
- Update dependencies: golang.org/x/image 0.37.0 -> 0.38.0
- Add Wire code generation guidelines to ARCHITECTURE.md
- Disable Go cache in CI build workflow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"carrot_bbs/internal/dto"
|
||||
@@ -39,21 +40,21 @@ type subjectResponse struct {
|
||||
}
|
||||
|
||||
type materialResponse struct {
|
||||
ID string `json:"id"`
|
||||
SubjectID string `json:"subject_id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
FileType string `json:"file_type"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
FileURL string `json:"file_url"`
|
||||
FileName string `json:"file_name"`
|
||||
DownloadCount int `json:"download_count"`
|
||||
AuthorID string `json:"author_id,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Subject *subjectResponse `json:"subject,omitempty"`
|
||||
ID string `json:"id"`
|
||||
SubjectID string `json:"subject_id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
FileType string `json:"file_type"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
FileURL string `json:"file_url"`
|
||||
FileName string `json:"file_name"`
|
||||
DownloadCount int `json:"download_count"`
|
||||
AuthorID string `json:"author_id,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
Subject *subjectResponse `json:"subject,omitempty"`
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
@@ -170,11 +171,11 @@ func (h *MaterialHandler) ListMaterials(c *gin.Context) {
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{
|
||||
"list": result,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"has_more": int64(page*pageSize) < total,
|
||||
"list": result,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
"has_more": int64(page*pageSize) < total,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -305,7 +306,7 @@ func (h *MaterialHandler) AdminUpdateSubject(c *gin.Context) {
|
||||
func (h *MaterialHandler) AdminDeleteSubject(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := h.materialService.DeleteSubject(id); err != nil {
|
||||
if err == service.ErrSubjectHasMaterials {
|
||||
if errors.Is(err, service.ErrSubjectHasMaterials) {
|
||||
response.BadRequest(c, "学科下存在资料,无法删除")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user