fix: issues
This commit is contained in:
@@ -245,6 +245,7 @@ func (svc *Service) Create(ctx context.Context, tenant *model.Tenants, user *mod
|
||||
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -268,6 +269,35 @@ func (svc *Service) GetPostByHash(ctx context.Context, tenantID int64, hash stri
|
||||
return svc.GetPostByID(ctx, postId)
|
||||
}
|
||||
|
||||
// ForceDelete
|
||||
func (svc *Service) ForceDelete(ctx context.Context, tenantID, userID, postID int64) error {
|
||||
_, span := otel.Start(ctx, "users.service.ForceDelete")
|
||||
defer span.End()
|
||||
span.SetAttributes(
|
||||
attribute.Int64("tenant.id", tenantID),
|
||||
attribute.Int64("user.id", userID),
|
||||
attribute.Int64("post.id", postID),
|
||||
)
|
||||
tbl := table.Posts
|
||||
|
||||
stmt := tbl.
|
||||
DELETE().
|
||||
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 {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete
|
||||
func (svc *Service) Delete(ctx context.Context, tenantID, userID, postID int64) error {
|
||||
_, span := otel.Start(ctx, "users.service.Delete")
|
||||
@@ -294,6 +324,7 @@ func (svc *Service) Delete(ctx context.Context, tenantID, userID, postID int64)
|
||||
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -330,6 +361,7 @@ func (svc *Service) Update(ctx context.Context, tenantID, userID, postID int64,
|
||||
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -348,6 +380,7 @@ func (svc *Service) AttachAssets(ctx context.Context, tenantID, userID, postID i
|
||||
|
||||
post, err := svc.ForceGetPostByID(ctx, postID)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -371,6 +404,7 @@ func (svc *Service) AttachAssets(ctx context.Context, tenantID, userID, postID i
|
||||
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -389,6 +423,7 @@ func (svc *Service) UpdateMeta(ctx context.Context, tenantID, userID, postID int
|
||||
|
||||
post, err := svc.ForceGetPostByID(ctx, postID)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -411,6 +446,91 @@ func (svc *Service) UpdateMeta(ctx context.Context, tenantID, userID, postID int
|
||||
span.SetAttributes(semconv.DBStatementKey.String(stmt.DebugSql()))
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return svc.Update(ctx, tenantID, userID, postID, post)
|
||||
}
|
||||
|
||||
// UpdateStatus
|
||||
func (svc *Service) UpdateStatus(ctx context.Context, tenantID, userID, postID int64, status fields.PostStatus) error {
|
||||
_, span := otel.Start(ctx, "users.service.UpdateStatus")
|
||||
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 {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
post.Status = status
|
||||
|
||||
tbl := table.Posts
|
||||
stmt := tbl.
|
||||
UPDATE(tbl.UpdatedAt, tbl.Status).
|
||||
SET(
|
||||
tbl.UpdatedAt.SET(TimestampT(time.Now())),
|
||||
tbl.Status.SET(Int16(int16(status))),
|
||||
).
|
||||
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 {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return svc.Update(ctx, tenantID, userID, postID, post)
|
||||
}
|
||||
|
||||
// UpdateStage
|
||||
func (svc *Service) UpdateStage(ctx context.Context, tenantID, userID, postID int64, stage fields.PostStage) error {
|
||||
_, span := otel.Start(ctx, "users.service.UpdateStage")
|
||||
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 {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
post.Stage = stage
|
||||
|
||||
tbl := table.Posts
|
||||
stmt := tbl.
|
||||
UPDATE(tbl.UpdatedAt, tbl.Stage).
|
||||
SET(
|
||||
tbl.UpdatedAt.SET(TimestampT(time.Now())),
|
||||
tbl.Stage.SET(Int16(int16(stage))),
|
||||
).
|
||||
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 {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user