Add missing gRPC functions
This commit is contained in:
@@ -2,27 +2,15 @@ package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/google/uuid"
|
||||
"github.com/santhosh-tekuri/jsonschema/v5"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type MobilityAccountsHandler struct {
|
||||
storage storage.Storage
|
||||
config *viper.Viper
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, storage storage.Storage) MobilityAccountsHandler {
|
||||
return MobilityAccountsHandler{
|
||||
storage: storage,
|
||||
config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
func (h MobilityAccountsHandler) Login(username string, password string, namespace string) (*storage.Account, error) {
|
||||
|
||||
if password == "" {
|
||||
@@ -100,6 +88,7 @@ func (h MobilityAccountsHandler) UpdateData(accountid string, datas map[string]a
|
||||
dataschemas := h.config.GetStringMap("data_schemas")
|
||||
for k, v := range datas {
|
||||
if !h.config.GetBool("allow_any_data") && dataschemas[k] == nil {
|
||||
fmt.Println("data scope not allowed")
|
||||
return nil, errors.New("data scope not allowed")
|
||||
}
|
||||
|
||||
@@ -107,16 +96,19 @@ func (h MobilityAccountsHandler) UpdateData(accountid string, datas map[string]a
|
||||
s := dataschemas[k].(map[string]string)
|
||||
sch, err := jsonschema.Compile(s["schema"])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = sch.Validate(v); err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
account.Data[k] = v
|
||||
}
|
||||
account.Data[k] = v
|
||||
}
|
||||
if err = h.storage.DB.UpdateAccount(*account); err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -132,3 +124,11 @@ func (h MobilityAccountsHandler) GetAccounts(namespaces []string) (accounts []st
|
||||
accounts, err = h.storage.DB.GetAccounts(namespaces)
|
||||
return
|
||||
}
|
||||
|
||||
func (h MobilityAccountsHandler) GetAccountsBatch(accountIds []string) (accounts []storage.Account, err error) {
|
||||
if len(accountIds) == 0 {
|
||||
return accounts, nil
|
||||
}
|
||||
accounts, err = h.storage.DB.GetAccountsByIds(accountIds)
|
||||
return
|
||||
}
|
||||
|
||||
18
handlers/handlers.go
Normal file
18
handlers/handlers.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type MobilityAccountsHandler struct {
|
||||
storage storage.Storage
|
||||
config *viper.Viper
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, storage storage.Storage) MobilityAccountsHandler {
|
||||
return MobilityAccountsHandler{
|
||||
storage: storage,
|
||||
config: cfg,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user