Example #1
0
func (match *Match) createMatch(request *restful.Request, response *restful.Response) {
	newMatch := new(Match)

	newMatch.CreateAt = time.Now()
	newMatch.PlaceId = match.post.PlaceId
	newMatch.PostId = match.post.Id
	newMatch.UserIdX = match.user.Id
	newMatch.UserImageX = match.user.UrlPicture
	newMatch.UserNameX = match.user.Name
	newMatch.UserIdY = match.post.UserId
	newMatch.UserNameY = match.post.UserName
	newMatch.Validated = false

	resp, err := r.Table("matchs").Insert(newMatch).RunWrite(api.Sess)
	if err != nil {
		response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
		helpers.PrintLog(request, response, match.user.Name)
		return
	}
	go func() {
		notif := notification.SetMatchReceive()
		notif.UserId = match.post.UserId
		notif.UserIdFrom = match.user.Id
		notif.IdThing = resp.GeneratedKeys[0]
		notif.Name = match.user.Name
		notif.IdLink = match.post.Id
		notif.CreateNotification()
	}()

	newMatch.Id = resp.GeneratedKeys[0]
	response.WriteHeaderAndEntity(http.StatusCreated, newMatch)

	helpers.PrintLog(request, response, match.user.Name)
}
Example #2
0
func (match *Match) removeMatch(request *restful.Request, response *restful.Response) {

	_, err := r.Table("matchs").Get(match.Id).Delete().Run(api.Sess)
	if err != nil {
		response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
		helpers.PrintLog(request, response, match.user.Name)
		return
	}
	if match.Validated == false {
		notif := notification.SetMatchReceive()
		notif.IdThing = match.Id
		notif.UserIdFrom = match.user.Id
		notif.RemoveNotification()
	}

	response.WriteHeader(http.StatusOK)
}