Example #1
0
func getAllTrips(message *mq.Message) {
	trips, err := db.Table("Trips").Run(session)
	util.LogOnError(err, "[Trip Worker] Erro on getAllTrips")

	var rows []interface{}
	err = trips.All(&rows)
	util.LogOnError(err, "[Trip Worker] Erro on All function")

	message.ResponseCode = http.StatusOK
	message.Response = rows

	trips.Close()
}
Example #2
0
//Post manages post method requests
func (t TripHandler) Post(request *http.Request) (int, interface{}) {
	body, err := ioutil.ReadAll(request.Body)
	util.LogOnError(err, "Post error reading request body")

	var message mq.Message
	message.CorrelationID = uuid.NewV4().String()
	message.RequestAction = "POST"
	message.Request = string(body)

	Tasks.PublishMessage(message, "Trip", message.CorrelationID, "callback")

	return processMessage(&message)
}
Example #3
0
//Get manages get method requests
func (t TripHandler) Get(request *http.Request, vars map[string]string) (int, interface{}) {

	var message mq.Message
	message.CorrelationID = uuid.NewV4().String()
	if vars["id"] == "" {
		message.RequestAction = "GET_ALL"
	} else {
		message.RequestAction = "GET"
		message.Request = vars["id"]
	}

	Tasks.PublishMessage(message, "Trip", message.CorrelationID, "callback")

	return processMessage(&message)
}
Example #4
0
func postTrip(message *mq.Message) {
	var trip models.Trip
	trip.Initialize()
	trip.LoadJSON(message.Request.(string))

	if trip.Validate() {
		resp, err := db.Table("Trips").Insert(trip).RunWrite(session)
		util.LogOnError(err, "[Trip Worker] Erro inserting new Trip")

		message.ResponseCode = http.StatusOK
		message.Response = resp
	} else {
		message.ResponseCode = http.StatusBadRequest
		message.Response = nil
	}
}
Example #5
0
func getTrip(message *mq.Message) {
	var trip models.Trip
	trip.ID = message.Request.(string)

	result, err := db.Table("Trips").Get(trip.ID).Run(session)
	util.LogOnError(err, "[Trip Worker] Erro on getTrip")

	if result == nil {
		message.ResponseCode = http.StatusNotFound
		message.Response = nil
	} else {
		err = result.One(&trip)
		util.LogOnError(err, "[Trip Worker] Erro on One function")

		message.ResponseCode = http.StatusOK
		message.Response = trip
	}
	result.Close()
}
Example #6
0
func loginUser(message *mq.Message) {
	message.ResponseCode = http.StatusOK
	message.Response = nil
}