初始化项目

This commit is contained in:
lianghuanjie
2024-12-05 20:51:35 +08:00
commit e2ba6924b8
30 changed files with 1560 additions and 0 deletions

45
internal/model/nh_task_model.go Executable file
View File

@@ -0,0 +1,45 @@
package model
import (
"context"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhTaskModel = (*customNhTaskModel)(nil)
type (
// NhTaskModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhTaskModel.
NhTaskModel interface {
nhTaskModel
withSession(session sqlx.Session) NhTaskModel
FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error)
}
customNhTaskModel struct {
*defaultNhTaskModel
}
)
func (m *customNhTaskModel) FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error) {
query := fmt.Sprintf("select %s from %s where community_id = ?", nhTaskRows, m.table)
var tasks []*NhTask
err := m.conn.QueryRowsCtx(ctx, &tasks, query, communityId)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return nil, err
}
return tasks, nil
}
// NewNhTaskModel returns a model for the database table.
func NewNhTaskModel(conn sqlx.SqlConn) NhTaskModel {
return &customNhTaskModel{
defaultNhTaskModel: newNhTaskModel(conn),
}
}
func (m *customNhTaskModel) withSession(session sqlx.Session) NhTaskModel {
return NewNhTaskModel(sqlx.NewSqlConnFromSession(session))
}