Updating movies.go with MovieModel: this struct is the gateway between our app and the database. Adding CRUD methods alongside for the Movie object. Creating models.go: this file holds a Models struct wrapping all of our Models. This way, we are able to use in our application struct in our main.go.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"greenlight.craftr.fr/internal/validator"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"greenlight.craftr.fr/internal/validator"
|
||||
)
|
||||
|
||||
// Movie
|
||||
@@ -41,3 +43,28 @@ func ValidateMovie(v *validator.Validator, movie *Movie) {
|
||||
// Not that we're using the Unique helper in the line below to check that all values in the input.Genres slice are unique
|
||||
v.Check(validator.Unique(movie.Genres), "genres", "must not contain duplicate values")
|
||||
}
|
||||
|
||||
// MovieModel struct type wraps a sql.DB connection pool
|
||||
type MovieModel struct {
|
||||
DB *sql.DB
|
||||
}
|
||||
|
||||
// Insert : Inserting a new record in the movies table
|
||||
func (m MovieModel) Insert(movie *Movie) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get : Fetching a specific record from the movies table
|
||||
func (m MovieModel) Get(id int64) (*Movie, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Update : Updating a specific record in the movies table
|
||||
func (m MovieModel) Update(movie *Movie) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete : Deleting a specific record from the movies table
|
||||
func (m MovieModel) Delete(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user