user-favorite-menus_controller.go 2.0 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/service"
)

type UserFavoriteMenusController struct {
	beego.BaseController
}

func (controller *UserFavoriteMenusController) UpdateFavoriteMenus() {
	userService := service.NewUserService(nil)
	updateFavoriteMenusCommand := &command.UpdateFavoriteMenusCommand{}
	controller.Unmarshal(updateFavoriteMenusCommand)
	userId, _ := controller.GetInt64(":userId")
	updateFavoriteMenusCommand.UserId = userId
	data, err := userService.UpdateFavoriteMenus(updateFavoriteMenusCommand)
	controller.Response(data, err)
}

func (controller *UserFavoriteMenusController) GetFavoriteMenus() {
	userService := service.NewUserService(nil)
	getFavoriteMenusQuery := &query.GetFavoriteMenusQuery{}
	userId, _ := controller.GetInt64(":userId")
	getFavoriteMenusQuery.UserId = userId
	data, err := userService.GetFavoriteMenus(getFavoriteMenusQuery)
	controller.Response(data, err)
}

func (controller *UserFavoriteMenusController) DeleteFavoriteMenus() {
	userService := service.NewUserService(nil)
	deleteFavoriteMenusCommand := &command.DeleteFavoriteMenusCommand{}
	controller.Unmarshal(deleteFavoriteMenusCommand)
	userId, _ := controller.GetInt64(":userId")
	deleteFavoriteMenusCommand.UserId = userId
	code, _ := controller.GetInt(":code")
	deleteFavoriteMenusCommand.Code = code
	data, err := userService.DeleteFavoriteMenus(deleteFavoriteMenusCommand)
	controller.Response(data, err)
}

func (controller *UserFavoriteMenusController) UpdateFavorite() {
	userService := service.NewUserService(nil)
	updateFavoriteMenusCommand := &command.UpdateFavoriteCommand{}
	controller.Unmarshal(updateFavoriteMenusCommand)
	data, err := userService.UpdateFavorite(updateFavoriteMenusCommand)
	controller.Response(data, err)
}