feat(post): enhance post handling with channel integration

- Updated PostHandler to include channel information in post responses.
- Introduced PostChannelBrief DTO to represent channel details associated with posts.
- Modified post conversion functions to support channel data, ensuring proper mapping of channel IDs to channel names.
- Enhanced ChannelRepository and ChannelService to facilitate batch retrieval of channels by IDs.
- Updated wire generation to inject channel service into post handler for improved functionality.
This commit is contained in:
lafay
2026-03-25 00:58:41 +08:00
parent fc0d6ff19d
commit 7c14cf5bab
7 changed files with 137 additions and 40 deletions

View File

@@ -8,6 +8,7 @@ import (
type ChannelService interface {
ListActive() ([]*model.Channel, error)
ListAll() ([]*model.Channel, error)
MapByIDs(ids []string) (map[string]*model.Channel, error)
Create(name, slug, description string, sortOrder int, isActive bool) (*model.Channel, error)
Update(id, name, slug, description string, sortOrder int, isActive bool) (*model.Channel, error)
Delete(id string) error
@@ -29,6 +30,20 @@ func (s *channelServiceImpl) ListAll() ([]*model.Channel, error) {
return s.channelRepo.ListAll()
}
func (s *channelServiceImpl) MapByIDs(ids []string) (map[string]*model.Channel, error) {
list, err := s.channelRepo.ListByIDs(ids)
if err != nil {
return nil, err
}
m := make(map[string]*model.Channel, len(list))
for _, ch := range list {
if ch != nil {
m[ch.ID] = ch
}
}
return m, nil
}
func (s *channelServiceImpl) Create(name, slug, description string, sortOrder int, isActive bool) (*model.Channel, error) {
channel := &model.Channel{
Name: name,