Beispiel #1
0
func (match *Match) acceptMatch(request *restful.Request, response *restful.Response) {

	match.Validated = true
	match.ValidatedAt = time.Now()
	match.UserImageY = match.user.UrlPicture

	talk := new(talk.Talk)
	talk.MatchId = match.Id
	talk.UserIdX = match.UserIdX
	talk.UserIdY = match.UserIdY
	talk.UserNameX = match.UserNameX
	talk.UserNameY = match.UserNameY

	if talk.GetTalkByUsersId() == false {
		if err := talk.CreateTalk(); err != nil {
			response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
			helpers.PrintLog(request, response, match.user.Name)
			return
		}
	}
	_, err := r.Table("matchs").Get(match.Id).Update(match).RunWrite(api.Sess)
	if err != nil {
		talk.RemoveTalk()
		response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
		helpers.PrintLog(request, response, match.user.Name)
		return
	}
	go func() {
		notif := notification.SetAcceptMatchReceive()
		notif.UserId = match.UserIdX
		notif.UserIdFrom = match.user.Id
		notif.IdThing = match.Id
		notif.Name = match.UserNameY
		notif.IdLink = match.PostId
		notif.CreateNotification()
	}()

	render := AcceptMatch{Match: *match, Talk: *talk}
	response.WriteHeaderAndEntity(http.StatusOK, render)

	helpers.PrintLog(request, response, match.user.Name)
}