Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion configs/scripts/run_servers.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

set "PROJECT_ROOT_DIR=absolute-path-to-project-root-directory"
set "PROJECT_ROOT_DIR=E:\nexster-runtime\nexster"

cd /d "%PROJECT_ROOT_DIR%"

Expand Down Expand Up @@ -35,4 +35,6 @@ rem Run boarding_finder server
cd ..\..\boarding_finder\cmd
start "" /B go run main.go > "%PROJECT_ROOT_DIR%\logs\bdFinder_server.log" 2>&1

cd /d "%PROJECT_ROOT_DIR%\configs\scripts"

echo --done--
2 changes: 2 additions & 0 deletions pkgs/models/user/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Interface interface {
DeleteUser(ctx context.Context, key string) error
CreateDocument(ctx context.Context, doc *UserCreateInfo) (string, error)
ListFacDepOfAllUsers(ctx context.Context) ([]*map[string]string, error)
// CountOfAllUsers(ctx context.Context) (int, error)
CountOfAllUsers(ctx context.Context) (totalUsers, maleUsers, femaleUsers int, err error)
}

// TODO:
Expand Down
15 changes: 15 additions & 0 deletions pkgs/models/user/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ package user

const listFacDepOfAllUsersQry string = `FOR doc IN users
RETURN { key: doc._key, faculty: doc.faculty, field: doc.field }`

const getUserSignupsQry string = `RETURN LENGTH (FOR user IN users
FILTER user.createdAt >= @fromDate && user.createdAt <=@toDate
RETURN user._key)`

//haritha mihimal all users
//const getAllUsersCountQry string = `RETURN LENGTH(FOR user IN users
// RETURN user._key)`
//

const getAllUsersCountQry string = `
LET totalUsers = LENGTH(FOR user IN users RETURN user._key)
LET maleUsers = LENGTH(FOR user IN users FILTER user.gender == "male" RETURN user._key)
LET femaleUsers = LENGTH(FOR user IN users FILTER user.gender == "female" RETURN user._key)
RETURN { totalUsers, maleUsers, femaleUsers }`
27 changes: 27 additions & 0 deletions pkgs/models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,30 @@ func (uc *userCtrler) CreateDocument(ctx context.Context, doc *UserCreateInfo) (
func (uc *userCtrler) ListFacDepOfAllUsers(ctx context.Context) ([]*map[string]string, error) {
return uc.ListUsersV2(ctx, listFacDepOfAllUsersQry, map[string]interface{}{})
}
func (uc *userCtrler) CountOfAllUsers(ctx context.Context) (totalUsers, maleUsers, femaleUsers int, err error) {
cursor, err := uc.argClient.Db.Query(ctx, getAllUsersCountQry, nil)
if err != nil {
return
}
defer cursor.Close()

if !cursor.HasMore() {
err = fmt.Errorf("cursor has no more results")
return
}

var result struct {
TotalUsers int `json:"totalUsers"`
MaleUsers int `json:"maleUsers"`
FemaleUsers int `json:"femaleUsers"`
}
_, err = cursor.ReadDocument(ctx, &result)
if err != nil {
return
}
totalUsers = result.TotalUsers
maleUsers = result.MaleUsers
femaleUsers = result.FemaleUsers
err = nil
return
}
2 changes: 2 additions & 0 deletions usrmgmt/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func main() {
w.Write([]byte("You are in usrmgmt/test page...!"))
})


router.GET("/usrmgmt/insights/users/all",srv.GetAllUsers) // get all user count
router.GET("/usrmgmt/all/friends", srv.ListFriendInfo)
router.GET("/usrmgmt/friends/:user_id/count", srv.GetFriendsCount)

Expand Down
2 changes: 2 additions & 0 deletions usrmgmt/pkg/server/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Interface interface {
EmailAccountCreationLink(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
CreateUserAccount(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
ValidatePasswordResetLink(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
GetAllUsers(w http.ResponseWriter, r *http.Request, _ httprouter.Params) // all user
}

type FriendRequest struct {
Expand Down Expand Up @@ -63,4 +64,5 @@ type ServerConfig struct {
DefaultUserRoles []string `yaml:"defaultUserRoles"`
RegLinkExpireTime int `yaml:"regLinkExpireTime"`
PasswdResetLinkExpireTime int `yaml:"passwdResetLinkExpireTime"`

}
30 changes: 29 additions & 1 deletion usrmgmt/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
//"os/user"
"strconv"
"time"

Expand Down Expand Up @@ -65,7 +66,7 @@ type server struct {
tokenGen gjwt.Interface
}

var _ Interface = (*server)(nil)
var _ Interface = (*server)(nil)

func New(cfg *ServerConfig, sgrInterface socigr.Interface, logger *lg.Logger, mailIntfce umail.Interface, jwtTokenGen gjwt.Interface) *server {
return &server{
Expand All @@ -76,6 +77,33 @@ func New(cfg *ServerConfig, sgrInterface socigr.Interface, logger *lg.Logger, ma
tokenGen: jwtTokenGen,
}
}
// add a comment
func (s *server) GetAllUsers(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
respBody := map[string]interface{}{
"state": failed,
"data": map[string]int{},
}
jwtUserKey, ok := r.Context().Value(jwt.JwtUserKey).(string)
if !ok {
s.logger.Infof("failed to count all users: unsupported user_key type in JWT token: unauthorized request: user_key=%v", r.Context().Value(jwt.JwtUserKey))
s.sendRespDefault(w, http.StatusUnauthorized, respBody)
return
}
totalUsers, maleUsers, femaleUsers, err := s.scGraph.GetAllUsers(r.Context(), jwtUserKey) //change the function name here
if err != nil {
s.logger.Errorf("failed to count all users: %v: userKey=%s", err, jwtUserKey)
s.sendRespDefault(w, http.StatusInternalServerError, respBody)
return
}
respBody["state"] = success
respBody["data"] = map[string]int{
"totalUsers": totalUsers,
"maleUsers": maleUsers,
"femaleUsers": femaleUsers,
}
s.sendRespDefault(w, http.StatusOK, respBody)
}


func (s *server) ListFriendReqs(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
headers := map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions usrmgmt/pkg/social_graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func NewGrphCtrler(frIntfce freq.Interface, frndIntfce frnd.Interface, usrIntfce
interestsInCtrler: interestsInIntfce,
}
}
// added discription about the retun values
func (sgr *socialGraph) GetAllUsers(ctx context.Context, userKey string) (int, int, int, error) { //remove userKey
return sgr.usrCtrler.CountOfAllUsers(ctx) // change the function name
}

func (sgr *socialGraph) ListFriendReqs(ctx context.Context, userKey string, offset, count int) ([]*map[string]string, error) {
friendReqs, err := sgr.fReqCtrler.ListStringValueJson(ctx, listFriendReqs, map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions usrmgmt/pkg/social_graph/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ type Interface interface {
ExistUserForIndexEmail(ctx context.Context, indexNo, email string) (bool, error)
ExistUserForEmail(ctx context.Context, email string) (bool, error)
ForgotPasswordReset(ctx context.Context, email, newPasswd string) error
GetAllUsers(ctx context.Context, userKey string) (int,int,int, error)
}