优化
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type AnnouncementInput struct {
|
||||
@@ -22,15 +23,12 @@ func NewAnnouncementService(uc *biz.AnnouncementUsecase) *AnnouncementService {
|
||||
return &AnnouncementService{uc: uc}
|
||||
}
|
||||
|
||||
func announcementDTO(item *biz.Announcement) map[string]any {
|
||||
func announcementDTO(item *biz.Announcement) *dto.AnnouncementResponse {
|
||||
attachments := any([]any{})
|
||||
if len(item.Attachments) > 0 {
|
||||
_ = json.Unmarshal(item.Attachments, &attachments)
|
||||
}
|
||||
return map[string]any{
|
||||
"ID": item.ID, "CreatedAt": item.CreatedAt, "UpdatedAt": item.UpdatedAt, "DeletedAt": nil,
|
||||
"title": item.Title, "content": item.Content, "userID": item.UserID, "attachments": attachments,
|
||||
}
|
||||
return &dto.AnnouncementResponse{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, DeletedAt: nil, Title: item.Title, Content: item.Content, UserID: item.UserID, Attachments: attachments}
|
||||
}
|
||||
|
||||
func announcementDO(in AnnouncementInput) *biz.Announcement {
|
||||
@@ -53,7 +51,7 @@ func (s *AnnouncementService) DeleteByIDs(ctx context.Context, ids []uint) error
|
||||
return s.uc.DeleteByIDs(ctx, ids)
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) Find(ctx context.Context, id uint) (map[string]any, error) {
|
||||
func (s *AnnouncementService) Find(ctx context.Context, id uint) (*dto.AnnouncementResponse, error) {
|
||||
item, err := s.uc.Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -61,26 +59,26 @@ func (s *AnnouncementService) Find(ctx context.Context, id uint) (map[string]any
|
||||
return announcementDTO(item), nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]map[string]any, int64, error) {
|
||||
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]*dto.AnnouncementResponse, int64, error) {
|
||||
items, total, err := s.uc.List(ctx, biz.AnnouncementFilter{Page: page, PageSize: pageSize, StartCreatedAt: start, EndCreatedAt: end})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
result := make([]map[string]any, 0, len(items))
|
||||
result := make([]*dto.AnnouncementResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, announcementDTO(item))
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]map[string]any, error) {
|
||||
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]*dto.SelectOptionResponse, error) {
|
||||
items, err := s.uc.UserOptions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]map[string]any, 0, len(items))
|
||||
result := make([]*dto.SelectOptionResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, map[string]any{"label": item.Label, "value": item.Value})
|
||||
result = append(result, &dto.SelectOptionResponse{Label: item.Label, Value: item.Value})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user