Skip to content

Commit

Permalink
rfac: revert all backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaditya-G committed Oct 25, 2024
1 parent 3b2b92a commit 53773ec
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions backend/db/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,23 +357,23 @@ func AddUserInfoToDb(username string, userId string, userAgent string, ip string
}

func GetUserInfo(userId string) string {
info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result()
var _info models.UserInfo
err := json.Unmarshal([]byte(info), &_info)
if err != nil {
info, _ := redisClient.Get(ctx, fmt.Sprintf("info:%v", userId)).Result()
var _info models.UserInfo
err := json.Unmarshal([]byte(info), &_info)
if(err != nil){
logging.LogException(err)
panic(err)
}
formattedInfo := fmt.Sprintf(
"UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s",
_info.UserID,
_info.Username,
_info.IP,
_info.Location,
_info.OS,
_info.Agent,
_info.Channel,
)
"UserID: %s\nName: %s\nIP: %s\nLocation: %s\nOS: %s\nAgent: %s\nChatChannel: %s",
_info.UserID,
_info.Username,
_info.IP,
_info.Location,
_info.OS,
_info.Agent,
_info.Channel,
)
return formattedInfo
}

Expand Down Expand Up @@ -423,6 +423,7 @@ func UpsertProject(project models.Project) {
"projectAppStoreLink": string(project.AppStoreLink),
"projectGithubLink": string(project.GithubLink),
"projectPlayStoreLink": string(project.PlayStoreLink),

}).Result()
if err != nil {
logging.LogException(err)
Expand All @@ -447,32 +448,32 @@ func UpsertProject(project models.Project) {
// return project
// }

func GetAllProjects() ([]models.Project, error) {
func GetAllProjects() ([]models.Project , error) {
keys, err := redisClient.Keys(redisClient.Context(), "project:*").Result()
if err != nil {
logging.LogException(err)
return nil, err
return nil , err
}
var projects []models.Project
for _, key := range keys {
result, err := redisClient.HGetAll(redisClient.Context(), key).Result()
if err != nil {
logging.LogException(err)
return nil, err
return nil , err
}
project := models.Project{
Name: key[len("project:"):],
Category: models.ProjectCategory(result["projectCategory"]),
ShortDesc: result["projectShortDescription"],
LongDesc: result["projectLongDescription"],
ImageLink: result["projectImageLink"],
AppStoreLink: result["projectAppStoreLink"],
GithubLink: result["projectGithubLink"],
Name: key[len("project:"):],
Category: models.ProjectCategory(result["projectCategory"]),
ShortDesc: result["projectShortDescription"],
LongDesc: result["projectLongDescription"],
ImageLink: result["projectImageLink"],
AppStoreLink: result["projectAppStoreLink"],
GithubLink: result["projectGithubLink"],
PlayStoreLink: result["projectPlayStoreLink"],
}
projects = append(projects, project)
}
return projects, nil
return projects , nil
}

func isValidProjectCategory(category models.ProjectCategory) bool {
Expand All @@ -485,29 +486,30 @@ func isValidProjectCategory(category models.ProjectCategory) bool {
}

func DeleteProject(projectName string) string {

if !projectExists(projectName) {
err := fmt.Errorf("project %s does not exist", projectName)
logging.LogException(err)
return err.Error()
}


key := "project:" + projectName
_, err := redisClient.Del(redisClient.Context(), key).Result()
if err != nil {
logging.LogException(err)
return err.Error()
}

return fmt.Sprintf("project %v deleted succesfully", projectName)
return fmt.Sprintf("project %v deleted succesfully" , projectName)
}

func projectExists(projectName string) bool {
func projectExists( projectName string) bool {
key := "project:" + projectName
exists, err := redisClient.Exists(redisClient.Context(), key).Result()
if err != nil {
logging.LogException(err)
return false
}
return exists == 1
}
}

0 comments on commit 53773ec

Please sign in to comment.