Skip to content

Commit

Permalink
fix: Posts not written to db
Browse files Browse the repository at this point in the history
The db writer channel was matching on reference pointers to the create
and delete post events, not the value type. The serve command was
changed to use value types for the channels as this is better practice.
  • Loading branch information
snorremd committed Oct 23, 2023
1 parent 3fa933a commit df5a4c5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions db/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (writer *Writer) Subscribe() {

case post := <-writer.postChan:
switch post := post.(type) {
case *models.CreatePostEvent:
case models.CreatePostEvent:
createPost(writer.db, post.Post)
case *models.DeletePostEvent:
case models.DeletePostEvent:
deletePost(writer.db, post.Post)
default:
log.Info("Unknown post type")
Expand All @@ -53,6 +53,9 @@ func (writer *Writer) Subscribe() {
}

func createPost(db *sql.DB, post models.Post) error {
log.WithFields(log.Fields{
"uri": post.Uri,
}).Info("Creating post")
// Post insert query
insertPost := sqlbuilder.NewInsertBuilder()
sql, args := insertPost.InsertInto("posts").Cols("uri", "created_at").Values(post.Uri, post.CreatedAt).Build()
Expand Down

0 comments on commit df5a4c5

Please sign in to comment.