refactor nkode-core

This commit is contained in:
2025-01-21 01:19:27 -06:00
parent 3ed12cee68
commit c5e95239b5
46 changed files with 318 additions and 434 deletions

View File

@@ -1,10 +1,7 @@
package models
import (
"fmt"
"github.com/google/uuid"
"net/mail"
"strings"
"go-nkode/pkg/nkode-core/entities"
)
type SetNKodeResp struct {
@@ -12,8 +9,8 @@ type SetNKodeResp struct {
}
type RandomSvgInterfaceResp struct {
Svgs []string `json:"svgs"`
Colors []RGBColor `json:"colors"`
Svgs []string `json:"svgs"`
Colors []entities.RGBColor `json:"colors"`
}
type RefreshTokenResp struct {
@@ -21,7 +18,7 @@ type RefreshTokenResp struct {
}
type NewCustomerPost struct {
NKodePolicy NKodePolicy `json:"nkode_policy"`
NKodePolicy entities.NKodePolicy `json:"nkode_policy"`
}
type GenerateSignupRestInterfacePost struct {
@@ -39,9 +36,9 @@ type SetNKodePost struct {
}
type ConfirmNKodePost struct {
CustomerId string `json:"customer_id"`
KeySelection KeySelection `json:"key_selection"`
SessionId string `json:"session_id"`
CustomerId string `json:"customer_id"`
KeySelection entities.KeySelection `json:"key_selection"`
SessionId string `json:"session_id"`
}
type GetLoginInterfacePost struct {
@@ -50,20 +47,15 @@ type GetLoginInterfacePost struct {
}
type LoginPost struct {
CustomerId string `json:"customer_id"`
UserEmail string `json:"email"`
KeySelection KeySelection `json:"key_selection"`
CustomerId string `json:"customer_id"`
UserEmail string `json:"email"`
KeySelection entities.KeySelection `json:"key_selection"`
}
type RenewAttributesPost struct {
CustomerId string `json:"customer_id"`
}
type RefreshTokenPost struct {
UserEmail string `json:"email"`
CustomerId string `json:"customer_id"`
}
type ResetNKodePost struct {
UserEmail string `json:"email"`
CustomerId string `json:"customer_id"`
@@ -72,96 +64,3 @@ type ResetNKodePost struct {
type CreateNewCustomerResp struct {
CustomerId string `json:"customer_id"`
}
type GenerateSignupResetInterfaceResp struct {
SessionId string `json:"session_id"`
UserIdxInterface IdxInterface `json:"user_interface"`
SvgInterface []string `json:"svg_interface"`
Colors []RGBColor `json:"colors"`
}
type GetLoginInterfaceResp struct {
UserIdxInterface IdxInterface `json:"user_interface"`
SvgInterface []string `json:"svg_interface"`
AttrsPerKey int `json:"attrs_per_key"`
NumbOfKeys int `json:"numb_of_keys"`
Colors []RGBColor `json:"colors"`
}
type KeySelection []int
type CustomerId uuid.UUID
func CustomerIdToString(customerId CustomerId) string {
customerUuid := uuid.UUID(customerId)
return customerUuid.String()
}
type SessionId uuid.UUID
type UserId uuid.UUID
func UserIdFromString(userId string) UserId {
id, err := uuid.Parse(userId)
if err != nil {
fmt.Errorf("unable to parse user id %+v", err)
}
return UserId(id)
}
func (s *SessionId) String() string {
id := uuid.UUID(*s)
return id.String()
}
type UserEmail string
func ParseEmail(email string) (UserEmail, error) {
_, err := mail.ParseAddress(email)
if err != nil {
return "", err
}
return UserEmail(strings.ToLower(email)), err
}
type IdxInterface []int
type SvgIdInterface []int
func SessionIdFromString(sessionId string) (SessionId, error) {
id, err := uuid.Parse(sessionId)
if err != nil {
return SessionId{}, err
}
return SessionId(id), nil
}
type EncipheredNKode struct {
Code string
Mask string
}
type RGBColor struct {
Red int `json:"red"`
Green int `json:"green"`
Blue int `json:"blue"`
}
var SetColors = []RGBColor{
{0, 0, 0}, // Black
{255, 0, 0}, // Red
{0, 128, 0}, // Dark Green
{0, 0, 255}, // Blue
{244, 200, 60}, // Yellow
{255, 0, 255}, // Magenta
{0, 200, 200}, // Cyan
{127, 0, 127}, // Purple
{232, 92, 13}, // Orange
{0, 127, 127}, // Teal
{127, 127, 0}, // Olive
{127, 0, 0}, // Dark Red
{128, 128, 128}, // Gray
{228, 102, 102}, // Dark Purple
{185, 17, 240}, // Salmon
{16, 200, 100}, // Green
}