fix: convert customer, session ids to uuid for json un/marshal in both post and resp

This commit is contained in:
2024-09-13 18:55:33 -05:00
parent b29612924a
commit b7a4a5cf4c
4 changed files with 82 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"encoding/json"
"errors"
"github.com/google/uuid"
"go-nkode/core/api"
"log"
"net/http"
@@ -56,7 +57,7 @@ func (h *NKodeHandler) CreateNewCustomerHandler(w http.ResponseWriter, r *http.R
return
}
respBody := CreateNewCustomerResp{
CustomerId: *customerId,
CustomerId: uuid.UUID(*customerId).String(),
}
respBytes, err := json.Marshal(respBody)
if err != nil {
@@ -98,7 +99,13 @@ func (h *NKodeHandler) GenerateSignupInterfaceHandler(w http.ResponseWriter, r *
log.Println(err)
return
}
resp, err := h.Api.GenerateSignupInterface(signupPost.Username, CustomerId(signupPost.CustomerId), kp)
customerId, err := uuid.Parse(signupPost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
resp, err := h.Api.GenerateSignupInterface(signupPost.Username, CustomerId(customerId), kp)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
@@ -133,7 +140,19 @@ func (h *NKodeHandler) SetNKodeHandler(w http.ResponseWriter, r *http.Request) {
log.Println(err)
return
}
confirmInterface, err := h.Api.SetNKode(CustomerId(setNKodePost.CustomerId), SessionId(setNKodePost.SessionId), setNKodePost.KeySelection)
customerId, err := uuid.Parse(setNKodePost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
sessionId, err := uuid.Parse(setNKodePost.SessionId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
confirmInterface, err := h.Api.SetNKode(CustomerId(customerId), SessionId(sessionId), setNKodePost.KeySelection)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
@@ -171,7 +190,19 @@ func (h *NKodeHandler) ConfirmNKodeHandler(w http.ResponseWriter, r *http.Reques
log.Println(err)
return
}
err = h.Api.ConfirmNKode(CustomerId(confirmNKodePost.CustomerId), SessionId(confirmNKodePost.SessionId), confirmNKodePost.KeySelection)
customerId, err := uuid.Parse(confirmNKodePost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
sessionId, err := uuid.Parse(confirmNKodePost.SessionId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
err = h.Api.ConfirmNKode(CustomerId(customerId), SessionId(sessionId), confirmNKodePost.KeySelection)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
@@ -194,7 +225,13 @@ func (h *NKodeHandler) GetLoginInterfaceHandler(w http.ResponseWriter, r *http.R
log.Println(err)
return
}
loginInterface, err := h.Api.GetLoginInterface(loginInterfacePost.Username, CustomerId(loginInterfacePost.CustomerId))
customerId, err := uuid.Parse(loginInterfacePost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
loginInterface, err := h.Api.GetLoginInterface(loginInterfacePost.Username, CustomerId(customerId))
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
@@ -230,7 +267,13 @@ func (h *NKodeHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
log.Println(err)
return
}
err = h.Api.Login(CustomerId(loginPost.CustomerId), loginPost.Username, loginPost.KeySelection)
customerId, err := uuid.Parse(loginPost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
err = h.Api.Login(CustomerId(customerId), loginPost.Username, loginPost.KeySelection)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
@@ -253,8 +296,13 @@ func (h *NKodeHandler) RenewAttributesHandler(w http.ResponseWriter, r *http.Req
log.Println(err)
return
}
err = h.Api.RenewAttributes(CustomerId(renewAttributesPost.CustomerId))
customerId, err := uuid.Parse(renewAttributesPost.CustomerId)
if err != nil {
internalServerErrorHandler(w)
log.Println(err)
return
}
err = h.Api.RenewAttributes(CustomerId(customerId))
if err != nil {
internalServerErrorHandler(w)
log.Println(err)

View File

@@ -17,45 +17,45 @@ type NewCustomerPost struct {
}
type GenerateSignupInterfacePost struct {
CustomerId uuid.UUID `json:"customer_id"`
AttrsPerKey int `json:"attrs_per_key"`
NumbOfKeys int `json:"numb_of_keys"`
Username Username `json:"username"`
CustomerId string `json:"customer_id"`
AttrsPerKey int `json:"attrs_per_key"`
NumbOfKeys int `json:"numb_of_keys"`
Username Username `json:"username"`
}
type SetNKodePost struct {
CustomerId uuid.UUID `json:"customer_id"`
KeySelection KeySelection `json:"key_selection"`
SessionId uuid.UUID `json:"session_id"`
CustomerId string `json:"customer_id"`
KeySelection []int `json:"key_selection"`
SessionId string `json:"session_id"`
}
type ConfirmNKodePost struct {
CustomerId uuid.UUID `json:"customer_id"`
CustomerId string `json:"customer_id"`
KeySelection KeySelection `json:"key_selection"`
SessionId uuid.UUID `json:"session_id"`
SessionId string `json:"session_id"`
}
type GetLoginInterfacePost struct {
Username Username `json:"username"`
CustomerId uuid.UUID `json:"customer_id"`
Username Username `json:"username"`
CustomerId string `json:"customer_id"`
}
type LoginPost struct {
CustomerId uuid.UUID `json:"customer_id"`
CustomerId string `json:"customer_id"`
Username Username `json:"username"`
KeySelection KeySelection `json:"key_selection"`
}
type RenewAttributesPost struct {
CustomerId uuid.UUID `json:"customer_id"`
CustomerId string `json:"customer_id"`
}
type CreateNewCustomerResp struct {
CustomerId CustomerId `json:"customer_id"`
CustomerId string `json:"customer_id"`
}
type GenerateSignupInterfaceResp struct {
SessionId SessionId `json:"session_id"`
SessionId string `json:"session_id"`
UserIdxInterface IdxInterface `json:"user_interface"`
SvgInterface []string `json:"svg_interface"`
}