Refactor menu processing logic to improve error handling and streamline argument management

- Simplified argument handling for the menu process by removing unnecessary checks and directly appending locale to args.
- Enhanced error handling by ensuring that the menu process is required and throwing exceptions with appropriate status codes.
- Refactored the processMenu function to utilize a handle for executing the menu process, improving clarity and error management.
This commit is contained in:
Max 2025-05-27 12:39:39 +08:00
parent b97933e357
commit c638d7e7c2

View file

@ -159,12 +159,11 @@ func exportAPI() error {
process = "yao.app.Menu"
args := []interface{}{}
if Setting.Menu.Process != "" {
if Setting.Menu.Args != nil {
args = Setting.Menu.Args
}
if Setting.Menu.Args != nil {
args = Setting.Menu.Args
}
args = append(args, "$query.locale")
path = api.Path{
Label: "App Menu",
Description: "App Menu",
@ -386,36 +385,21 @@ func processIcons(process *process.Process) interface{} {
func processMenu(p *process.Process) interface{} {
if Setting.Menu.Process != "" {
return process.
New(Setting.Menu.Process, p.Args...).
WithGlobal(p.Global).
WithSID(p.Sid).
Run()
if Setting.Menu.Process == "" {
exception.New("menu.process is required", 400).Throw()
}
args := map[string]interface{}{
"select": []string{"id", "name", "icon", "parent", "path", "blocks", "visible_menu"},
"withs": map[string]interface{}{
"children": map[string]interface{}{
"query": map[string]interface{}{
"select": []string{"id", "name", "icon", "parent", "path", "blocks", "visible_menu"},
},
},
},
"wheres": []map[string]interface{}{
{"column": "status", "value": "enabled"},
{"column": "parent", "op": "null"},
},
"limit": 200,
"orders": []map[string]interface{}{{"column": "rank", "option": "asc"}},
handle, err := process.Of(Setting.Menu.Process, p.Args...)
if err != nil {
exception.New(err.Error(), 400).Throw()
}
return process.
New("models.xiang.menu.get", args).
WithGlobal(p.Global).
WithSID(p.Sid).
Run()
err = handle.WithGlobal(p.Global).WithSID(p.Sid).Execute()
if err != nil {
exception.New(err.Error(), 500).Throw()
}
defer handle.Dispose()
return handle.Value()
}
func processSetting(process *process.Process) interface{} {