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
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
}

View File

@ -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
}

View File

@ -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
}