Categorygithub.com/AndresCampuzano/golang-dashboard
modulepackage
0.0.0-20240727012753-771e28a6c511
Repository: https://github.com/andrescampuzano/golang-dashboard.git
Documentation: pkg.go.dev

# README

golang-pet

GOLANG-DASHBOARD

license last-commit repo-top-language repo-language-count

Go



๐Ÿ“ Overview

This is a JSON API server written in Go that provides endpoints for managing users, customers, products, sales, and expenses.


๐Ÿ“ฆ Features

  • User authentication and authorization
  • CRUD operations for users, customers, products, sales, and expenses
  • Integration with AWS S3 for file storage

Additional Information

Database Storage

The server uses PostgreSQL as its database backend. It provides a NewPostgresStore function to create a new instance of PostgresStore, which establishes a connection to the PostgreSQL database and initializes necessary extensions.

AWS S3 Integration

The server integrates with AWS S3 for file storage. The BucketBasics struct encapsulates Amazon S3 actions such as uploading and deleting files. It provides methods for uploading base64-encoded images to an S3 bucket and deleting files from the bucket.

Helper Functions

The server includes helper functions for handling JSON responses, HTTP request routing, and working with PostgreSQL array types.


๐Ÿ“‚ Repository Structure

โ””โ”€โ”€ golang-dashboard/
    โ”œโ”€โ”€ Makefile
    โ”œโ”€โ”€ api.go
    โ”œโ”€โ”€ auth.go
    โ”œโ”€โ”€ customer.service.go
    โ”œโ”€โ”€ customer.storage.go
    โ”œโ”€โ”€ customer.types.go
    โ”œโ”€โ”€ database.go
    โ”œโ”€โ”€ expense.service.go
    โ”œโ”€โ”€ expense.storage.go
    โ”œโ”€โ”€ expense.types.go
    โ”œโ”€โ”€ earnings.service.go
    โ”œโ”€โ”€ earnings.storage.go
    โ”œโ”€โ”€ earnings.types.go
    โ”œโ”€โ”€ go.mod
    โ”œโ”€โ”€ go.sum
    โ”œโ”€โ”€ main.go
    โ”œโ”€โ”€ product.service.go
    โ”œโ”€โ”€ product.storage.go
    โ”œโ”€โ”€ product.types.go
    โ”œโ”€โ”€ s3.go
    โ”œโ”€โ”€ sale.service.go
    โ”œโ”€โ”€ sale.storage.go
    โ”œโ”€โ”€ sale.types.go
    โ”œโ”€โ”€ storage.go
    โ”œโ”€โ”€ user.service.go
    โ”œโ”€โ”€ user.storage.go
    โ”œโ”€โ”€ user.types.go
    โ””โ”€โ”€ utils.go

๐Ÿ›ฃ๏ธ Endpoints

The server exposes the following endpoints:

  • POST /login: User login
  • POST /signup: User sign up

Protected routes with JWT

  • GET /users: Get all users
  • GET /users/{id}: Get user by ID
  • GET /customers: Get all customers
  • GET /customers/{id}: Get customer by ID
  • POST /customers: Create a new customer
  • PUT /customers/{id}: Update customer by ID
  • DELETE /customers/{id}: Delete customer by ID
  • GET /products: Get all products
  • GET /products/{id}: Get product by ID
  • POST /products: Create a new product
  • PUT /products/{id}: Update product by ID
  • DELETE /products/{id}: Delete product by ID
  • GET /sales: Get all sales
  • GET /sales/{id}: Get sale by ID
  • POST /sales: Create a new sale
  • GET /expenses: Get all expenses
  • GET /expenses/{id}: Get expense by ID
  • POST /expenses: Create a new expense
  • PUT /expenses/{id}: Update expense by ID
  • DELETE /expenses/{id}: Delete expense by ID
  • GET /earnings: Get earnings by month calculated from multiple postgres tables

๐Ÿงฉ Dependencies

This project depends on the following external packages:


๐Ÿš€ Getting Started

Requirements

You may need to configure environment variables or configuration files for database connection, AWS credentials, and other settings.

Ensure you have the following dependencies installed on your system:

  • Go: version go1.22.2

โš™๏ธ Installation

  1. Clone the golang-dashboard repository:
git clone https://github.com/AndresCampuzano/golang-dashboard
  1. Change to the project directory:
cd golang-dashboard
  1. Install the dependencies:
go mod download

๐Ÿค– Running golang-dashboard

Use the following command to run golang-dashboard:

make run

โš™๏ธ Configuration

This project requires the following environment variables to be set for proper operation:

PostgreSQL

  • POSTGRES_USER: PostgreSQL username
  • POSTGRES_DB_NAME: PostgreSQL database name
  • POSTGRES_PASSWORD: PostgreSQL password

AWS

  • AWS_ACCESS_KEY_ID: AWS access key ID for accessing AWS services
  • AWS_SECRET_ACCESS_KEY: AWS secret access key for accessing AWS services
  • AWS_REGION: AWS region where resources are located
  • AWS_S3_BUCKET_NAME: Name of the AWS S3 bucket for file storage
  • AWS_S3_BUCKET_URL: URL of the AWS S3 bucket for accessing stored files

Amazon RDS

  • AMAZON_RDS_USER: Username for Amazon RDS database
  • AMAZON_RDS_DB_NAME: Name of the Amazon RDS database
  • AMAZON_RDS_PASSWORD: Password for Amazon RDS database
  • AMAZON_RDS_ENDPOINT: Endpoint for connecting to Amazon RDS database

JWT

  • JWT_SECRET: Secret key for JWT token generation

SendGrid Emails

  • SENDGRID_API_KEY: SendGrid API Key
  • SENDGRID_CUSTOM_SENDER: Custom email sender

๐Ÿงช Tests

Embrace the chaos, this is a work in progress!

# Functions

ColorFromLocalConstants retrieves the color from the constants based on the label.
ConvertFromDBArray converts a PostgreSQL array string to a slice of strings.
ConvertToDBArray converts a slice of strings to a format suitable for PostgreSQL array type.
NewAPIServer creates a new instance of APIServer.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
S3ParamsFromBase64 converts a base64 string with MIME type to ImageDataS3.
No description provided by the author
WriteJSON writes the given data as JSON to the HTTP response with the provided status code.

# Variables

Colors contains available color options.

# Structs

APIServer represents an HTTP server for handling API requests.
BucketBasics encapsulates the Amazon Simple storage Service (Amazon S3) actions.
No description provided by the author
Color represents a color option.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author