//
// get.go
// Copyright (C) 2024 veypi <i@veypi.com>
// Distributed under terms of the MIT license.
//

package access

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

type getIDReq struct {
	ID string `src:"path@id" desc:"记录ID"`
}

var _ = Router.Get("/{id}", "获取访问权限详情", getAccess)

func getAccess(x *vigo.X, req *getIDReq) (*models.Access, error) {
	// 查询数据库
	var access models.Access
	err := cfg.DB().Where("id = ?", req.ID).First(&access).Error
	if err != nil {
		return nil, vigo.NewError("未找到资源").WithCode(404)
	}

	return &access, nil
}
