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:"status"`
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 status Activity
err := row.Scan(&status.Id,
&status.Name, &status.Note, &status.CreatedAt, &status.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 &status, nil
}
/*
// PutNote creates a status with this name and status
func PutActivity(db *sql.DB, name string, status string) (string, error) {
// TODO make guid but not slug
id := slugify.MakeLang(name, "en")
query := `
INSERT INTO activity (id, name, status)
VALUES ($1, $2, $3)
`
_, err := db.Exec(query, slug, name, status)
return slug, err
}
*/