72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type Announcement struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Title string
|
|
Content string
|
|
UserID *int
|
|
Attachments json.RawMessage
|
|
}
|
|
|
|
type AnnouncementFilter struct {
|
|
Page, PageSize int
|
|
StartCreatedAt, EndCreatedAt *time.Time
|
|
}
|
|
|
|
type AnnouncementRepo interface {
|
|
Create(context.Context, *Announcement) error
|
|
Delete(context.Context, string) error
|
|
DeleteByIDs(context.Context, []string) error
|
|
Update(context.Context, *Announcement) error
|
|
Find(context.Context, string) (*Announcement, error)
|
|
List(context.Context, AnnouncementFilter) ([]*Announcement, int64, error)
|
|
UserOptions(context.Context) ([]UserOption, error)
|
|
}
|
|
|
|
type UserOption struct {
|
|
Label string
|
|
Value uint
|
|
}
|
|
|
|
type AnnouncementUsecase struct{ repo AnnouncementRepo }
|
|
|
|
func NewAnnouncementUsecase(repo AnnouncementRepo) *AnnouncementUsecase {
|
|
return &AnnouncementUsecase{repo: repo}
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) Create(ctx context.Context, item *Announcement) error {
|
|
return uc.repo.Create(ctx, item)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) Update(ctx context.Context, item *Announcement) error {
|
|
return uc.repo.Update(ctx, item)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) Delete(ctx context.Context, id string) error {
|
|
return uc.repo.Delete(ctx, id)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) DeleteByIDs(ctx context.Context, ids []string) error {
|
|
return uc.repo.DeleteByIDs(ctx, ids)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) Find(ctx context.Context, id string) (*Announcement, error) {
|
|
return uc.repo.Find(ctx, id)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) List(ctx context.Context, filter AnnouncementFilter) ([]*Announcement, int64, error) {
|
|
return uc.repo.List(ctx, filter)
|
|
}
|
|
|
|
func (uc *AnnouncementUsecase) UserOptions(ctx context.Context) ([]UserOption, error) {
|
|
return uc.repo.UserOptions(ctx)
|
|
}
|