Simplify query calls

This commit is contained in:
2022-10-18 16:20:58 +08:00
parent 35b303f796
commit a062e37a4c
2 changed files with 36 additions and 56 deletions

View File

@@ -45,6 +45,15 @@ func ( this QueryResult ) Message() ( string, error ) {
if this.Schedules == nil {
q := *this.Query
if len( *q.Results ) == 0 {
terms := make( []string, len(*q.SearchTerms), len(*q.SearchTerms) )
for i, term := range *q.SearchTerms {
terms[i] = term.Org
}
return "", fmt.Errorf( "Not Found: \"%s\"", strings.Join( terms, "\", \"" ) )
}
if q.Key == "" {
sort.Sort( query.ByKey( *q.Results ) )
for _, entry := range *q.Results {
@@ -53,7 +62,7 @@ func ( this QueryResult ) Message() ( string, error ) {
sb.WriteString( " " )
writeShortRoute( &this.Lang, &sb, busStop )
}
} else if 1 == len( *q.SearchTerms ) && 0 < len( *q.Results ) {
} else if 1 == len( *q.SearchTerms ) {
// Route listing
st := map[string] *BusStop{}
@@ -101,12 +110,6 @@ func ( this QueryResult ) Message() ( string, error ) {
sb.WriteString( "\n" )
}
} else if 1 < len( *q.SearchTerms ) && len( *q.Results ) == 0 {
terms := make( []string, len(*q.SearchTerms), len(*q.SearchTerms) )
for i, term := range *q.SearchTerms {
terms[i] = term.Org
}
return "", fmt.Errorf( "Not Found: \"%s\"", strings.Join( terms, "\", \"" ) )
} else {
return "", fmt.Errorf( "%s", "Unreachable condition occured!?" )
}