Example #1
0
/**
 * Retourneer hoofd categorieen
 *
 * @author A. Glansbeek en P. Kompier
 * @version 1.0
 * @date 2011-12-18
 */
func (cr *CategoryController) ReadMany(cx *goweb.Context) {
	var m structs.WordpressHeadCategory

	models.CallWordpressApi(cx, &m, "get_category_index", nil)

	var headCategories []structs.HeadCategory
	for _, category := range m.Categories {
		// Alleen parents 0 (dat is hoofd category)
		if category.Parent == 0 {
			headCategories = append(headCategories, structs.HeadCategory{category.Id, category.Title})
		}
	}

	cx.RespondWithData(headCategories)
}
Example #2
0
/**
 * Retourneer alle artikelen
 *
 * @author A. Glansbeek en P. Kompier
 * @version 1.0
 * @date 2011-12-18
 */
func (cr *ArticleController) ReadMany(cx *goweb.Context) {

	var m structs.WordpressPostMany

	// Als category_id is, pak dan alleen article van die category
	if cx.PathParams["category_id"] != "" {
		params := map[string]string{
			"category_id": cx.PathParams["category_id"],
		}

		models.CallWordpressApi(cx, &m, "get_category_posts", params)
	} else {
		models.CallWordpressApi(cx, &m, "get_recent_posts", nil)
	}

	var mapper = make(map[string][]structs.Article)

	for _, post := range m.Posts {

		// Nieuw struct artikel
		article := createArticle(post)

		// Zet het artikel in de goede category
		_, present := mapper[article.Category]

		if present {
			mapper[article.Category] = append(mapper[article.Category], article)
		} else {
			var articles []structs.Article
			articles = append(articles, article)
			mapper[article.Category] = articles
		}
	}

	cx.RespondWithData(mapper)
}
Example #3
0
/**
 * GET artikel met id [1..n], retourneer een artikel
 *
 * @author A. Glansbeek en P. Kompier
 * @version 1.0
 * @date 2011-12-18
 */
func (cr *ArticleController) Read(id string, cx *goweb.Context) {
	params := map[string]string{"post_id": id}
	var m structs.WordpressPost

	models.CallWordpressApi(cx, &m, "get_post", params)

	if m.Post.Id == 0 {
		var str []string
		str = append(str, "Het opgevraagde id bestaat niet")

		cx.Respond(nil, 202, str, cx)
	} else {
		cx.RespondWithData(createArticle(m.Post))
	}
}
Example #4
0
/**
 * Creert een nieuwe comment (tip)
 *
 * @author A. Glansbeek en P. Kompier
 * @version 1.0
 * @date 2011-12-18
 */
func (cr *CommentController) Create(cx *goweb.Context) {
	reqValues := cx.GetReqData()

	params := map[string]string{
		"post_id": reqValues.Get("post_id"),
		"name":    reqValues.Get("name"),
		"email":   reqValues.Get("email"),
		"content": reqValues.Get("content"),
	}

	var m structs.WordpressCommentResponse

	models.CallWordpressApi(cx, &m, "submit_comment", params)

	cx.RespondWithData(structs.TipResponse{m.Status})
}
Example #5
0
/**
 * Zoek functie!
 *
 * @author A. Glansbeek en P. Kompier
 * @version 1.0
 * @date 2012-01-06
 */
func (cr *SearchController) Read(input string, cx *goweb.Context) {
	params := map[string]string{"search": input}
	var m structs.WordpressPostMany

	models.CallWordpressApi(cx, &m, "get_search_results", params)

	var articles []structs.Article

	for _, post := range m.Posts {

		// Nieuw struct artikel
		article := createArticle(post)
		articles = append(articles, article)
	}

	cx.RespondWithData(articles)
}