2019-09-07 16:10:28 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Activity struct {
|
|
|
|
Id string `json:"id"`
|
2019-09-19 07:14:22 +00:00
|
|
|
Payload string `json:"status"`
|
2019-09-07 16:10:28 +00:00
|
|
|
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)
|
|
|
|
|
2019-09-19 07:14:22 +00:00
|
|
|
var status Activity
|
|
|
|
err := row.Scan(&status.Id,
|
|
|
|
&status.Name, &status.Note, &status.CreatedAt, &status.UpdatedAt)
|
2019-09-07 16:10:28 +00:00
|
|
|
|
|
|
|
// This is not an error from the user's perspective
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-09-19 07:14:22 +00:00
|
|
|
return &status, nil
|
2019-09-07 16:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-19 07:14:22 +00:00
|
|
|
// PutNote creates a status with this name and status
|
|
|
|
func PutActivity(db *sql.DB, name string, status string) (string, error) {
|
2019-09-07 16:10:28 +00:00
|
|
|
// TODO make guid but not slug
|
|
|
|
id := slugify.MakeLang(name, "en")
|
|
|
|
|
|
|
|
query := `
|
2019-09-19 07:14:22 +00:00
|
|
|
INSERT INTO activity (id, name, status)
|
2019-09-07 16:10:28 +00:00
|
|
|
VALUES ($1, $2, $3)
|
|
|
|
`
|
|
|
|
|
2019-09-19 07:14:22 +00:00
|
|
|
_, err := db.Exec(query, slug, name, status)
|
2019-09-07 16:10:28 +00:00
|
|
|
return slug, err
|
|
|
|
}
|
|
|
|
*/
|