candidate

package
v0.0.0-...-537b99d Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBSON

func GetBSON(entity *Candidate) *bson.D

GetBSON converts a candidate in to BSON type

Types

type Address

type Address struct {
	ID               string      `json:"id" gorm:"column:id,primary_key" validate:"required"`
	FormattedAddress string      `json:"formatted_address" gorm:"column:formatted_address" validate:"required"`
	Lat              string      `json:"lat" gorm:"column:lat" validate:"required"`
	Lng              string      `json:"lng" gorm:"column:lng" validate:"required"`
	City             string      `json:"city" gorm:"column:city" validate:"required"`
	Country          string      `json:"country" gorm:"column:country" validate:"required"`
	PinCode          string      `json:"pin_code" gorm:"column:pin_code" validate:"required"`
	Type             AddressType `json:"type" gorm:"column:type" validate:"required"`
	CandidateID      string
	CreatedAt        time.Time
	UpdatedAt        time.Time
	DeletedAt        *time.Time
}

Address represents address of a candidate

func (Address) TableName

func (Address) TableName() string

TableName to ensure table names are predictable

type AddressType

type AddressType string

AddressType represents address type of a candidate

type Candidate

type Candidate struct {
	ID         string     `json:"id" gorm:"column:id,primary_key" validate:"required"`
	Name       string     `json:"name" gorm:"column:name" validate:"required"`
	Age        int        `json:"age" gorm:"column:age" validate:"gte=0,lte=130"`
	RollNumber string     `json:"roll_number" gorm:"column:roll_number" validate:"required"`
	Email      string     `json:"email" gorm:"column:email" validate:"required"`
	Mobile     string     `json:"mobile" gorm:"column:mobile" validate:"required"`
	Address    []*Address `json:"address" gorm:"ForeignKey:CandidateID,PRELOAD:true" validate:"required"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
	DeletedAt  *time.Time
}

Candidate holds candidate details along with who columns

func (Candidate) TableName

func (Candidate) TableName() string

TableName to ensure table names are predictable

type DBContext

type DBContext struct {
	DB *gorm.DB
}

func NewSQLDBContext

func NewSQLDBContext(dialect string, dbName string) (*DBContext, error)

func (*DBContext) CreateCandidate

func (ctx *DBContext) CreateCandidate(fCtx *commons.FlowContext, candidate *Candidate) (*Candidate, error)

func (*DBContext) DeleteCandidate

func (ctx *DBContext) DeleteCandidate(f *commons.FlowContext, cid string) (*Candidate, error)

func (*DBContext) GetCandidate

func (ctx *DBContext) GetCandidate(f *commons.FlowContext, cid string) (*Candidate, error)

func (*DBContext) ListCandidates

func (ctx *DBContext) ListCandidates(f *commons.FlowContext, limit int, offset int) (*[]Candidate, error)

func (*DBContext) SafeClose

func (ctx *DBContext) SafeClose()

func (*DBContext) UpdateCandidate

func (ctx *DBContext) UpdateCandidate(f *commons.FlowContext, cid string, entity *Candidate) (string, error)

type MongoDBContext

type MongoDBContext struct {
	DB *mongo.Client
}

MongoDBContext holds db object

func NewCandidateMongoDBContext

func NewCandidateMongoDBContext(url string) (*MongoDBContext, error)

NewCandidateMongoDBContext creates repo object

func (*MongoDBContext) CreateCandidate

func (ctx *MongoDBContext) CreateCandidate(fCtx *commons.FlowContext, candidate *Candidate) (*Candidate, error)

CreateCandidate inserts a candidate in db

func (*MongoDBContext) DeleteCandidate

func (ctx *MongoDBContext) DeleteCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)

DeleteCandidate deletes candidate in db by candidate id

func (*MongoDBContext) GetCandidate

func (ctx *MongoDBContext) GetCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)

TODO: make it efficient, current implementation is very hacky GetCandidate gets candidates from db

func (*MongoDBContext) ListCandidates

func (ctx *MongoDBContext) ListCandidates(fCtx *commons.FlowContext, limit int, offset int) (*[]Candidate, error)

ListCandidates gets candidates from db

func (*MongoDBContext) SafeClose

func (ctx *MongoDBContext) SafeClose()

SafeClose gets called when program terminates

func (*MongoDBContext) UpdateCandidate

func (ctx *MongoDBContext) UpdateCandidate(fCtx *commons.FlowContext, cid string, entity *Candidate) (string, error)

UpdateCandidate updates candidate in db by candidate id

type RedisContext

type RedisContext struct {
	DB *redis.Pool
}

RedisContext holds redis db object

func NewCandidateRedisContext

func NewCandidateRedisContext(address string, password string, dbName string) (*RedisContext, error)

NewCandidateRedisContext creates Redis context for candidate

func (*RedisContext) CreateCandidate

func (ctx *RedisContext) CreateCandidate(candidate *Candidate) (*Candidate, error)

CreateCandidate create candidate in redis

func (*RedisContext) DeleteCandidate

func (ctx *RedisContext) DeleteCandidate(cid string) (*Candidate, error)

DeleteCandidate delete candidate by id

func (*RedisContext) GetCandidate

func (ctx *RedisContext) GetCandidate(cid string) (*Candidate, error)

GetCandidate get candidate by id TODO: make it efficient, current implementation is very hacky

func (*RedisContext) ListCandidates

func (ctx *RedisContext) ListCandidates(limit int64, offset int64) (*[]Candidate, error)

ListCandidates list all candidates from redis

func (*RedisContext) SafeClose

func (ctx *RedisContext) SafeClose()

SafeClose gets called on program termination

func (*RedisContext) UpdateCandidate

func (ctx *RedisContext) UpdateCandidate(cid string, key string, value string) (string, error)

UpdateCandidate update candidate

type ResourceContext

type ResourceContext struct {
	CandidateService ServiceContext
}

func NewCandidateResource

func NewCandidateResource() *ResourceContext

func (*ResourceContext) CreateCandidate

func (ctx *ResourceContext) CreateCandidate(w http.ResponseWriter, r *http.Request)

@Summary Create Candidate @Tags Candidate @Param candidate body models.Candidate true "Create Candidate" @Success 200 {object} models.Response @Failure 400 {object} models.Response @Router /candidates [post]

func (*ResourceContext) DeleteCandidate

func (ctx *ResourceContext) DeleteCandidate(w http.ResponseWriter, r *http.Request)

@Summary Delete Candidate @Tags Candidate @Param CandidateID path string true "Candidate ID" @Success 200 {object} models.Response @Failure 400 {object} models.Response @Router /candidates/{CandidateID} [delete]

func (*ResourceContext) GetCandidate

func (ctx *ResourceContext) GetCandidate(w http.ResponseWriter, r *http.Request)

@Summary Get Candidate @Tags Candidate @Param CandidateID path string true "Candidate ID" @Success 200 {object} models.Response @Failure 400 {object} models.Response @Router /candidates/{CandidateID} [get]

func (*ResourceContext) ListCandidate

func (ctx *ResourceContext) ListCandidate(w http.ResponseWriter, r *http.Request)

@Summary List Candidate @Tags Candidate @Param limit query int true "Limit" @Param offset query int true "Offset" @Success 200 {object} models.Response @Failure 400 {object} models.Response @Router /candidates [get]

func (*ResourceContext) NewCandidateRouter

func (ctx *ResourceContext) NewCandidateRouter() http.Handler

* New SubRouter for candidates

func (*ResourceContext) SafeClose

func (ctx *ResourceContext) SafeClose()

* SafeClose gets called when service gets shutdown

func (*ResourceContext) UpdateCandidate

func (ctx *ResourceContext) UpdateCandidate(w http.ResponseWriter, r *http.Request)

@Summary Update Candidate @Tags Candidate @Param candidate body models.Candidate true "Update Candidate" @Success 200 {object} models.Response @Failure 400 {object} models.Response @Router /candidates/{CandidateID} [put]

type Response

type Response struct {
	Data  Candidate        `json: "candidate"`
	Error commons.APIError `json: "error"`
}

Response is standard response from candidate api

type ServiceContext

type ServiceContext struct {
	DAO DBContext
}

ServiceContext maintains repo instance

func NewServiceContext

func NewServiceContext() *ServiceContext

NewServiceContext creates new ServiceContext

func (*ServiceContext) CreateCandidate

func (ctx *ServiceContext) CreateCandidate(f *commons.FlowContext, candidate *Candidate) (*Candidate, error)

CreateCandidate creates candidate

func (*ServiceContext) DeleteCandidate

func (ctx *ServiceContext) DeleteCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)

DeleteCandidate deletes candidate by candidate id

func (*ServiceContext) GetCandidate

func (ctx *ServiceContext) GetCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)

GetCandidate gets candidate by candidate id

func (*ServiceContext) ListCandidates

func (ctx *ServiceContext) ListCandidates(fCtx *commons.FlowContext, limit int, offset int) (*[]Candidate, error)

ListCandidates to list candidates with pagination

func (*ServiceContext) SafeClose

func (ctx *ServiceContext) SafeClose()

SafeClose gets called when main is about to complete

func (*ServiceContext) UpdateCandidate

func (ctx *ServiceContext) UpdateCandidate(fCtx *commons.FlowContext, cid string, entity *Candidate) (string, error)

UpdateCandidate updates candidate by candidate id

Jump to

Keyboard shortcuts

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