From 7350fe5b19284b3ea00229cf03a445f7d471448e Mon Sep 17 00:00:00 2001 From: Eren Date: Sat, 12 Feb 2022 19:35:17 +0300 Subject: [PATCH] name changes --- .../constants/ProjectContextKeys/projectContextKeys.go | 2 +- src/services/blog-api/handler/loginHandler.go | 4 ++-- src/services/blog-api/middleware/authorization.go | 4 ++-- src/services/blog-api/services/user-service.go | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/services/blog-api/constants/ProjectContextKeys/projectContextKeys.go b/src/services/blog-api/constants/ProjectContextKeys/projectContextKeys.go index 72fd590..fd05dbb 100644 --- a/src/services/blog-api/constants/ProjectContextKeys/projectContextKeys.go +++ b/src/services/blog-api/constants/ProjectContextKeys/projectContextKeys.go @@ -1,3 +1,3 @@ -package projectcontextkeys +package ProjectContextKeys const USER_CONTEXT_KEY = "CurrentUser" diff --git a/src/services/blog-api/handler/loginHandler.go b/src/services/blog-api/handler/loginHandler.go index 946e3a8..3a488a5 100644 --- a/src/services/blog-api/handler/loginHandler.go +++ b/src/services/blog-api/handler/loginHandler.go @@ -2,7 +2,7 @@ package handler import ( "blog-on-containers/models" - . "blog-on-containers/services" + "blog-on-containers/services" "blog-on-containers/token" "fmt" "net/http" @@ -23,7 +23,7 @@ func LoginHandler(context *gin.Context) { } // validate the loginObj for valid credential adn if these are valid then - userService := NewUserService() + userService := services.NewUserService() if !userService.IsValidUsernameAndPassword(loginObj) { badRequest(context, http.StatusBadRequest, "invalid user", nil) } diff --git a/src/services/blog-api/middleware/authorization.go b/src/services/blog-api/middleware/authorization.go index 6741a70..bddba95 100644 --- a/src/services/blog-api/middleware/authorization.go +++ b/src/services/blog-api/middleware/authorization.go @@ -1,7 +1,7 @@ package middleware import ( - "blog-on-containers/constants/projectcontextkeys" + "blog-on-containers/constants/ProjectContextKeys" "blog-on-containers/models" . "blog-on-containers/services" "blog-on-containers/token" @@ -51,7 +51,7 @@ func addToContext(c *gin.Context, username string) { ReturnUnauthorized(c) } - c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), projectcontextkeys.USER_CONTEXT_KEY, user)) + c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), ProjectContextKeys.USER_CONTEXT_KEY, user)) } func Authorization(validRoles []int) gin.HandlerFunc { diff --git a/src/services/blog-api/services/user-service.go b/src/services/blog-api/services/user-service.go index 6b0170f..261173e 100644 --- a/src/services/blog-api/services/user-service.go +++ b/src/services/blog-api/services/user-service.go @@ -9,22 +9,22 @@ import ( ) var ( - repo *repository.MongoRepository + repoUsers *repository.MongoRepository ) -const m_COLLECTION_NAME = "users" +const m_COLLECTION_NAME_USERS = "users" type UserService struct{} func NewUserService() UserService { - repo = repository.GetMongoRepository(m_COLLECTION_NAME) + repoUsers = repository.GetMongoRepository(m_COLLECTION_NAME_USERS) return UserService{} } func (*UserService) IsValidUsernameAndPassword(loginObj models.LoginRequest) bool { filter := bson.M{"username": loginObj.UserName, "password": loginObj.Password} - count, err := repo.CountDocuments(filter) + count, err := repoUsers.CountDocuments(filter) return err == nil && count > 0 } @@ -32,7 +32,7 @@ func (*UserService) IsValidUsernameAndPassword(loginObj models.LoginRequest) boo func (*UserService) GetUserByUsername(username string) (User, error) { var user User filter := bson.M{"username": username} - err := repo.FindOne(filter, &user) + err := repoUsers.FindOne(filter, &user) return user, err }