This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
api/router/v1/badges.go

29 lines
655 B
Go

package v1
import (
"gractwo-api/database"
"time"
"github.com/gin-gonic/gin"
)
func GetUserBadges(c *gin.Context) {
type badge struct {
Id string
Name string
Desc string
Expl string
Img string
Date *time.Time
}
var badges []badge
userId := c.Param("user")
database.DB.Model(&database.User{}).Select("badges.id, badges.name, badges.desc, badges.expl, badges.img, given_badges.date").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)
if badges == nil {
c.JSON(404, "Not found")
} else {
c.JSON(200, badges)
}
}