From fa629f4b5d65b3f46a0ac4e873e7367a2567275d Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 27 Jul 2019 08:26:52 +1000 Subject: [PATCH] fix reports shorten some variable names --- common/email_store.go | 15 +++++++++------ common/page_store.go | 26 +++++++++++++------------- common/report_store.go | 8 ++++---- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/common/email_store.go b/common/email_store.go index 6a564d5d..4d67178b 100644 --- a/common/email_store.go +++ b/common/email_store.go @@ -1,7 +1,10 @@ package common -import "database/sql" -import "github.com/Azareal/Gosora/query_gen" +import ( + "database/sql" + + qgen "github.com/Azareal/Gosora/query_gen" +) var Emails EmailStore @@ -24,9 +27,9 @@ func NewDefaultEmailStore(acc *qgen.Accumulator) (*DefaultEmailStore, error) { }, acc.FirstError() } -func (store *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err error) { +func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err error) { email := Email{UserID: user.ID} - rows, err := store.getEmailsByUser.Query(user.ID) + rows, err := s.getEmailsByUser.Query(user.ID) if err != nil { return emails, err } @@ -46,7 +49,7 @@ func (store *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err return emails, rows.Err() } -func (store *DefaultEmailStore) VerifyEmail(email string) error { - _, err := store.verifyEmail.Exec(email) +func (s *DefaultEmailStore) VerifyEmail(email string) error { + _, err := s.verifyEmail.Exec(email) return err } diff --git a/common/page_store.go b/common/page_store.go index d7a8db5e..e9e887e0 100644 --- a/common/page_store.go +++ b/common/page_store.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - "github.com/Azareal/Gosora/query_gen" + qgen "github.com/Azareal/Gosora/query_gen" ) type CustomPageStmts struct { @@ -121,28 +121,28 @@ func (s *DefaultPageStore) parseAllowedGroups(raw string, page *CustomPage) erro return nil } -func (store *DefaultPageStore) Get(id int) (*CustomPage, error) { +func (s *DefaultPageStore) Get(id int) (*CustomPage, error) { page := &CustomPage{ID: id} rawAllowedGroups := "" - err := store.get.QueryRow(id).Scan(&page.Name, &page.Title, &page.Body, &rawAllowedGroups, &page.MenuID) + err := s.get.QueryRow(id).Scan(&page.Name, &page.Title, &page.Body, &rawAllowedGroups, &page.MenuID) if err != nil { return nil, err } - return page, store.parseAllowedGroups(rawAllowedGroups, page) + return page, s.parseAllowedGroups(rawAllowedGroups, page) } -func (store *DefaultPageStore) GetByName(name string) (*CustomPage, error) { +func (s *DefaultPageStore) GetByName(name string) (*CustomPage, error) { page := BlankCustomPage() rawAllowedGroups := "" - err := store.getByName.QueryRow(name).Scan(&page.ID, &page.Name, &page.Title, &page.Body, &rawAllowedGroups, &page.MenuID) + err := s.getByName.QueryRow(name).Scan(&page.ID, &page.Name, &page.Title, &page.Body, &rawAllowedGroups, &page.MenuID) if err != nil { return nil, err } - return page, store.parseAllowedGroups(rawAllowedGroups, page) + return page, s.parseAllowedGroups(rawAllowedGroups, page) } -func (store *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*CustomPage, err error) { - rows, err := store.getOffset.Query(offset, perPage) +func (s *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*CustomPage, err error) { + rows, err := s.getOffset.Query(offset, perPage) if err != nil { return pages, err } @@ -155,7 +155,7 @@ func (store *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*Cust if err != nil { return pages, err } - err = store.parseAllowedGroups(rawAllowedGroups, page) + err = s.parseAllowedGroups(rawAllowedGroups, page) if err != nil { return pages, err } @@ -165,11 +165,11 @@ func (store *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*Cust } // Always returns nil as there's currently no cache -func (store *DefaultPageStore) Reload(id int) error { +func (s *DefaultPageStore) Reload(id int) error { return nil } -func (store *DefaultPageStore) Delete(id int) error { - _, err := store.delete.Exec(id) +func (s *DefaultPageStore) Delete(id int) error { + _, err := s.delete.Exec(id) return err } diff --git a/common/report_store.go b/common/report_store.go index 51076e8c..ed17d73a 100644 --- a/common/report_store.go +++ b/common/report_store.go @@ -5,7 +5,7 @@ import ( "errors" "strconv" - "github.com/Azareal/Gosora/query_gen" + qgen "github.com/Azareal/Gosora/query_gen" ) // TODO: Make the default report forum ID configurable @@ -33,9 +33,9 @@ func NewDefaultReportStore(acc *qgen.Accumulator) (*DefaultReportStore, error) { } // ! There's a data race in this. If two users report one item at the exact same time, then both reports will go through -func (store *DefaultReportStore) Create(title string, content string, user *User, itemType string, itemID int) (int, error) { +func (s *DefaultReportStore) Create(title string, content string, user *User, itemType string, itemID int) (int, error) { var count int - err := store.exists.QueryRow(itemType + "_" + strconv.Itoa(itemID)).Scan(&count) + err := s.exists.QueryRow(itemType+"_"+strconv.Itoa(itemID), ReportForumID).Scan(&count) if err != nil && err != sql.ErrNoRows { return 0, err } @@ -43,7 +43,7 @@ func (store *DefaultReportStore) Create(title string, content string, user *User return 0, ErrAlreadyReported } - res, err := store.create.Exec(title, content, ParseMessage(content, 0, ""), user.LastIP, user.ID, user.ID, itemType+"_"+strconv.Itoa(itemID), ReportForumID) + res, err := s.create.Exec(title, content, ParseMessage(content, 0, ""), user.LastIP, user.ID, user.ID, itemType+"_"+strconv.Itoa(itemID), ReportForumID) if err != nil { return 0, err }