Пример #1
0
func HandleGamePageNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if params.ByName("wild") == "new" && models.SignedIn(w, r) {
		title := r.FormValue("gameTitle")
		dev := r.FormValue("gameDeveloper")
		pub := r.FormValue("gamePublisher")
		trailer := r.FormValue("gameTrailer")
		//copy := r.FormValue("gameCopyright")
		desc := r.FormValue("gameDescription")
		tagstr := r.FormValue("gameTags")
		var tags []string
		err := json.Unmarshal([]byte(tagstr), &tags)
		if err != nil || tags == nil {
			tags = []string{}
		}
		game := models.NewGame(title, pub, trailer)
		game.Description = desc
		game.Developer = dev
		err = models.Dal.CreateGame(*game)
		if err != nil {
			panic(err)
		}
		for _, tag := range tags {
			models.Dal.AddGameTag(game.GameId, tag)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(game.GameId), http.StatusFound)
	} else {
		http.NotFound(w, r)
	}
}
Пример #2
0
func HandleReviewEditAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		reviewid := params.ByName("wild")
		//reviewid := r.FormValue("reviewID")
		user := models.RequestUser(r)
		//gameid := r.FormValue("gameID")
		review := r.FormValue("reviewBody")
		rating, _ := strconv.ParseFloat(r.FormValue("reviewRate"), 64)
		rev, err := models.Dal.FindReview(reviewid)
		if err != nil {
			panic(err)
		}
		rev.Body = review
		rev.Rating = rating
		if rev.UserId != user.UserId {
			models.RenderTemplate(w, r, "review/edit", map[string]interface{}{"Review": rev})
			return
		}
		err = models.Dal.UpdateReview(*rev)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/review/"+rev.ReviewId, http.StatusFound)
	}
}
Пример #3
0
func HandleGamePage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	encgameid := params.ByName("wild")
	if encgameid == "new" {
		HandleGamePageNew(w, r, params)
		return
	}
	var err error
	gameid, err := url.QueryUnescape(encgameid)
	if err != nil {
		panic(err)
	}
	var game *models.Game
	game, err = models.Dal.FindGame(gameid)
	if err != nil {
		panic(err)
	}
	game.UpdateRating()
	revs, err := models.Dal.FindTopReviewsByGame(gameid, 5)
	if err != nil {
		panic(err)
	}
	vids, err := models.Dal.FindTopVideosByGame(gameid, 6)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "game/page", map[string]interface{}{"Game": game, "TopReviews": revs, "TopUserVids": vids})
}
Пример #4
0
func HandleVideo(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	videoid := params.ByName("wild")
	vid, err := models.Dal.FindVideo(videoid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "video/uservideo", map[string]interface{}{"Video": vid, "VideoWidth": 640, "VideoHeight": 480})
}
Пример #5
0
func HandleReview(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	reviewid := params.ByName("wild")
	rev, err := models.Dal.FindReview(reviewid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "review/review", map[string]interface{}{"Review": rev})
}
Пример #6
0
func HandleReviewNew(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		gam, err := models.Dal.FindGame(gameid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "review/new", map[string]interface{}{"Game": gam})
	}
}
Пример #7
0
func HandleGameClaimAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		err := models.Dal.AddUserGame(models.RequestUser(r).UserId, gameid)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(gameid), http.StatusFound)
	}
}
Пример #8
0
func HandleReviewNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		//reviewid := r.FormValue("reviewID")
		user := models.RequestUser(r)
		//gameid := r.FormValue("gameID")
		review := r.FormValue("reviewBody")
		rating, _ := strconv.ParseFloat(r.FormValue("reviewRate"), 64)
		rev := models.NewReview(user.UserId, gameid, review, rating)
		http.Redirect(w, r, "/review/"+rev.ReviewId, http.StatusFound)
	}
}
Пример #9
0
func HandleVideoNewAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		vidurl := r.FormValue("vidURL")
		user := models.RequestUser(r)
		vid := models.NewVideo(user.UserId, gameid, vidurl)
		err := models.Dal.CreateVideo(*vid)
		if err != nil {
			panic(err)
		}
		http.Redirect(w, r, "/videos/"+url.QueryEscape(vid.ID), http.StatusFound)
	}
}
Пример #10
0
func HandleGameVideos(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	gameid := params.ByName("wild")
	game, err := models.Dal.FindGame(gameid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	vids, err = models.Dal.FindVideosByGame(gameid)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "videos/allgamevideos", map[string]interface{}{"Game": game, "AllVideos": vids})
}
Пример #11
0
func HandleUserVideos(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	userid := params.ByName("wild")
	user, err := models.GlobalUserStore.FindUser(userid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	vids, err = models.Dal.FindVideosByUser(user.UserId)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "videos/alluservideos", map[string]interface{}{"User": user, "AllVideos": vids})
}
Пример #12
0
func HandleGameEditAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		title := r.FormValue("gameTitle")
		dev := r.FormValue("gameDeveloper")
		pub := r.FormValue("gamePublisher")
		trailer := r.FormValue("gameTrailer")
		//copy := r.FormValue("gameCopyright")
		desc := r.FormValue("gameDescription")
		tagstr := r.FormValue("gameTags")
		var tags []string
		err := json.Unmarshal([]byte(tagstr), &tags)
		if err != nil || tags == nil {
			tags = []string{}
		}
		for k, v := range tags {
			t, err := url.QueryUnescape(v)
			if err == nil {
				tags[k] = t
			}
		}
		var currtags []string
		currtags, err = models.Dal.FindTagsByGame(gameid)
		if err != nil || currtags == nil {
			currtags = []string{}
		}
		game := models.Game{GameId: gameid, Title: title, Developer: dev, Publisher: pub, URL: trailer, Description: desc}
		err = models.Dal.UpdateGame(game)
		if err != nil {
			panic(err)
		}
		for _, t := range currtags {
			found := false
			for k, v := range tags {
				if t == v {
					found = true
					tags = append(tags[:k], tags[k+1:]...)
					break
				}
			}
			if !found {
				models.Dal.DeleteGameTag(gameid, t)
			}
		}
		for _, t := range tags {
			models.Dal.AddGameTag(gameid, t)
		}
		http.Redirect(w, r, "/game/"+url.QueryEscape(game.GameId), http.StatusFound)
	}
}
Пример #13
0
func HandleUserPage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	userid := params.ByName("wild")
	user, err := models.GlobalUserStore.FindUser(userid)
	if err != nil {
		panic(err)
	}
	var vids []models.Video
	var revs []models.Review
	vids, err = models.Dal.FindTopVideosByUser(userid, 10)
	if err != nil {
		panic(err)
	}
	revs, err = models.Dal.FindTopReviewsByUser(userid, 10)
	if err != nil {
		panic(err)
	}
	models.RenderTemplate(w, r, "users/view", map[string]interface{}{"User": user, "Reviews": revs, "Videos": vids})
}
Пример #14
0
func HandleFriendAdd(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		friendid := params.ByName("wild")
		friend, err := models.GlobalUserStore.FindUser(friendid)
		if err != nil {
			panic(err)
		}
		user := models.RequestUser(r)
		if user == nil || friend == nil || user.UserId == friend.UserId {
			models.RenderTemplate(w, r, "users/friend", nil)
			return
		}
		err = models.Dal.AddUserFriend(user.UserId, friendid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "users/friend", map[string]interface{}{"Friend": friend})
	}
}
Пример #15
0
func HandleGameEditPage(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
	if models.SignedIn(w, r) {
		gameid := params.ByName("wild")
		game, err := models.Dal.FindGame(gameid)
		if err != nil {
			panic(err)
		}
		if game == nil {
			http.Redirect(w, r, "/?flash=Game+Not+Found", http.StatusNotFound)
			return
		}
		tags := []string{}
		tags, err = models.Dal.FindTagsByGame(gameid)
		if err != nil {
			panic(err)
		}
		models.RenderTemplate(w, r, "game/edit", map[string]interface{}{"Game": game, "Tags": tags})
	}
}