phoneof/adapters/messaging/db.go

30 lines
791 B
Go
Raw Normal View History

2025-01-05 18:16:26 -05:00
package messaging
import (
"database/sql"
"log"
"time"
"git.simponic.xyz/simponic/phoneof/database"
)
func PersistMessageContinuation(dbConn *sql.DB, frenId string, messageId string, sentAt time.Time, frenSent bool) Continuation {
return func(message Message) ContinuationChain {
log.Printf("persisting message %v %s %s %s %v", message, frenId, messageId, sentAt, frenSent)
return func(success Continuation, failure Continuation) ContinuationChain {
_, err := database.SaveMessage(dbConn, &database.Message{
Id: messageId,
FrenId: frenId,
Message: message.Message,
Time: sentAt,
FrenSent: frenSent,
})
if err != nil {
log.Printf("err when saving message %s", err)
return failure(message)
}
return success(message)
}
}
}