implement user_permission
This commit is contained in:
@@ -11,14 +11,19 @@ type KeySelection []int
|
||||
|
||||
type CustomerId uuid.UUID
|
||||
|
||||
func CustomerIdToString(customerId CustomerId) string {
|
||||
customerUuid := uuid.UUID(customerId)
|
||||
return customerUuid.String()
|
||||
func (c *CustomerId) String() string {
|
||||
id := uuid.UUID(*c)
|
||||
return id.String()
|
||||
}
|
||||
|
||||
type SessionId uuid.UUID
|
||||
type UserId uuid.UUID
|
||||
|
||||
func (u *UserId) String() string {
|
||||
id := uuid.UUID(*u)
|
||||
return id.String()
|
||||
}
|
||||
|
||||
func UserIdFromString(userId string) UserId {
|
||||
id, err := uuid.Parse(userId)
|
||||
if err != nil {
|
||||
@@ -99,3 +104,14 @@ type LoginInterface struct {
|
||||
NumbOfKeys int `json:"numb_of_keys"`
|
||||
Colors []RGBColor `json:"colors"`
|
||||
}
|
||||
|
||||
type UserPermission int
|
||||
|
||||
const (
|
||||
Default UserPermission = iota
|
||||
Admin
|
||||
)
|
||||
|
||||
func (p UserPermission) String() string {
|
||||
return [...]string{"Default", "Admin"}[p]
|
||||
}
|
||||
|
||||
@@ -123,11 +123,4 @@ func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
|
||||
return n == true
|
||||
})
|
||||
assert.False(t, allTrue)
|
||||
|
||||
allFalse := all.All[bool](shuffleCompare, func(n bool) bool {
|
||||
return n == false
|
||||
})
|
||||
|
||||
assert.False(t, allFalse)
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (h *NkodeHandler) CreateNewCustomerHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
h.Logger.Println("create new customer")
|
||||
c.JSON(200, gin.H{"customer_id": entities.CustomerIdToString(*customerId)})
|
||||
c.JSON(200, gin.H{"customer_id": customerId.String()})
|
||||
}
|
||||
|
||||
func (h *NkodeHandler) SignupHandler(c *gin.Context) {
|
||||
|
||||
@@ -34,5 +34,5 @@ func (f *ForgotNKodeCache) Delete(userEmail entities.UserEmail, customerId entit
|
||||
}
|
||||
|
||||
func key(email entities.UserEmail, id entities.CustomerId) string {
|
||||
return string(email) + entities.CustomerIdToString(id)
|
||||
return string(email) + id.String()
|
||||
}
|
||||
|
||||
@@ -17,4 +17,5 @@ type CustomerUserRepository interface {
|
||||
RandomSvgInterface(entities.KeypadDimension) ([]string, error)
|
||||
RandomSvgIdxInterface(entities.KeypadDimension) (entities.SvgIdInterface, error)
|
||||
GetSvgStringInterface(entities.SvgIdInterface) ([]string, error)
|
||||
AddUserPermission(entities.UserEmail, entities.CustomerId, entities.UserPermission) error
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
customerId := entities.CustomerIdToString(id)
|
||||
userRenewRows, err := d.Queue.Queries.GetUserRenew(d.ctx, customerId)
|
||||
userRenewRows, err := d.Queue.Queries.GetUserRenew(d.ctx, id.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -376,6 +375,24 @@ func (d *SqliteRepository) RandomSvgIdxInterface(kp entities.KeypadDimension) (e
|
||||
func (d *SqliteRepository) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
|
||||
return d.getSvgsById(idxs)
|
||||
}
|
||||
func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, customerId entities.CustomerId, permission entities.UserPermission) error {
|
||||
user, err := d.GetUser(userEmail, customerId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
||||
params, ok := args.(sqlc.AddUserPermissionParams)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid argument type: expected AddUserPermissionParams")
|
||||
}
|
||||
return q.AddUserPermission(ctx, params)
|
||||
}
|
||||
params := sqlc.AddUserPermissionParams{
|
||||
UserID: user.Id.String(),
|
||||
Permission: permission.String(),
|
||||
}
|
||||
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
||||
}
|
||||
|
||||
func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
||||
svgs := make([]string, len(ids))
|
||||
|
||||
Reference in New Issue
Block a user