Fixed bug in publishing issue
This commit is contained in:
parent
e82a0c6abe
commit
32d80e87a0
@ -23,7 +23,6 @@ func (db *DB) AddIssue() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) PublishLatestIssue() error {
|
func (db *DB) PublishLatestIssue() error {
|
||||||
var id int64
|
|
||||||
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||||
updateQuery := "UPDATE issues SET published = true WHERE published = false"
|
updateQuery := "UPDATE issues SET published = true WHERE published = false"
|
||||||
insertQuery := "INSERT INTO issues (published) VALUES (?)"
|
insertQuery := "INSERT INTO issues (published) VALUES (?)"
|
||||||
@ -35,7 +34,7 @@ func (db *DB) PublishLatestIssue() error {
|
|||||||
return fmt.Errorf("error starting transaction: %v", err)
|
return fmt.Errorf("error starting transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.Exec(updateQuery, id); err != nil {
|
if _, err := tx.Exec(updateQuery); err != nil {
|
||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
}
|
}
|
||||||
|
@ -354,16 +354,3 @@ func ShowCurrentArticles(db *model.DB) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", articles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishLatestIssue(db *model.DB) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if err := db.PublishLatestIssue(); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
31
cmd/view/issues.go
Normal file
31
cmd/view/issues.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package view
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"streifling.com/jason/cpolis/cmd/control"
|
||||||
|
"streifling.com/jason/cpolis/cmd/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PublishLatestIssue(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if err := db.PublishLatestIssue(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session, err := s.Get(r, "cookie")
|
||||||
|
if err != nil {
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
|
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"])
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user