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:
parent
b97933e357
commit
c638d7e7c2
1 changed files with 15 additions and 31 deletions
|
|
@ -159,12 +159,11 @@ func exportAPI() error {
|
||||||
|
|
||||||
process = "yao.app.Menu"
|
process = "yao.app.Menu"
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
if Setting.Menu.Process != "" {
|
if Setting.Menu.Args != nil {
|
||||||
if Setting.Menu.Args != nil {
|
args = Setting.Menu.Args
|
||||||
args = Setting.Menu.Args
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args = append(args, "$query.locale")
|
||||||
path = api.Path{
|
path = api.Path{
|
||||||
Label: "App Menu",
|
Label: "App Menu",
|
||||||
Description: "App Menu",
|
Description: "App Menu",
|
||||||
|
|
@ -386,36 +385,21 @@ func processIcons(process *process.Process) interface{} {
|
||||||
|
|
||||||
func processMenu(p *process.Process) interface{} {
|
func processMenu(p *process.Process) interface{} {
|
||||||
|
|
||||||
if Setting.Menu.Process != "" {
|
if Setting.Menu.Process == "" {
|
||||||
|
exception.New("menu.process is required", 400).Throw()
|
||||||
return process.
|
|
||||||
New(Setting.Menu.Process, p.Args...).
|
|
||||||
WithGlobal(p.Global).
|
|
||||||
WithSID(p.Sid).
|
|
||||||
Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args := map[string]interface{}{
|
handle, err := process.Of(Setting.Menu.Process, p.Args...)
|
||||||
"select": []string{"id", "name", "icon", "parent", "path", "blocks", "visible_menu"},
|
if err != nil {
|
||||||
"withs": map[string]interface{}{
|
exception.New(err.Error(), 400).Throw()
|
||||||
"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"}},
|
|
||||||
}
|
}
|
||||||
return process.
|
|
||||||
New("models.xiang.menu.get", args).
|
err = handle.WithGlobal(p.Global).WithSID(p.Sid).Execute()
|
||||||
WithGlobal(p.Global).
|
if err != nil {
|
||||||
WithSID(p.Sid).
|
exception.New(err.Error(), 500).Throw()
|
||||||
Run()
|
}
|
||||||
|
defer handle.Dispose()
|
||||||
|
return handle.Value()
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSetting(process *process.Process) interface{} {
|
func processSetting(process *process.Process) interface{} {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue