add v1 GET endpoints

This commit is contained in:
Stanislaw
2022-12-25 23:14:45 +01:00
parent 3f17d6e985
commit 92ece902f7
12 changed files with 258 additions and 33 deletions

View File

@@ -1,6 +1,10 @@
package router
import "github.com/gin-gonic/gin"
import (
v1 "gractwo-api/router/v1"
"github.com/gin-gonic/gin"
)
//docs "github.com/go-project-name/docs"
@@ -13,8 +17,9 @@ func InitRouter() *gin.Engine {
apiv1 := r.Group("/api/v1")
apiv1.Use()
{
r.GET("./", )
apiv1.GET("/admincards", v1.GetAdminCards)
apiv1.GET("/images", v1.GetImages)
apiv1.GET("/splash", v1.GetSplash)
}
return r
}

16
router/v1/admincard.go Normal file
View File

@@ -0,0 +1,16 @@
package v1
import (
"gractwo-api/database"
"github.com/gin-gonic/gin"
)
func GetAdminCards(c *gin.Context) {
var AdminCardList []database.Admincard
err := database.DB.Find(&AdminCardList).Error
if err != nil {
c.JSON(404, "Not found")
}
c.JSON(200, AdminCardList)
}

16
router/v1/image.go Normal file
View File

@@ -0,0 +1,16 @@
package v1
import (
"gractwo-api/database"
"github.com/gin-gonic/gin"
)
func GetImages(c *gin.Context){
var ImageList []database.Image
err :=database.DB.Find(&ImageList).Error
if err != nil {
c.JSON(404, "Not found")
}
c.JSON(200, ImageList)
}

17
router/v1/splash.go Normal file
View File

@@ -0,0 +1,17 @@
package v1
import (
"gractwo-api/database"
"math/rand"
"github.com/gin-gonic/gin"
)
func GetSplash(c *gin.Context) {
var SplashList []database.Splash
err := database.DB.Find(&SplashList).Error
if err != nil {
c.JSON(404, "Not found")
}
c.JSON(200, SplashList[rand.Intn(len(SplashList)-1-0+1)+0])
}