Documentation ¶
Index ¶
- func GetBSON(entity *Candidate) *bson.D
- type Address
- type AddressType
- type Candidate
- type DBContext
- func (ctx *DBContext) CreateCandidate(fCtx *commons.FlowContext, candidate *Candidate) (*Candidate, error)
- func (ctx *DBContext) DeleteCandidate(f *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *DBContext) GetCandidate(f *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *DBContext) ListCandidates(f *commons.FlowContext, limit int, offset int) (*[]Candidate, error)
- func (ctx *DBContext) SafeClose()
- func (ctx *DBContext) UpdateCandidate(f *commons.FlowContext, cid string, entity *Candidate) (string, error)
- type MongoDBContext
- func (ctx *MongoDBContext) CreateCandidate(fCtx *commons.FlowContext, candidate *Candidate) (*Candidate, error)
- func (ctx *MongoDBContext) DeleteCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *MongoDBContext) GetCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *MongoDBContext) ListCandidates(fCtx *commons.FlowContext, limit int, offset int) (*[]Candidate, error)
- func (ctx *MongoDBContext) SafeClose()
- func (ctx *MongoDBContext) UpdateCandidate(fCtx *commons.FlowContext, cid string, entity *Candidate) (string, error)
- type RedisContext
- func (ctx *RedisContext) CreateCandidate(candidate *Candidate) (*Candidate, error)
- func (ctx *RedisContext) DeleteCandidate(cid string) (*Candidate, error)
- func (ctx *RedisContext) GetCandidate(cid string) (*Candidate, error)
- func (ctx *RedisContext) ListCandidates(limit int64, offset int64) (*[]Candidate, error)
- func (ctx *RedisContext) SafeClose()
- func (ctx *RedisContext) UpdateCandidate(cid string, key string, value string) (string, error)
- type ResourceContext
- func (ctx *ResourceContext) CreateCandidate(w http.ResponseWriter, r *http.Request)
- func (ctx *ResourceContext) DeleteCandidate(w http.ResponseWriter, r *http.Request)
- func (ctx *ResourceContext) GetCandidate(w http.ResponseWriter, r *http.Request)
- func (ctx *ResourceContext) ListCandidate(w http.ResponseWriter, r *http.Request)
- func (ctx *ResourceContext) NewCandidateRouter() http.Handler
- func (ctx *ResourceContext) SafeClose()
- func (ctx *ResourceContext) UpdateCandidate(w http.ResponseWriter, r *http.Request)
- type Response
- type ServiceContext
- func (ctx *ServiceContext) CreateCandidate(f *commons.FlowContext, candidate *Candidate) (*Candidate, error)
- func (ctx *ServiceContext) DeleteCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *ServiceContext) GetCandidate(fCtx *commons.FlowContext, cid string) (*Candidate, error)
- func (ctx *ServiceContext) ListCandidates(fCtx *commons.FlowContext, limit int, offset int) (*[]Candidate, error)
- func (ctx *ServiceContext) SafeClose()
- func (ctx *ServiceContext) UpdateCandidate(fCtx *commons.FlowContext, cid string, entity *Candidate) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
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
type DBContext ¶
func (*DBContext) CreateCandidate ¶
func (*DBContext) DeleteCandidate ¶
func (*DBContext) GetCandidate ¶
func (*DBContext) ListCandidates ¶
func (*DBContext) UpdateCandidate ¶
type MongoDBContext ¶
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 ¶
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 ¶
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 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