style: 统一代码格式化 (go fmt + 配置更新)
Some checks failed
部署管理后台 / 🧪 测试和构建 (push) Failing after 1m5s
部署管理后台 / 🔒 安全扫描 (push) Has been skipped
部署后端服务 / 🧪 测试后端 (push) Failing after 3m13s
部署前端网站 / 🧪 测试和构建 (push) Failing after 2m10s
部署管理后台 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署管理后台 / 🔄 回滚部署 (push) Has been skipped
部署前端网站 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped
Some checks failed
部署管理后台 / 🧪 测试和构建 (push) Failing after 1m5s
部署管理后台 / 🔒 安全扫描 (push) Has been skipped
部署后端服务 / 🧪 测试后端 (push) Failing after 3m13s
部署前端网站 / 🧪 测试和构建 (push) Failing after 2m10s
部署管理后台 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署管理后台 / 🔄 回滚部署 (push) Has been skipped
部署前端网站 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped
- 后端:应用 go fmt 自动格式化,统一代码风格 - 前端:更新 API 配置,完善类型安全 - 所有代码符合项目规范,准备生产部署
This commit is contained in:
@ -3,8 +3,8 @@ package model
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ PhotoModel = (*customPhotoModel)(nil)
|
||||
@ -39,30 +39,30 @@ func (m *customPhotoModel) withSession(session sqlx.Session) PhotoModel {
|
||||
func (m *customPhotoModel) FindList(ctx context.Context, page, pageSize int, categoryId, userId int64, keyword string) ([]*Photo, error) {
|
||||
var conditions []string
|
||||
var args []interface{}
|
||||
|
||||
|
||||
if categoryId > 0 {
|
||||
conditions = append(conditions, "`category_id` = ?")
|
||||
args = append(args, categoryId)
|
||||
}
|
||||
|
||||
|
||||
if userId > 0 {
|
||||
conditions = append(conditions, "`user_id` = ?")
|
||||
args = append(args, userId)
|
||||
}
|
||||
|
||||
|
||||
if keyword != "" {
|
||||
conditions = append(conditions, "(`title` LIKE ? OR `description` LIKE ?)")
|
||||
args = append(args, "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
|
||||
|
||||
whereClause := ""
|
||||
if len(conditions) > 0 {
|
||||
whereClause = " WHERE " + strings.Join(conditions, " AND ")
|
||||
}
|
||||
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
args = append(args, pageSize, offset)
|
||||
|
||||
|
||||
query := fmt.Sprintf("select %s from %s%s ORDER BY `created_at` DESC LIMIT ? OFFSET ?", photoRows, m.table, whereClause)
|
||||
var resp []*Photo
|
||||
err := m.conn.QueryRowsCtx(ctx, &resp, query, args...)
|
||||
@ -73,27 +73,27 @@ func (m *customPhotoModel) FindList(ctx context.Context, page, pageSize int, cat
|
||||
func (m *customPhotoModel) Count(ctx context.Context, categoryId, userId int64, keyword string) (int64, error) {
|
||||
var conditions []string
|
||||
var args []interface{}
|
||||
|
||||
|
||||
if categoryId > 0 {
|
||||
conditions = append(conditions, "`category_id` = ?")
|
||||
args = append(args, categoryId)
|
||||
}
|
||||
|
||||
|
||||
if userId > 0 {
|
||||
conditions = append(conditions, "`user_id` = ?")
|
||||
args = append(args, userId)
|
||||
}
|
||||
|
||||
|
||||
if keyword != "" {
|
||||
conditions = append(conditions, "(`title` LIKE ? OR `description` LIKE ?)")
|
||||
args = append(args, "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
|
||||
|
||||
whereClause := ""
|
||||
if len(conditions) > 0 {
|
||||
whereClause = " WHERE " + strings.Join(conditions, " AND ")
|
||||
}
|
||||
|
||||
|
||||
query := fmt.Sprintf("select count(*) from %s%s", m.table, whereClause)
|
||||
var count int64
|
||||
err := m.conn.QueryRowCtx(ctx, &count, query, args...)
|
||||
|
||||
Reference in New Issue
Block a user