64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
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/util"
|
|
)
|
|
|
|
// Role management for RBAC
|
|
type WebSite struct {
|
|
Cache cachex.Cacher
|
|
Trans *util.Trans
|
|
WebSiteDAL *dal.WebSite
|
|
}
|
|
|
|
// Query roles from the data access object based on the provided parameters and options.
|
|
func (a *WebSite) Query(ctx context.Context) (*schema.WebSite, error) {
|
|
result, err := a.WebSiteDAL.Query(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// Create a new role in the data access object.
|
|
func (a *WebSite) Create(ctx context.Context, formItem *schema.WebSiteForm) (*schema.WebSite, error) {
|
|
|
|
item := &schema.WebSite{
|
|
ID: util.NewXID(),
|
|
CreatedAt: time.Now(),
|
|
}
|
|
if err := formItem.FillTo(item); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := a.WebSiteDAL.Create(ctx, item); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return item, nil
|
|
}
|
|
|
|
// Update the specified role in the data access object.
|
|
func (a *WebSite) Update(ctx context.Context, id string, formItem *schema.WebSiteForm) error {
|
|
article, err := a.WebSiteDAL.Get(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := formItem.FillTo(article); err != nil {
|
|
return err
|
|
}
|
|
article.UpdatedAt = time.Now()
|
|
|
|
if err := a.WebSiteDAL.Update(ctx, article); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|