add badges

This commit is contained in:
Stanislaw
2023-01-21 02:10:32 +01:00
parent fa0ae10a7f
commit 4c33520f46
7 changed files with 41 additions and 12 deletions

View File

@@ -21,6 +21,7 @@ func InitRouter() *gin.Engine {
apiv1.GET("/persons-of-note", v1.GetAdminCards)
apiv1.GET("/index-images", v1.GetImages)
apiv1.GET("/splash", v1.GetSplash)
apiv1.GET("/badges/:user", v1.GetUserBadges)
}
return r
}

14
router/v1/badges.go Normal file
View File

@@ -0,0 +1,14 @@
package v1
import (
"gractwo-api/database"
"github.com/gin-gonic/gin"
)
func GetUserBadges(c *gin.Context) {
var badges []database.Badge
userId := c.Param("user")
database.DB.Model(&database.User{}).Select("badges.id, badges.name, badges.desc, badges.expl, badges.img").Joins("join given_badges on users.user_id = given_badges.user_id").Joins("join badges on badges.id = badges.id").Where("users.user_id = ?", userId).Scan(&badges)
c.JSON(200, badges)
}

View File

@@ -13,5 +13,5 @@ func GetSplash(c *gin.Context) {
if err != nil {
c.JSON(404, "Not found")
}
c.JSON(200, SplashList[rand.Intn(len(SplashList)-1-0+1)+0])
c.JSON(200, SplashList[rand.Intn(len(SplashList))])
}