Add status page

This commit is contained in:
m15o 2022-02-20 08:03:39 +01:00
parent c5c2cacd1b
commit b4c45f92b6
6 changed files with 34 additions and 32 deletions

View file

@ -62,11 +62,12 @@ func (s *Storage) CreateStatus(status model.Status) error {
func (s *Storage) StatusById(id int64) (model.Status, error) {
var status model.Status
err := s.db.QueryRow(
`SELECT id, author, content, face from statuses WHERE id=$1`, id).Scan(
`SELECT id, author, content, face, created_at from statuses WHERE id=$1`, id).Scan(
&status.Id,
&status.User,
&status.Content,
&status.Face,
&status.CreatedAt,
)
return status, err
}

View file

@ -69,7 +69,7 @@ func createAtomEntryFromStatus(status model.Status) *Entry {
Link: []Link{
{
Rel: "alternate",
Href: fmt.Sprintf("https://status.cafe/users/%s", status.User),
Href: fmt.Sprintf("https://status.cafe/status/%d", status.Id),
Type: "text/html",
},
},

View file

@ -85,6 +85,7 @@ func New(cfg *config.Config, sess *session.Session, data *storage.Storage, v vpu
router.HandleFunc("/users/{user}", h.showUserView).Methods(http.MethodGet)
router.HandleFunc("/users/{user}/status", h.showUserStatusView).Methods(http.MethodGet)
router.HandleFunc("/users/{user}/status.json", h.showUserStatusJSONView).Methods(http.MethodGet)
router.HandleFunc("/statuses/{id}", h.showStatusView).Methods(http.MethodGet)
router.HandleFunc("/users/{user}/badge.png", h.showUserStatusImageViewEmoji).Methods(http.MethodGet)
router.PathPrefix("/assets/").Handler(

View file

@ -316,21 +316,12 @@ var TplMap = map[string]string{
<input type="submit" value="Submit">
</form>
{{ end }}`,
"status": `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>status cafe</title>
<link rel="stylesheet" href="/assets/style.css"/>
<meta name="description" content="your friends' updates">
</head>
<body>
{{ if .status.Content }}
{{ template "status" .status }}
{{ end }}
</body>
</html>`,
"status": `{{ define "content" }}
<section>
<h1>Status</h1>
{{ template "status" .status }}
</section>
{{ end }}`,
"status-updater": `{{ define "content" }}
<section>
<h1>Status Updater</h1>

View file

@ -1,15 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>status cafe</title>
<link rel="stylesheet" href="/assets/style.css"/>
<meta name="description" content="your friends' updates">
</head>
<body>
{{ if .status.Content }}
{{ template "status" .status }}
{{ end }}
</body>
</html>
{{ define "content" }}
<section>
<h1>Status</h1>
{{ template "status" .status }}
</section>
{{ end }}

View file

@ -0,0 +1,18 @@
package handler
import (
"net/http"
)
func (h *Handler) showStatusView(w http.ResponseWriter, r *http.Request) {
protectClickJacking(w)
user, _ := h.sess.Get(r)
status, err := h.storage.StatusById(RouteInt64Param(r, "id"))
if err != nil {
serverError(w, err)
return
}
h.renderLayout(w, "status", map[string]interface{}{
"status": status,
}, user)
}