Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

carfloresf/the-sun-god

Repository files navigation

Feed API challenge

How to start DB?

  • This app uses SQLite3. You don't need to start it.

How to build?

  • Run make build to compile the project directly on your OS (tested on MAC M1), binary will be added to build directory, it was tested with go 1.19+.

How to run?

  • Run make run it was tested with go 1.19+.

How to run tests?

  • Run make lint to run linter.
  • Run make test to execute unit tests.
  • Run make integration-test to execute integration tests, you need Venom installed.

Implementation details

  • This app uses:
    • Go 1.19
    • [Gin] to handle requests, responses, validations (validator V10).
    • [SQLite3] to store data.
    • [Migrate] to manage database migrations.
    • [sqlMock & Moq] to mock dependencies in unit-tests.
    • golangci-lint to lint code.
    • Venom to run integration tests (You have to install it, script will download it only for Mac M1/M2).
    • Valid SubReddits are stored in a txt file that is loaded at startup.

Postman

Run in Postman

Endpoints

CreatePost

Description:

Method: POST

http://localhost:8082/v1/post

Body (raw)

{
  "title": "titulo",
  "subreddit": "/r/nvidia",
  "link": "https://www.twi2tch.tv/elmariana",
  "content": "content is mututally exclusive with link, choose wisely",
  "score": 1232132,
  "nsfw": true,
  "promoted": false
}

Response (raw)

{
  "id": "35ce6d85-2260-484d-b656-24f90408efe9"
}

Update Post Score

Description:

Method: POST

http://localhost:8082/v1/post/score

Body (raw)

{
  "id":"2bf5b210-b4f4-47b3-bc7e-bd5034bf129d",
  "score":45
}

Response (raw)

{
  "error": null
}

Get Feed

Description:

Method: GET

http://localhost:8082/v1/feed?page=1&limit=10

Response (raw)

{
  "data": [
    {
      "id": "88539220-1d68-42de-aa5c-150115ddcecd",
      "title": "titulo",
      "author": "t2_Ej6sNFr4",
      "subreddit": "/r/nvidia",
      "link": "https://www.twi2tch.tv/elmariana",
      "score": 1232132,
      "promoted": false,
      "nsfw": true
    },
    {
      "id": "35ce6d85-2260-484d-b656-24f90408efe9",
      "title": "titulo",
      "author": "t2_rcXbzrcA",
      "subreddit": "/r/nvidia",
      "link": "https://www.twi2tch.tv/elmariana",
      "score": 1232132,
      "promoted": false,
      "nsfw": true
    }
  ],
  "pagination": {
    "pageCount": 2,
    "next": "/v1/feed?page=2",
    "page": 1,
    "limit": 2,
    "total": 62
  }
}

Author: Carlos Flores

Releases

No releases published

Packages

No packages published