package biz import ( "context" "time" "github.com/guxuan/hailin_service/internal/mods/rbac/dal" "github.com/guxuan/hailin_service/internal/mods/rbac/schema" "github.com/guxuan/hailin_service/pkg/cachex" "github.com/guxuan/hailin_service/pkg/errors" "github.com/guxuan/hailin_service/pkg/util" ) // Role management for RBAC type Video struct { Cache cachex.Cacher Trans *util.Trans VideoDAL *dal.Video } // Query roles from the data access object based on the provided parameters and options. func (a *Video) Query(ctx context.Context, params schema.VideoQueryParam) (*schema.VideoQueryResult, error) { params.Pagination = true result, err := a.VideoDAL.Query(ctx, params, schema.VideoQueryOptions{ QueryOptions: util.QueryOptions{ OrderFields: []util.OrderByParam{ {Field: "sequence", Direction: util.DESC}, }, }, }) if err != nil { return nil, err } return result, nil } // Get the specified role from the data access object. func (a *Video) Get(ctx context.Context, id string) (*schema.Video, error) { video, err := a.VideoDAL.Get(ctx, id) if err != nil { return nil, err } else if video == nil { return nil, errors.NotFound("", "Banner not found") } return video, nil } // Create a new role in the data access object. func (a *Video) Create(ctx context.Context, formItem *schema.VideoForm) (*schema.Video, error) { video := &schema.Video{ ID: util.NewXID(), CreatedAt: time.Now(), } if err := formItem.FillTo(video); err != nil { return nil, err } if err := a.VideoDAL.Create(ctx, video); err != nil { return nil, err } return video, nil } // Update the specified role in the data access object. func (a *Video) Update(ctx context.Context, id string, formItem *schema.VideoForm) error { video, err := a.VideoDAL.Get(ctx, id) if err != nil { return err } if err := formItem.FillTo(video); err != nil { return err } video.UpdatedAt = time.Now() if err := a.VideoDAL.Update(ctx, video); err != nil { return err } return nil } // Delete the specified role from the data access object. func (a *Video) Delete(ctx context.Context, id string) error { exists, err := a.VideoDAL.Exists(ctx, id) if err != nil { return err } else if !exists { return errors.NotFound("", "Role not found") } if err := a.VideoDAL.Delete(ctx, id); err != nil { return err } return nil }