Chore: project init
This commit is contained in:
38
internal/announcement/service.go
Normal file
38
internal/announcement/service.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user