API REST para saber en base a un punto (lat, long), la sucursal más cercana al mismo.

location

API REST para saber en base a un punto (lat, long), la sucursal más cercana al mismo.

Construido con 🛠

  • Golang - Lenguaje de programación.
  • SQLite - Base de datos.
  • Docker - Manejador de contenedores.
  • Swagger - Documentación de la API.

Comenzando 🚀

Pre-requisitos

Herramientas necesarias para la ejecución local del servicio:

  • Go go1.15.6+.
  • Docker 19.03.6+.

Ejemplo ejecutando localmente

  • Configurar variable de entorno LOCATION_ENVIRONMENT=local.
$ export LOCATION_ENVIRONMENT=local
  • Ejecutar:
$ go build
$ go run main.go

Respuesta:

[GIN-debug] GET    /branch-offices/branch-office/:id --> location/pkg/routes.(*handler).Get-fm (3 handlers)
[GIN-debug] POST   /branch-offices/branch-office --> location/pkg/routes.(*handler).Create-fm (3 handlers)
[GIN-debug] GET    /branch-offices/nearest   --> location/pkg/routes.(*handler).Nearest-fm (3 handlers)
[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default
[GIN-debug] Listening and serving HTTP on :8080
  • Para ejecutar los tests:
$ go test ./...

?   	location	[no test files]
?   	location/api	[no test files]
ok  	location/pkg/cmd	0.008s
?   	location/pkg/cmd/mocks	[no test files]
?   	location/pkg/config	[no test files]
?   	location/pkg/db	[no test files]
?   	location/pkg/db/mocks	[no test files]
?   	location/pkg/db/model	[no test files]
ok  	location/pkg/routes	0.012s
  • Para evaluar coverage:
$ go test -coverprofile=coverage.out ./...

?   	location	[no test files]
?   	location/api	[no test files]
ok  	location/pkg/cmd	0.008s	coverage: 90.9% of statements
?   	location/pkg/cmd/mocks	[no test files]
?   	location/pkg/config	[no test files]
?   	location/pkg/db	[no test files]
?   	location/pkg/db/mocks	[no test files]
?   	location/pkg/db/model	[no test files]
ok  	location/pkg/routes	0.011s	coverage: 77.1% of statements
  • Coverage de manera más detallada:
$ go tool cover -func=coverage.out

location/pkg/cmd/cmd.go:22:		Build		100.0%
location/pkg/cmd/cmd.go:26:		Nearest		100.0%
location/pkg/cmd/cmd.go:52:		Get		0.0%
location/pkg/cmd/cmd.go:60:		Create		100.0%
location/pkg/cmd/cmd.go:70:		all		100.0%
location/pkg/cmd/cmd.go:74:		Find		100.0%
location/pkg/cmd/translator.go:8:	toModel		100.0%
location/pkg/cmd/translator.go:17:	toApi		100.0%
location/pkg/cmd/translator.go:26:	toApis		100.0%
location/pkg/routes/route.go:22:	AddHandler	100.0%
location/pkg/routes/route.go:33:	Get		0.0%
location/pkg/routes/route.go:49:	Create		70.0%
location/pkg/routes/route.go:65:	create		100.0%
location/pkg/routes/route.go:75:	alreadyExists	100.0%
location/pkg/routes/route.go:82:	Nearest		100.0%
total:					(statements)	82.7%

Ejemplo usando imagen docker

$ sudo docker image build -t location:0.0.1 .
$ sudo docker run --network host location:0.0.1

API

Documentación Swagger más detallada en el archivo swagger.yaml.

Esta API sirve para dar de alta sucursales, para consultar la sucursal por id y también para encontrar la sucursal más cercana a un punto dado. Este punto debe estar expresado en latitud y longitud en coordenadas decimales simples con el siguiente formato:

Ejemplo de ubicación de Buenos Aires:

Latitud:-34.6083
Longitud:-58.3712
  • Creación de sucursal

Permite crear una sucursal con su latitud, longitud y dirección.

request:

POST http://localhost:8080/branch-offices/branch-office

{
    "latitude":-34.6083,
    "longitude":-58.3712,
    "address":"just a random address 123"
}

response:

200 OK

{
    "id":1,
    "latitude":-34.6083,
    "longitude":-58.3712,
    "address":"just a random address 123"
}

Ejemplo:

$ curl -v -d '{"longitude":-58.45678, "latitude":-34.12345, "address":"buenos aires 1234"}' POST http://localhost:8080/branch-offices/branch-office

Respuesta:

* Rebuilt URL to: POST/
* Could not resolve host: POST
* Closing connection 0
curl: (6) Could not resolve host: POST
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#1)
> POST /branch-offices/branch-office HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 76
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 76 out of 76 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Wed, 06 Jan 2021 16:28:12 GMT
< Content-Length: 81
< 
* Connection #1 to host localhost left intact
{"id":1,"longitude":-58.45678,"latitude":-34.12345,"address":"buenos aires 1234"}
  • Obtener sucursal por ID

Permite obtener los datos de la sucursal conociendo su id.

request:

GET http://localhost:8080/branch-offices/branch-office/1

response:

200 OK
{
    "latitude":-34.6083,
    "longitude":-58.3712,
    "address":"just a random address 123",
    "id":1
}

Ejemplo:

$ curl -v GET http://localhost:8080/branch-offices/branch-office/1

Respuesta:

* Rebuilt URL to: GET/
* Could not resolve host: GET
* Closing connection 0
curl: (6) Could not resolve host: GET
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#1)
> GET /branch-offices/branch-office/1 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Wed, 06 Jan 2021 16:29:25 GMT
< Content-Length: 81
< 
* Connection #1 to host localhost left intact
{"id":1,"longitude":-58.45678,"latitude":-34.12345,"address":"buenos aires 1234"}
  • Buscar la sucursal más cercana

Permite buscar la sucursal más cercana al punto (latitud y longitud) elegido.

request:

GET http://localhost:8080/branch-offices/nearest?latitude=-34.6083&longitude=-58.3712

response:

200 OK
{
    "latitude":-34.6083,
    "longitude":-58.3712,
    "address":"just a random address 123",
    "id":1
}

Ejemplo:

$ curl -v GET 'http://localhost:8080/branch-offices/nearest?longitude=-58.45678&latitude=-34.12345'

Respuesta:

* Rebuilt URL to: GET/
* Could not resolve host: GET
* Closing connection 0
curl: (6) Could not resolve host: GET
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#1)
> GET /branch-offices/nearest?longitude=-58.45678&latitude=-34.12345 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Wed, 06 Jan 2021 16:30:31 GMT
< Content-Length: 81
< 
* Connection #1 to host localhost left intact
{"id":1,"longitude":-58.45678,"latitude":-34.12345,"address":"buenos aires 1234"}

Roadmap

  • Estructura de proyecto
  • Pensar algoritmo
  • Readme
  • Algoritmo terminado
  • Tipos de datos de latitud y longitud
  • Test unitarios
  • Logs
  • Dockerizar
  • Documentación Swagger
Similar Resources

Ecommerce-api - Rest api of e-commerce web application

Ecommerce-api - Rest api of e-commerce web application

E-commerce Rest API Swagger documentation to test api Domain diagram

Jan 2, 2023

REST API for RabbitMQ, Write with Google Go(lang).

RabbitMQ HTTP API REST HTTP API for RabbitMQ, it's not RabbitMQ Management Plugin. Status: Under active development. Required: * RabbitMQ (2.8+) * Go(

Aug 29, 2022

Simple Bank is a simple REST API that allows users to perform transferences with each other.

Simple Bank is a simple REST API that allows users to perform transferences with each other. 🔧 Technologies Golang Docker PostgreSQ

Feb 15, 2022

Sample Go REST API implementation with DDD using Clean Architecture.

This layer is a part developed for client-side (mobile, web, etc.) applications to access our domain. It will forward the requests from this layer to the application layer and expose the response it receives from the application layer.

Jan 3, 2023

Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and GraphQL.

Go GraphQL Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and Gr

Oct 15, 2021

This product about make link to be short link with golang rest api

This project using golang with go fiber, firebase, and dependency injection

Oct 13, 2021

Instagram Backend HTTP REST API using GO Lang and Mongo DB

Instagram Backend HTTP REST API using GO Lang and Mongo DB Project for Appointy Summer Internship . Project built within 25 hrs, with no prior knowled

Oct 10, 2021

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Oct 10, 2021

A REST API with GET/POST Endpoints

Instagram-Backend-API(NO EXTRA DEPENDENCIES) Designed and Developed an HTTP JSON REST API mocking of instagram posts and users schema which capable of

Oct 10, 2021
Go (Golang) API REST with Gin FrameworkGo (Golang) API REST with Gin Framework

go-rest-api-aml-service Go (Golang) API REST with Gin Framework 1. Project Description Build REST APIs to support AML service with the support of exte

Nov 21, 2021
API desarrollada en Go (Golang) para modificar precios en una tienda eCommerce (Shopify)
API desarrollada en Go (Golang) para modificar precios en una tienda eCommerce (Shopify)

Go eCommerce API API para modificar precios de productos en una tienda eCommerce de Shopify. Instrucciones Ingresar a la tienda eCommerce. Seleccionar

Oct 1, 2021
Laboratorios y guías en español para aprender Docker de manera práctica

Docker Labs Laboratorios y guías en español para aprender Docker de manera práctica. Iniciando Clona el repositorio Navega a través de la carpeta de l

Jun 21, 2022
Projeto de biomecânica para tentar avaliar photoelasticidade
Projeto de biomecânica para tentar avaliar photoelasticidade

Alunos Carlos Manuel de Jesus Puentes Valdes 11812591 O que esse programa faz? A partir de uma região da imagem, vão ser buscadas regiões vizinhas de

Dec 1, 2021
Repositório para macetar o Gin com requests.

macetada/gin Repositório para macetar o Gin com requests. Subindo o server docker build -t gin . docker run --rm -p 8082:80 gin ou: docker pull ghcr.i

Dec 10, 2021
Requser - Aplicação responsável por solicitar ao concierge, listas de permissões, inclusão de permissão, exclusão de permissão para o ambiente.

requser ⚠ Atenção ⚠ ?? Esta área está em desenvolvimento ?? Aplicação responsável por solicitar ao https://github.com/Pinablink/concierge, listas de p

Dec 31, 2021
Goemail - Libreria sencilla y completa para el envio de correos con golang (go)

SENDING EMAIL - GoEmail Install librery go get github.com/Leonardo-Antonio/goemail Use Configuración y envío del mensaje (html template) func main ()

Dec 31, 2021
Implementación una base de datos que almacene la información relativa a una tarjeta de crédito utilizando PostgreSQL y BoltDB.

Bases de Datos I: Trabajo Práctico 1. Introducción El objetivo del trabajo práctico es implementar una base de datos que almacene la información relat

Dec 20, 2021
Creacion de una applicacion web en go con acceso a operaciones CRUD en base de datos.

CRUD_con_go_tut Creacion de una applicacion web en go con acceso a operaciones CRUD. Repo de seguimiento del tutorial del canal Developteca de Youtube

Jan 13, 2022
Jeen is a package wrapper that is used as a web application base for the go language.

Jeen Jeen is a package wrapper that is used as a web application base for the go language. Package Wrappers? Yes, because jeen works by using other av

Feb 21, 2022