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",
|
||||
Long: `List all existing conversations in descending order of recent activity.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conversations, err := store.GetConversations()
|
||||
conversations, err := store.Conversations()
|
||||
if err != nil {
|
||||
fmt.Println("Could not fetch conversations.")
|
||||
return
|
||||
@ -64,7 +64,7 @@ var lsCmd = &cobra.Command{
|
||||
categorized := map[string][]string{}
|
||||
|
||||
for _, conversation := range conversations {
|
||||
lastMessage, err := store.GetLastMessage(&conversation)
|
||||
lastMessage, err := store.LastMessage(&conversation)
|
||||
if lastMessage == nil || err != nil {
|
||||
continue
|
||||
}
|
||||
@ -128,7 +128,7 @@ var viewCmd = &cobra.Command{
|
||||
Fatal("Conversation not found with short name: %s\n", shortName)
|
||||
}
|
||||
|
||||
messages, err := store.GetMessages(conversation)
|
||||
messages, err := store.Messages(conversation)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
func (s *Store) GetConversations() ([]Conversation, error) {
|
||||
func (s *Store) Conversations() ([]Conversation, error) {
|
||||
var conversations []Conversation
|
||||
err := s.db.Find(&conversations).Error
|
||||
return conversations, err
|
||||
@ -98,7 +98,7 @@ func (s *Store) GetConversations() ([]Conversation, error) {
|
||||
|
||||
func (s *Store) ConverstionShortNameCompletions(shortName string) []string {
|
||||
var completions []string
|
||||
conversations, _ := s.GetConversations() // ignore error for completions
|
||||
conversations, _ := s.Conversations() // ignore error for completions
|
||||
for _, conversation := range conversations {
|
||||
if shortName == "" || strings.HasPrefix(conversation.ShortName.String, shortName) {
|
||||
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
|
||||
}
|
||||
|
||||
func (s *Store) GetMessages(conversation *Conversation) ([]Message, error) {
|
||||
func (s *Store) Messages(conversation *Conversation) ([]Message, error) {
|
||||
var messages []Message
|
||||
err := s.db.Where("conversation_id = ?", conversation.ID).Find(&messages).Error
|
||||
return messages, err
|
||||
}
|
||||
|
||||
func (s *Store) GetLastMessage(conversation *Conversation) (*Message, error) {
|
||||
func (s *Store) LastMessage(conversation *Conversation) (*Message, error) {
|
||||
var message Message
|
||||
err := s.db.Where("conversation_id = ?", conversation.ID).Last(&message).Error
|
||||
return &message, err
|
||||
|
Loading…
Reference in New Issue
Block a user