Skip to content

A program that performs CRUD operations on a mock bike-shop database using Gin. This program is meant to be ran locally

License

Notifications You must be signed in to change notification settings

ScriptMang/conch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conch

A locally ran program that uses gin to create api endpoints that perform CRUD Operations.
For this project I'm simulating a bikshop database that keeps a table of invoices.

Prior to Running

  • This program requires that both the go programming language
    and PostgreSQL be installed on your local machine.
    It also requires a program like Postman to send http requests to the database.

  • Make sure to import the psql dump file into PostgreSQL.
    Use the following command 'psql --username= Bikeshop < .sql'.
    Note: replace placeholder info within the angle brackets with your own.

  • Inside the bikeshop.go file replace the substring 'username' within the uri variable.
    Provide the username you used to create the database in PostgreSQL instead.

How to Run

The program is ran using the terminal. Typing go run .
or by running its binary ./conch within in its directory, starts the program.
A prompt will show up asking for outside internet connection, always deny it.

While the programs is still running, open Postman.
Then, send a request using the following options below to run the crud operation.

Note About the CRUD Operations

some CRUD Operations will require you to pass JSON to the responsebody
('Body' in PostMan) along with the request. In that case, where ever you see <struct>
in 'CRUD Operations' replace it with the expected json format for the object listed below.
Also, do not send the id attribute as part of the json object, its created along with the invoice.
For routes that end in :usr_id or :id replace it with an integer number.
To end the program in the terminal, type ^c(ctrl-c).

JSON Format for an Account

{
  "username": string,
  "fname": string,
  "lname": string,
  "address": string,
  "password": string
}

JSON Format for a User

{ 
  "id": int,
  "username": string,
  "fname": string,
  "lname": string,
  "address": string
}

JSON Format for an Invoice

{
  "id": int,
  "usr_id": int,
  "product": string,
  "category": string,
  "price": float,
  "quantity": int
}

JSON Format for Login-Creds

{
  "username": string,
  "pswd": []byte
}

Notes about the json objects

Adding an account creates an entry in the Users table and the password table

Although you don't directly pass a json struct for a user object in the request body, you still need to provide its id for other routes. i.e :usr_id.

The id properties are never passed but created

User and Invoice structs' id properties :usr_id and :id respectfully are assigned after creation. They're incremented after insertion(pass or fail) by the database.

Passwords for Account structs get encrypted

After sending a Post request to create an account, the password is encrypted and stored in the database.

CRUD Operations

  • Add a user account to the table
    POST localhost:8080/create/Account/ <account>
  • Login into your account
    POST localhost:8080/account/login <login-creds>
  • Read all the users from the table
    GET localhost:8080/users
  • Read all the invoices from the table
    GET localhost:8080/users/invoices
  • Read a specific user from the table
    GET localhost:8080/user/:usr_id
  • Read all the invoices for a specific user
    GET localhost:8080/user/:usr_id/invoices
  • Read an invoice for a specific user
    GET localhost:8080/user/:usr_id/invoice/:id
  • Add an invoice to a specific user
    POST localhost:8080/user/:usr_id/invoices
  • Update all the fields on an existing invoice
    PUT localhost:8080/user/:usr_id/invoice/:id <invoice>
  • Patch one or more fields on an existing invoice
    PATCH localhost:8080/user/:usr_id/invoice/:id <invoice>
  • Delete an existing account
    DELETE localhost:8080/account <login-creds>
  • Delete an existing invoice
    DELETE localhost:8080/user/:usr_id/invoice/:id

About

A program that performs CRUD operations on a mock bike-shop database using Gin. This program is meant to be ran locally

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages