services

package
v0.0.0-...-b63fe73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

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).

func (*ContactRepository) Insert

func (r *ContactRepository) Insert(contact *models.Contact) error

Insert adds a new contact to the repository and persists the change to the contacts.json file. Returns the inserted contact and an error if the file cannot be saved.

func (*ContactRepository) Update

func (r *ContactRepository) Update(contact *models.Contact) error

Update modifies an existing contact in the repository and persists the change to the contacts.json file. Returns an error if the contact is not found or the file cannot be saved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL