Categorygithub.com/KevuTheDev/notes-backend-api
module
0.0.0-20240924214951-73a53bac2f18
Repository: https://github.com/kevuthedev/notes-backend-api.git
Documentation: pkg.go.dev

# README

Notes - Backend API

A backend API for a notes app. A future frontend for the application will be located here.


Summary

This is a JSON API using Go as a backend language.

Uses the following Go library to setup the backend:

Uses PostgreSQL as the database of choice

Uses Docker to run PostgreSQL


Endpoints

MethodURL PatternAction
GET/v1/pingPing route to test if server is active
GET/v1/healthcheckShow application health and version information
GET/v1/notesShow the details of all notes
POST/v1/notesCreate a new note
GET/v1/notes/:idShow the details of a specific note
PATCH/v1/notes/:idUpdate the details of a specific note
DELETE/v1/notes/:idDelete a specific note

Notes Model

type Note struct {
	ID           int64     `json:"id"`                // unique id for the note
	CreatedAt    time.Time `json:"created_at"`        // when the note was created
	LastUpdateAt time.Time `json:"last_updated_at"`   // when the note was last updated
	Title        string    `json:"title"`             // title of note
	Content      string    `json:"content,omitempty"` // content of note
	Tags         []string  `json:"tags,omitempty"`    // tags of note
	Version      int32     `json:"version"`           // number of times the note was updated
}

Notes Form

Title: string - Cannot be empty Content: string - Can be empty Tags: []string - Can be empty

CreatedAt: time.Time (Assigned at POST) LastUpdateAt: time.Time (Assigned at POST, updated at PATCH)

Database

-- Database Creation
CREATE DATABASE notebook;

-- Create role notebook 
CREATE ROLE notebook WITH LOGIN PASSWORD 'pa55word'; -- Remember to change this unsecure password 

--- Add citext extension
CREATE EXTENSION IF NOT EXISTS citext;

--- Grant privilage to user on specific database
GRANT ALL PRIVILEGES ON DATABASE EXAMPLE_DB TO EXAMPLE_USER;
--- Switch to database
\c EXAMPLE_DB postgres
--- Grant privilage on schema to user
GRANT ALL ON SCHEMA public TO EXAMPLE_USER;


GRANT ALL PRIVILEGES ON DATABASE notebook TO notebook;

GRANT ALL ON SCHEMA public TO notebook;


Current Goals

  • Create database migrations for notes

.env FILE

NOTEBOOK_DB_DSN="postgres://postgres_dsn"


Database migration tool

migrate


Postgres UUID


Special thanks to Alex Edwards to his book, Let's Go and Let's Go Further

# Packages

No description provided by the author