Code Monkey home page Code Monkey logo

home-inventory-api's Introduction

Logo

Organize your items at home in a simple way.

About

This is a simple API to organize your items at home. It allows you to create rooms, boxes, and items.

You can also add items into boxes, remove items from boxes, and other functionalities.

The API is built with Go and uses MySQL as the database. It also uses Docker to run the app and the database. The API is also versioned and uses Sentry to log errors. The API uses smtp to send emails to users. The API uses JWT to authenticate users. The API use AWS S3 to store the assets.

See Documentation

Get Started

  1. Clone the repository
  2. Clone app.env.example to app.env and fill the environment variables
  3. Run docker-compose --env-file app.env up to start the app or if you use make, then use of the Makefile commands
  4. Run docker exec -it home-inventory-api-workspace-1 /bin/bash -c "make run" to start running the API
  5. Also you must need run migrations on your database
  6. Access the API at http://0.0.0.0:your-port

Business Keywords

  • User: A person who uses the API
  • Room: A place in the house where boxes are located
  • Box: A container that holds items
  • Item: An object that is stored in a box
  • ItemKeyword: A keyword that describes an item
  • Asset: A file that is stored in the cloud
  • BoxItem: A relation between a box and an item, it contains the quantity of the item in the box
  • BoxTransaction: A register of the movement of items in boxes
  • Version: A version of the API

Features

  • Authentication
    • Register a user
    • Login a user
  • Rooms
    • Create a room
    • List all rooms (paginated)
    • Update a room
    • Delete a room
  • Boxes
    • Create a box
    • List all boxes (paginated)
    • Update a box
    • Delete a box
    • Add items into a box
    • Remove items from a box
    • Transfer items from a box to another
  • Items
    • Create an item with a photo
    • List all items (paginated)
    • Update an item and its photo
    • Delete an item
  • Assets
    • Create an asset

API Structure

The API is versioned and the current version is v1.

The API use a Hexagonal Architecture and the structure is as follows:

App schema

On the application layer, the business logic is implemented. The business logic is implemented.

On the domain layer, there are some elements like:

  • Entities: They are the main objects of the application.
  • Repositories: They are the interfaces that define the methods to interact with the database.
  • Services: They are the interfaces that define the methods to interact with external services.

There are interesting services in domain layer:

  • EventBus: It is a service that allows to publish async events.
  • EmailSender: It is a service that allows to send emails to users.
  • FileManager: It is a service that allows to store files in the cloud.
  • TokenGenerator: It is a service that allows to generate/decode tokens for users.

On the infrastructure layer, the implementation of the interfaces is done. The implementation is done using the database, the email service, the file storage, etc.

Here is where the API is implemented. The API is implemented using the echo framework, and the persistence with gorm.

There are two features that cross the entire layers. There are the logger and notifier (sentry).

Development flow

The coding flow is as follows:

  1. Create a task in the project board
  2. Create a branch from main with the name feat-number
  3. Implement the feature. The feature must be tested
  4. Create a pull request to main
  5. The pull request must be reviewed and tested. There are some actions to do test.
  6. The pull request is merged to main is all test pass and if it satisfies the task.

Testing

The API is tested using the testing package and the testify package. For the repositories, the test is done using SQL testing using sqlmock package.

home-inventory-api's People

Contributors

jibaru avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

home-inventory-api's Issues

Can not get items without keywords

The endpoint GET /api/v1/items is not retrieving items without keywords. This probably happens because there is an INNER JOIN on gorm repository and not LEFT JOIN.

Uploaded asset file to S3 has 0 bytes

Problem:

image

Policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject"
            ],
            "Resource": "arn:aws:s3:::home-inventory-api/*"
        }
    ]
}

I think you need to perform a file.Seek(0, 0) to move the pointer to the start position before upload.

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.