From b0c6a8e0f97f18bb8c8c2b31caf9d121a53e9cb5 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Mon, 8 Apr 2024 13:56:25 +0200 Subject: [PATCH] v1.3.0: back: use lib for the request data Signed-off-by: GnomeZworc --- cmd/login.go | 3 ++- internal/createLogin.go | 5 +++-- internal/struct.go | 15 --------------- 3 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 internal/struct.go diff --git a/cmd/login.go b/cmd/login.go index 97027da..75a645f 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -5,6 +5,7 @@ import ( "github.com/labstack/echo/v4" logins "gitlab.g3e.fr/h6n/users/internal" + login_lib "gitlab.g3e.fr/h6n/users/lib/login" ) // Login @@ -16,7 +17,7 @@ import ( // @Param request body logins.RequestLogin true "request body" // @Success 200 {object} logins.ResponseLogin func login(c echo.Context) error { - var request logins.RequestLogin + var request login_lib.RequestLogin if err := c.Bind(&request); err != nil { return c.JSON(http.StatusBadRequest, err) } diff --git a/internal/createLogin.go b/internal/createLogin.go index 7484bf9..8609ae5 100644 --- a/internal/createLogin.go +++ b/internal/createLogin.go @@ -9,6 +9,7 @@ import ( "github.com/biscuit-auth/biscuit-go/v2" "github.com/biscuit-auth/biscuit-go/v2/parser" "gitlab.g3e.fr/h6n/users/lib" + login_lib "gitlab.g3e.fr/h6n/users/lib/login" "golang.org/x/crypto/bcrypt" "gorm.io/gorm" ) @@ -18,8 +19,8 @@ func CheckPasswordHash(password, hash string) bool { return err == nil } -func CreateLogin(db *gorm.DB, request RequestLogin) (ResponseLogin, error) { - var response ResponseLogin +func CreateLogin(db *gorm.DB, request login_lib.RequestLogin) (login_lib.ResponseLogin, error) { + var response login_lib.ResponseLogin var user = Users{Email: request.Username} if err := db.First(&user); err.Error != nil { diff --git a/internal/struct.go b/internal/struct.go deleted file mode 100644 index a32b8fb..0000000 --- a/internal/struct.go +++ /dev/null @@ -1,15 +0,0 @@ -package logins - -type ( - // RequestLogin model info - RequestLogin struct { - Username string `json:"username"` - Password string `json:"password"` - } - - // ResponseLogin model info - ResponseLogin struct { - Token string `json:"token"` - PublicKey string `json:"publickey"` - } -)