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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/google/uuid"
|
||||||
"go-nkode/core/api"
|
"go-nkode/core/api"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -56,7 +57,7 @@ func (h *NKodeHandler) CreateNewCustomerHandler(w http.ResponseWriter, r *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
respBody := CreateNewCustomerResp{
|
respBody := CreateNewCustomerResp{
|
||||||
CustomerId: *customerId,
|
CustomerId: uuid.UUID(*customerId).String(),
|
||||||
}
|
}
|
||||||
respBytes, err := json.Marshal(respBody)
|
respBytes, err := json.Marshal(respBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,7 +99,13 @@ func (h *NKodeHandler) GenerateSignupInterfaceHandler(w http.ResponseWriter, r *
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -133,7 +140,19 @@ func (h *NKodeHandler) SetNKodeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -171,7 +190,19 @@ func (h *NKodeHandler) ConfirmNKodeHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -194,7 +225,13 @@ func (h *NKodeHandler) GetLoginInterfaceHandler(w http.ResponseWriter, r *http.R
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -230,7 +267,13 @@ func (h *NKodeHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -253,8 +296,13 @@ func (h *NKodeHandler) RenewAttributesHandler(w http.ResponseWriter, r *http.Req
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
customerId, err := uuid.Parse(renewAttributesPost.CustomerId)
|
||||||
err = h.Api.RenewAttributes(CustomerId(renewAttributesPost.CustomerId))
|
if err != nil {
|
||||||
|
internalServerErrorHandler(w)
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = h.Api.RenewAttributes(CustomerId(customerId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internalServerErrorHandler(w)
|
internalServerErrorHandler(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|||||||
@@ -17,45 +17,45 @@ type NewCustomerPost struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GenerateSignupInterfacePost struct {
|
type GenerateSignupInterfacePost struct {
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
AttrsPerKey int `json:"attrs_per_key"`
|
AttrsPerKey int `json:"attrs_per_key"`
|
||||||
NumbOfKeys int `json:"numb_of_keys"`
|
NumbOfKeys int `json:"numb_of_keys"`
|
||||||
Username Username `json:"username"`
|
Username Username `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetNKodePost struct {
|
type SetNKodePost struct {
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
KeySelection KeySelection `json:"key_selection"`
|
KeySelection []int `json:"key_selection"`
|
||||||
SessionId uuid.UUID `json:"session_id"`
|
SessionId string `json:"session_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfirmNKodePost struct {
|
type ConfirmNKodePost struct {
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
KeySelection KeySelection `json:"key_selection"`
|
KeySelection KeySelection `json:"key_selection"`
|
||||||
SessionId uuid.UUID `json:"session_id"`
|
SessionId string `json:"session_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetLoginInterfacePost struct {
|
type GetLoginInterfacePost struct {
|
||||||
Username Username `json:"username"`
|
Username Username `json:"username"`
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginPost struct {
|
type LoginPost struct {
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
Username Username `json:"username"`
|
Username Username `json:"username"`
|
||||||
KeySelection KeySelection `json:"key_selection"`
|
KeySelection KeySelection `json:"key_selection"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenewAttributesPost struct {
|
type RenewAttributesPost struct {
|
||||||
CustomerId uuid.UUID `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNewCustomerResp struct {
|
type CreateNewCustomerResp struct {
|
||||||
CustomerId CustomerId `json:"customer_id"`
|
CustomerId string `json:"customer_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenerateSignupInterfaceResp struct {
|
type GenerateSignupInterfaceResp struct {
|
||||||
SessionId SessionId `json:"session_id"`
|
SessionId string `json:"session_id"`
|
||||||
UserIdxInterface IdxInterface `json:"user_interface"`
|
UserIdxInterface IdxInterface `json:"user_interface"`
|
||||||
SvgInterface []string `json:"svg_interface"`
|
SvgInterface []string `json:"svg_interface"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package nkode
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
m "go-nkode/core/model"
|
m "go-nkode/core/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ func (n *NKodeAPI) GenerateSignupInterface(username m.Username, customerId m.Cus
|
|||||||
resp := m.GenerateSignupInterfaceResp{
|
resp := m.GenerateSignupInterfaceResp{
|
||||||
UserIdxInterface: signupSession.SetIdxInterface,
|
UserIdxInterface: signupSession.SetIdxInterface,
|
||||||
SvgInterface: svgInterface,
|
SvgInterface: svgInterface,
|
||||||
SessionId: signupSession.Id,
|
SessionId: uuid.UUID(signupSession.Id).String(),
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
19
main_test.go
19
main_test.go
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"go-nkode/core/api"
|
"go-nkode/core/api"
|
||||||
m "go-nkode/core/model"
|
m "go-nkode/core/model"
|
||||||
@@ -26,7 +25,7 @@ func TestApi(t *testing.T) {
|
|||||||
|
|
||||||
username := m.Username("test_username")
|
username := m.Username("test_username")
|
||||||
signupInterfaceBody := m.GenerateSignupInterfacePost{
|
signupInterfaceBody := m.GenerateSignupInterfacePost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
AttrsPerKey: kp.AttrsPerKey,
|
AttrsPerKey: kp.AttrsPerKey,
|
||||||
NumbOfKeys: kp.NumbOfKeys,
|
NumbOfKeys: kp.NumbOfKeys,
|
||||||
Username: username,
|
Username: username,
|
||||||
@@ -41,8 +40,8 @@ func TestApi(t *testing.T) {
|
|||||||
setKeySelection, err := m.SelectKeyByAttrIdx(setInterface, userPasscode, kp_set)
|
setKeySelection, err := m.SelectKeyByAttrIdx(setInterface, userPasscode, kp_set)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setNKodeBody := m.SetNKodePost{
|
setNKodeBody := m.SetNKodePost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
SessionId: uuid.UUID(signupInterfaceResp.SessionId),
|
SessionId: signupInterfaceResp.SessionId,
|
||||||
KeySelection: setKeySelection,
|
KeySelection: setKeySelection,
|
||||||
}
|
}
|
||||||
var setNKodeResp m.SetNKodeResp
|
var setNKodeResp m.SetNKodeResp
|
||||||
@@ -51,14 +50,14 @@ func TestApi(t *testing.T) {
|
|||||||
confirmKeySelection, err := m.SelectKeyByAttrIdx(confirmInterface, userPasscode, kp_set)
|
confirmKeySelection, err := m.SelectKeyByAttrIdx(confirmInterface, userPasscode, kp_set)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmNKodeBody := m.ConfirmNKodePost{
|
confirmNKodeBody := m.ConfirmNKodePost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
KeySelection: confirmKeySelection,
|
KeySelection: confirmKeySelection,
|
||||||
SessionId: uuid.UUID(signupInterfaceResp.SessionId),
|
SessionId: signupInterfaceResp.SessionId,
|
||||||
}
|
}
|
||||||
testApiPost(t, base+api.ConfirmNKode, confirmNKodeBody, nil)
|
testApiPost(t, base+api.ConfirmNKode, confirmNKodeBody, nil)
|
||||||
|
|
||||||
loginInterfaceBody := m.GetLoginInterfacePost{
|
loginInterfaceBody := m.GetLoginInterfacePost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
Username: username,
|
Username: username,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,20 +67,20 @@ func TestApi(t *testing.T) {
|
|||||||
loginKeySelection, err := m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
loginKeySelection, err := m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginBody := m.LoginPost{
|
loginBody := m.LoginPost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
Username: username,
|
Username: username,
|
||||||
KeySelection: loginKeySelection,
|
KeySelection: loginKeySelection,
|
||||||
}
|
}
|
||||||
|
|
||||||
testApiPost(t, base+api.Login, loginBody, nil)
|
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)
|
testApiPost(t, base+api.RenewAttributes, renewBody, nil)
|
||||||
|
|
||||||
loginKeySelection, err = m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
loginKeySelection, err = m.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginBody = m.LoginPost{
|
loginBody = m.LoginPost{
|
||||||
CustomerId: uuid.UUID(customerResp.CustomerId),
|
CustomerId: customerResp.CustomerId,
|
||||||
Username: username,
|
Username: username,
|
||||||
KeySelection: loginKeySelection,
|
KeySelection: loginKeySelection,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user