data

package
v0.0.0-...-bf0f985 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllBikes

func GetAllBikes(db *gorm.DB, page string, perPage string) interface{}

GetAllBikes will return all the bikes with the pagination asked

func InitDB

func InitDB(config config.Config) *gorm.DB

InitDB will initialise the database connection and the scheme

Types

type Bike

type Bike struct {
	// add basic ID/Created@/Updated@/Delete@ through Gorm
	gorm.Model
	Name              string `gorm:"uniqueIndex:bike_uniqueness"`
	Brand             Brand
	BrandID           int    `json:"-" gorm:"uniqueIndex:bike_uniqueness"`
	Year              string `gorm:"uniqueIndex:bike_uniqueness"`
	Description       string
	Image             []Image              `gorm:"many2many:bike_images"`
	Components        []Component          `gorm:"many2many:bike_components;"`
	SupportedStandard []standards.Standard `gorm:"-"`
	PutNotSupported
}

Bike contains the defintion of the bike and all its attached components

func (Bike) Delete

func (Bike) Delete(db *gorm.DB, values url.Values, id int) (int, interface{})

Delete the bike on DB given an bike ID -int-

func (Bike) Get

func (Bike) Get(db *gorm.DB, values url.Values, id int) (int, interface{})

Get Bike will return the request bike struct

func (Bike) Post

func (Bike) Post(db *gorm.DB, values url.Values, request *http.Request, id int, adj string) (int, interface{})

Post Handle Post request from http

type Brand

type Brand struct {
	gorm.Model
	Name         string
	Description  string
	Image        int
	CreationYear int
	EndYear      int
	Country      string
	PutNotSupported
	DeleteNotSupported
}

Brand hold the brand defintion

func (Brand) Get

func (Brand) Get(db *gorm.DB, values url.Values, id int) (int, interface{})

Get will return the asked Brand

func (Brand) Post

func (Brand) Post(db *gorm.DB, values url.Values, request *http.Request, id int, adj string) (int, interface{})

Post will save the brand

type Component

type Component struct {
	// add basic ID/Created@/Updated@/Delete@ through Gorm
	gorm.Model
	Name        string `gorm:"uniqueIndex:component_uniqueness"`
	Brand       Brand
	BrandID     int `json:"-" gorm:"uniqueIndex:component_uniqueness"`
	Type        ComponentType
	TypeID      int `json:"-"`
	Description string
	Standards   []standards.Standard `gorm:"many2many:component_standards"`
	Images      []Image              `gorm:"many2many:component_images"`
	Year        string               `gorm:"uniqueIndex:component_uniqueness"`
	PutNotSupported
	DeleteNotSupported
}

Component : Generic struct to regroup most common properties

func (Component) Get

func (Component) Get(db *gorm.DB, values url.Values, id int) (int, interface{})

Get return a generic Component

func (Component) Post

func (Component) Post(db *gorm.DB, values url.Values, request *http.Request, id int, adj string) (int, interface{})

Post will save the component in database

type ComponentInt

type ComponentInt interface {
	GetName() string
	GetBrand() Brand
	GetType() ComponentType
	GetDescription() string
	GetStandards() []standards.StandardInt
	GetImages() []Image
}

ComponentInt : the standard COmponent interface that needs to complies to in order to be a component

type ComponentType

type ComponentType struct {
	gorm.Model
	Name        string
	Description string
}

ComponentType is the defintion of the type of bike component

type DeleteNotSupported

type DeleteNotSupported struct{}

DeleteNotSupported default response when you cannot Get the resource

func (DeleteNotSupported) Delete

func (DeleteNotSupported) Delete(db *gorm.DB, values url.Values, id int) (int, interface{})

Delete returns a 405

type GetNotSupported

type GetNotSupported struct{}

GetNotSupported default response when you cannot Get the resource

func (GetNotSupported) Get

func (GetNotSupported) Get(db *gorm.DB, values url.Values, id int) (int, interface{})

Get returns a 405

type Image

type Image struct {
	gorm.Model
	Name          string `gorm:"uniqueIndex:image_uniqueness"`
	Path          string `gorm:"uniqueIndex:image_uniqueness"`
	Type          string
	ContentType   string
	ContentLength int64
	Content       []byte `sql:"-"`
	PutNotSupported
	DeleteNotSupported
}

Image is the description and the pointer to the image

func (Image) Get

func (Image) Get(db *gorm.DB, values url.Values, id int) (int, interface{})

Get will return the image (content type is image/jpeg) TODO : make the content detection working

func (Image) Post

func (Image) Post(db *gorm.DB, values url.Values, request *http.Request, id int, adj string) (int, interface{})

Post saves the images to the "upload" directory (shouldn't it go to S3 ? )

type PostNotSupported

type PostNotSupported struct{}

PostNotSupported default response when you cannot Post the resource

func (PostNotSupported) Post

func (PostNotSupported) Post(db *gorm.DB, values url.Values, request *http.Request, id int, adj string) (int, interface{})

Post returns a 405

type PutNotSupported

type PutNotSupported struct{}

PutNotSupported default response when you cannot Get the resource

func (PutNotSupported) Put

func (PutNotSupported) Put(db *gorm.DB, values url.Values, body io.ReadCloser) (int, interface{})

Put returns a 405

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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