2023-05-31 18:39:07 -05:00
|
|
|
package badges
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"safetwitch-backend/extractor"
|
|
|
|
"safetwitch-backend/extractor/twitch"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Routes(route *gin.Engine) {
|
|
|
|
auth := route.Group("/api/badges")
|
|
|
|
|
2023-06-07 11:25:52 -05:00
|
|
|
auth.GET("", func(context *gin.Context) {
|
2023-05-31 18:39:07 -05:00
|
|
|
query := context.Query("streamerName")
|
|
|
|
if query != "" {
|
|
|
|
data, err := twitch.GetStreamerBadges(query)
|
|
|
|
if err != nil {
|
|
|
|
context.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
|
|
|
} else {
|
|
|
|
data, err := twitch.GetTwitchBadges()
|
|
|
|
if err != nil {
|
|
|
|
context.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|