1
0

Changes for new justguestbook structure.

This commit is contained in:
Alexander Andreev 2023-05-22 01:14:25 +04:00
parent ee35bb38ea
commit 7a9a6c06f0
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 16 additions and 16 deletions

View File

@ -14,7 +14,7 @@ import (
"git.arav.su/Arav/dwelling-home/internal/http" "git.arav.su/Arav/dwelling-home/internal/http"
mfsqlite "git.arav.su/Arav/dwelling-home/pkg/mindflow/database/sqlite" mfsqlite "git.arav.su/Arav/dwelling-home/pkg/mindflow/database/sqlite"
gbsqlite "git.arav.su/Arav/justguestbook/database/sqlite" gb "git.arav.su/Arav/justguestbook"
) )
var version string var version string
@ -53,7 +53,7 @@ func main() {
} }
} }
guestbookDB, err := gbsqlite.New(path.Join(*databasesPath, "guestbook.sqlite")) guestbookDB, err := gb.NewSQLiteDB(path.Join(*databasesPath, "guestbook.sqlite"))
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -12,7 +12,7 @@ import (
"git.arav.su/Arav/justcaptcha/pkg/captcha" "git.arav.su/Arav/justcaptcha/pkg/captcha"
"git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb" "git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb"
"git.arav.su/Arav/justcaptcha/pkg/dwcaptcha" "git.arav.su/Arav/justcaptcha/pkg/dwcaptcha"
"git.arav.su/Arav/justguestbook/guestbook" "git.arav.su/Arav/justguestbook"
) )
// Guestbook API /////////////////////////////////////////////////////////////// // Guestbook API ///////////////////////////////////////////////////////////////
@ -20,15 +20,15 @@ import (
type GuestbookApiHandlers struct { type GuestbookApiHandlers struct {
Owner string Owner string
PageSize int64 PageSize int64
db guestbook.Guestbook db justguestbook.Guestbook
} }
func NewGuestbookApiHandlers(owner string, pageSz int64, db guestbook.Guestbook) *GuestbookApiHandlers { func NewGuestbookApiHandlers(owner string, pageSz int64, db justguestbook.Guestbook) *GuestbookApiHandlers {
return &GuestbookApiHandlers{Owner: owner, PageSize: pageSz, db: db} return &GuestbookApiHandlers{Owner: owner, PageSize: pageSz, db: db}
} }
func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) { func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
var entry *guestbook.Entry var entry *justguestbook.Entry
var err error var err error
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
@ -47,7 +47,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
message = strings.ReplaceAll(message, "\n\r", "\n") message = strings.ReplaceAll(message, "\n\r", "\n")
message = strings.ReplaceAll(message, "\r", "\n") message = strings.ReplaceAll(message, "\r", "\n")
entry, err = guestbook.NewEntry(r.FormValue("name"), message, entry, err = justguestbook.NewEntry(r.FormValue("name"), message,
r.FormValue("website"), r.FormValue("hide_website") != "") r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil { if err != nil {
InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w) InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w)
@ -64,7 +64,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
} }
func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) { func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
var entry *guestbook.Entry var entry *justguestbook.Entry
var err error var err error
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
@ -78,7 +78,7 @@ func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
message = strings.ReplaceAll(message, "\n\r", "\n") message = strings.ReplaceAll(message, "\n\r", "\n")
message = strings.ReplaceAll(message, "\r", "\n") message = strings.ReplaceAll(message, "\r", "\n")
entry, err = guestbook.NewEntry(r.FormValue("name"), message, entry, err = justguestbook.NewEntry(r.FormValue("name"), message,
r.FormValue("website"), r.FormValue("hide_website") != "") r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -104,7 +104,7 @@ func (h *GuestbookApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
} }
func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) { func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
var reply *guestbook.Reply var reply *justguestbook.Reply
var err error var err error
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
@ -116,7 +116,7 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
message = strings.ReplaceAll(message, "\n\r", "\n") message = strings.ReplaceAll(message, "\n\r", "\n")
message = strings.ReplaceAll(message, "\r", "\n") message = strings.ReplaceAll(message, "\r", "\n")
reply, err = guestbook.NewReply(id, message) reply, err = justguestbook.NewReply(id, message)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
@ -130,7 +130,7 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
} }
func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request) { func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request) {
var reply *guestbook.Reply var reply *justguestbook.Reply
var err error var err error
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
@ -142,7 +142,7 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request)
message = strings.ReplaceAll(message, "\n\r", "\n") message = strings.ReplaceAll(message, "\n\r", "\n")
message = strings.ReplaceAll(message, "\r", "\n") message = strings.ReplaceAll(message, "\r", "\n")
reply, err = guestbook.NewReply(id, message) reply, err = justguestbook.NewReply(id, message)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return

View File

@ -13,11 +13,11 @@ import (
"git.arav.su/Arav/dwelling-home/web" "git.arav.su/Arav/dwelling-home/web"
"git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb" "git.arav.su/Arav/justcaptcha/pkg/captcha/inmemdb"
"git.arav.su/Arav/justcaptcha/pkg/dwcaptcha" "git.arav.su/Arav/justcaptcha/pkg/dwcaptcha"
"git.arav.su/Arav/justguestbook/guestbook" "git.arav.su/Arav/justguestbook"
) )
type Handlers struct { type Handlers struct {
guestbookDB guestbook.Guestbook guestbookDB justguestbook.Guestbook
mindflowDB mindflow.Mindflow mindflowDB mindflow.Mindflow
captchaExpire time.Duration captchaExpire time.Duration
guestbookOwner string guestbookOwner string
@ -25,7 +25,7 @@ type Handlers struct {
} }
func NewHandlers(captchaExpire time.Duration, gbOwner string, gbPageSize int64, func NewHandlers(captchaExpire time.Duration, gbOwner string, gbPageSize int64,
gdb guestbook.Guestbook, mdb mindflow.Mindflow) *Handlers { gdb justguestbook.Guestbook, mdb mindflow.Mindflow) *Handlers {
return &Handlers{ return &Handlers{
guestbookDB: gdb, guestbookDB: gdb,
mindflowDB: mdb, mindflowDB: mdb,