This commit is contained in:
lbenedar
2026-03-17 18:13:51 +03:00
parent 639e75dd6c
commit 9dadd5d256
2 changed files with 21 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
"github.com/lib/pq"
)
type MovieModel struct {
@@ -22,7 +23,13 @@ type Movie struct {
}
func (m MovieModel) Insert(movie *Movie) error {
return nil
query := `
INSERT INTO movies (title, year, runtime, genres)
VALUES ($1, $2, $3, $4)
RETURNING id, created_at, version`
args := []any{movie.Title, movie.Year, movie.Runtime, pq.Array(movie.Genres)}
return m.DB.QueryRow(query, args...).Scan(&movie.ID, &movie.CreatedAt, &movie.Version)
}
func (m MovieModel) Get(id int64) (*Movie, error) {