Skip to content

Repository files navigation

Go API

Product   |    Stack   |    Structure   |    Execution   |    Acknowledgements

GitHub AWS Go Fiber PostgresSQL GORM Redis Godog

💻 Product

The Go API is a RESTful service designed for managing users and their associated notes. It provides operations for creating, reading, updating, and deleting users, as well as managing notes for individual users.

Users are uniquely identified by a UUID (user_id), and the API allows for the creation of users with specific attributes like name. It also enables the association of notes with each user, where notes are identified by a unique UUID (note_id).

Upon creation, a new user with the provided attributes is stored in the system, and the service can query existing users, modify user details, or delete them. Similarly, the notes system allows for creating, reading, updating, and deleting notes attached to a specific user.

Each API operation either performs a specific CRUD (Create, Read, Update, Delete) action on the user resource or the note resource, with interaction between the two based on user identities.

⚙ Stack

This project was developed using the following technologies:

Technologies
Go 1.22.5 PostgreSQL
Fiber GORM
AWS Sdk Redis
Cucumber

🎯 Objective

  • Create new users in the system with a specified name.
  • Retrieve details of a user using their unique user_id.
  • Update the name of an existing user.
  • Delete users based on their user_id.
  • List and retrieve notes associated with a specific user.
  • Create new notes linked to a user.
  • Delete notes attached to a specific user.

🌌 API Endpoints

Create User: POST /v1/users

Creates a new user with the following request body:

{
  "name": "John Doe"
}

Retrieve User: GET /v1/users/{user_id}

Retrieves the details of a user by their user_id.

Delete User: DELETE /v1/users/{user_id}

Deletes the user identified by the user_id.

List Notes for User: GET /v1/users/{user_id}/notes

Retrieves all notes associated with the user identified by user_id.

Retrieve Specific Note: GET /v1/users/{user_id}/notes/{note_id}

Retrieves a specific note attached to a user by note_id.

Create Note: POST /v1/users/{user_id}/notes

Creates a new note for the user with the following request body:

{
  "title": "new note",
  "content": "6238b914-0f07-44c3-b039-d5e76af1f1db"
}

Delete Note: DELETE /v1/users/{user_id}/notes/{note_id}

Deletes a specific note associated with the user by note_id.

🌌 Structure

For the organization of the application, it was separated into several folders so that they were distributed according to their functions. The folder structure can be seen in depth here

  • go-api

    • env

      • Contains local environment variables.
    • internal

      • Contains all application layers.
      • config
        • Contains all projects configs (DB, properties, dependency wiring).
      • delivery
        • Contains the entrance layer to the api (controllers, DTOs, contracts, etc...).
      • domain
        • Contains all project's business logic (entities, use cases, adapters).
      • integration
        • Contains the implementation of external dependencies (DB, webservices, topics publishers).
    • cmd

      • Contains golang entrypoint.
    • scripts

      • Contains miscellaneous scripts.

⏩ Execution

Prerequisites

Testing

  • Run the following command to run the tests with coverage:
    • Windows/MacOS/Linux
      make tests

Running locally

  • Make sure Docker is running on your machine.

  • Run the following command to start the application infrastructure locally:

    • Windows/MacOS/Linux
      make docker-up
  • Start the application:

    • Windows/MacOS/Linux
      make run
  • To stop the application just hit Ctrl + C:

❤️ Acknowledgements

I migrated this project from a previous repository to this one to better organize my studies and share the knowledge I have acquired in Go. Since the commit history and original authorship of the code may not be fully preserved in this repository, I want to acknowledge the original authors and contributors of the project bellow:

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages