github.com/dimeko/sapi@v0.0.0-20231115204413-952501e4268a/app/app.go (about)

     1  package app
     2  
     3  import (
     4  	"github.com/dimeko/sapi/models"
     5  	"github.com/dimeko/sapi/store"
     6  )
     7  
     8  type App struct {
     9  	Store models.Actions
    10  }
    11  
    12  func New() *App {
    13  	store := store.New()
    14  	return &App{
    15  		Store: store,
    16  	}
    17  }
    18  
    19  func (a *App) List(limit, offset string) ([]*models.User, error) {
    20  	users, err := a.Store.List(limit, offset)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	return users, nil
    25  }
    26  
    27  func (a *App) Get(id string) (*models.User, error) {
    28  	user, err := a.Store.Get(id)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	return user, nil
    33  }
    34  
    35  func (a *App) Create(payload models.UserPayload) (*models.User, error) {
    36  	user, err := a.Store.Create(payload)
    37  
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return user, nil
    42  }
    43  
    44  func (a *App) Update(id string, payload models.UserPayload) (*models.User, error) {
    45  	updatedUser, err := a.Store.Update(id, payload)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	return updatedUser, nil
    50  }
    51  
    52  func (a *App) Delete(id string) error {
    53  	err := a.Store.Delete(id)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	return nil
    58  
    59  }