feat(channel): integrate channel functionality into post management
All checks were successful
Build Backend / build (push) Successful in 19m14s
Build Backend / build-docker (push) Successful in 1m28s

- Added Channel support in Post model, including ChannelID field in PostRequest and PostResponse DTOs.
- Updated PostService and PostRepository to handle channel-specific logic for creating and listing posts.
- Introduced ChannelRepository and ChannelService, along with corresponding handlers for managing channels.
- Enhanced router to include routes for channel management and public channel listing.
- Seeded default channels in the database during initialization.
This commit is contained in:
lafay
2026-03-24 22:27:53 +08:00
parent 15f0f1605e
commit fc0d6ff19d
19 changed files with 416 additions and 42 deletions

32
internal/model/channel.go Normal file
View File

@@ -0,0 +1,32 @@
package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// Channel 频道配置(用于帖子分区)
type Channel struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
Name string `json:"name" gorm:"type:varchar(100);not null"`
Slug string `json:"slug" gorm:"type:varchar(100);uniqueIndex;not null"`
Description string `json:"description" gorm:"type:varchar(255)"`
SortOrder int `json:"sort_order" gorm:"default:0;index"`
IsActive bool `json:"is_active" gorm:"default:true;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
func (c *Channel) BeforeCreate(tx *gorm.DB) error {
if c.ID == "" {
c.ID = uuid.New().String()
}
return nil
}
func (Channel) TableName() string {
return "channels"
}