61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/loveuer/nf"
|
||
|
"github.com/loveuer/nfflow/internal/handler"
|
||
|
"github.com/loveuer/nfflow/internal/middleware/auth"
|
||
|
"github.com/loveuer/nfflow/internal/middleware/front"
|
||
|
"github.com/loveuer/nfflow/internal/middleware/oplog"
|
||
|
"github.com/loveuer/nfflow/internal/middleware/privilege"
|
||
|
"github.com/loveuer/nfflow/internal/model"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func initApp(ctx context.Context) *nf.App {
|
||
|
engine := nf.New(nf.Config{})
|
||
|
|
||
|
app := engine.Group("/api")
|
||
|
app.Get("/available", func(c *nf.Ctx) error {
|
||
|
return c.JSON(nf.Map{"status": 200, "ok": true, "time": time.Now()})
|
||
|
})
|
||
|
|
||
|
{
|
||
|
api := app.Group("/user")
|
||
|
api.Post("/auth/login", oplog.NewOpLog(ctx), handler.AuthLogin)
|
||
|
api.Get("/auth/login", auth.NewAuth(), handler.AuthVerify)
|
||
|
api.Post("/auth/logout", auth.NewAuth(), oplog.NewOpLog(ctx), handler.AuthLogout)
|
||
|
|
||
|
mng := api.Group("/manage")
|
||
|
mng.Use(auth.NewAuth(), privilege.Verify(
|
||
|
privilege.RelationAnd,
|
||
|
model.PrivilegeUserManage,
|
||
|
))
|
||
|
|
||
|
mng.Get("/user/list", handler.ManageUserList)
|
||
|
mng.Post("/user/create", oplog.NewOpLog(ctx), handler.ManageUserCreate)
|
||
|
mng.Post("/user/update", oplog.NewOpLog(ctx), handler.ManageUserUpdate)
|
||
|
mng.Post("/user/delete", oplog.NewOpLog(ctx), handler.ManageUserDelete)
|
||
|
}
|
||
|
|
||
|
{
|
||
|
api := app.Group("/log")
|
||
|
api.Use(auth.NewAuth(), privilege.Verify(privilege.RelationAnd, model.PrivilegeOpLog))
|
||
|
api.Get("/category/list", handler.LogCategories())
|
||
|
api.Get("/content/list", handler.LogList)
|
||
|
}
|
||
|
|
||
|
{
|
||
|
api := app.Group("/task")
|
||
|
|
||
|
api.Get("/list", handler.TaskList)
|
||
|
api.Post("/create", handler.TaskCreate)
|
||
|
api.Post("/input/create", handler.TaskInputCreate)
|
||
|
api.Post("/input/update", handler.TaskInputUpdate)
|
||
|
}
|
||
|
|
||
|
engine.Use(front.NewFront(&front.DefaultFront, "dist/front/browser"))
|
||
|
|
||
|
return engine
|
||
|
}
|