Exemple #1
0
func (cr *MyAPIController) Read(id string, cx *goweb.Context) {

	if id == "1" {
		cx.RespondWithData(TestEntity{id, "Mat", 28})
	} else if id == "2" {
		cx.RespondWithData(TestEntity{id, "Laurie", 27})
	} else {
		cx.RespondWithNotFound()
	}

}
Exemple #2
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)
}
Exemple #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))
	}
}
Exemple #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})
}
Exemple #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)
}
Exemple #6
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)
}
Exemple #7
0
func (cr *MyAPIController) UpdateMany(cx *goweb.Context) {
	cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
Exemple #8
0
func (cr *MyAPIController) Update(id string, cx *goweb.Context) {
	cx.RespondWithData(TestEntity{id, "Mat", 28})
}
Exemple #9
0
func (cr *MyAPIController) ReadMany(cx *goweb.Context) {
	cx.RespondWithData([]TestEntity{TestEntity{"1", "Mat", 28}, TestEntity{"2", "Laurie", 27}})
}