mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
2 years ago
|
package api
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
|
||
|
"github.com/go-sonic/sonic/consts"
|
||
|
"github.com/go-sonic/sonic/service"
|
||
|
"github.com/go-sonic/sonic/service/assembler"
|
||
|
)
|
||
|
|
||
|
type ArchiveHandler struct {
|
||
|
PostService service.PostService
|
||
|
PostAssembler assembler.PostAssembler
|
||
|
}
|
||
|
|
||
|
func NewArchiveHandler(postService service.PostService, postAssemeber assembler.PostAssembler) *ArchiveHandler {
|
||
|
return &ArchiveHandler{
|
||
|
PostService: postService,
|
||
|
PostAssembler: postAssemeber,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *ArchiveHandler) ListYearArchives(ctx *gin.Context) (interface{}, error) {
|
||
|
posts, err := a.PostService.GetByStatus(ctx, []consts.PostStatus{consts.PostStatusPublished}, consts.PostTypePost, nil)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return a.PostAssembler.ConvertToArchiveYearVOs(ctx, posts)
|
||
|
}
|
||
|
|
||
|
func (a *ArchiveHandler) ListMonthArchives(ctx *gin.Context) (interface{}, error) {
|
||
|
posts, err := a.PostService.GetByStatus(ctx, []consts.PostStatus{consts.PostStatusPublished}, consts.PostTypePost, nil)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return a.PostAssembler.ConvertTOArchiveMonthVOs(ctx, posts)
|
||
|
}
|