2022-11-05 07:13:58 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2022-11-05 11:18:12 -07:00
|
|
|
"net/http"
|
2022-11-05 07:13:58 -07:00
|
|
|
|
2022-11-05 11:18:12 -07:00
|
|
|
"github.com/labstack/echo/v5"
|
2022-11-05 07:13:58 -07:00
|
|
|
"github.com/pocketbase/pocketbase"
|
2022-11-05 11:18:12 -07:00
|
|
|
"github.com/pocketbase/pocketbase/core"
|
|
|
|
"github.com/pocketbase/pocketbase/models"
|
2022-11-05 07:13:58 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := pocketbase.New()
|
|
|
|
|
2022-11-05 11:18:12 -07:00
|
|
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
|
|
|
e.Router.AddRoute(echo.Route{
|
|
|
|
Method: http.MethodGet,
|
|
|
|
Path: "/api/custom/tunes/byTuneId/:tuneId",
|
|
|
|
Handler: func(c echo.Context) error {
|
|
|
|
record, _err := app.Dao().FindFirstRecordByData("tunes", "tuneId", c.PathParam("tuneId"))
|
|
|
|
|
|
|
|
if _err != nil {
|
|
|
|
return c.JSON(http.StatusNotFound, _err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_errors := app.Dao().ExpandRecord(record, []string{"author"}, func(relCollection *models.Collection, relIds []string) ([]*models.Record, error) {
|
|
|
|
record, _err := app.Dao().FindFirstRecordByData(relCollection.Name, "id", relIds[0])
|
|
|
|
|
|
|
|
return []*models.Record{record}, _err
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(_errors) > 0 {
|
|
|
|
return c.JSON(http.StatusNotFound, _errors)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, record)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
e.Router.AddRoute(echo.Route{
|
|
|
|
Method: http.MethodGet,
|
|
|
|
Path: "/api/custom/iniFiles/bySignature/:signature",
|
|
|
|
Handler: func(c echo.Context) error {
|
|
|
|
record, _err := app.Dao().FindFirstRecordByData("iniFiles", "signature", c.PathParam("signature"))
|
|
|
|
|
|
|
|
if _err != nil {
|
|
|
|
return c.JSON(http.StatusNotFound, _err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(http.StatusOK, record)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2022-11-05 07:13:58 -07:00
|
|
|
if err := app.Start(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|