2023-05-18 10:17:08 -04:00
|
|
|
package users
|
|
|
|
|
|
|
|
import (
|
2023-05-20 16:30:12 -04:00
|
|
|
"safetwitch-backend/extractor"
|
2023-05-29 22:18:04 -04:00
|
|
|
"safetwitch-backend/extractor/twitch"
|
2023-05-20 16:30:12 -04:00
|
|
|
|
2023-05-18 10:17:08 -04:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Routes(route *gin.Engine) {
|
2023-05-26 10:17:55 -04:00
|
|
|
auth := route.Group("/api/users")
|
2023-05-18 10:17:08 -04:00
|
|
|
|
2023-05-20 16:30:12 -04:00
|
|
|
auth.GET("/:streamerName", func(context *gin.Context) {
|
2023-05-29 22:18:04 -04:00
|
|
|
data, err := twitch.GetStreamerInfo(context.Param("streamerName"))
|
2023-05-20 22:18:10 -04:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() == "streamer not found" {
|
|
|
|
context.JSON(404, gin.H{
|
|
|
|
"status": "error",
|
|
|
|
"message": "streamer not found",
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
context.Error(err)
|
|
|
|
}
|
2023-05-22 18:11:42 -04:00
|
|
|
return
|
2023-05-20 22:18:10 -04:00
|
|
|
}
|
2023-05-22 18:11:42 -04:00
|
|
|
|
|
|
|
context.JSON(200, extractor.FormatMessage(data, true))
|
2023-05-18 10:17:08 -04:00
|
|
|
})
|
|
|
|
}
|