Giter Site home page Giter Site logo

matcher's Introduction

Matcher

Prerequisites

Using package github.com/joho/godotenv to load .env file from directory. Need to create a .env file in root of the project and add the following environment variables:

POSTGRES_PASSWORD=password
POSTGRES_USER=postgres
POSTGRES_PORT=5432
POSTGRES_HOST=pg
POSTGRES_DB=matcher
TEST_DB_HOST=localhost
TEST_DB_NAME=matchertest

To Run

docker-compose up starts postgres db and golang application. Golang api is listening on port 3001.

Overview

This is a simple api that exposes 4 endpoints:

  • GET /v1/users/:id Gets a user by user id
  • POST /v1/users Creates a user
  • GET /v1/likes/:userId Get all the users that like the :userId user
  • POST /v1/likes Create a new like relationship

Uses docker to run both a postgres DB and the golang application. On docker-compose up will run make docker-fresh which first cleans the DB (deletes the data) and then seeds it with new test data.

Using a VS Code extension https://github.com/Huachao/vscode-restclient this allows you to run CURL commands within vscode from the http.rest file.

Structure

Loosely modeled after Clean Architecture https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

Main entry point is in the api/main.go. Usecase folder contains the application services. The services is where the major business logic is each is based off of an interface which decoupels the service implementation and any code thats using it.

The api folder is all the files associated with communication of REST in this case. It contains the handlers specific for each different route. Input a collection of structs used for validating the data that is entering the system. Output used to create a contract for the data sent/returned.

Using the interface also makes it much easier to write unit tests that only are testing the service and are not dependent on other services.

Entity folder contains application wide entities/structs. These are mostly the db models

Repository folder contains the data access layer structs, each are responsible for one folder and the services can only access the data through the corresponding repository.

Seeders is a seperate application where there is another main.go file. This is used to seed the database with test data currently only seeding test users.

db folder is where the database connection is created and any db scripts that are nesassary for creating the database.

Config folder is used for any application configuration that is required at startup. Generally these config variables are from environment files.

Commands

Using Makefle

  • make run to run the application locally.
  • make seed-up to seed the DB with test data
  • make seed-down to remove data within the db
  • make test-unit to run all unit tests
  • make test-integration to run integration tests

Endpoints

Create User

POST http://localhost:3001/v1/users
Content-Type: application/json

{
    "firstName": "Toby",
    "lastName": "Test",
    "email": "[email protected]",
    "pass": "newPassword"
}

Get likes, gets who likes the user. Takes query params for pagination the default values are: page=0 pageSize=100

GET http://localhost:3001/v1/likes/fb8fb77f-295d-4126-bef9-9aea2b93ae43?page=10&pageSize=3

Create like, fromId and toId need to be uuids and within the DB

POST http://localhost:3001/v1/likes
Content-Type: application/json
{
    "fromId": "05563251-45af-4bb9-b5bf-21cae961b254",
    "toId": "fb8fb77f-295d-4126-bef9-9aea2b93ae43"
}

Notes

There is no authorization or authentication due to its complexity, I would use a JWT based auth solution and use gin's middleware to interagat the token for authentication and authorization (the user id within + scopes).

matcher's People

Contributors

dgkincaid avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.