Remove Get prefix from Store methods
It feels better this way (and to the rest of Go, apparently)
This commit is contained in:
parent
b87c3ffc53
commit
4e3976fc73
@ -25,7 +25,7 @@ var lsCmd = &cobra.Command{
|
|||||||
Short: "List existing conversations",
|
Short: "List existing conversations",
|
||||||
Long: `List all existing conversations in descending order of recent activity.`,
|
Long: `List all existing conversations in descending order of recent activity.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
conversations, err := store.GetConversations()
|
conversations, err := store.Conversations()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Could not fetch conversations.")
|
fmt.Println("Could not fetch conversations.")
|
||||||
return
|
return
|
||||||
@ -64,7 +64,7 @@ var lsCmd = &cobra.Command{
|
|||||||
categorized := map[string][]string{}
|
categorized := map[string][]string{}
|
||||||
|
|
||||||
for _, conversation := range conversations {
|
for _, conversation := range conversations {
|
||||||
lastMessage, err := store.GetLastMessage(&conversation)
|
lastMessage, err := store.LastMessage(&conversation)
|
||||||
if lastMessage == nil || err != nil {
|
if lastMessage == nil || err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ var viewCmd = &cobra.Command{
|
|||||||
Fatal("Conversation not found with short name: %s\n", shortName)
|
Fatal("Conversation not found with short name: %s\n", shortName)
|
||||||
}
|
}
|
||||||
|
|
||||||
messages, err := store.GetMessages(conversation)
|
messages, err := store.Messages(conversation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Could not retrieve messages for conversation: %s\n", conversation.Title)
|
Fatal("Could not retrieve messages for conversation: %s\n", conversation.Title)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (s *Store) SaveMessage(message *Message) error {
|
|||||||
return s.db.Create(message).Error
|
return s.db.Create(message).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetConversations() ([]Conversation, error) {
|
func (s *Store) Conversations() ([]Conversation, error) {
|
||||||
var conversations []Conversation
|
var conversations []Conversation
|
||||||
err := s.db.Find(&conversations).Error
|
err := s.db.Find(&conversations).Error
|
||||||
return conversations, err
|
return conversations, err
|
||||||
@ -98,7 +98,7 @@ func (s *Store) GetConversations() ([]Conversation, error) {
|
|||||||
|
|
||||||
func (s *Store) ConverstionShortNameCompletions(shortName string) []string {
|
func (s *Store) ConverstionShortNameCompletions(shortName string) []string {
|
||||||
var completions []string
|
var completions []string
|
||||||
conversations, _ := s.GetConversations() // ignore error for completions
|
conversations, _ := s.Conversations() // ignore error for completions
|
||||||
for _, conversation := range conversations {
|
for _, conversation := range conversations {
|
||||||
if shortName == "" || strings.HasPrefix(conversation.ShortName.String, shortName) {
|
if shortName == "" || strings.HasPrefix(conversation.ShortName.String, shortName) {
|
||||||
completions = append(completions, fmt.Sprintf("%s\t%s", conversation.ShortName.String, conversation.Title))
|
completions = append(completions, fmt.Sprintf("%s\t%s", conversation.ShortName.String, conversation.Title))
|
||||||
@ -113,13 +113,13 @@ func (s *Store) ConversationByShortName(shortName string) (*Conversation, error)
|
|||||||
return &conversation, err
|
return &conversation, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetMessages(conversation *Conversation) ([]Message, error) {
|
func (s *Store) Messages(conversation *Conversation) ([]Message, error) {
|
||||||
var messages []Message
|
var messages []Message
|
||||||
err := s.db.Where("conversation_id = ?", conversation.ID).Find(&messages).Error
|
err := s.db.Where("conversation_id = ?", conversation.ID).Find(&messages).Error
|
||||||
return messages, err
|
return messages, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetLastMessage(conversation *Conversation) (*Message, error) {
|
func (s *Store) LastMessage(conversation *Conversation) (*Message, error) {
|
||||||
var message Message
|
var message Message
|
||||||
err := s.db.Where("conversation_id = ?", conversation.ID).Last(&message).Error
|
err := s.db.Where("conversation_id = ?", conversation.ID).Last(&message).Error
|
||||||
return &message, err
|
return &message, err
|
||||||
|
Loading…
Reference in New Issue
Block a user