Skip to content

bigpanther/billton

Repository files navigation

warrant

Install required tooling

Install the following on your machine.

  • Go version 1.21+
  • Postgres 16.1+
  • XCode on your Mac from the App Store
  • Flutter fpr mobile development
  • Postman for API access

Add the following line in your ~/.zshrc. In the terminal, run the following command

grep 'export PATH=$PATH:$(go env GOPATH)/bin' ~/.zshrc || echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.zshrc

Clone this repository

git clone https://github.com/bigpanther/billton.git

Open the code in Visual Studio Code

Install the atlas tool for database migrations

brew install ariga/tap/atlas

Fetching latest code from Github (Terminal)

git checkout main
git pull --rebase

git checkout <your-branch>
git rebase main

# Make changes and commit the code

# Push the changes to github
git push origin <your-branch>

You can use the VSCode git extension to run the same steps from the UI instead of the terminal.

run the program

To run the program, use

make run-dev

Test Warranty Creation

Open a new terminal and run

curl --location 'http://localhost:8080/warranties' \
--header 'Content-Type: application/json' \
--data '{
    "transaction_time": "2023-06-29T20:52:20.015924-07:00",
    "expiry_time": "2024-07-03T20:52:20.015924-07:00",
    "brand_name": "Samsung",
    "amount": 100000,
    "store_name": "Costco"
}'

Expect to get back a response with a generated ID

Test warranty fetch

curl --location 'http://localhost:8080/warranties/<replace this with the ID from the previous step>'

Add a new model and a database table

soda generate fizz create_users

In the migration up file, add the new table schema

create_table("users") {
    t.Column("id", "uuid", {primary: true})
    t.Column("name", "string", {})
    t.Timestamps()
}

In the down migration file, add the reverse

drop_table("users")

See db migrations and fizz for details on migrations.

Create a model under the models directory to map the DB table

package models

import (
	"time"

	"github.com/google/uuid"
)

type User struct {
	ID        uuid.UUID `json:"id" db:"id" rw:"r"`
	Name      string    `json:"name" db:"name"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published