39 lines
774 B
Go
39 lines
774 B
Go
package announcement
|
|
|
|
import "fmt"
|
|
|
|
type Service struct {
|
|
repo *Repository
|
|
}
|
|
|
|
func NewService(repo *Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) GetAll() ([]Announcement, error) {
|
|
return s.repo.FindAll()
|
|
}
|
|
|
|
func (s *Service) Create(title, content string) (*Announcement, error) {
|
|
a := &Announcement{Title: title, Content: content}
|
|
return a, s.repo.Create(a)
|
|
}
|
|
|
|
func (s *Service) Update(id, title, content string) (*Announcement, error) {
|
|
a, err := s.repo.FindByID(id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("공지사항을 찾을 수 없습니다")
|
|
}
|
|
if title != "" {
|
|
a.Title = title
|
|
}
|
|
if content != "" {
|
|
a.Content = content
|
|
}
|
|
return a, s.repo.Save(a)
|
|
}
|
|
|
|
func (s *Service) Delete(id string) error {
|
|
return s.repo.Delete(id)
|
|
}
|