Add status page
This commit is contained in:
parent
c5c2cacd1b
commit
b4c45f92b6
6 changed files with 34 additions and 32 deletions
|
|
@ -62,11 +62,12 @@ func (s *Storage) CreateStatus(status model.Status) error {
|
||||||
func (s *Storage) StatusById(id int64) (model.Status, error) {
|
func (s *Storage) StatusById(id int64) (model.Status, error) {
|
||||||
var status model.Status
|
var status model.Status
|
||||||
err := s.db.QueryRow(
|
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.Id,
|
||||||
&status.User,
|
&status.User,
|
||||||
&status.Content,
|
&status.Content,
|
||||||
&status.Face,
|
&status.Face,
|
||||||
|
&status.CreatedAt,
|
||||||
)
|
)
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func createAtomEntryFromStatus(status model.Status) *Entry {
|
||||||
Link: []Link{
|
Link: []Link{
|
||||||
{
|
{
|
||||||
Rel: "alternate",
|
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",
|
Type: "text/html",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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}", h.showUserView).Methods(http.MethodGet)
|
||||||
router.HandleFunc("/users/{user}/status", h.showUserStatusView).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("/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.HandleFunc("/users/{user}/badge.png", h.showUserStatusImageViewEmoji).Methods(http.MethodGet)
|
||||||
router.PathPrefix("/assets/").Handler(
|
router.PathPrefix("/assets/").Handler(
|
||||||
|
|
|
||||||
|
|
@ -316,21 +316,12 @@ var TplMap = map[string]string{
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
{{ end }}`,
|
{{ end }}`,
|
||||||
"status": `<!DOCTYPE html>
|
"status": `{{ define "content" }}
|
||||||
<html lang="en">
|
<section>
|
||||||
<head>
|
<h1>Status</h1>
|
||||||
<meta charset="UTF-8">
|
{{ template "status" .status }}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
</section>
|
||||||
<title>status cafe</title>
|
{{ end }}`,
|
||||||
<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-updater": `{{ define "content" }}
|
"status-updater": `{{ define "content" }}
|
||||||
<section>
|
<section>
|
||||||
<h1>Status Updater</h1>
|
<h1>Status Updater</h1>
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,6 @@
|
||||||
<!DOCTYPE html>
|
{{ define "content" }}
|
||||||
<html lang="en">
|
<section>
|
||||||
<head>
|
<h1>Status</h1>
|
||||||
<meta charset="UTF-8">
|
{{ template "status" .status }}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
</section>
|
||||||
<title>status cafe</title>
|
{{ end }}
|
||||||
<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>
|
|
||||||
18
web/handler/status_show.go
Normal file
18
web/handler/status_show.go
Normal 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)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue