api

package
v0.1.5-beta Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddPostRequest

type AddPostRequest struct {
	PostedBy int    `json:"postedBy" db:"PostedBy"`
	Content  string `json:"content" db:"content"`
	ParentID int    `json:"parentID" db:"ParentId"`
	Images   string `json:"images" db:"images"`
}

AddPostRequest struct should be used for request for adding a new Post in the database

type AssetCache

type AssetCache struct {
	File     *utility.FileMime // The filedata
	FileInfo fs.FileInfo       // The file metadata
	Err      error             // The Error being return (optional)
	Code     int               // The code being returned
	ETag     string            // The file's ETag
}

AssetCache is represents the Asset stored in the Cache

type ConstantFileOptions

type ConstantFileOptions struct {
	Path   string
	Mime   string
	MaxAge int
}

ConstantFileOptions is for the method github.com/Blockitifluy/CoffeeCo/api.ConstantFile

type ImageData

type ImageData struct {
	URL         string `db:"URL"`
	Content     []byte `db:"content"`
	ContentType string `db:"mimetype"`
}

ImageData contains the URL, content, content-type of an image

type LoginUser

type LoginUser struct {
	Handle   string `json:"handle" db:"handle"` // A unique name of the User
	Password string `json:"password"`           // Unhashed password
}

LoginUser is used for login users and contains:

  • Handle
  • Password (hasn't been hashed yet)

type PostDB

type PostDB struct {
	ID          int       `json:"ID" db:"ID"`
	PostedBy    int       `json:"postedBy" db:"postedBy"`
	Content     string    `json:"content" db:"content"`
	TimeCreated time.Time `json:"timeCreated" db:"timeCreated"`
	ParentID    int       `json:"parentID" db:"parentID"`
	WhoLiked    string    `json:"whoLiked" db:"whoLiked"`
	WhoDisliked string    `json:"whoDisliked" db:"whoDisliked"`
	Likes       int       `json:"likes" db:"likes"`
	Dislikes    int       `json:"dislikes" db:"dislikes"`
	Images      string    `json:"images" db:"images"`
}

PostDB is a struct replicata of the `Posts` table

type PostListBody

type PostListBody struct {
	Amount int `json:"amount"`
}

PostListBody is used by coffeecoserver/api.server.PostFeedList and only contains Amount int value.

type PublicUser

type PublicUser struct {
	ID          int    `json:"ID" db:"ID"`
	Username    string `json:"username" db:"username"` // A non-unique name
	Handle      string `json:"handle" db:"handle"`     // An unique handle
	Bio         string `json:"bio" db:"bio"`           // The description (biography)
	Followers   int    `json:"followers" db:"followers"`
	WhoFollowed string `json:"whoFollowed" db:"whoFollowed"` // How many users following
	Banner      string `json:"Banner" db:"banner"`           // Url to the Banner
	Profile     string `json:"Profile" db:"profile"`         // Url to the Profile
}

PublicUser is the root of most User structs contains non-personal information about the user

type RouteTemplate

type RouteTemplate struct {
	Methods []string
	Funct   http.HandlerFunc
	// contains filtered or unexported fields
}

RouteTemplate is a server route, not yet loaded by the server

type SentUser

type SentUser struct {
	*PublicUser

	Password string `json:"password"` // unhashed password
	Email    string `json:"email" db:"email"`
}

SentUser contains all the regular information from coffeecoserver/api.PublicUser as well as:

  • Password
  • Email

type Server

type Server struct {
	*mux.Router
	*sql.DB

	Address string
	Debug   bool
}

Server contains:

  • Server (Gorilla Mux),
  • Database (Sqlite)

func NewServer

func NewServer(address string, debug bool) *Server

NewServer creates a server with the database and routes added

func (*Server) APIAddPost

func (srv *Server) APIAddPost(w http.ResponseWriter, r *http.Request)

APIAddPost is an API call do not use outside of http requests

Adds a post to database. See more at coffeecoserver/api.AddPostRequest.

func (*Server) APIAddUser

func (srv *Server) APIAddUser(w http.ResponseWriter, r *http.Request)

APIAddUser is an api call. Doesn't work as expected when called outside an API context

Add user using the SentUser struct

func (*Server) APIAuthToID

func (srv *Server) APIAuthToID(w http.ResponseWriter, r *http.Request)

APIAuthToID is an api call. Doesn't work as expected when called outside an API context

Get a user's id using authorisation token via url

func (*Server) APIDownloadImage

func (srv *Server) APIDownloadImage(w http.ResponseWriter, r *http.Request)

APIDownloadImage is an api call. Doesn't work as expected when called outside an API context

Retrieves an image from the batabase, compress for network

func (*Server) APIGetCommentsFromPost

func (srv *Server) APIGetCommentsFromPost(w http.ResponseWriter, r *http.Request)

APIGetCommentsFromPost is an API call, only use in HTTP contexts

Get a the comment from a Post

func (*Server) APIGetPostFromID

func (srv *Server) APIGetPostFromID(w http.ResponseWriter, r *http.Request)

APIGetPostFromID is an API call, only use in HTTP contexts

Get a post based on the ID given

func (*Server) APIGetPostsFromUser

func (srv *Server) APIGetPostsFromUser(w http.ResponseWriter, r *http.Request)

APIGetPostsFromUser is an API call do not use outside of http requests

Gets a x amount of Posts from a User (Provided by ID)

func (*Server) APIGetUserPostHistory

func (srv *Server) APIGetUserPostHistory(w http.ResponseWriter, r *http.Request)

APIGetUserPostHistory is an API call do not use outside of http requests

Gets posts from a range by an user

func (*Server) APILoginUser

func (srv *Server) APILoginUser(w http.ResponseWriter, r *http.Request)

APILoginUser is an api call. Doesn't work as expected when called outside an API context

Logs in user via password and username

func (*Server) APIPostFeed

func (srv *Server) APIPostFeed(w http.ResponseWriter, r *http.Request)

APIPostFeed is an API call do not use outside of http requests

This is a work in progress will change in the future

func (*Server) APIPostFeedList

func (srv *Server) APIPostFeedList(w http.ResponseWriter, r *http.Request)

APIPostFeedList is an API call do not use outside of http requests

This returns a list version of coffeecoserver/api.Server.PostFeed

func (*Server) APISearchForUsers

func (srv *Server) APISearchForUsers(w http.ResponseWriter, r *http.Request)

APISearchForUsers is an api call. Doesn't work as expected when called outside an API context

Searches user by username and handle (Feed Type)

func (*Server) APISearchPost

func (srv *Server) APISearchPost(w http.ResponseWriter, r *http.Request)

APISearchPost is an API call do not use outside of http requests

Searches posts by content (Feed Type)

func (*Server) APIUploadImage

func (srv *Server) APIUploadImage(w http.ResponseWriter, r *http.Request)

APIUploadImage is an api call. Doesn't work as expected when called outside an API context

Uploads an image (png, jpeg and gif) with a limited size, compresses it and add to database

func (*Server) APIUserFromID

func (srv *Server) APIUserFromID(w http.ResponseWriter, r *http.Request)

APIUserFromID is an api call. Doesn't work as expected when called outside an API context

Get a user based on the id given via url.

func (*Server) AssetFiles

func (srv *Server) AssetFiles(w http.ResponseWriter, r *http.Request)

AssetFiles is an api call. Doesn't work as expected when called outside an API context

Sends files from `dist/assets` and caches it

func (*Server) AuthToID

func (srv *Server) AuthToID(auth string) (int, error)

AuthToID is the non-api version of APIAuthToID

func (*Server) ConstantFile

func (srv *Server) ConstantFile(Options ConstantFileOptions) http.HandlerFunc

ConstantFile is an api call. Doesn't work as expected when called outside an API context

First, reads and caches file then sends to client

func (*Server) IDToUser

func (srv *Server) IDToUser(ID int) (*User, error)

IDToUser get the ID from the User

func (*Server) InitTable

func (srv *Server) InitTable()

InitTable adds tables to the database if the database already has been initated

func (*Server) LoadAssets

func (srv *Server) LoadAssets()

LoadAssets loads asset urls

func (*Server) Routes

func (srv *Server) Routes()

Routes method adds routes to the server (Self explainitary)

func (*Server) Run

func (srv *Server) Run()

Run runs the server

func (*Server) SendAssetsFile

func (srv *Server) SendAssetsFile(w http.ResponseWriter, r *http.Request, Data AssetCache)

SendAssetsFile sends the AssetCache to the client

type User

type User struct {
	*PublicUser

	Email string `json:"email" db:"email"`
	Auth  string `json:"auth" db:"auth"` // Authorisation Token
	// contains filtered or unexported fields
}

User contains all the user information provided from the database

func (*User) GenerateAuth

func (u *User) GenerateAuth() string

GenerateAuth generates an auth token from the user

Jump to

Keyboard shortcuts

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