This commit is contained in:
lbenedar
2026-03-17 17:58:22 +03:00
parent 850c006d46
commit 639e75dd6c
3 changed files with 73 additions and 0 deletions

31
internal/data/models.go Normal file
View File

@@ -0,0 +1,31 @@
package data
import (
"database/sql"
"errors"
)
var (
ErrRecordNotFound = errors.New("record not found")
)
type Models struct {
Movies interface {
Insert(movie *Movie) error
Get(id int64) (*Movie, error)
Update(movie *Movie) error
Delete(id int64) error
}
}
func NewModels(db *sql.DB) Models {
return Models{
Movies: MovieModel{DB: db},
}
}
func NewMockModels() Models {
return Models{
Movies: MockMovieModel{},
}
}

View File

@@ -1,11 +1,16 @@
package data
import (
"database/sql"
"time"
"gitea.local.lab/Lbenedar/greenlight/internal/validator"
)
type MovieModel struct {
DB *sql.DB
}
type Movie struct {
ID int64 `json:"id"`
CreatedAt time.Time `json:"-"`
@@ -16,6 +21,40 @@ type Movie struct {
Version int32 `json:"version"`
}
func (m MovieModel) Insert(movie *Movie) error {
return nil
}
func (m MovieModel) Get(id int64) (*Movie, error) {
return nil, nil
}
func (m MovieModel) Update(movie *Movie) error {
return nil
}
func (m MovieModel) Delete(id int64) error {
return nil
}
type MockMovieModel struct{}
func (m MockMovieModel) Insert(movie *Movie) error {
return nil
}
func (m MockMovieModel) Get(id int64) (*Movie, error) {
return nil, nil
}
func (m MockMovieModel) Update(movie *Movie) error {
return nil
}
func (m MockMovieModel) Delete(id int64) error {
return nil
}
func ValidateMovie(v *validator.Validator, movie *Movie) {
v.Check(movie.Title != "", "title", "must be provided")
v.Check(len(movie.Title) <= 500, "title", "must not be more than 500 bytes long")