Browse Source

reduce verbosity

master
Lars Hoogestraat 3 years ago
parent
commit
36b135f4b4
  1. 20
      controllers/account.go
  2. 46
      controllers/article.go
  3. 12
      controllers/category.go
  4. 12
      controllers/file.go
  5. 22
      controllers/site.go
  6. 18
      controllers/user.go
  7. 8
      controllers/user_invite.go
  8. 2
      middleware/template.go
  9. 2
      middleware/template_handler.go
  10. 34
      models/article.go
  11. 20
      models/category.go
  12. 24
      models/file.go
  13. 40
      models/site.go
  14. 12
      models/token.go
  15. 32
      models/user.go
  16. 10
      models/user_invite.go

20
controllers/account.go

@ -69,7 +69,7 @@ func AdminProfilePostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
if err := ctx.UserService.UpdateUser(u, changePassword); err != nil {
if err := ctx.UserService.Update(u, changePassword); err != nil {
return &middleware.Template{
Name: tplAdminProfile,
Active: "profile",
@ -157,14 +157,14 @@ func ActivateAccountPostHandler(ctx *middleware.AppContext, w http.ResponseWrite
user.Password = []byte(password)
user.Active = true
if _, err := ctx.UserService.CreateUser(user); err != nil {
if _, err := ctx.UserService.Create(user); err != nil {
return &middleware.Template{
Name: tplAdminActivateAccount,
Err: err,
}
}
if err := ctx.UserInviteService.RemoveInvite(ui.ID); err != nil {
if err := ctx.UserInviteService.Remove(ui.ID); err != nil {
return &middleware.Template{
Name: tplAdminLogin,
Active: "users",
@ -182,7 +182,7 @@ func ActivateAccountPostHandler(ctx *middleware.AppContext, w http.ResponseWrite
func ResetPasswordHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
hash := getVar(r, "hash")
t, err := ctx.TokenService.GetToken(hash, models.PasswordReset, time.Duration(1)*time.Hour)
t, err := ctx.TokenService.Get(hash, models.PasswordReset, time.Duration(1)*time.Hour)
if err != nil {
if err == sql.ErrNoRows {
@ -211,7 +211,7 @@ func ResetPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
repassword := r.FormValue("password_repeat")
hash := getVar(r, "hash")
t, err := ctx.TokenService.GetToken(hash, models.PasswordReset, time.Duration(1)*time.Hour)
t, err := ctx.TokenService.Get(hash, models.PasswordReset, time.Duration(1)*time.Hour)
if err != nil {
return &middleware.Template{
@ -220,7 +220,7 @@ func ResetPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
u, err := ctx.UserService.GetUserByID(t.Author.ID)
u, err := ctx.UserService.GetByID(t.Author.ID)
if err != nil {
return &middleware.Template{
@ -238,7 +238,7 @@ func ResetPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
u.Password = []byte(password)
err = ctx.UserService.UpdateUser(u, true)
err = ctx.UserService.Update(u, true)
if err != nil {
return &middleware.Template{
@ -248,7 +248,7 @@ func ResetPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
go func(hash string) {
err = ctx.TokenService.RemoveToken(hash, models.PasswordReset)
err = ctx.TokenService.Remove(hash, models.PasswordReset)
if err != nil {
logger.Log.Errorf("could not remove token %s error %v", hash, err)
@ -278,7 +278,7 @@ func ForgotPasswordHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
func ForgotPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
email := r.FormValue("email")
u, err := ctx.UserService.GetUserByMail(email)
u, err := ctx.UserService.GetByMail(email)
if err != nil {
if httperror.Equals(err, sql.ErrNoRows) {
@ -316,7 +316,7 @@ func ForgotPasswordPostHandler(ctx *middleware.AppContext, w http.ResponseWriter
Type: models.PasswordReset,
}
err = ctx.TokenService.CreateToken(t)
err = ctx.TokenService.Create(t)
if err != nil {
return &middleware.Template{

46
controllers/article.go

@ -22,7 +22,7 @@ func GetArticleHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *htt
month := getVar(r, "month")
slug := getVar(r, "slug")
a, err := ctx.ArticleService.GetArticleBySlug(utils.AppendString(year, "/", month, "/", slug), nil, models.OnlyPublished)
a, err := ctx.ArticleService.GetBySlug(utils.AppendString(year, "/", month, "/", slug), nil, models.OnlyPublished)
if err != nil {
return &middleware.Template{
@ -31,7 +31,7 @@ func GetArticleHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *htt
}
}
c, err := ctx.CategoryService.ListCategories(models.CategoriesWithPublishedArticles)
c, err := ctx.CategoryService.List(models.CategoriesWithPublishedArticles)
if err != nil {
return &middleware.Template{
@ -61,7 +61,7 @@ func GetArticleByIDHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
}
}
a, err := ctx.ArticleService.GetArticleByID(id, nil, models.OnlyPublished)
a, err := ctx.ArticleService.GetByID(id, nil, models.OnlyPublished)
if err != nil {
return &middleware.Template{
@ -70,7 +70,7 @@ func GetArticleByIDHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
}
}
c, err := ctx.CategoryService.ListCategories(models.CategoriesWithPublishedArticles)
c, err := ctx.CategoryService.List(models.CategoriesWithPublishedArticles)
if err != nil {
return &middleware.Template{
@ -92,7 +92,7 @@ func GetArticleByIDHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
func ListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
page := getPageParam(r)
t, err := ctx.ArticleService.CountArticles(nil, nil, models.OnlyPublished)
t, err := ctx.ArticleService.Count(nil, nil, models.OnlyPublished)
p := &models.Pagination{
Total: t,
@ -109,7 +109,7 @@ func ListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *h
}
}
a, err := ctx.ArticleService.ListArticles(nil, nil, p, models.OnlyPublished)
a, err := ctx.ArticleService.List(nil, nil, p, models.OnlyPublished)
if err != nil {
return &middleware.Template{
@ -119,7 +119,7 @@ func ListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *h
}
}
c, err := ctx.CategoryService.ListCategories(models.CategoriesWithPublishedArticles)
c, err := ctx.CategoryService.List(models.CategoriesWithPublishedArticles)
if err != nil {
return &middleware.Template{
@ -146,7 +146,7 @@ func ListArticlesCategoryHandler(ctx *middleware.AppContext, w http.ResponseWrit
category := getVar(r, "categorySlug")
c, err := ctx.CategoryService.GetCategoryBySlug(category)
c, err := ctx.CategoryService.GetBySlug(category)
if err != nil {
return &middleware.Template{
@ -156,7 +156,7 @@ func ListArticlesCategoryHandler(ctx *middleware.AppContext, w http.ResponseWrit
}
}
t, err := ctx.ArticleService.CountArticles(nil, c, models.OnlyPublished)
t, err := ctx.ArticleService.Count(nil, c, models.OnlyPublished)
p := &models.Pagination{
Total: t,
@ -173,7 +173,7 @@ func ListArticlesCategoryHandler(ctx *middleware.AppContext, w http.ResponseWrit
}
}
a, err := ctx.ArticleService.ListArticles(nil, c, p, models.OnlyPublished)
a, err := ctx.ArticleService.List(nil, c, p, models.OnlyPublished)
if err != nil {
return &middleware.Template{
@ -183,7 +183,7 @@ func ListArticlesCategoryHandler(ctx *middleware.AppContext, w http.ResponseWrit
}
}
cs, err := ctx.CategoryService.ListCategories(models.CategoriesWithPublishedArticles)
cs, err := ctx.CategoryService.List(models.CategoriesWithPublishedArticles)
if err != nil {
return &middleware.Template{
@ -206,7 +206,7 @@ func ListArticlesCategoryHandler(ctx *middleware.AppContext, w http.ResponseWrit
//IndexArticlesHandler returns the template information for the index page
func IndexArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
a, err := ctx.ArticleService.IndexArticles(nil, nil, nil, models.OnlyPublished)
a, err := ctx.ArticleService.Index(nil, nil, nil, models.OnlyPublished)
if err != nil {
return &middleware.Template{
@ -248,7 +248,7 @@ func RSSFeed(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request)
func AdminListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
u, _ := middleware.User(r)
t, err := ctx.ArticleService.CountArticles(u, nil, models.All)
t, err := ctx.ArticleService.Count(u, nil, models.All)
if err != nil {
return &middleware.Template{
@ -265,7 +265,7 @@ func AdminListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter,
RelURL: "admin/articles/page",
}
a, err := ctx.ArticleService.ListArticles(u, nil, p, models.All)
a, err := ctx.ArticleService.List(u, nil, p, models.All)
if err != nil {
return &middleware.Template{
@ -285,7 +285,7 @@ func AdminListArticlesHandler(ctx *middleware.AppContext, w http.ResponseWriter,
// AdminArticleNewHandler returns the template which shows the form to create a new article
func AdminArticleNewHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
c, err := ctx.CategoryService.ListCategories(models.AllCategories)
c, err := ctx.CategoryService.List(models.AllCategories)
if err != nil {
return &middleware.Template{
@ -306,12 +306,14 @@ func AdminArticleNewHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
// AdminArticleNewPostHandler handles the creation of a new article
func AdminArticleNewPostHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
u, _ := middleware.User(r)
a := &models.Article{
Headline: r.FormValue("headline"),
Teaser: r.FormValue("teaser"),
Content: r.FormValue("content"),
Author: u,
}
cid, err := parseInt(r.FormValue("categoryID"))
if err != nil {
@ -324,7 +326,7 @@ func AdminArticleNewPostHandler(ctx *middleware.AppContext, w http.ResponseWrite
return previewArticle(a)
}
id, err := ctx.ArticleService.CreateArticle(a)
id, err := ctx.ArticleService.Create(a)
if err != nil {
return &middleware.Template{
@ -360,7 +362,7 @@ func AdminArticleEditHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
a, err := ctx.ArticleService.GetArticleByID(id, u, models.All)
a, err := ctx.ArticleService.GetByID(id, u, models.All)
if err != nil {
return &middleware.Template{
@ -406,7 +408,7 @@ func AdminArticleEditPostHandler(ctx *middleware.AppContext, w http.ResponseWrit
return previewArticle(a)
}
if err = ctx.ArticleService.UpdateArticle(a, u); err != nil {
if err = ctx.ArticleService.Update(a, u); err != nil {
return &middleware.Template{
Name: tplAdminArticleEdit,
Err: err,
@ -440,7 +442,7 @@ func AdminArticlePublishHandler(ctx *middleware.AppContext, w http.ResponseWrite
}
}
a, err := ctx.ArticleService.GetArticleByID(id, u, models.All)
a, err := ctx.ArticleService.GetByID(id, u, models.All)
var action models.Action
@ -486,7 +488,7 @@ func AdminArticlePublishPostHandler(ctx *middleware.AppContext, w http.ResponseW
}
}
if err := ctx.ArticleService.PublishArticle(id, u); err != nil {
if err := ctx.ArticleService.Publish(id, u); err != nil {
return &middleware.Template{
RedirectPath: "admin/articles",
Err: err,
@ -516,7 +518,7 @@ func AdminArticleDeleteHandler(ctx *middleware.AppContext, w http.ResponseWriter
}
}
a, err := ctx.ArticleService.GetArticleByID(id, u, models.All)
a, err := ctx.ArticleService.GetByID(id, u, models.All)
if err != nil {
return &middleware.Template{
@ -558,7 +560,7 @@ func AdminArticleDeletePostHandler(ctx *middleware.AppContext, w http.ResponseWr
}
}
err = ctx.ArticleService.DeleteArticle(id, u)
err = ctx.ArticleService.Delete(id, u)
if err != nil {
return &middleware.Template{
RedirectPath: "admin/articles",

12
controllers/category.go

@ -14,7 +14,7 @@ import (
)
func AdminListCategoriesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
c, err := ctx.CategoryService.ListCategories(models.AllCategories)
c, err := ctx.CategoryService.List(models.AllCategories)
if err != nil {
return &middleware.Template{
@ -48,7 +48,7 @@ func AdminCategoryNewPostHandler(ctx *middleware.AppContext, w http.ResponseWrit
Author: u,
}
id, err := ctx.CategoryService.CreateCategory(c)
id, err := ctx.CategoryService.Create(c)
if err != nil {
return &middleware.Template{
@ -82,7 +82,7 @@ func AdminCategoryEditHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
c, err := ctx.CategoryService.GetCategoryByID(id)
c, err := ctx.CategoryService.GetByID(id)
if err != nil {
return &middleware.Template{
@ -122,7 +122,7 @@ func AdminCategoryEditPostHandler(ctx *middleware.AppContext, w http.ResponseWri
Author: u,
}
if err = ctx.CategoryService.UpdateCategory(c); err != nil {
if err = ctx.CategoryService.Update(c); err != nil {
return &middleware.Template{
Name: tplAdminCategoryEdit,
Err: err,
@ -154,7 +154,7 @@ func AdminCategoryDeleteHandler(ctx *middleware.AppContext, w http.ResponseWrite
}
}
c, err := ctx.CategoryService.GetCategoryByID(id)
c, err := ctx.CategoryService.GetByID(id)
if err != nil {
return &middleware.Template{
@ -194,7 +194,7 @@ func AdminCategoryDeletePostHandler(ctx *middleware.AppContext, w http.ResponseW
}
}
err = ctx.CategoryService.DeleteCategory(id)
err = ctx.CategoryService.Delete(id)
if err != nil {
return &middleware.Template{

12
controllers/file.go

@ -21,7 +21,7 @@ func FileGetHandler(ctx *middleware.AppContext) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
rv := getVar(r, "filename")
f, err := ctx.FileService.GetFileByName(rv, nil)
f, err := ctx.FileService.GetByName(rv, nil)
if err != nil {
http.Error(w, "the file was not found", http.StatusNotFound)
@ -61,7 +61,7 @@ func AdminListFilesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
page := getPageParam(r)
t, err := ctx.FileService.CountFiles(u)
t, err := ctx.FileService.Count(u)
if err != nil {
return &middleware.Template{
@ -78,7 +78,7 @@ func AdminListFilesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
RelURL: "admin/files/page",
}
fs, err := ctx.FileService.ListFiles(u, p)
fs, err := ctx.FileService.List(u, p)
if err != nil {
return &middleware.Template{
@ -176,7 +176,7 @@ func AdminUploadFilePostHandler(ctx *middleware.AppContext, w http.ResponseWrite
file.Filename = h.Filename
}
_, err = ctx.FileService.UploadFile(file, data)
_, err = ctx.FileService.Upload(file, data)
if err != nil {
return &middleware.Template{
@ -209,7 +209,7 @@ func AdminUploadDeleteHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
f, err := ctx.FileService.GetFileByID(id, u)
f, err := ctx.FileService.GetByID(id, u)
if err != nil {
return &middleware.Template{
@ -251,7 +251,7 @@ func AdminUploadDeletePostHandler(ctx *middleware.AppContext, w http.ResponseWri
}
}
err = ctx.FileService.DeleteFile(id, ctx.ConfigService.File.Location, u)
err = ctx.FileService.Delete(id, ctx.ConfigService.File.Location, u)
warnMsg := ""
if err != nil {

22
controllers/site.go

@ -17,7 +17,7 @@ import (
//SiteHandler returns the site template only published sites are considered
func SiteHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
site, err := ctx.SiteService.GetSiteByLink(getVar(r, "site"), models.OnlyPublished)
site, err := ctx.SiteService.GetByLink(getVar(r, "site"), models.OnlyPublished)
if err != nil {
if err == sql.ErrNoRows {
@ -44,7 +44,7 @@ func SiteHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Requ
func AdminSitesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
page := getPageParam(r)
total, err := ctx.SiteService.CountSites(models.All)
total, err := ctx.SiteService.Count(models.All)
if err != nil {
return &middleware.Template{
@ -61,7 +61,7 @@ func AdminSitesHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *htt
RelURL: "admin/sites/page",
}
sites, err := ctx.SiteService.ListSites(models.All, pagination)
sites, err := ctx.SiteService.List(models.All, pagination)
if err != nil {
return &middleware.Template{
@ -110,7 +110,7 @@ func AdminSiteNewPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
return previewSite(s)
}
siteID, err := ctx.SiteService.CreateSite(s)
siteID, err := ctx.SiteService.Create(s)
if err != nil {
return &middleware.Template{
Name: tplAdminSiteNew,
@ -143,7 +143,7 @@ func AdminSiteEditHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *
}
}
s, err := ctx.SiteService.GetSiteByID(siteID, models.All)
s, err := ctx.SiteService.GetByID(siteID, models.All)
if err != nil {
return &middleware.Template{
@ -185,7 +185,7 @@ func AdminSiteEditPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
return previewSite(s)
}
if err := ctx.SiteService.UpdateSite(s); err != nil {
if err := ctx.SiteService.Update(s); err != nil {
return &middleware.Template{
Name: tplAdminSites,
Err: err,
@ -230,7 +230,7 @@ func AdminSiteOrderHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
}
}
if err := ctx.SiteService.OrderSite(siteID, d); err != nil {
if err := ctx.SiteService.Order(siteID, d); err != nil {
return &middleware.Template{
Name: tplAdminSites,
Err: err,
@ -259,7 +259,7 @@ func AdminSitePublishHandler(ctx *middleware.AppContext, w http.ResponseWriter,
}
}
s, err := ctx.SiteService.GetSiteByID(siteID, models.All)
s, err := ctx.SiteService.GetByID(siteID, models.All)
if err != nil {
return &middleware.Template{
@ -311,7 +311,7 @@ func AdminSitePublishPostHandler(ctx *middleware.AppContext, w http.ResponseWrit
}
}
if err := ctx.SiteService.PublishSite(siteID); err != nil {
if err := ctx.SiteService.Publish(siteID); err != nil {
return &middleware.Template{
Name: tplAdminSites,
Err: err,
@ -340,7 +340,7 @@ func AdminSiteDeleteHandler(ctx *middleware.AppContext, w http.ResponseWriter, r
}
}
site, err := ctx.SiteService.GetSiteByID(siteID, models.All)
site, err := ctx.SiteService.GetByID(siteID, models.All)
if err != nil {
return &middleware.Template{
@ -381,7 +381,7 @@ func AdminSiteDeletePostHandler(ctx *middleware.AppContext, w http.ResponseWrite
}
}
err = ctx.SiteService.DeleteSite(siteID)
err = ctx.SiteService.Delete(siteID)
if err != nil {
return &middleware.Template{
Name: tplAdminSites,

18
controllers/user.go

@ -17,7 +17,7 @@ import (
func AdminUsersHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
page := getPageParam(r)
total, err := ctx.UserService.CountUsers(models.All)
total, err := ctx.UserService.Count(models.All)
if err != nil {
return &middleware.Template{
Name: tplAdminUsers,
@ -33,7 +33,7 @@ func AdminUsersHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *htt
RelURL: "admin/users/page",
}
users, err := ctx.UserService.ListUsers(p)
users, err := ctx.UserService.List(p)
if err != nil {
return &middleware.Template{
@ -46,7 +46,7 @@ func AdminUsersHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *htt
var userInvites []models.UserInvite
if cu, _ := middleware.User(r); cu.IsAdmin {
userInvites, err = ctx.UserInviteService.ListUserInvites()
userInvites, err = ctx.UserInviteService.List()
if err != nil {
return &middleware.Template{
@ -91,7 +91,7 @@ func AdminUserNewPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
IsAdmin: convertCheckbox(r, "admin"),
}
userID, err := ctx.UserService.CreateUser(u)
userID, err := ctx.UserService.Create(u)
if err != nil {
return &middleware.Template{
Name: tplAdminUserNew,
@ -124,7 +124,7 @@ func AdminUserEditHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *
}
}
u, err := ctx.UserService.GetUserByID(userID)
u, err := ctx.UserService.GetByID(userID)
if err != nil {
return &middleware.Template{
@ -170,7 +170,7 @@ func AdminUserEditPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
changePassword = true
}
if err := ctx.UserService.UpdateUser(u, changePassword); err != nil {
if err := ctx.UserService.Update(u, changePassword); err != nil {
return &middleware.Template{
Name: tplAdminUserEdit,
Err: err,
@ -192,7 +192,7 @@ func AdminUserEditPostHandler(ctx *middleware.AppContext, w http.ResponseWriter,
func AdminUserDeleteHandler(ctx *middleware.AppContext, w http.ResponseWriter, r *http.Request) *middleware.Template {
userID, err := parseInt(getVar(r, "userID"))
user, err := ctx.UserService.GetUserByID(userID)
user, err := ctx.UserService.GetByID(userID)
if err != nil {
return &middleware.Template{
@ -244,7 +244,7 @@ func AdminUserDeletePostHandler(ctx *middleware.AppContext, w http.ResponseWrite
}
}
user, err := ctx.UserService.GetUserByID(userID)
user, err := ctx.UserService.GetByID(userID)
if err != nil {
return &middleware.Template{
@ -254,7 +254,7 @@ func AdminUserDeletePostHandler(ctx *middleware.AppContext, w http.ResponseWrite
}
}
if err := ctx.UserService.RemoveUser(user); err != nil {
if err := ctx.UserService.Remove(user); err != nil {
return &middleware.Template{
Name: tplAdminUsers,
Active: "users",

8
controllers/user_invite.go

@ -27,7 +27,7 @@ func AdminUserInviteNewPostHandler(ctx *middleware.AppContext, w http.ResponseWr
CreatedBy: user,
}
inviteID, err := ctx.UserInviteService.CreateUserInvite(ui)
inviteID, err := ctx.UserInviteService.Create(ui)
if err != nil {
return &middleware.Template{
@ -67,7 +67,7 @@ func AdminUserInviteResendPostHandler(ctx *middleware.AppContext, w http.Respons
}
}
ui, err := ctx.UserInviteService.GetInvite(inviteID)
ui, err := ctx.UserInviteService.Get(inviteID)
if err != nil {
return &middleware.Template{
@ -104,7 +104,7 @@ func AdminUserInviteDeleteHandler(ctx *middleware.AppContext, w http.ResponseWri
}
}
invite, err := ctx.UserInviteService.GetInvite(inviteID)
invite, err := ctx.UserInviteService.Get(inviteID)
if err != nil {
return &middleware.Template{
@ -142,7 +142,7 @@ func AdminUserInviteDeletePostHandler(ctx *middleware.AppContext, w http.Respons
}
}
if err := ctx.UserInviteService.RemoveInvite(inviteID); err != nil {
if err := ctx.UserInviteService.Remove(inviteID); err != nil {
return &middleware.Template{
Name: tplAdminUsers,
Active: "users",

2
middleware/template.go

@ -140,7 +140,7 @@ func FuncMap(ss models.SiteService, cfg *settings.Settings) template.FuncMap {
return template.HTML(out)
},
"GetSites": func() []models.Site {
sites, err := ss.ListSites(models.OnlyPublished, nil)
sites, err := ss.List(models.OnlyPublished, nil)
if err != nil {
logger.Log.Error(err)

2
middleware/template_handler.go

@ -142,7 +142,7 @@ func (ctx AppContext) AuthHandler(handler http.Handler) http.Handler {
return
}
u, err := ctx.UserService.GetUserByID(userid)
u, err := ctx.UserService.GetByID(userid)
if err != nil {
logger.Log.Error(err)
rw.WriteHeader(http.StatusUnauthorized)

34
models/article.go

@ -91,8 +91,8 @@ type ArticleService struct {
AppConfig settings.Application
}
// CreateArticle creates an article
func (as ArticleService) CreateArticle(a *Article) (int, error) {
// Create creates an article
func (as ArticleService) Create(a *Article) (int, error) {
curTime := time.Now()
for i := 0; i < 10; i++ {
@ -122,8 +122,8 @@ func (as ArticleService) CreateArticle(a *Article) (int, error) {
return artID, nil
}
//UpdateArticle updates an article
func (as ArticleService) UpdateArticle(a *Article, u *User) error {
//Update updates an article
func (as ArticleService) Update(a *Article, u *User) error {
if err := a.validate(); err != nil {
return err
}
@ -142,8 +142,8 @@ func (as ArticleService) UpdateArticle(a *Article, u *User) error {
return as.Datasource.Update(a)
}
//PublishArticle publishes or 'unpublishes' an article
func (as ArticleService) PublishArticle(id int, u *User) error {
//Publish publishes or 'unpublishes' an article
func (as ArticleService) Publish(id int, u *User) error {
a, err := as.Datasource.Get(id, nil, All)
if err != nil {
@ -159,8 +159,8 @@ func (as ArticleService) PublishArticle(id int, u *User) error {
return as.Datasource.Publish(a)
}
//DeleteArticle deletes an article
func (as ArticleService) DeleteArticle(id int, u *User) error {
//Delete deletes an article
func (as ArticleService) Delete(id int, u *User) error {
a, err := as.Datasource.Get(id, nil, All)
if err != nil {
@ -176,9 +176,9 @@ func (as ArticleService) DeleteArticle(id int, u *User) error {
return as.Datasource.Delete(a.ID)
}
// GetArticleBySlug gets a article by the slug.
// GetBySlug gets a article by the slug.
// The publishedCriteria defines whether the published and/or unpublished articles should be considered
func (as ArticleService) GetArticleBySlug(s string, u *User, pc PublishedCriteria) (*Article, error) {
func (as ArticleService) GetBySlug(s string, u *User, pc PublishedCriteria) (*Article, error) {
a, err := as.Datasource.GetBySlug(s, u, pc)
if err != nil {
@ -199,9 +199,9 @@ func (as ArticleService) GetArticleBySlug(s string, u *User, pc PublishedCriteri
return a, nil
}
// GetArticleByID get a article by the id.
// GetByID get a article by the id.
// The publishedCriteria defines whether the published and/or unpublished articles should be considered
func (as ArticleService) GetArticleByID(id int, u *User, pc PublishedCriteria) (*Article, error) {
func (as ArticleService) GetByID(id int, u *User, pc PublishedCriteria) (*Article, error) {
a, err := as.Datasource.Get(id, u, pc)
if err != nil {
@ -222,15 +222,15 @@ func (as ArticleService) GetArticleByID(id int, u *User, pc PublishedCriteria) (
return a, nil
}
// CountArticles returns the number of articles.
// Count returns the number of articles.
// The publishedCriteria defines whether the published and/or unpublished articles should be considered
func (as ArticleService) CountArticles(u *User, c *Category, pc PublishedCriteria) (int, error) {
func (as ArticleService) Count(u *User, c *Category, pc PublishedCriteria) (int, error) {
return as.Datasource.Count(u, c, pc)
}
// ListArticles returns all article by the slug.
// List returns all article by the slug.
// The publishedCriteria defines whether the published and/or unpublished articles should be considered
func (as ArticleService) ListArticles(u *User, c *Category, p *Pagination, pc PublishedCriteria) ([]Article, error) {
func (as ArticleService) List(u *User, c *Category, p *Pagination, pc PublishedCriteria) ([]Article, error) {
return as.Datasource.List(u, c, p, pc)
}
@ -279,7 +279,7 @@ type IndexArticle struct {
Articles []Article
}
func (as ArticleService) IndexArticles(u *User, c *Category, p *Pagination, pc PublishedCriteria) ([]IndexArticle, error) {
func (as ArticleService) Index(u *User, c *Category, p *Pagination, pc PublishedCriteria) ([]IndexArticle, error) {
arts, err := as.Datasource.List(u, c, p, pc)
if err != nil {

20
models/category.go

@ -62,7 +62,7 @@ func (c Category) SlugEscape() string {
return url.PathEscape(c.Slug)
}
func (cs CategoryService) GetCategoryBySlug(s string) (*Category, error) {
func (cs CategoryService) GetBySlug(s string) (*Category, error) {
c, err := cs.Datasource.GetBySlug(s)
if err != nil {
@ -75,7 +75,7 @@ func (cs CategoryService) GetCategoryBySlug(s string) (*Category, error) {
return c, nil
}
func (cs CategoryService) GetCategoryByID(id int) (*Category, error) {
func (cs CategoryService) GetByID(id int) (*Category, error) {
c, err := cs.Datasource.Get(id)
if err != nil {
@ -88,16 +88,16 @@ func (cs CategoryService) GetCategoryByID(id int) (*Category, error) {
return c, nil
}
func (cs CategoryService) CountCategories(fc FilterCriteria) (int, error) {
func (cs CategoryService) Count(fc FilterCriteria) (int, error) {
return cs.Datasource.Count(fc)
}
func (cs CategoryService) ListCategories(fc FilterCriteria) ([]Category, error) {
func (cs CategoryService) List(fc FilterCriteria) ([]Category, error) {
return cs.Datasource.List(fc)
}
// CreateCategory creates a category
func (cs CategoryService) CreateCategory(c *Category) (int, error) {
//Create creates a category
func (cs CategoryService) Create(c *Category) (int, error) {
for i := 0; i < 10; i++ {
c.Slug = utils.CreateURLSafeSlug(c.Name, i)
_, err := cs.Datasource.GetBySlug(c.Slug)
@ -122,8 +122,8 @@ func (cs CategoryService) CreateCategory(c *Category) (int, error) {
return cid, nil
}
//UpdateCategory updates a category
func (cs CategoryService) UpdateCategory(c *Category) error {
//Update updates a category
func (cs CategoryService) Update(c *Category) error {
if err := c.validate(); err != nil {
return err
}
@ -131,8 +131,8 @@ func (cs CategoryService) UpdateCategory(c *Category) error {
return cs.Datasource.Update(c)
}
//DeleteCategory removes a category
func (cs CategoryService) DeleteCategory(id int) error {
//Delete removes a category
func (cs CategoryService) Delete(id int) error {
c, err := cs.Datasource.Get(id)
if err != nil {

24
models/file.go

@ -60,32 +60,32 @@ type FileService struct {
Datasource FileDatasourceService
}
//GetFileByID returns the file based on the fileID; it the user is given and it is a non admin
//GetByID returns the file based on the fileID; it the user is given and it is a non admin
//only file specific to this user is returned
func (fs FileService) GetFileByID(fileID int, u *User) (*File, error) {
func (fs FileService) GetByID(fileID int, u *User) (*File, error) {
return fs.Datasource.Get(fileID, u)
}
//GetFileByName returns the file based on the filename; it the user is given and it is a non admin
//GetByName returns the file based on the filename; it the user is given and it is a non admin
//only file specific to this user is returned
func (fs FileService) GetFileByName(filename string, u *User) (*File, error) {
func (fs FileService) GetByName(filename string, u *User) (*File, error) {
return fs.Datasource.GetByFilename(filename, u)
}
//ListFiles returns a list of files based on the filename; it the user is given and it is a non admin
//List returns a list of files based on the filename; it the user is given and it is a non admin
//only files specific to this user are returned
func (fs FileService) ListFiles(u *User, p *Pagination) ([]File, error) {
func (fs FileService) List(u *User, p *Pagination) ([]File, error) {
return fs.Datasource.List(u, p)
}
//CountFiles returns a number of files based on the filename; it the user is given and it is a non admin
//Count returns a number of files based on the filename; it the user is given and it is a non admin
//only files specific to this user are counted
func (fs FileService) CountFiles(u *User) (int, error) {
func (fs FileService) Count(u *User) (int, error) {
return fs.Datasource.Count(u)
}
//DeleteFile deletes a file based on fileID; users which are not the owner are not allowed to remove files; except admins
func (fs FileService) DeleteFile(fileID int, location string, u *User) error {
//Delete deletes a file based on fileID; users which are not the owner are not allowed to remove files; except admins
func (fs FileService) Delete(fileID int, location string, u *User) error {
file, err := fs.Datasource.Get(fileID, u)
if err != nil {
@ -107,8 +107,8 @@ func (fs FileService) DeleteFile(fileID int, location string, u *User) error {
return os.Remove(filepath.Join(location, file.Filename))
}
//UploadFile uploaded files will be saved at the configured file location, filename is saved in the database
func (fs FileService) UploadFile(f *File, data []byte) (int, error) {
//Upload uploaded files will be saved at the configured file location, filename is saved in the database
func (fs FileService) Upload(f *File, data []byte) (int, error) {
if err := f.validate(); err != nil {
return -1, err
}

40
models/site.go

@ -114,13 +114,13 @@ type SiteService struct {
Datasource SiteDatasourceService
}
// ListSites returns all sites
func (ss SiteService) ListSites(pc PublishedCriteria, p *Pagination) ([]Site, error) {
//List returns all sites
func (ss SiteService) List(pc PublishedCriteria, p *Pagination) ([]Site, error) {
return ss.Datasource.List(pc, p)
}
//PublishSite switches the publish state of the site
func (ss SiteService) PublishSite(siteID int) error {
//Publish switches the publish state of the site
func (ss SiteService) Publish(siteID int) error {
s, err := ss.Datasource.Get(siteID, All)
if err != nil {
@ -136,8 +136,8 @@ func (ss SiteService) PublishSite(siteID int) error {
return nil
}
// CreateSite creates a site
func (ss SiteService) CreateSite(s *Site) (int, error) {
//Create creates a site
func (ss SiteService) Create(s *Site) (int, error) {
if err := s.validate(ss.Datasource, true); err != nil {
return -1, err
}
@ -155,14 +155,14 @@ func (ss SiteService) CreateSite(s *Site) (int, error) {
return ss.Datasource.Create(s)
}
//OrderSite reorder the site
func (ss SiteService) OrderSite(siteID int, dir Direction) error {
//Order reorder the site
func (ss SiteService) Order(siteID int, dir Direction) error {
return ss.Datasource.Order(siteID, dir)
}
//UpdateSite updates a site
func (ss SiteService) UpdateSite(s *Site) error {
oldSite, err := ss.GetSiteByID(s.ID, All)
//Update updates a site
func (ss SiteService) Update(s *Site) error {
oldSite, err := ss.GetByID(s.ID, All)
if err != nil {
return err
@ -181,9 +181,9 @@ func (ss SiteService) UpdateSite(s *Site) error {
return ss.Datasource.Update(s)
}
//DeleteSite deletes a site
func (ss SiteService) DeleteSite(siteID int) error {
s, err := ss.GetSiteByID(siteID, All)
//Delete deletes a site
func (ss SiteService) Delete(siteID int) error {
s, err := ss.GetByID(siteID, All)
if err != nil {
return err
@ -192,19 +192,19 @@ func (ss SiteService) DeleteSite(siteID int) error {
return ss.Datasource.Delete(s)
}
// GetSiteByLink Get a site by the link.
func (ss SiteService) GetSiteByLink(link string, pc PublishedCriteria) (*Site, error) {
// GetByLink Get a site by the link.
func (ss SiteService) GetByLink(link string, pc PublishedCriteria) (*Site, error) {
return ss.Datasource.GetByLink(link, pc)
}
// GetSiteByID Get a site by the id.
func (ss SiteService) GetSiteByID(siteID int, pc PublishedCriteria) (*Site, error) {
// GetByID Get a site by the id.
func (ss SiteService) GetByID(siteID int, pc PublishedCriteria) (*Site, error) {
return ss.Datasource.Get(siteID, pc)
}
// CountSites returns the number of sites
func (ss SiteService) CountSites(pc PublishedCriteria) (int, error) {
// Count returns the number of sites
func (ss SiteService) Count(pc PublishedCriteria) (int, error) {
return ss.Datasource.Count(pc)
}

12
models/token.go

@ -65,8 +65,8 @@ type TokenService struct {
Datasource TokenDatasourceService
}
//CreateToken creates a new token
func (ts TokenService) CreateToken(t *Token) error {
//Create creates a new token
func (ts TokenService) Create(t *Token) error {
t.Hash = utils.RandomHash(32)
_, err := ts.Datasource.Create(t)
@ -74,9 +74,9 @@ func (ts TokenService) CreateToken(t *Token) error {
return err
}
//GetToken gets all token for a defined token type expires after a defined time
//Get gets all token for a defined token type expires after a defined time
//Expired tokens will be removed
func (ts TokenService) GetToken(hash string, tt TokenType, expireAfter time.Duration) (*Token, error) {
func (ts TokenService) Get(hash string, tt TokenType, expireAfter time.Duration) (*Token, error) {
token, err := ts.Datasource.Get(hash, tt)
if err != nil {
@ -95,7 +95,7 @@ func (ts TokenService) GetToken(hash string, tt TokenType, expireAfter time.Dura
return token, nil
}
//RemoveToken removes a token
func (ts TokenService) RemoveToken(hash string, tt TokenType) error {
//Remove removes a token
func (ts TokenService) Remove(hash string, tt TokenType) error {
return ts.Datasource.Remove(hash, tt)
}

32
models/user.go

@ -161,18 +161,18 @@ func (us UserService) duplicateUsername(username string) error {
return nil
}
//CountUsers returns the amount of users
func (us UserService) CountUsers(a AdminCriteria) (int, error) {
//Count returns the amount of users
func (us UserService) Count(a AdminCriteria) (int, error) {
return us.Datasource.Count(a)
}
//ListUsers returns a list of users. Limits the amount based on the defined pagination
func (us UserService) ListUsers(p *Pagination) ([]User, error) {
//List returns a list of users. Limits the amount based on the defined pagination
func (us UserService) List(p *Pagination) ([]User, error) {
return us.Datasource.List(p)
}
//GetUserByID gets the user based on the given id; will not contain the user password
func (us UserService) GetUserByID(userID int) (*User, error) {
//GetByID gets the user based on the given id; will not contain the user password
func (us UserService) GetByID(userID int) (*User, error) {
u, err := us.Datasource.Get(userID)
if err != nil {
if err == sql.ErrNoRows {
@ -184,8 +184,8 @@ func (us UserService) GetUserByID(userID int) (*User, error) {
return u, nil
}
//GetUserByUsername gets the user based on the given username; will contain the user password
func (us UserService) GetUserByUsername(username string) (*User, error) {
//GetByUsername gets the user based on the given username; will contain the user password
func (us UserService) GetByUsername(username string) (*User, error) {
u, err := us.Datasource.GetByUsername(username)
if err != nil {
if err == sql.ErrNoRows {
@ -197,8 +197,8 @@ func (us UserService) GetUserByUsername(username string) (*User, error) {
return u, nil
}
//GetUserByMail gets the user based on the given mail; will contain the user password
func (us UserService) GetUserByMail(mail string) (*User, error) {
//GetByMail gets the user based on the given mail; will contain the user password
func (us UserService) GetByMail(mail string) (*User, error) {
u, err := us.Datasource.GetByMail(mail)
if err != nil {
@ -211,9 +211,9 @@ func (us UserService) GetUserByMail(mail string) (*User, error) {
return u, nil
}
//CreateUser creates the user
//Create creates the user
//If an UserInterceptor is available the action PreCreate is executed before creating and PostCreate after creating the user
func (us UserService) CreateUser(u *User) (int, error) {
func (us UserService) Create(u *User) (int, error) {
if us.UserInterceptor != nil {
if err := us.UserInterceptor.PreCreate(u); err != nil {
return -1, httperror.InternalServerError(fmt.Errorf("error while executing user interceptor 'PreCreate' error %v", err))
@ -253,9 +253,9 @@ func (us UserService) CreateUser(u *User) (int, error) {
return userID, nil
}
//UpdateUser updates the user
//Update updates the user
//If an UserInterceptor is available the action PreUpdate is executed before updating and PostUpdate after updating the user
func (us UserService) UpdateUser(u *User, changePassword bool) error {
func (us UserService) Update(u *User, changePassword bool) error {
oldUser, err := us.Datasource.Get(u.ID)
if err != nil {
@ -367,8 +367,8 @@ func (us UserService) Authenticate(u *User, loginMethod settings.LoginMethod, pa
return u, nil
}
// RemoveUser removes the user returns an error if no administrator would remain
func (us UserService) RemoveUser(u *User) error {
// Remove removes the user returns an error if no administrator would remain
func (us UserService) Remove(u *User) error {
if us.UserInterceptor != nil {
if err := us.UserInterceptor.PreRemove(u); err != nil {
return httperror.InternalServerError(fmt.Errorf("error while executing user interceptor 'PreRemove' error %v", err))

10
models/user_invite.go

@ -59,11 +59,11 @@ func (ui UserInvite) validate(uis UserInviteService) error {
return nil
}
func (uis UserInviteService) ListUserInvites() ([]UserInvite, error) {
func (uis UserInviteService) List() ([]UserInvite, error) {
return uis.Datasource.List()
}
func (uis UserInviteService) UpdateUserInvites(ui *UserInvite) error {
func (uis UserInviteService) Update(ui *UserInvite) error {
ui.Hash = utils.RandomHash(32)
if err := ui.validate(uis); err != nil {
@ -73,7 +73,7 @@ func (uis UserInviteService) UpdateUserInvites(ui *UserInvite) error {
return uis.Datasource.Update(ui)
}
func (uis UserInviteService) CreateUserInvite(ui *UserInvite) (int, error) {
func (uis UserInviteService) Create(ui *UserInvite) (int, error) {
ui.Hash = utils.RandomHash(32)
if err := ui.validate(uis); err != nil {
@ -83,7 +83,7 @@ func (uis UserInviteService) CreateUserInvite(ui *UserInvite) (int, error) {
return uis.Datasource.Create(ui)
}
func (uis UserInviteService) GetInvite(inviteID int) (*UserInvite, error) {
func (uis UserInviteService) Get(inviteID int) (*UserInvite, error) {
return uis.Datasource.Get(inviteID)
}
@ -91,6 +91,6 @@ func (uis UserInviteService) GetByHash(hash string) (*UserInvite, error) {
return uis.Datasource.GetByHash(hash)
}
func (uis UserInviteService) RemoveInvite(inviteID int) error {
func (uis UserInviteService) Remove(inviteID int) error {
return uis.Datasource.Remove(inviteID)
}

Loading…
Cancel
Save