fix reports

shorten some variable names
This commit is contained in:
Azareal 2019-07-27 08:26:52 +10:00
parent 22cb2701b2
commit fa629f4b5d
3 changed files with 26 additions and 23 deletions

View File

@ -1,7 +1,10 @@
package common package common
import "database/sql" import (
import "github.com/Azareal/Gosora/query_gen" "database/sql"
qgen "github.com/Azareal/Gosora/query_gen"
)
var Emails EmailStore var Emails EmailStore
@ -24,9 +27,9 @@ func NewDefaultEmailStore(acc *qgen.Accumulator) (*DefaultEmailStore, error) {
}, acc.FirstError() }, 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} email := Email{UserID: user.ID}
rows, err := store.getEmailsByUser.Query(user.ID) rows, err := s.getEmailsByUser.Query(user.ID)
if err != nil { if err != nil {
return emails, err return emails, err
} }
@ -46,7 +49,7 @@ func (store *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err
return emails, rows.Err() return emails, rows.Err()
} }
func (store *DefaultEmailStore) VerifyEmail(email string) error { func (s *DefaultEmailStore) VerifyEmail(email string) error {
_, err := store.verifyEmail.Exec(email) _, err := s.verifyEmail.Exec(email)
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/Azareal/Gosora/query_gen" qgen "github.com/Azareal/Gosora/query_gen"
) )
type CustomPageStmts struct { type CustomPageStmts struct {
@ -121,28 +121,28 @@ func (s *DefaultPageStore) parseAllowedGroups(raw string, page *CustomPage) erro
return nil return nil
} }
func (store *DefaultPageStore) Get(id int) (*CustomPage, error) { func (s *DefaultPageStore) Get(id int) (*CustomPage, error) {
page := &CustomPage{ID: id} page := &CustomPage{ID: id}
rawAllowedGroups := "" 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 { if err != nil {
return nil, err 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() page := BlankCustomPage()
rawAllowedGroups := "" 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 { if err != nil {
return nil, err 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) { func (s *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*CustomPage, err error) {
rows, err := store.getOffset.Query(offset, perPage) rows, err := s.getOffset.Query(offset, perPage)
if err != nil { if err != nil {
return pages, err return pages, err
} }
@ -155,7 +155,7 @@ func (store *DefaultPageStore) GetOffset(offset int, perPage int) (pages []*Cust
if err != nil { if err != nil {
return pages, err return pages, err
} }
err = store.parseAllowedGroups(rawAllowedGroups, page) err = s.parseAllowedGroups(rawAllowedGroups, page)
if err != nil { if err != nil {
return pages, err 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 // 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 return nil
} }
func (store *DefaultPageStore) Delete(id int) error { func (s *DefaultPageStore) Delete(id int) error {
_, err := store.delete.Exec(id) _, err := s.delete.Exec(id)
return err return err
} }

View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
"strconv" "strconv"
"github.com/Azareal/Gosora/query_gen" qgen "github.com/Azareal/Gosora/query_gen"
) )
// TODO: Make the default report forum ID configurable // 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 // ! 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 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 { if err != nil && err != sql.ErrNoRows {
return 0, err return 0, err
} }
@ -43,7 +43,7 @@ func (store *DefaultReportStore) Create(title string, content string, user *User
return 0, ErrAlreadyReported 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 { if err != nil {
return 0, err return 0, err
} }