feat: update page

This commit is contained in:
yanghao05
2025-04-09 21:03:23 +08:00
parent 2346983d67
commit 1f27611dc7
7 changed files with 203 additions and 105 deletions

View File

@@ -6,7 +6,6 @@ import (
"time"
"quyun/app/requests"
"quyun/database/fields"
"quyun/database/schemas/public/model"
"quyun/database/schemas/public/table"
@@ -29,9 +28,7 @@ func (m *postsModel) Prepare() error {
func (m *postsModel) BuildConditionWithKey(key *string) BoolExpression {
tbl := table.Posts
cond := tbl.DeletedAt.IS_NULL().AND(
tbl.Status.EQ(Int32(int32(fields.PostStatusPublished))),
)
cond := tbl.DeletedAt.IS_NULL()
if key == nil || *key == "" {
return cond
@@ -58,8 +55,6 @@ func (m *postsModel) GetByID(ctx context.Context, id int64) (*model.Posts, error
WHERE(
tbl.ID.EQ(Int64(id)).AND(
tbl.DeletedAt.IS_NULL(),
).AND(
tbl.Status.EQ(Int32(int32(fields.PostStatusPublished))),
),
)
m.log.Infof("sql: %s", stmt.DebugSql())
@@ -211,3 +206,21 @@ func (m *postsModel) Buy(ctx context.Context, userId, postId int64) error {
}
return nil
}
// DeleteByID soft delete item
func (m *postsModel) DeleteByID(ctx context.Context, id int64) error {
tbl := table.Posts
stmt := tbl.
UPDATE(tbl.DeletedAt).
SET(TimestampT(time.Now())).
WHERE(
tbl.ID.EQ(Int64(id)),
)
m.log.Infof("sql: %s", stmt.DebugSql())
if _, err := stmt.ExecContext(ctx, db); err != nil {
m.log.Errorf("error deleting post: %v", err)
return err
}
return nil
}