IIC2173-2015-2-Grupo2/news-api

View on GitHub
models/category.go

Summary

Maintainability
A
1 hr
Test Coverage
package models

import (
    "github.com/jmcvetta/neoism"
)

/*
Category model
*/
type Category struct {
    ID   int64  `json:"id"`
    Name string `json:"name"`
}

// ---------------------------------------------------------------------------

/*
GetCategories returns collection of news
*/
func GetCategories(db *neoism.Database) (*[]Category, error) {

    var categories []Category
    if err := db.Cypher(&neoism.CypherQuery{
        Statement: `MATCH (category:Category)
                RETURN DISTINCT ID(category) as id, category.name as name`,
        Result: &categories,
    }); err != nil {
        return nil, err
    }
    return &categories, nil
}