package app_user

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

type appUserIDReq struct {
	AppID  string `src:"path@app_id" desc:"应用ID"`
	UserID string `src:"path@user_id" desc:"用户ID"`
}

var _ = Router.Get("/{user_id}", "获取应用用户详情", getAppUser)

func getAppUser(x *vigo.X, req *appUserIDReq) (*models.AppUser, error) {
	appUser := &models.AppUser{}
	err := cfg.DB().Where("app_id = ? AND user_id = ?", req.AppID, req.UserID).First(appUser).Error
	if err != nil {
		return nil, vigo.NewError("app_user not found").WithCode(404)
	}

	return appUser, nil
}
