Example #1
0
func GetAll(c *gin.Context) {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	result, err := service.GetAll(transportFactory, protocolFactory)

	if err != nil {
		m := fmt.Sprintf("%v", err)
		c.JSON(http.StatusExpectationFailed, util.FailResponse(m))
	} else {
		parse := make([]interface{}, len(result))
		for i := range result {
			parse[i] = model.PersonResponse(result[i])
		}
		c.JSON(http.StatusCreated, util.ListResponse("success", "", parse))
	}
}
Example #2
0
func Update(c *gin.Context) {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	var json model.Person
	c.BindJSON(&json)
	person := model.PersonUpdate(json.ID, json.Identity, json.Firstname, json.Middlename, json.Lastname, json.Address, json.Age, json.Active)
	result, err := service.Update(transportFactory, protocolFactory, person)
	if err != nil {
		m := fmt.Sprintf("%v", err)
		c.JSON(http.StatusExpectationFailed, util.FailResponse(m))
	} else {
		parse := map[string]interface{}{
			"person": model.PersonResponse(result),
		}
		c.JSON(http.StatusCreated, util.ObjectResponse("success", "", parse))
	}
}