迁移公告,邮件
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
)
|
||||
|
||||
type AnnouncementInput struct {
|
||||
ID uint
|
||||
Title string
|
||||
Content string
|
||||
UserID *uint
|
||||
Attachments json.RawMessage
|
||||
}
|
||||
|
||||
type AnnouncementService struct{ uc *biz.AnnouncementUsecase }
|
||||
|
||||
func NewAnnouncementService(uc *biz.AnnouncementUsecase) *AnnouncementService {
|
||||
return &AnnouncementService{uc: uc}
|
||||
}
|
||||
|
||||
func announcementDTO(item *biz.Announcement) map[string]any {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func announcementDO(in AnnouncementInput) *biz.Announcement {
|
||||
return &biz.Announcement{ID: in.ID, Title: in.Title, Content: in.Content, UserID: in.UserID, Attachments: in.Attachments}
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) Create(ctx context.Context, in AnnouncementInput) error {
|
||||
return s.uc.Create(ctx, announcementDO(in))
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) Update(ctx context.Context, in AnnouncementInput) error {
|
||||
return s.uc.Update(ctx, announcementDO(in))
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) Delete(ctx context.Context, id uint) error {
|
||||
return s.uc.Delete(ctx, id)
|
||||
}
|
||||
|
||||
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) {
|
||||
item, err := s.uc.Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return announcementDTO(item), nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]map[string]any, 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))
|
||||
for _, item := range items {
|
||||
result = append(result, announcementDTO(item))
|
||||
}
|
||||
return result, total, nil
|
||||
}
|
||||
|
||||
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]map[string]any, error) {
|
||||
items, err := s.uc.UserOptions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]map[string]any, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, map[string]any{"label": item.Label, "value": item.Value})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz"
|
||||
)
|
||||
|
||||
type EmailService struct{ uc *biz.EmailUsecase }
|
||||
|
||||
func NewEmailService(uc *biz.EmailUsecase) *EmailService { return &EmailService{uc: uc} }
|
||||
|
||||
func (s *EmailService) Test(ctx context.Context) error { return s.uc.Test(ctx) }
|
||||
|
||||
func (s *EmailService) Send(ctx context.Context, to, subject, body string) error {
|
||||
return s.uc.Send(ctx, to, subject, body)
|
||||
}
|
||||
|
||||
func (s *EmailService) Alert(ctx context.Context, subject, body string) error {
|
||||
return s.uc.Alert(ctx, subject, body)
|
||||
}
|
||||
@@ -3,4 +3,4 @@ package service
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is service providers.
|
||||
var ProviderSet = wire.NewSet(NewAdminService, NewSystemService, NewAccessService, NewSettingsService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService)
|
||||
var ProviderSet = wire.NewSet(NewAdminService, NewSystemService, NewAccessService, NewSettingsService, NewVersionService, NewExportService, NewAuditService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService)
|
||||
|
||||
Reference in New Issue
Block a user