planet

package module
v0.0.0-...-d438797 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 4 Imported by: 0

README

Test codecov CodeFactor

🌎 The planets api 🪐

The planets API was made to manage planets, here you can create, find, list, and delete planets.

Application architecture

This project was divided into three applications:

  • command-api: Responsible only for writing to the database.
  • processor: Responsible for processing the planets created async.
  • query-api: Responsible for reading the planets.

planet_architecture

Requirements to run:
  • 🐳 Docker compose
  • Go
  • Postman
  • 🐂 GNU Make
How to run?
  • Run docker-compose up command inside the project folder.
  • Run make run-command-api to start the command server.
  • Run make run-processor to start the processor server.
  • Run make run-query-api to start the query server.

The postman link to see the API documentation.

How to run tests?
  • Run docker-compose up command inside the project folder.
  • Run make run-test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknown = Error{
		Code:    "PNT-001",
		Message: "There was an unknown error processing your request.",
	}
	ErrDecodeRequest = Error{
		Code:    "PNT-002",
		Message: "There was unable to decode your request.",
	}
	ErrPlanetIDEmpty = Error{
		Code:    "PNT-003",
		Message: "The PlanetID must not be empty.",
	}
	ErrPlanetAlreadyProcessed = Error{
		Code:    "PNT-004",
		Message: "The planet has already been processed.",
	}
)

Functions

This section is empty.

Types

type CreatePlanetCommand

type CreatePlanetCommand struct {
	Name    string `json:"name"`
	Climate string `json:"climate"`
	Terrain string `json:"terrain"`
}

func (*CreatePlanetCommand) Validate

func (c *CreatePlanetCommand) Validate() map[string]string

type CreatePlanetEvent

type CreatePlanetEvent struct {
	PlanetID   ID  `json:"planet_id"`
	RetryCount int `json:"retry_count"`
}

type Deleter

type Deleter interface {
	Delete(id ID) error
}

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (Error) Error

func (e Error) Error() string

type EventProcessor

type EventProcessor interface {
	Process(data interface{}) error
}

type EventType

type EventType int
const CreatedEvent EventType = iota

func (EventType) String

func (e EventType) String() string

type EventsProcessor

type EventsProcessor map[string]EventProcessor

type Film

type Film struct {
	Title       string    `bson:"title" json:"title"`
	ReleaseDate time.Time `bson:"release_date" json:"release_date"`
}

type Films

type Films []Film

type HttpHandler

type HttpHandler interface {
	Handle(c *gin.Context)
}

type ID

type ID string

type KafkaRead

type KafkaRead interface {
	Read()
}

type KafkaWriter

type KafkaWriter interface {
	Write(topic string, eventType EventType, msg []byte) error
}

type Metadata

type Metadata struct {
	Page       int `json:"page"`
	PerPage    int `json:"per_page"`
	PageCount  int `json:"page_count"`
	TotalCount int `json:"total_count"`
}

type PageFilterRequest

type PageFilterRequest struct {
	Name    string `form:"name"`
	Page    int    `form:"page"`
	PerPage int    `form:"per_page"`
}

func (*PageFilterRequest) Validate

func (p *PageFilterRequest) Validate() map[string]string

type Pagination

type Pagination struct {
	Meta    Metadata    `json:"_metadata"`
	Results interface{} `json:"results"`
}

type PlanetDocument

type PlanetDocument struct {
	PlanetID       ID       `bson:"planetID" json:"planet_id"`
	Name           string   `bson:"name" json:"name"`
	Climate        []string `bson:"climate" json:"climate"`
	Terrain        []string `bson:"terrain" json:"terrain"`
	Films          Films    `bson:"films" json:"films"`
	Status         string   `bson:"status" json:"status"`
	mgm.IDField    `bson:" ,inline" json:"-"`
	mgm.DateFields `bson:" ,inline"`
}

type ReadUpdater

type ReadUpdater interface {
	Reader
	Updater
}

type Reader

type Reader interface {
	ReadByPlanetId(id ID) (PlanetDocument, error)
	ReadAll(filter PageFilterRequest) ([]PlanetDocument, error)
	Count() (int, error)
}

type StateResponse

type StateResponse struct {
	PlanetID ID     `json:"planet_id"`
	Status   string `json:"status"`
}

type Status

type Status int
const (
	Processing Status = iota
	Processed
	Failed
)

func (Status) String

func (p Status) String() string

type Updater

type Updater interface {
	Update(planet PlanetDocument) error
}

type Writer

type Writer interface {
	Write(createPlanet CreatePlanetCommand) (PlanetDocument, error)
}

Directories

Path Synopsis
cmd
database
internal
slice

Jump to

Keyboard shortcuts

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