Enhance mentions handling in Neo API
- Convert keywords to lowercase for case-insensitive matching in handleMentions method. - Introduce test data for mentions to improve testing and demonstration of functionality. - Implement filtering of mentions based on keywords, allowing users to retrieve relevant mentions more effectively. - Append test mentions to actual mentions before returning the response, enhancing the API's usability.
This commit is contained in:
parent
13e17ae386
commit
35168845ae
1 changed files with 37 additions and 1 deletions
38
neo/api.go
38
neo/api.go
|
|
@ -382,7 +382,7 @@ func (neo *DSL) handleMentions(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get keywords from query parameter
|
// Get keywords from query parameter
|
||||||
keywords := c.Query("keywords")
|
keywords := strings.ToLower(c.Query("keywords"))
|
||||||
mentions, err := neo.GetMentions(keywords)
|
mentions, err := neo.GetMentions(keywords)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(500, gin.H{"message": err.Error(), "code": 500})
|
c.JSON(500, gin.H{"message": err.Error(), "code": 500})
|
||||||
|
|
@ -390,6 +390,42 @@ func (neo *DSL) handleMentions(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add test data
|
||||||
|
testMentions := []Mention{
|
||||||
|
{
|
||||||
|
ID: "assistant_1",
|
||||||
|
Name: "Alice AI",
|
||||||
|
Type: "assistant",
|
||||||
|
Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Alice",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "assistant_2",
|
||||||
|
Name: "Bob Bot",
|
||||||
|
Type: "assistant",
|
||||||
|
Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Bob",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "assistant_3",
|
||||||
|
Name: "Carol AI",
|
||||||
|
Type: "assistant",
|
||||||
|
Avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=Carol",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter mentions by keywords
|
||||||
|
if keywords != "" {
|
||||||
|
filtered := []Mention{}
|
||||||
|
for _, m := range testMentions {
|
||||||
|
if strings.Contains(strings.ToLower(m.Name), keywords) {
|
||||||
|
filtered = append(filtered, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testMentions = filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append test data to actual mentions
|
||||||
|
mentions = append(mentions, testMentions...)
|
||||||
|
|
||||||
c.JSON(200, map[string]interface{}{"data": mentions})
|
c.JSON(200, map[string]interface{}{"data": mentions})
|
||||||
c.Done()
|
c.Done()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue