feat: now child posts created without updated_at

This commit is contained in:
Yanislav Igonin 2021-11-20 19:01:54 +02:00
parent 9e8e860cf5
commit e15aa86ad8

View File

@ -2,7 +2,9 @@ package repositories
import ( import (
"context" "context"
Config "micrach/config"
Db "micrach/db" Db "micrach/db"
"time"
"github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4"
) )
@ -80,19 +82,19 @@ func (r *PostsRepository) GetCount() (int, error) {
func (r *PostsRepository) Create(p Post) (int, error) { func (r *PostsRepository) Create(p Post) (int, error) {
sql := ` sql := `
INSERT INTO posts (is_parent, parent_id, title, text, is_sage) INSERT INTO posts (is_parent, parent_id, title, text, is_sage, updated_at)
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id RETURNING id
` `
var row pgx.Row var row pgx.Row
if p.IsParent { if p.IsParent {
row = Db.Pool.QueryRow( row = Db.Pool.QueryRow(
context.TODO(), sql, p.IsParent, nil, p.Title, p.Text, p.IsSage, context.TODO(), sql, p.IsParent, nil, p.Title, p.Text, p.IsSage, time.Now(),
) )
} else { } else {
row = Db.Pool.QueryRow( row = Db.Pool.QueryRow(
context.TODO(), sql, p.IsParent, p.ParentID, p.Title, p.Text, p.IsSage, context.TODO(), sql, p.IsParent, p.ParentID, p.Title, p.Text, p.IsSage, nil,
) )
} }
@ -166,19 +168,19 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) {
func (r *PostsRepository) CreateInTx(tx pgx.Tx, p Post) (int, error) { func (r *PostsRepository) CreateInTx(tx pgx.Tx, p Post) (int, error) {
sql := ` sql := `
INSERT INTO posts (is_parent, parent_id, title, text, is_sage) INSERT INTO posts (is_parent, parent_id, title, text, is_sage, updated_at)
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id RETURNING id
` `
var row pgx.Row var row pgx.Row
if p.IsParent { if p.IsParent {
row = tx.QueryRow( row = tx.QueryRow(
context.TODO(), sql, p.IsParent, nil, p.Title, p.Text, p.IsSage, context.TODO(), sql, p.IsParent, nil, p.Title, p.Text, p.IsSage, time.Now(),
) )
} else { } else {
row = tx.QueryRow( row = tx.QueryRow(
context.TODO(), sql, p.IsParent, p.ParentID, p.Title, p.Text, p.IsSage, context.TODO(), sql, p.IsParent, p.ParentID, p.Title, p.Text, p.IsSage, nil,
) )
} }