people

package
v0.0.0-...-9197a6d Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PeopleHandler

type PeopleHandler struct {
	// DB is the database connection.
	DB *gorm.DB
}

PeopleHandler handles requests to the /people endpoint.

func NewPeopleHandler

func NewPeopleHandler(db *gorm.DB) *PeopleHandler

NewPeopleHandler returns a new PeopleHandler. Englobes the request to the database.

func (*PeopleHandler) Create

func (h *PeopleHandler) Create(w http.ResponseWriter, r *http.Request)

Create adds a new person to the database. Returns 201 with the person if successful. Returns 400 if the request body is not valid JSON. Returns 500 if the person could not be created.

func (*PeopleHandler) Delete

func (h *PeopleHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete removes a person from the database. Returns 200 if successful. Returns 404 if no person was found. Returns 500 if the person could not be removed.

func (*PeopleHandler) Get

Get retrieves a person from the database. Returns 200 with the person if successful. Returns 404 if no person was found. Returns 500 if the person could not be retrieved.

func (*PeopleHandler) GetAll

func (h *PeopleHandler) GetAll(w http.ResponseWriter, r *http.Request)

GetAll retrieves all people from the database, except if a "q" query parameter was provided, then search for people with name match. Returns 200 with the people if successful. Returns 404 if no people were found. Returns 500 if the people could not be retrieved.

func (*PeopleHandler) Update

func (h *PeopleHandler) Update(w http.ResponseWriter, r *http.Request)

Update updates a person in the database. Returns 200 with the person if successful. Returns 400 if the request body is not valid JSON. Returns 404 if no person was found. Returns 500 if the person could not be updated.

type Person

type Person struct {
	// ID is the primary key for the table.
	// As default, GORM uses a unsigned int for ID, but for real world environments, consider use more robust solution for ID.
	// For example, Ticket Server, UUID, Twitter Snowflake, etc.
	ID uint `json:"id" gorm:"primary_key"`
	// Name is used to perform search in Person model using simple LIKE statement.
	// This strategy is not optimized for performance, but for simplicity.
	// Please, refer other full_search, fuzzy_search, etc. strategies for more information.
	// PostreSQL (pg_trgm extension): https://www.postgresql.org/docs/9.6/pgtrgm.html
	// PostgreSQL (fuzzystrmatch extension): https://www.postgresql.org/docs/9.1/fuzzystrmatch.html
	// PostgresSQL (tsvector and tsquery): https://www.postgresql.org/docs/10/datatype-textsearch.html
	Name string `json:"name"`
	// Email is a string of phone number of the person.
	Email string `json:"email"`
	// Phone is a string of phone number of the person.
	Phone string `json:"phone"`
}

Person is a struct that holds base info about and individual. Improvements IDEA: https://developers.google.com/people/api/rest/v1/people/get

Jump to

Keyboard shortcuts

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