Documentation
¶
Index ¶
- type ContactRepository
- func (r *ContactRepository) Delete(id int) error
- func (r *ContactRepository) EmailUnique(email string, id int) bool
- func (r *ContactRepository) Get(id int) (*models.Contact, error)
- func (r *ContactRepository) GetAll(query ...string) ([]*models.Contact, error)
- func (r *ContactRepository) Insert(contact *models.Contact) error
- func (r *ContactRepository) Update(contact *models.Contact) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContactRepository ¶
type ContactRepository struct {
// contains filtered or unexported fields
}
ContactRepository manages a collection of contacts.
func NewRepository ¶
func NewRepository() (*ContactRepository, error)
NewRepository creates a new ContactRepository from the data in the contacts.json file. It reads the JSON file, unmarshal the data into a slice of Contact structs, and returns a new ContactRepository. Returns an error if the file cannot be read or the JSON cannot be unmarshalled.
func (*ContactRepository) Delete ¶
func (r *ContactRepository) Delete(id int) error
Delete removes a contact from the repository by ID and persists the change to the contacts.json file. Returns an error if the contact is not found or the file cannot be saved.
func (*ContactRepository) EmailUnique ¶
func (r *ContactRepository) EmailUnique(email string, id int) bool
EmailUnique checks if a contact with the same email address already exists in the repository.
func (*ContactRepository) Get ¶
func (r *ContactRepository) Get(id int) (*models.Contact, error)
Get returns a contact by ID if found, or an error if not found.
func (*ContactRepository) GetAll ¶
func (r *ContactRepository) GetAll(query ...string) ([]*models.Contact, error)
GetAll returns all contacts in the repository. If a query string is provided, it filters the contacts whose Email, First, or Last includes the query string (case insensitive).