feat: enhance post management with pagination, search, and order functionality
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 11s

- Added search input for filtering posts by keywords.
- Implemented pagination controls for navigating through posts.
- Introduced order selector for sorting posts based on various criteria.
- Enhanced post item display with additional metrics (view count, like count, comment count).
- Added dropdown menu for post actions (edit, view, toggle privacy, delete).
- Integrated double confirmation for delete action.
- Updated user profile to support background image upload.
- Improved user security settings with better layout and validation.
- Refactored auth context to use useCallback for logout function.
- Added command palette component for improved command execution.
- Introduced popover component for better UI interactions.
- Implemented debounce hooks for optimized state updates.
- Updated localization files with new keys for improved internationalization.
- Added tailwind configuration for styling.
This commit is contained in:
2025-09-25 00:51:29 +08:00
parent 59b68613cd
commit 64b1c54911
44 changed files with 2790 additions and 474 deletions

View File

@ -1,110 +1,110 @@
package service
import (
"github.com/snowykami/neo-blog/internal/dto"
"github.com/snowykami/neo-blog/internal/model"
"github.com/snowykami/neo-blog/internal/repo"
"github.com/snowykami/neo-blog/pkg/errs"
"gorm.io/gorm"
"github.com/snowykami/neo-blog/internal/dto"
"github.com/snowykami/neo-blog/internal/model"
"github.com/snowykami/neo-blog/internal/repo"
"github.com/snowykami/neo-blog/pkg/errs"
"gorm.io/gorm"
)
type AdminService struct{}
func NewAdminService() *AdminService {
return &AdminService{}
return &AdminService{}
}
func (c *AdminService) GetDashboard() (map[string]any, error) {
var (
postCount, commentCount, userCount, viewCount int64
err error
mustCount = func(q *gorm.DB, dest *int64) {
if err == nil {
err = q.Count(dest).Error
}
}
mustScan = func(q *gorm.DB, dest *int64) {
if err == nil {
err = q.Scan(dest).Error
}
}
)
db := repo.GetDB()
var (
postCount, commentCount, userCount, viewCount int64
err error
mustCount = func(q *gorm.DB, dest *int64) {
if err == nil {
err = q.Count(dest).Error
}
}
mustScan = func(q *gorm.DB, dest *int64) {
if err == nil {
err = q.Scan(dest).Error
}
}
)
db := repo.GetDB()
mustCount(db.Model(&model.Comment{}), &commentCount)
mustCount(db.Model(&model.Post{}), &postCount)
mustCount(db.Model(&model.User{}), &userCount)
mustScan(db.Model(&model.Post{}).Select("SUM(view_count)"), &viewCount)
mustCount(db.Model(&model.Comment{}), &commentCount)
mustCount(db.Model(&model.Post{}), &postCount)
mustCount(db.Model(&model.User{}), &userCount)
mustScan(db.Model(&model.Post{}).Select("SUM(view_count)"), &viewCount)
if err != nil {
return nil, err
}
return map[string]any{
"total_comments": commentCount,
"total_posts": postCount,
"total_users": userCount,
"total_views": viewCount,
}, nil
if err != nil {
return nil, err
}
return map[string]any{
"total_comments": commentCount,
"total_posts": postCount,
"total_users": userCount,
"total_views": viewCount,
}, nil
}
func (c *AdminService) CreateOidcConfig(req *dto.AdminOidcConfigDto) error {
oidcConfig := &model.OidcConfig{
Name: req.Name,
DisplayName: req.DisplayName,
Icon: req.Icon,
ClientID: req.ClientID,
ClientSecret: req.ClientSecret,
OidcDiscoveryUrl: req.OidcDiscoveryUrl,
Enabled: req.Enabled,
Type: req.Type,
}
return repo.Oidc.CreateOidcConfig(oidcConfig)
oidcConfig := &model.OidcConfig{
Name: req.Name,
DisplayName: req.DisplayName,
Icon: req.Icon,
ClientID: req.ClientID,
ClientSecret: req.ClientSecret,
OidcDiscoveryUrl: req.OidcDiscoveryUrl,
Enabled: req.Enabled,
Type: req.Type,
}
return repo.Oidc.CreateOidcConfig(oidcConfig)
}
func (c *AdminService) DeleteOidcConfig(id string) error {
if id == "" {
return errs.ErrBadRequest
}
return repo.Oidc.DeleteOidcConfig(id)
if id == "" {
return errs.ErrBadRequest
}
return repo.Oidc.DeleteOidcConfig(id)
}
func (c *AdminService) GetOidcConfigByID(id string) (*dto.AdminOidcConfigDto, error) {
if id == "" {
return nil, errs.ErrBadRequest
}
config, err := repo.Oidc.GetOidcConfigByID(id)
if err != nil {
return nil, err
}
return config.ToAdminDto(), nil
if id == "" {
return nil, errs.ErrBadRequest
}
config, err := repo.Oidc.GetOidcConfigByID(id)
if err != nil {
return nil, err
}
return config.ToAdminDto(), nil
}
func (c *AdminService) ListOidcConfigs(onlyEnabled bool) ([]*dto.AdminOidcConfigDto, error) {
configs, err := repo.Oidc.ListOidcConfigs(onlyEnabled)
if err != nil {
return nil, err
}
var dtos []*dto.AdminOidcConfigDto
for _, config := range configs {
dtos = append(dtos, config.ToAdminDto())
}
return dtos, nil
configs, err := repo.Oidc.ListOidcConfigs(onlyEnabled)
if err != nil {
return nil, err
}
var dtos []*dto.AdminOidcConfigDto
for _, config := range configs {
dtos = append(dtos, config.ToAdminDto())
}
return dtos, nil
}
func (c *AdminService) UpdateOidcConfig(req *dto.AdminOidcConfigDto) error {
if req.ID == 0 {
return errs.ErrBadRequest
}
oidcConfig := &model.OidcConfig{
Model: gorm.Model{ID: req.ID},
Name: req.Name,
DisplayName: req.DisplayName,
Icon: req.Icon,
ClientID: req.ClientID,
ClientSecret: req.ClientSecret,
OidcDiscoveryUrl: req.OidcDiscoveryUrl,
Enabled: req.Enabled,
Type: req.Type,
}
return repo.Oidc.UpdateOidcConfig(oidcConfig)
if req.ID == 0 {
return errs.ErrBadRequest
}
oidcConfig := &model.OidcConfig{
Model: gorm.Model{ID: req.ID},
Name: req.Name,
DisplayName: req.DisplayName,
Icon: req.Icon,
ClientID: req.ClientID,
ClientSecret: req.ClientSecret,
OidcDiscoveryUrl: req.OidcDiscoveryUrl,
Enabled: req.Enabled,
Type: req.Type,
}
return repo.Oidc.UpdateOidcConfig(oidcConfig)
}