feat: release v1.0.0
This commit is contained in:
@@ -3,7 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"net/netip"
|
||||
db "server/internal/db/sqlc"
|
||||
"server/internal/db"
|
||||
"server/internal/db/sqlc"
|
||||
"server/internal/model/common"
|
||||
"server/internal/model/response"
|
||||
"server/internal/pkg/dberr"
|
||||
@@ -12,27 +13,27 @@ import (
|
||||
)
|
||||
|
||||
type PostService struct {
|
||||
queries *db.Queries
|
||||
store *db.Store
|
||||
}
|
||||
|
||||
func NewPostService(queries *db.Queries) *PostService {
|
||||
func NewPostService(store *db.Store) *PostService {
|
||||
return &PostService{
|
||||
queries: queries,
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PostService) ListPage(ctx context.Context, p *common.Pagination) ([]db.ListPublishedPostsRow, int64, error) {
|
||||
params := db.ListPublishedPostsParams{
|
||||
func (s *PostService) ListPage(ctx context.Context, p *common.Pagination) ([]sqlc.ListPublishedPostsRow, int64, error) {
|
||||
params := sqlc.ListPublishedPostsParams{
|
||||
Limit: p.PageSize,
|
||||
Offset: (p.Page - 1) * p.PageSize,
|
||||
}
|
||||
|
||||
total, err := s.queries.CountPublishedPosts(ctx)
|
||||
total, err := s.store.CountPublishedPosts(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
list, err := s.queries.ListPublishedPosts(ctx, params)
|
||||
list, err := s.store.ListPublishedPosts(ctx, params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -45,13 +46,13 @@ func (s *PostService) ListPage(ctx context.Context, p *common.Pagination) ([]db.
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
func (s *PostService) GetPost(ctx context.Context, slug string, ip netip.Addr) (*db.GetPublicPostBySlugRow, error) {
|
||||
post, err := s.queries.GetPublicPostBySlug(ctx, slug)
|
||||
func (s *PostService) GetPost(ctx context.Context, slug string, ip netip.Addr) (*sqlc.GetPublicPostBySlugRow, error) {
|
||||
post, err := s.store.GetPublicPostBySlug(ctx, slug)
|
||||
if err != nil {
|
||||
return nil, dberr.MapNoRows(err, errs.ErrPostNotFound)
|
||||
}
|
||||
|
||||
_ = s.queries.IncrementPostStatsView(ctx, db.IncrementPostStatsViewParams{
|
||||
_ = s.store.IncrementPostStatsView(ctx, sqlc.IncrementPostStatsViewParams{
|
||||
PostID: post.ID,
|
||||
Ip: ip,
|
||||
})
|
||||
@@ -59,12 +60,12 @@ func (s *PostService) GetPost(ctx context.Context, slug string, ip netip.Addr) (
|
||||
return &post, nil
|
||||
}
|
||||
|
||||
func (s *PostService) ListCategoryStats(ctx context.Context) ([]db.ListCategoryStatsRow, error) {
|
||||
return s.queries.ListCategoryStats(ctx)
|
||||
func (s *PostService) ListCategoryStats(ctx context.Context) ([]sqlc.ListCategoryStatsRow, error) {
|
||||
return s.store.ListCategoryStats(ctx)
|
||||
}
|
||||
|
||||
func (s *PostService) ListArchives(ctx context.Context) ([]response.ArchiveYear, error) {
|
||||
list, err := s.queries.ListArchives(ctx)
|
||||
list, err := s.store.ListArchives(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -111,3 +112,7 @@ func (s *PostService) ListArchives(ctx context.Context) ([]response.ArchiveYear,
|
||||
|
||||
return archive, nil
|
||||
}
|
||||
|
||||
func (s *PostService) ListPostTags(ctx context.Context) ([]sqlc.Tag, error) {
|
||||
return s.store.ListAllTags(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user