snippets

package module
v0.0.0-...-8e7fc4b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 4 Imported by: 0

README

Snippy

Backend of the Snippy service - lightning-fast solution for managing code snippets.

Installation and run

git clone git@github.com:mbredikhin/snippy.git && cd snippy
# Build services
make build
# Create and start containers
make run
# Run database migrations
make migrate-up
# Seed database
make db-seed
# API host name: http://localhost:8001
# curl -X POST --data '{"username":"username", "password":"password"}' http://localhost:8001/auth/sign-in
# curl -X POST --data '{"name":"My snippets collection"}' --header 'Authorization: Bearer {{token}}' http://localhost:8001/api/lists

API Reference

Run In Postman

Register new user
  POST /auth/sign-up

Body:

Key Type Description
username string Required. Your username
password string Required. Your password
name string Your full name

Response

{
    "status": "ok"
}
Login with username and password
  POST /auth/sign-in

Body:

Key Type Description
username string Required. Your username
password string Required. Your password

Response

{
    "data": {
        "token": string
    }
}

Send given token in Authorization HTTP header – Authorization: "Bearer %s"

Create a new list of snippets
  POST /api/lists

Body:

Key Type Description
name string Required. Collection name

Response

{
    "data": {
        "id": number,
        "name": string
    }
}
Get all lists
  GET /api/lists

Query parameters:

Parameter Type Description
page number Page
limit number Pagination limit

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}
Get list by id
  GET /api/lists/:id

Query parameters:

Parameter Type Description
id number Required. Collection ID

Response

{
    "data": {
        "id": number,
        "name": string
    }
}
Update list
  PUT /api/lists/:id

Body:

Key Type Description
name string Required. Collection name

Response

{
    "data": {
        "id": number,
        "name": string
    }
}
Delete list
  DELETE /api/lists/:id

Body:

Key Type Description
id number Required. Collection ID

Response

{
    "data": {
        "id": number
    }
}
Add language
  POST /api/languages

Body:

Key Type Description
name string Required. Language name

Response

{
    "data": {
        "id": number
    }
}
Get list of languages
  GET /api/languages

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}
Create new snippet
  POST /api/lists/:id/snippets

Body:

Key Type Description
name string Required. Snippet name
language_id number Required. Language ID
description string Required. Text description
content string Required. Snippet content

Response

{
    "data": {
        "id": number
    }
}
Get all snippets of the list
  GET /api/lists/:id/snippets

Query parameters:

Parameter Type Description
tag_ids number[] Filters snippets with any of entered tags assigned
page number Page
limit number Pagination limit

Response

{
    "data": [
        {
            "id": number,
            "list_id": number,
            "name": string,
            "language_id": number,
            "description": string,
            "content": string
        }
    ]
}
Get snippet
  GET /api/snippets/:id

Response

{
    "data": {
        "id": number,
        "list_id": number,
        "name": string,
        "language_id": number,
        "description": number,
        "content": string
    }
}
Update snippet
  PUT /api/snippets/:id

Body:

Key Type Description
name string Required. Snippet name
language_id number Required. Language ID
list_id number Required. Collection ID
description string Required. Text description
content string Required. Snippet content

Response

{
    "status": "ok"
}
Delete snippet
  DELETE /api/snippets/:id

Response

{
    "status": "ok"
}
Add snippet to favourites
  POST /api/snippets/favourites

Body:

Key Type Description
id number Required. Snippet ID

Response

{
    "status": "ok"
}
Remove snippet from favourites
  DELETE /api/snippets/favourites

Body:

Key Type Description
id number Required. Snippet ID

Response

{
    "status": "ok"
}
Get ids of favourite snippets
  GET /api/snippets/favourites

Response

{
    "data": [number]
}
Add tag
  POST /api/tags

Body:

Key Type Description
name string Required. Tag ID

Response

{
    "data": {
        "id": number
    }
}
Update tag
  PUT /api/tags/:id

Body:

Key Type Description
id number Required. Tag ID

Response

{
    "status": "ok"
}
Delete tag
  DELETE /api/tags/:id

Response

{
    "status": "ok"
}
Get tag
  GET /api/tags/:id

Response

{
    "data": {
        "id": number,
        "name": string
    }
}
Get list of tags
  GET /api/tags

Response

{
    "data": [
        {
            "id": number,
            "name": string
        }
    ]
}
Get list of tags assigned to the snippet
  GET /api/snippets/:id/tags

Response

{
    "data": [number]
}
Assign tag to the snippet
  POST /api/snippets/:id/tags

Body:

Key Type Description
tag_id number Required. Tag ID

Response

{
    "status": "ok"
}
Unassign tag from the snippet
  DELETE /api/snippets/:id/tags

Body:

Key Type Description
tag_id number Required. Tag ID

Response

{
    "status": "ok"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddLanguageResponse

type AddLanguageResponse struct {
	ID *int `json:"id"`
}

AddLanguageResponse model

type AddSnippetToFavouritesInput

type AddSnippetToFavouritesInput struct {
	ID *int `json:"id"`
}

AddSnippetToFavouritesInput model

type AddTagResponse

type AddTagResponse struct {
	ID *int `json:"id"`
}

AddTagResponse model

type AddTagToSnippetInput

type AddTagToSnippetInput struct {
	TagID *int `json:"tag_id"`
}

AddTagToSnippetInput model

type CreateSnippetResponse

type CreateSnippetResponse struct {
	ID *int `json:"id"`
}

CreateSnippetRespnse model

type DeleteListResponse

type DeleteListResponse struct {
	ID *int `json:"id"`
}

DeleteListResponse model

type Language

type Language struct {
	ID   int    `json:"id" db:"id"`
	Name string `json:"name" db:"name" binding:"required"`
}

Language model

type List

type List struct {
	ID   int    `json:"id" db:"id"`
	Name string `json:"name" db:"name" binding:"required"`
}

List of snippets model

type PaginationParams

type PaginationParams struct {
	Page  int
	Limit int
}

type RemoveSnippetFromFavouritesInput

type RemoveSnippetFromFavouritesInput struct {
	ID *int `json:"id"`
}

RemoveSnippetFromFavouritesInput model

type RemoveTagFromSnippetInput

type RemoveTagFromSnippetInput struct {
	TagID *int `json:"tag_id"`
}

RemoveTagFromSnippetInput model

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server - http server

func (*Server) Run

func (s *Server) Run(port string, handler http.Handler) error

Run - up http server

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown - down http server

type SignInInput

type SignInInput struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

SignInInput model

type SignInResponse

type SignInResponse struct {
	Token *string `json:"token"`
}

SignInResponse model

type Snippet

type Snippet struct {
	ID          int    `json:"id" db:"id"`
	ListID      int    `json:"list_id" db:"list_id"`
	Name        string `json:"name" db:"name" binding:"required"`
	LanguageID  int    `json:"language_id" db:"language_id" binding:"required"`
	Description string `json:"description" db:"description" binding:"required"`
	Content     string `json:"content" db:"content" binding:"required"`
}

Snippet model

type Tag

type Tag struct {
	ID   int    `json:"id" db:"id"`
	Name string `json:"name" db:"name" binding:"required"`
}

Tag model

type UpdateListInput

type UpdateListInput struct {
	Name *string `json:"name"`
}

UpdateListInput model

func (UpdateListInput) Validate

func (i UpdateListInput) Validate() error

Validate - list input validation

type UpdateSnippetInput

type UpdateSnippetInput struct {
	Name        *string `json:"name"`
	ListID      *int    `json:"list_id"`
	LanguageID  *int    `json:"language_id"`
	Description *string `json:"description"`
	Content     *string `json:"content"`
}

UpdateSnippetInput model

func (UpdateSnippetInput) Validate

func (i UpdateSnippetInput) Validate() error

Validate - snippet input validation

type UpdateTagInput

type UpdateTagInput struct {
	Name *string `json:"name"`
}

UpdateTagInput model

func (UpdateTagInput) Validate

func (i UpdateTagInput) Validate() error

Validate - tag input validation

type User

type User struct {
	ID       int    `json:"-" db:"id"`
	Name     string `json:"name"`
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

User model

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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