subhub/data/models/activity.go

54 lines
1.1 KiB
Go

package models
import (
"database/sql"
"time"
)
type Activity struct {
Id string `json:"id"`
Payload string `json:"note"`
Remote bool `json:"remote"`
Group `json:"group"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// GetActivity gets a Activity at any slug
func GetActivity(db *sql.DB, slug string) (*Activity, error) {
row := db.QueryRow(`
SELECT id, Payload, remote, goupid, created_at, updated_at
FROM activity WHERE id = $1
`, slug)
var note Activity
err := row.Scan(&note.Slug,
&note.Name, &note.Note, &note.CreatedAt, &note.UpdatedAt)
// This is not an error from the user's perspective
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &note, nil
}
/*
// PutNote creates a note with this name and note
func PutActivity(db *sql.DB, name string, note string) (string, error) {
// TODO make guid but not slug
id := slugify.MakeLang(name, "en")
query := `
INSERT INTO activity (id, name, note)
VALUES ($1, $2, $3)
`
_, err := db.Exec(query, slug, name, note)
return slug, err
}
*/