@@ -357,23 +357,23 @@ func AddUserInfoToDb(username string, userId string, userAgent string, ip string
357
357
}
358
358
359
359
func GetUserInfo (userId string ) string {
360
- info , _ := redisClient .Get (ctx , fmt .Sprintf ("info:%v" , userId )).Result ()
361
- var _info models.UserInfo
362
- err := json .Unmarshal ([]byte (info ), & _info )
363
- if err != nil {
360
+ info , _ := redisClient .Get (ctx , fmt .Sprintf ("info:%v" , userId )).Result ()
361
+ var _info models.UserInfo
362
+ err := json .Unmarshal ([]byte (info ), & _info )
363
+ if ( err != nil ) {
364
364
logging .LogException (err )
365
365
panic (err )
366
366
}
367
367
formattedInfo := fmt .Sprintf (
368
- "UserID: %s\n Name: %s\n IP: %s\n Location: %s\n OS: %s\n Agent: %s\n ChatChannel: %s" ,
369
- _info .UserID ,
370
- _info .Username ,
371
- _info .IP ,
372
- _info .Location ,
373
- _info .OS ,
374
- _info .Agent ,
375
- _info .Channel ,
376
- )
368
+ "UserID: %s\n Name: %s\n IP: %s\n Location: %s\n OS: %s\n Agent: %s\n ChatChannel: %s" ,
369
+ _info .UserID ,
370
+ _info .Username ,
371
+ _info .IP ,
372
+ _info .Location ,
373
+ _info .OS ,
374
+ _info .Agent ,
375
+ _info .Channel ,
376
+ )
377
377
return formattedInfo
378
378
}
379
379
@@ -423,6 +423,7 @@ func UpsertProject(project models.Project) {
423
423
"projectAppStoreLink" : string (project .AppStoreLink ),
424
424
"projectGithubLink" : string (project .GithubLink ),
425
425
"projectPlayStoreLink" : string (project .PlayStoreLink ),
426
+
426
427
}).Result ()
427
428
if err != nil {
428
429
logging .LogException (err )
@@ -447,32 +448,32 @@ func UpsertProject(project models.Project) {
447
448
// return project
448
449
// }
449
450
450
- func GetAllProjects () ([]models.Project , error ) {
451
+ func GetAllProjects () ([]models.Project , error ) {
451
452
keys , err := redisClient .Keys (redisClient .Context (), "project:*" ).Result ()
452
453
if err != nil {
453
454
logging .LogException (err )
454
- return nil , err
455
+ return nil , err
455
456
}
456
457
var projects []models.Project
457
458
for _ , key := range keys {
458
459
result , err := redisClient .HGetAll (redisClient .Context (), key ).Result ()
459
460
if err != nil {
460
461
logging .LogException (err )
461
- return nil , err
462
+ return nil , err
462
463
}
463
464
project := models.Project {
464
- Name : key [len ("project:" ):],
465
- Category : models .ProjectCategory (result ["projectCategory" ]),
466
- ShortDesc : result ["projectShortDescription" ],
467
- LongDesc : result ["projectLongDescription" ],
468
- ImageLink : result ["projectImageLink" ],
469
- AppStoreLink : result ["projectAppStoreLink" ],
470
- GithubLink : result ["projectGithubLink" ],
465
+ Name : key [len ("project:" ):],
466
+ Category : models .ProjectCategory (result ["projectCategory" ]),
467
+ ShortDesc : result ["projectShortDescription" ],
468
+ LongDesc : result ["projectLongDescription" ],
469
+ ImageLink : result ["projectImageLink" ],
470
+ AppStoreLink : result ["projectAppStoreLink" ],
471
+ GithubLink : result ["projectGithubLink" ],
471
472
PlayStoreLink : result ["projectPlayStoreLink" ],
472
473
}
473
474
projects = append (projects , project )
474
475
}
475
- return projects , nil
476
+ return projects , nil
476
477
}
477
478
478
479
func isValidProjectCategory (category models.ProjectCategory ) bool {
@@ -485,29 +486,30 @@ func isValidProjectCategory(category models.ProjectCategory) bool {
485
486
}
486
487
487
488
func DeleteProject (projectName string ) string {
488
-
489
+
489
490
if ! projectExists (projectName ) {
490
491
err := fmt .Errorf ("project %s does not exist" , projectName )
491
492
logging .LogException (err )
492
493
return err .Error ()
493
494
}
494
495
496
+
495
497
key := "project:" + projectName
496
498
_ , err := redisClient .Del (redisClient .Context (), key ).Result ()
497
499
if err != nil {
498
500
logging .LogException (err )
499
501
return err .Error ()
500
502
}
501
503
502
- return fmt .Sprintf ("project %v deleted succesfully" , projectName )
504
+ return fmt .Sprintf ("project %v deleted succesfully" , projectName )
503
505
}
504
506
505
- func projectExists (projectName string ) bool {
507
+ func projectExists ( projectName string ) bool {
506
508
key := "project:" + projectName
507
509
exists , err := redisClient .Exists (redisClient .Context (), key ).Result ()
508
510
if err != nil {
509
511
logging .LogException (err )
510
512
return false
511
513
}
512
514
return exists == 1
513
- }
515
+ }
0 commit comments