fix: jobs

This commit is contained in:
Rogee
2025-01-16 15:59:21 +08:00
parent 2cd7f2a2b8
commit 3a8bb03cb7
12 changed files with 619 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ import (
"backend/app/requests"
"backend/database"
"backend/database/fields"
"backend/database/models/qvyun_v2/public/model"
"backend/database/models/qvyun_v2/public/table"
"backend/providers/hashids"
@@ -308,8 +309,10 @@ func (svc *Service) Update(ctx context.Context, tenantID, userID, postID int64,
attribute.Int64("user.id", userID),
attribute.Int64("post.id", postID),
)
tbl := table.Posts
post.UpdatedAt = time.Now()
tbl := table.Posts
stmt := tbl.
UPDATE(
tbl.MutableColumns.Except(
@@ -332,3 +335,84 @@ func (svc *Service) Update(ctx context.Context, tenantID, userID, postID int64,
return nil
}
// AttachAssets to post
func (svc *Service) AttachAssets(ctx context.Context, tenantID, userID, postID int64, mediaAssets []fields.MediaAsset) error {
_, span := otel.Start(ctx, "users.service.AttachAssets")
defer span.End()
span.SetAttributes(
attribute.Int64("tenant.id", tenantID),
attribute.Int64("user.id", userID),
attribute.Int64("post.id", postID),
)
post, err := svc.ForceGetPostByID(ctx, postID)
if err != nil {
return err
}
assets := append(post.Assets.Data, mediaAssets...)
post.Assets.Data = assets
tbl := table.Posts
stmt := tbl.
UPDATE(tbl.UpdatedAt, tbl.Assets).
SET(
tbl.UpdatedAt.SET(TimestampT(time.Now())),
tbl.Assets.SET(Json(post.Assets)),
).
WHERE(
tbl.ID.EQ(Int64(postID)).AND(
tbl.TenantID.EQ(Int64(tenantID)).AND(
tbl.UserID.EQ(Int64(userID)),
),
),
)
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
return err
}
return svc.Update(ctx, tenantID, userID, postID, post)
}
// UpdateMeta
func (svc *Service) UpdateMeta(ctx context.Context, tenantID, userID, postID int64, meta fields.PostMeta) error {
_, span := otel.Start(ctx, "users.service.UpdateMeta")
defer span.End()
span.SetAttributes(
attribute.Int64("tenant.id", tenantID),
attribute.Int64("user.id", userID),
attribute.Int64("post.id", postID),
)
post, err := svc.ForceGetPostByID(ctx, postID)
if err != nil {
return err
}
post.Meta = meta
tbl := table.Posts
stmt := tbl.
UPDATE(tbl.UpdatedAt, tbl.Meta).
SET(
tbl.UpdatedAt.SET(TimestampT(time.Now())),
tbl.Meta.SET(Json(post.Meta)),
).
WHERE(
tbl.ID.EQ(Int64(postID)).AND(
tbl.TenantID.EQ(Int64(tenantID)).AND(
tbl.UserID.EQ(Int64(userID)),
),
),
)
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
return err
}
return svc.Update(ctx, tenantID, userID, postID, post)
}