Skip to content

Commit

Permalink
name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alnck committed Feb 12, 2022
1 parent 0e1f0e9 commit 7350fe5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package projectcontextkeys
package ProjectContextKeys

const USER_CONTEXT_KEY = "CurrentUser"
4 changes: 2 additions & 2 deletions src/services/blog-api/handler/loginHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/blog-api/middleware/authorization.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/services/blog-api/services/user-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ 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
}

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
}

0 comments on commit 7350fe5

Please sign in to comment.