Code Monkey home page Code Monkey logo

bar-code-generator's Introduction

Barcode Generator

This project was developed using Python during NLW 2024 event from Rocketseat.

Techs

Overview

A single POST route was made using Flask ("/create_tag") to provide the functionality of creating tags for barcode. Python Barcode lib was used to handle this barcode generation and Cerberus for body validation schemas. Pytest was used to create unit tests for the use case.

I've tried using Clean Code principles for building highly scalable and mantainable software acrchitecture:

  • main: contains the core application like the server and routes
  • views: handle the HTTP layer
  • controllers: contains the entities with the business logic
  • drivers: contains the external libs like barcode handler
  • errors: the handler for exceptions
  • validators: the validation schemas for requests using Cerberus

How to run

Virtual environment

# using pipenv
pipenv install

# activate virtual env
pipenv shell
  • Using virtualenv

# using virtualenv
pip install virtualenv
python -m venv .venv

# active virtual env (for Unix/MacOS)
source venv/bin/activate

# active virtual env (for Windows)
.venv\Scripts\activate

# install the deps
pip install -r requirements.txt

Run the project

The project will run on http://localhost:3000/

# using pipenv
pipenv run run.py

# using virtualvenv
python run run.py

Create a barcode

You can use any API platform to test it. Endpoint: http://localhost:3000/create_tag

REQUEST BODY

{
  "product_code": "123456"
}

RESPONSE 200 (Success)

{
	"data": {
		"count": 1,
		"path": "123456.png",
		"type": "Tag Image"
	}
}

RESPONSE 422 (Unprocessable Entity)

Request Body
{
  "mock_unexistent_field": "123456"
}
Response
{
	"errors": [
		{
			"detail": {
				"mock_unexistent_field": [
					"unknown field"
				],
				"product_code": [
					"required field"
				]
			},
			"name": "Unprocessable Entity"
		}
	]
}

If success, a .png file with the generated barcode will be created in ./src.

Run unit tests

pytest

bar-code-generator's People

Contributors

bfukumori avatar

Watchers

 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.