gobookie

package module
v0.0.0-...-6e4d277 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 19 Imported by: 0

README

SAMLA

SAMLA: A new version of bookie, written in Go :)

Running SAMLA

Run docker container

docker run -e POSTGRES_PASSWORD=bookie -e POSTGRES_USER=bookie -e POSTGRES_DB=bookie -p 5432:5432 -d postgres

Run Migrations

Install migrate from here https://github.com/golang-migrate/migrate.

$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
$ migrate -database postgres://bookie:bookie@localhost:5432/bookie?sslmode=disable -path migrations up

Frontend

Install dependencies

npm install

Run app

npm run dev

Run storybook

npm run storybook

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authentication

func Authentication(s *Server) func(next http.Handler) http.Handler

HTTP middleware setting a value on the request context

func DBInit

func DBInit() (*pgxpool.Pool, error)

DBInit - Connects to database

func Error

func Error(msg string) error

Error - A function that returns a custom error message

func IsAdmin

func IsAdmin(next http.Handler) http.Handler

HTTP middleware setting a value on the request context

func RespondWithError

func RespondWithError(w http.ResponseWriter, code int, msg string)

RespondWithError - Return an error

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

RespondWithJSON - Respond with a json formatted string

func RespondWithStatusCode

func RespondWithStatusCode(w http.ResponseWriter, code int)

RespondWithStatusCode - Respond with a status code without setting a message

Types

type Bookmark

type Bookmark struct {
	ID          uint      `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Body        string    `json:"body"`
	Image       string    `json:"image"`
	URL         string    `json:"url"`
	Archived    bool      `json:"archived"`
	Deleted     bool      `json:"deleted"`
	Tags        string    `json:"tags"`
	CreatedAt   time.Time `json:"createdAt"`
}

Bookmark Models

type BookmarkList

type BookmarkList struct {
	ID          uint   `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Image       string `json:"image"`
	URL         string `json:"url"`
	Archived    bool   `json:"archived"`
	Deleted     bool   `json:"deleted"`
	Tags        string `json:"tags"`
}

Bookmark list model

type Bookmarks

type Bookmarks struct {
	Bookmarks []Bookmark
}

Bookmarks - A collection of bookmarks

type CreateBookmarkRequest

type CreateBookmarkRequest struct {
	URL string `json:"url"`
}

CreateBookmarkRequest - Used for creating a bookmark

type CreateTagRequest

type CreateTagRequest struct {
	BookmarkID int    `json:"bookmarkID"`
	TagName    string `json:"tagName"`
}

type CreateUserRequest

type CreateUserRequest struct {
	Email          string `json:"email"`
	Password       string `json:"password"`
	VerifyPassword string `json:"verify_password"`
}

type PaginatedBookmarks

type PaginatedBookmarks struct {
	Page       int             `json:"page"`
	TotalPages int             `json:"totalPages"`
	Limit      int             `json:"limit"`
	Data       []*BookmarkList `json:"data"`
}

type Server

type Server struct {
	DB     *pgxpool.Pool
	Router *chi.Mux
}

Server struct

func (*Server) BookmarkRepositoryCount

func (s *Server) BookmarkRepositoryCount() (int, error)

BookmarkRepositoryCount Get total amount of bookmarks

func (*Server) BookmarkRepositoryDeleteBookmarkByID

func (s *Server) BookmarkRepositoryDeleteBookmarkByID(bookmarkID string) (int64, error)

BookmarkRepositoryDeleteBookmarkByID - Delete a specifc bookmark by its database id

func (*Server) BookmarkRepositoryGetAllBookmarks

func (s *Server) BookmarkRepositoryGetAllBookmarks(page int, limit int, archived bool, deleted bool, tags []string) ([]*BookmarkList, error)

BookmarkRepositoryGetAllBookmarks - Get all bookmarks from database

func (*Server) BookmarkRepositoryGetBookmarkByID

func (s *Server) BookmarkRepositoryGetBookmarkByID(bookmarkID string) (Bookmark, error)

BookmarkRepositoryGetBook.markByID - Get a specifc bookmark by its database id

func (*Server) BookmarkRepositoryInsert

func (s *Server) BookmarkRepositoryInsert(bookmark *CreateBookmarkRequest, userId uint) (int, error)

BookmarkRepositoryInsert - Insert bookmark into database

func (*Server) BookmarkRepositoryPatchBookmark

func (s *Server) BookmarkRepositoryPatchBookmark(bookmark Bookmark) error

BookmarkRepositoryPatchBookmark - Patch a specifc bookmark by its database id

func (*Server) BookmarkRepositoryTrashBookmarkByID

func (s *Server) BookmarkRepositoryTrashBookmarkByID(bookmarkID string) (int64, error)

BookmarkRepositoryTrashBookmarkByID - Mark bookmark as deleted

func (*Server) BookmarkRepositoryUpdateBookmark

func (s *Server) BookmarkRepositoryUpdateBookmark(bookmark Bookmark) error

BookmarkRepositoryUpdateBookmark - Update a specifc bookmark by its database id

func (*Server) CorsOptions

func (s *Server) CorsOptions(w http.ResponseWriter, r *http.Request)

DeleteBookmark Delete a specific bookmark by its ID

func (*Server) CreateBookmark

func (s *Server) CreateBookmark(w http.ResponseWriter, r *http.Request)

CreateBookmark Create bookmark

func (*Server) CreateTag

func (s *Server) CreateTag(w http.ResponseWriter, r *http.Request)

func (*Server) CreateUser

func (s *Server) CreateUser(w http.ResponseWriter, r *http.Request)

Only admin can run user APIs

func (*Server) DeleteBookmark

func (s *Server) DeleteBookmark(w http.ResponseWriter, r *http.Request)

DeleteBookmark Delete a specific bookmark by its ID

func (*Server) DeleteTag

func (s *Server) DeleteTag(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteUser

func (s *Server) DeleteUser(w http.ResponseWriter, r *http.Request)

func (*Server) GetBookmark

func (s *Server) GetBookmark(w http.ResponseWriter, r *http.Request)

GetBookmark Get a specific bookmark by its ID

func (*Server) ListBookmarks

func (s *Server) ListBookmarks(w http.ResponseWriter, r *http.Request)

ListBookmarks Return all bookmarks

func (*Server) ListTags

func (s *Server) ListTags(w http.ResponseWriter, r *http.Request)

func (*Server) ListUsers

func (s *Server) ListUsers(w http.ResponseWriter, r *http.Request)

func (*Server) MoveBookmarkToTrash

func (s *Server) MoveBookmarkToTrash(w http.ResponseWriter, r *http.Request)

DeleteBookmark Delete a specific bookmark by its ID

func (*Server) TagsRepositoryCreateTag

func (s *Server) TagsRepositoryCreateTag(bookmarkID int, TagName string) error

func (*Server) TagsRepositoryDeleteTagByBookmarkIDAndTagID

func (s *Server) TagsRepositoryDeleteTagByBookmarkIDAndTagID(bookmarkID int, tagName string) error

func (*Server) TagsRepositoryGetTags

func (s *Server) TagsRepositoryGetTags() (Tags, error)

func (*Server) TagsRepositoryGetTagsByBookmarkID

func (s *Server) TagsRepositoryGetTagsByBookmarkID(bookmarkID int) (Tags, error)

func (*Server) TagsRepositoryUpdateTagByID

func (s *Server) TagsRepositoryUpdateTagByID(tagID int, TagNameUpdate string) error

func (*Server) UpdateBookmark

func (s *Server) UpdateBookmark(w http.ResponseWriter, r *http.Request)

UpdateBookmark Update a bookmark by its ID

func (*Server) UpdateTag

func (s *Server) UpdateTag(w http.ResponseWriter, r *http.Request)

func (*Server) UpdateUser

func (s *Server) UpdateUser(w http.ResponseWriter, r *http.Request)

func (*Server) UserLogin

func (s *Server) UserLogin(w http.ResponseWriter, r *http.Request)

func (*Server) UserLogout

func (s *Server) UserLogout(w http.ResponseWriter, r *http.Request)

func (*Server) UserRepositoryCreate

func (s *Server) UserRepositoryCreate(user *CreateUserRequest) (int, error)

UserRepositoryCreate - Creates a new user in DB

func (*Server) UserRepositoryDeleteAccessToken

func (s *Server) UserRepositoryDeleteAccessToken(token string) error

func (*Server) UserRepositoryExists

func (s *Server) UserRepositoryExists(email string, hashed_password string) (int, error)

func (*Server) UserRepositoryIsAuthenticated

func (s *Server) UserRepositoryIsAuthenticated(userId int) (bool, error)

func (*Server) UserRepositoryIsAuthenticatedByToken

func (s *Server) UserRepositoryIsAuthenticatedByToken(token string) (User, bool)

func (*Server) UserRepositoryList

func (s *Server) UserRepositoryList() ([]*User, error)

UserRepositoryList - List all users

func (*Server) UserRepositoryLogin

func (s *Server) UserRepositoryLogin(userId int) (string, error)

type Tag

type Tag struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

type Tags

type Tags struct {
	Tags []Tag
}

type UpdateBookmarkRequest

type UpdateBookmarkRequest struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Body        string `json:"body,omitempty"`
	Image       string `json:"image,omitempty"`
	URL         string `json:"url,omitempty"`
	Archived    *bool  `json:"archived,omitempty"`
	Deleted     *bool  `json:"deleted,omitempty"`
}

UpdateBookmarkRequest - PUT/PATCH object

type UpdateTagRequest

type UpdateTagRequest struct {
	TagName string `json:"tagName"`
}

type User

type User struct {
	ID          uint      `json:"id"`
	Email       string    `json:"email"`
	APIToken    string    `json:"api_token"`
	IsAdmin     bool      `json:"is_admin"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	AccessToken string    `json:"access_token"`
	LoggedInAt  time.Time `json:"loggedin_at"`
}

type UserLogin

type UserLogin struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type Users

type Users struct {
	Users []User
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL