forked from ebhomengo/niki
35 lines
801 B
Go
35 lines
801 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"git.gocasts.ir/ebhomengo/niki/domain/authorization/service"
|
|
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
"git.gocasts.ir/ebhomengo/niki/pkg/database/mysql"
|
|
"git.gocasts.ir/ebhomengo/niki/types"
|
|
)
|
|
|
|
type DB struct {
|
|
conn *mysql.DB
|
|
}
|
|
|
|
func New(conn *mysql.DB) *DB {
|
|
return &DB{conn: conn}
|
|
}
|
|
|
|
func (m DB) Store(ctx context.Context, req service.StoreRoleRequest) (types.ID, error) {
|
|
const op = "domain.authorization.repository.role.store"
|
|
|
|
result, err := m.conn.Conn().ExecContext(ctx, "INSERT INTO roles VALUES (`?,?`)", req.Title, req.TitleFa)
|
|
if err != nil {
|
|
return 0, richerror.New(op).WithErr(err)
|
|
}
|
|
|
|
roleID, err := result.LastInsertId()
|
|
if err != nil {
|
|
return 0, richerror.New(op).WithErr(err)
|
|
}
|
|
|
|
return types.ID(roleID), nil
|
|
}
|