Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package usecase
- import (
- "challenge-goapi/model"
- "challenge-goapi/repository"
- "fmt"
- )
- type CustomerUseCase interface {
- CreateNewCustomer(customer model.Customer) (model.Customer, error)
- FindAllCustomer() ([]model.Customer, error)
- FindCustomerById(id string) (model.Customer, error)
- UpdateCustomer(customer model.Customer) (model.Customer, error)
- DeleteCustomer(id string) error
- }
- type customerUseCase struct {
- repo repository.CustomerRepository
- }
- func (c *customerUseCase) CreateNewCustomer(customer model.Customer) (model.Customer, error) {
- return c.repo.Create(customer)
- }
- func (c *customerUseCase) FindAllCustomer() ([]model.Customer, error) {
- return c.repo.List()
- }
- func (c *customerUseCase) FindCustomerById(id string) (model.Customer, error) {
- return c.repo.Get(id)
- }
- func (c *customerUseCase) UpdateCustomer(customer model.Customer) (model.Customer, error) {
- _, err := c.repo.Get(customer.Id)
- if err != nil {
- return model.Customer{}, fmt.Errorf("customer with ID %d not found", customer.Id)
- }
- return c.repo.Update(customer)
- }
- func (c *customerUseCase) DeleteCustomer(id string) error {
- _, err := c.repo.Get(id)
- if err != nil {
- return fmt.Errorf("customer with ID %d not found", id)
- }
- return c.repo.Delete(id)
- }
- func NewCustomerUseCase(repo repository.CustomerRepository) CustomerUseCase {
- return &customerUseCase{repo: repo}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement