From 6fde7ffd750383f7e7fda3ffb02cd3f532918f02 Mon Sep 17 00:00:00 2001 From: jay-dee7 Date: Tue, 2 Nov 2021 16:48:27 +0530 Subject: [PATCH] fix: initial user signup fix Signed-off-by: jay-dee7 --- auth/signup.go | 1 - cache/register_for_beta.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/auth/signup.go b/auth/signup.go index 68974f26..028dec19 100644 --- a/auth/signup.go +++ b/auth/signup.go @@ -160,7 +160,6 @@ func (a *auth) SignUp(ctx echo.Context) error { if err := u.Validate(a.store); err != nil { return ctx.JSON(http.StatusBadRequest, echo.Map{ "error": err.Error(), - "msg": "bananas", }) } diff --git a/cache/register_for_beta.go b/cache/register_for_beta.go index 4cf68809..ddd6a836 100644 --- a/cache/register_for_beta.go +++ b/cache/register_for_beta.go @@ -6,6 +6,7 @@ import ( "net/http" "regexp" + "github.com/dgraph-io/badger/v3" "github.com/labstack/echo/v4" ) @@ -59,17 +60,19 @@ func (ds *dataStore) RegisterForBeta(ctx echo.Context) error { key := []byte("email") var value BetaRegister list, err := ds.Get([]byte("email")) - - if err != nil { + if err != nil || err == badger.ErrKeyNotFound { value.Emails = []string{body["email"]} if err := ds.Set(key, value.Bytes()); err != nil { return ctx.JSON(http.StatusInternalServerError, echo.Map{ "error": err.Error(), }) } + return ctx.JSON(http.StatusOK, echo.Map{ + "message": "Success", + }) } - if err := json.Unmarshal(list, &value); err != nil { + if err = json.Unmarshal(list, &value); err != nil { return ctx.JSON(http.StatusInternalServerError, echo.Map{ "error": err.Error(), }) @@ -97,10 +100,11 @@ func (ds *dataStore) RegisterForBeta(ctx echo.Context) error { func (ds *dataStore) GetAllEmail(ctx echo.Context) error { bz, err := ds.Get([]byte("email")) - if err != nil { + if err != nil && err != badger.ErrKeyNotFound { return ctx.JSON(http.StatusInternalServerError, echo.Map{ "error": "couldn't get them all", }) } + return ctx.JSONBlob(http.StatusOK, bz) }