database

package
v0.0.0-...-fb2c725 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DBContextKey contextKey = "db"

Variables

This section is empty.

Functions

func GetLazyPaginatedResponsePG

func GetLazyPaginatedResponsePG[V any](storage *PostgresqlStorage, r *http.Request, query string) ([]*V, error)

Types

type Book

type Book struct {
	ID              int       `json:"id" db:"id"`
	Title           string    `json:"title" db:"title"`
	Author          string    `json:"author" db:"author"`
	Genre           string    `json:"genre" db:"genre"`
	PublicationDate time.Time `json:"publicationDate" db:"publication_date"`
	Publisher       string    `json:"publisher" db:"publisher"`
	ISBN            string    `json:"isbn" db:"isbn"`
	PageCount       string    `json:"pageCount" db:"page_count"`
	Language        string    `json:"language" db:"language"`
	Format          string    `json:"format" db:"format"`
}

type BookReview

type BookReview struct {
	ID        int       `json:"id" db:"id"`
	BookID    int       `json:"book_id" db:"book_id"`
	UserID    int       `json:"user_id" db:"user_id"`
	Score     int       `json:"score" db:"score"`
	Review    string    `json:"review" db:"review"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

type CreateBookReviewDto

type CreateBookReviewDto struct {
	BookID int    `json:"bookId" db:"book_id" validate:"nonzero"`
	UserID int    `json:"userId" db:"user_id"`
	Score  int    `json:"score" db:"score" validate:"nonzero"`
	Review string `json:"review" db:"review" validate:"nonzero"`
}

type PostgresqlStorage

type PostgresqlStorage struct {
	// contains filtered or unexported fields
}

func GetPgStorageFromRequest

func GetPgStorageFromRequest(r *http.Request) (*PostgresqlStorage, error)

func NewPostgresStorage

func NewPostgresStorage() (*PostgresqlStorage, error)

func (*PostgresqlStorage) CreateBookReview

func (storage *PostgresqlStorage) CreateBookReview(createUserDto *CreateBookReviewDto) (*BookReview, error)

func (*PostgresqlStorage) CreateUser

func (storage *PostgresqlStorage) CreateUser(first_name, last_name, email, password string) (*User, error)

func (*PostgresqlStorage) DeleteBookById

func (storage *PostgresqlStorage) DeleteBookById(id int) error

func (*PostgresqlStorage) DeleteBookReviewById

func (storage *PostgresqlStorage) DeleteBookReviewById(id int) error

func (*PostgresqlStorage) DeleteUserById

func (storage *PostgresqlStorage) DeleteUserById(id int) error

func (*PostgresqlStorage) GetBookById

func (storage *PostgresqlStorage) GetBookById(id int) (*Book, error)

func (*PostgresqlStorage) GetBookReviewById

func (storage *PostgresqlStorage) GetBookReviewById(id int) (*BookReview, error)

func (*PostgresqlStorage) GetBookReviews

func (storage *PostgresqlStorage) GetBookReviews(r *http.Request) ([]*BookReview, error)

func (*PostgresqlStorage) GetBookReviewsByBookId

func (storage *PostgresqlStorage) GetBookReviewsByBookId(id int, r *http.Request) ([]*BookReview, error)

func (*PostgresqlStorage) GetBooks

func (storage *PostgresqlStorage) GetBooks(r *http.Request) ([]*Book, error)

func (*PostgresqlStorage) GetRoleById

func (storage *PostgresqlStorage) GetRoleById(id int) (*Role, error)

func (*PostgresqlStorage) GetUserByEmail

func (storage *PostgresqlStorage) GetUserByEmail(email string) (*User, error)

func (*PostgresqlStorage) GetUserById

func (storage *PostgresqlStorage) GetUserById(id int) (*User, error)

func (*PostgresqlStorage) GetUsers

func (storage *PostgresqlStorage) GetUsers(r *http.Request) ([]*User, error)

func (*PostgresqlStorage) UpdateBookById

func (storage *PostgresqlStorage) UpdateBookById(id int, payload *UpdateBookDto) (*Book, error)

func (*PostgresqlStorage) UpdateBookReview

func (storage *PostgresqlStorage) UpdateBookReview(id int, updateBookReviewDto UpdateBookReviewDto) (*BookReview, error)

func (*PostgresqlStorage) UpdateUserById

func (storage *PostgresqlStorage) UpdateUserById(id int, payload *UpdateUserDto) (*User, error)

func (*PostgresqlStorage) UpdateUserProfileImageUrl

func (storage *PostgresqlStorage) UpdateUserProfileImageUrl(id int, objectKey string) error

type Role

type Role struct {
	ID        int       `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

type Storage

type Storage interface {
	GetUsers(r *http.Request) ([]*User, error)
	GetUserById(int) (*User, error)
	GetUserByEmail(string) (*User, error)
	CreateUser(firstName, lastName, email, password string) (*User, error)
	DeleteUserById(int) error
	GetRoleById(int) (*Role, error)
	UpdateUserProfileImageUrl(id int, objectKey string) error

	// Books
	GetBooks(r *http.Request) ([]*Book, error)

	// Book Reviews
	GetBookReviews(r *http.Request) ([]*BookReview, error)
	GetBookReviewById(id int) (*BookReview, error)
	DeleteBookReviewById(id int) error
	UpdateBookReview(id int, updateBookReviewDto UpdateBookReviewDto) (*BookReview, error)
}

type UpdateBookDto

type UpdateBookDto struct {
	Title           string    `json:"title" validate:"nonzero" db:"title"`
	Author          string    `json:"author" validate:"nonzero" db:"author"`
	Genre           string    `json:"genre" validate:"nonzero" db:"genre"`
	PublicationDate time.Time `json:"publicationDate" validate:"nonzero" db:"publication_date"`
	Publisher       string    `json:"publisher" validate:"nonzero" db:"publisher"`
	ISBN            string    `json:"isbn" validate:"nonzero" db:"isbn"`
	PageCount       string    `json:"pageCount" validate:"nonzero" db:"page_count"`
	Language        string    `json:"language" validate:"nonzero" db:"language"`
	Format          string    `json:"format" validate:"nonzero" db:"format"`
}

type UpdateBookReviewDto

type UpdateBookReviewDto struct {
	Score     int       `json:"score" db:"score" validate:"nonzero"`
	Review    string    `json:"review" db:"review" validate:"nonzero"`
	UpdatedAt time.Time `db:"updated_at"`
}

type UpdateUserDto

type UpdateUserDto struct {
	ID        int    `json:"id" validate:"nonzero"`
	FirstName string `json:"firstName" validate:"nonzero"`
	LastName  string `json:"lastName" validate:"nonzero"`
	Email     string `json:"email" validate:"nonzero"`
}

type User

type User struct {
	ID              int       `json:"id" db:"id"`
	FirstName       string    `json:"first_name" db:"first_name"`
	LastName        string    `json:"last_name" db:"last_name"`
	Email           string    `json:"email" db:"email"`
	Password        string    `json:"password,omitempty" db:"password"`
	RoleId          int       `json:"role_id" db:"role_id"`
	ProfileImageUrl string    `json:"profile_image_url" db:"profile_image_url"`
	CreatedAt       time.Time `json:"created_at" db:"created_at"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL