mirror of https://github.com/jlelse/GoBlog
Allow to delete notifications
This commit is contained in:
parent
1b2eed9897
commit
1898536bf1
1
http.go
1
http.go
|
@ -212,6 +212,7 @@ func buildStaticHandlersRouters() error {
|
|||
notificationsRouter.Use(authMiddleware)
|
||||
notificationsRouter.Get("/", notificationsAdmin)
|
||||
notificationsRouter.Get(paginationPath, notificationsAdmin)
|
||||
notificationsRouter.Post("/delete", notificationsAdminDelete)
|
||||
|
||||
if ap := appConfig.ActivityPub; ap != nil && ap.Enabled {
|
||||
activitypubRouter = chi.NewRouter()
|
||||
|
|
|
@ -46,6 +46,11 @@ func saveNotification(n *notification) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func deleteNotification(id int) error {
|
||||
_, err := appDbExec("delete from notifications where id = @id", sql.Named("id", id))
|
||||
return err
|
||||
}
|
||||
|
||||
type notificationsRequestConfig struct {
|
||||
offset, limit int
|
||||
}
|
||||
|
@ -157,3 +162,17 @@ func notificationsAdmin(w http.ResponseWriter, r *http.Request) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func notificationsAdminDelete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.Atoi(r.FormValue("notificationid"))
|
||||
if err != nil {
|
||||
serveError(w, r, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
err = deleteNotification(id)
|
||||
if err != nil {
|
||||
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, ".", http.StatusFound)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,18 @@ func initTemplateStrings() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getTemplateStringVariant(lang, name string) (result string) {
|
||||
func getTemplateStringVariant(input ...string) (result string) {
|
||||
var lang, name string
|
||||
if l := len(input); l == 1 {
|
||||
lang = appConfig.Blogs[appConfig.DefaultBlog].Lang
|
||||
name = input[0]
|
||||
} else if l == 2 {
|
||||
lang = input[0]
|
||||
name = input[1]
|
||||
} else {
|
||||
// Wrong number of input strings
|
||||
return ""
|
||||
}
|
||||
m, ok := templateStrings[lang]
|
||||
if !ok {
|
||||
m = templateStrings[defaultStrings]
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
{{ define "title" }}
|
||||
<title>{{ string .Blog.Lang "notifications" }} - {{ .Blog.Title }}</title>
|
||||
<title>{{ string "notifications" }} - {{ .Blog.Title }}</title>
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
<main>
|
||||
<h1>{{ string .Blog.Lang "notifications" }}</h1>
|
||||
<h1>{{ string "notifications" }}</h1>
|
||||
{{ range $i, $notification := .Data.Notifications }}
|
||||
<p>
|
||||
ID: {{ $notification.ID }}<br/>
|
||||
Time: {{ unixtodate $notification.Time }}<br/>
|
||||
Text: {{ $notification.Text }}
|
||||
</p>
|
||||
<div class="p">
|
||||
<p><i>{{ unixtodate $notification.Time }}</i></p>
|
||||
{{ md $notification.Text }}
|
||||
<form method="post">
|
||||
<input type="hidden" name="notificationid" value="{{ $notification.ID }}">
|
||||
<input type="submit" formaction="/notifications/delete" value="{{ string "delete" }}">
|
||||
</form>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ if .Data.HasPrev }}
|
||||
<p><a href="{{ .Data.Prev }}">{{ string .Blog.Lang "prev" }}</a></p>
|
||||
<p><a href="{{ .Data.Prev }}">{{ string "prev" }}</a></p>
|
||||
{{ end }}
|
||||
{{ if .Data.HasNext }}
|
||||
<p><a href="{{ .Data.Next }}">{{ string .Blog.Lang "next" }}</a></p>
|
||||
<p><a href="{{ .Data.Next }}">{{ string "next" }}</a></p>
|
||||
{{ end }}
|
||||
</main>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue