repository

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Post

type Post struct {
	ID        uint   `gorm:"primaryKey;autoIncrement"`
	URLHandle string `gorm:"unique;not null"`
	AuthorID  uint   `gorm:"not null"`
	Author    User
	Title     string
	Summary   string
	Body      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Post DB schema

type PostRepository

type PostRepository interface {
	AddPost(post *types.Post, author *User) (*Post, error)
	GetPost(urlHandle string) (*Post, error)
	GetPosts() ([]Post, error)
}

PostRepository interface defining post-related database operations.

func CreatePostRepository

func CreatePostRepository(logger *zap.SugaredLogger, repository Repository) PostRepository

CreatePostRepository instantiates the postRepository

type Repository

type Repository interface {
	Select(query interface{}, args ...interface{}) *gorm.DB
	Find(out interface{}, where ...interface{}) *gorm.DB
	Create(value interface{}) *gorm.DB
	Updates(value interface{}) *gorm.DB
	Delete(value interface{}) *gorm.DB
	Where(query interface{}, args ...interface{}) *gorm.DB
	Preload(column string, conditions ...interface{}) *gorm.DB
	Close() error
	AutoMigrate(value interface{}) error
}

Repository defines the database access layer

func CreateRepository

func CreateRepository() Repository

CreateRepository established a DB connection and returns the repository. If, for some reason, the DB connection fails, the error is logged and the application terminates.

type User

type User struct {
	ID           uint   `gorm:"primaryKey;autoIncrement"`
	UserName     string `gorm:"unique;not null"`
	PasswordHash string `gorm:"not null"`
	Posts        []Post `gorm:"foreignKey:AuthorID"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

User DB schema

type UserRepository

type UserRepository interface {
	AddUser(user *types.User) (*User, error)
	GetUser(userName string) (*User, error)
	GetUsers() ([]User, error)
	UpdateUser(user *types.User) (*User, error)
}

UserRepository interface defining user-related database operations.

func CreateUserRepository

func CreateUserRepository(logger *zap.SugaredLogger, repository Repository) UserRepository

CreateUserRepository instantiates the userRepository using the logger and the global repository.

Jump to

Keyboard shortcuts

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