article

package
v0.0.0-...-9c0a888 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	gorm.Model
	UserID  uint32 `json:"user_id" gorm:"not null"`
	Title   string `json:"title" gorm:"not null"`
	Content string `json:"content"`
}

Article corresponds to articles users can write

type Repository

type Repository interface {
	CreateArticle(article *Article) (*Article, error)
	GetUserArticles(userID uint32) (*[]Article, error)
	GetAllArticles() (*[]Article, error)
	GetArticlebyID(ID uint32) (*Article, error)
	DeleteArticle(ID uint32) (bool, error)
}

Repository interface for a layer of abstraction over the db functions

func NewDatabaseRepo

func NewDatabaseRepo(db *gorm.DB) Repository

NewDatabaseRepo adds a layer of abstraction so that everything in the interface Repository can be accessed only via the instance of this function

type Service

type Service interface {
	CreateArticle(article *Article) (*Article, error)
	GetUserArticles(userID uint32) (*[]Article, error)
	GetAllArticles() (*[]Article, error)
	GetArticleByID(ID uint32) (*Article, error)
	DeleteArticle(ID uint32) (bool, error)
}

Service is another abstraction over repository

func NewService

func NewService(r Repository) Service

NewService impl

Jump to

Keyboard shortcuts

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