article

package
v0.0.0-...-4ff884c Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoutes

func NewRoutes(c Controller) router.Router

NewRoutes creates a router for Article and sets the endpoints

Types

type Article

type Article struct {
	ID        uint       `json:"id" gorm:"primary_key"`
	Title     string     `json:"title"`
	Content   string     `json:"content"`
	Author    string     `json:"author"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at,omitempty" sql:"index"`
}

Article represents the article entity's attributes.

func (*Article) Decode

func (a *Article) Decode(r *http.Request) error

type Controller

type Controller interface {
	// Create requests the received article to be stored
	Create(a *Article) error
	// List returns all the stored articles
	List() (*[]Article, error)
}

Controller defines the methods to be exposed in Controller layer

func NewController

func NewController(r Repository) Controller

NewController creates a new Controller with access to Repository methods

type MockController

type MockController struct {
	mock.Mock
}

MockController injects mock dependency into controller

func (*MockController) Create

func (m *MockController) Create(article *Article) error

Create represents the mocked method for Create feature in Controller layer

func (*MockController) List

func (m *MockController) List() (*[]Article, error)

List represents the mocked method for List feature in Controller layer

type MockRepository

type MockRepository struct {
	mock.Mock
}

MockRepository injects mock dependency into repository

func (*MockRepository) Create

func (m *MockRepository) Create(article *Article) error

Create represents the mocked method for Create feature in Repository layer

func (*MockRepository) List

func (m *MockRepository) List() (*[]Article, error)

List represents the mocked method for List feature in Repository layer

type Repository

type Repository interface {
	// Create inserts the article into the database
	Create(a *Article) error
	// List selects all articles from database
	List() (*[]Article, error)
}

Repository defines the methods to be exposed in Repository layer

func NewRepository

func NewRepository(db database.Driver) Repository

NewRepository creates a new Repository with access to database

Jump to

Keyboard shortcuts

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