mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 13:13:00 -05:00
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package users
|
|
|
|
import (
|
|
"safetwitch-backend/extractor"
|
|
"safetwitch-backend/extractor/twitch"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Routes(route *gin.Engine) {
|
|
auth := route.Group("/api/users")
|
|
|
|
auth.GET("/:streamerName", func(context *gin.Context) {
|
|
data, err := twitch.GetStreamerInfo(context.Param("streamerName"))
|
|
if err != nil {
|
|
if err.Error() == "streamer not found" {
|
|
context.JSON(404, gin.H{
|
|
"status": "error",
|
|
"message": "streamer not found",
|
|
})
|
|
} else {
|
|
context.Error(err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
|
})
|
|
|
|
type postData struct {
|
|
Streamers []string `json:"streamers"`
|
|
}
|
|
|
|
auth.POST("/isLive/bulk", func(context *gin.Context) {
|
|
var f postData
|
|
err := context.ShouldBindJSON(&f)
|
|
if err != nil {
|
|
context.Error(err)
|
|
return
|
|
}
|
|
|
|
data, err := twitch.BulkCheckIfStreamerIsLive(f.Streamers)
|
|
if err != nil {
|
|
context.Error(err)
|
|
return
|
|
}
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
|
})
|
|
|
|
auth.POST("/followingStreamer/bulk", func(context *gin.Context) {
|
|
var f postData
|
|
err := context.ShouldBindJSON(&f)
|
|
if err != nil {
|
|
context.Error(err)
|
|
return
|
|
}
|
|
|
|
data, err := twitch.BulkFollowingUser(f.Streamers)
|
|
if err != nil {
|
|
context.Error(err)
|
|
return
|
|
}
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
|
})
|
|
}
|