fix: convert customer, session ids to uuid for json un/marshal in both post and resp
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package nkode
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
m "go-nkode/core/model"
|
||||
)
|
||||
|
||||
@@ -51,7 +52,7 @@ func (n *NKodeAPI) GenerateSignupInterface(username m.Username, customerId m.Cus
|
||||
resp := m.GenerateSignupInterfaceResp{
|
||||
UserIdxInterface: signupSession.SetIdxInterface,
|
||||
SvgInterface: svgInterface,
|
||||
SessionId: signupSession.Id,
|
||||
SessionId: uuid.UUID(signupSession.Id).String(),
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
19
main_test.go
19
main_test.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go-nkode/core/api"
|
||||
m "go-nkode/core/model"
|
||||
@@ -26,7 +25,7 @@ func TestApi(t *testing.T) {
|
||||
|
||||
username := m.Username("test_username")
|
||||
signupInterfaceBody := m.GenerateSignupInterfacePost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
AttrsPerKey: kp.AttrsPerKey,
|
||||
NumbOfKeys: kp.NumbOfKeys,
|
||||
Username: username,
|
||||
@@ -41,8 +40,8 @@ func TestApi(t *testing.T) {
|
||||
setKeySelection, err := m.SelectKeyByAttrIdx(setInterface, userPasscode, kp_set)
|
||||
assert.NoError(t, err)
|
||||
setNKodeBody := m.SetNKodePost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
SessionId: uuid.UUID(signupInterfaceResp.SessionId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
SessionId: signupInterfaceResp.SessionId,
|
||||
KeySelection: setKeySelection,
|
||||
}
|
||||
var setNKodeResp m.SetNKodeResp
|
||||
@@ -51,14 +50,14 @@ func TestApi(t *testing.T) {
|
||||
confirmKeySelection, err := m.SelectKeyByAttrIdx(confirmInterface, userPasscode, kp_set)
|
||||
assert.NoError(t, err)
|
||||
confirmNKodeBody := m.ConfirmNKodePost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
KeySelection: confirmKeySelection,
|
||||
SessionId: uuid.UUID(signupInterfaceResp.SessionId),
|
||||
SessionId: signupInterfaceResp.SessionId,
|
||||
}
|
||||
testApiPost(t, base+api.ConfirmNKode, confirmNKodeBody, nil)
|
||||
|
||||
loginInterfaceBody := m.GetLoginInterfacePost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
Username: username,
|
||||
}
|
||||
|
||||
@@ -68,20 +67,20 @@ func TestApi(t *testing.T) {
|
||||
loginKeySelection, err := m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||
assert.NoError(t, err)
|
||||
loginBody := m.LoginPost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
Username: username,
|
||||
KeySelection: loginKeySelection,
|
||||
}
|
||||
|
||||
testApiPost(t, base+api.Login, loginBody, nil)
|
||||
|
||||
renewBody := m.RenewAttributesPost{CustomerId: uuid.UUID(customerResp.CustomerId)}
|
||||
renewBody := m.RenewAttributesPost{CustomerId: customerResp.CustomerId}
|
||||
testApiPost(t, base+api.RenewAttributes, renewBody, nil)
|
||||
|
||||
loginKeySelection, err = m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||
assert.NoError(t, err)
|
||||
loginBody = m.LoginPost{
|
||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
||||
CustomerId: customerResp.CustomerId,
|
||||
Username: username,
|
||||
KeySelection: loginKeySelection,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user