/*
 * @description: 路由配置
 * @Author: CP
 * @Date: 2020-08-23 21:32:54
 * @FilePath: \design_quantity\web\routes\routes.go
 */
package routes

import (
	"github.com/kataras/iris/v12/mvc"
	"go.mod/bootstrap"
	"go.mod/services"
	"go.mod/web/api"
	"go.mod/web/middleware"
)

func Configure(b *bootstrap.Bootstrapper) {
	//service加载
	ProjectAccountService := services.NewProjectAccountService()
	LoginService := services.NewLoginService()
	ContractService := services.NewContractService()

	//CSRF相关
	//  b.Use(middleware.SetCsrf)

	//b.Party("/", protect)
	//protect := NewCsrf()

	// apiTree.Router.Use(middleware.JwtAuth().Serve)
	// 接口相关
	// 登陆接口
	apiLogin := mvc.New(b.Party("/api/login"))
	apiLogin.Register(LoginService)
	apiLogin.Handle(new(api.LoginApi))

	// 项目账号相关接口
	apiProjectAccount := mvc.New(b.Party("/api/projectAccount"))
	apiProjectAccount.Router.Use(middleware.JwtAuth().Serve)
	apiProjectAccount.Register(ProjectAccountService)
	apiProjectAccount.Handle(new(api.ProjectAccountApi))

	// 合同管理
	apiContract := mvc.New(b.Party("/api/contract"))
	apiContract.Router.Use(middleware.SessionsAuth)
	apiContract.Register(ContractService)
	// 中间件
	apiContract.Handle(new(api.ContractApi))

	apiUpload := mvc.New(b.Party("/api/upload"))
	apiUpload.Register(ContractService)
	apiUpload.Handle(new(api.UploadApi))

	// oss相关
	apiOss := mvc.New(b.Party("/api/oss"))
	apiOss.Handle(new(api.OssApi))

}
