A prototype of a web service for translating and sharing digital books and other textual media through a RESTful API.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.3 KiB

package bakamoews
import (
//User defines the user entity and it's fields
type User struct {
ID uint64 `json:"id"`
Name string `json:"name"` //Real name of user
Username string `json:"username,omitempty" sql:",notnull,unique"`
Email string `json:"email" sql:",notnull,unique"`
Password string `json:"password,omitempty"` //Plaintext if used when handling login requests, hash if pulled from database
DefaultLanguage string `json:"default_language,omitempty"`
Enabled bool `json:"-" sql:",default:true"` //Not sure if I'm going to use this
CreatedOn time.Time `json:"created_on,omitempty" sql:",default:now()"` //Unix timestamp of the time account was created. Empty when account first created
//ErrorResponse is a simple wrapper for error messages to be serialized into JSON
type ErrorResponse struct {
Level string `json:"level"`
Message string `json:"message"`
//UserService defines the functions a user service must implement
type UserService interface {
Create(*User) (*User, error)
Update(*User) (*User, error)
Delete(uint64, bool) error
User(uint64) (*User, error)
Authenticate(string, string) (*User, error)
List(int, int) ([]User, error)
//MediaService defines the functions a media service must implement
type MediaService interface {
Init(bool) error
CreateMediaGroup(*MediaGroup) (*MediaGroup, error)
CreateMedia(*Media) (*Media, error)
GetMediaGroup(uint64) (*MediaGroup, error)
GetMedia(uint64) (*Media, error)
GetChildrenMedia(uint64) (*[]Media, error)
GetChildrenMediaGroup(uint64) (*[]MediaGroup, error)
DeleteMedia(uint64) error
DeleteMediaGroup(uint64) error
UpdateMedia(*Media) (*Media, error)
UpdateMediaGroup(*MediaGroup) (*MediaGroup, error)
//TextService defines the functions a text service must implement
type TextService interface {
Init(string, string) error
//I should use an io.Reader/ReadCloser so I can pass http.Request.Body directly and stream the contents for better performance
Create(io.Reader, int64) (string, error)
Update(string, io.Reader, int64) error
Delete(string) error
Get(string) (io.ReadCloser, error)
Convert(string, string) (io.ReadCloser, error)
//Media represents a single piece of media with an associated Text ID
type Media struct {
ID uint64 `json:"id" sql:",pk"`
MediaGroupID uint64 `json:"media_group_id" sql:",notnull"`
Title string `json:"title" sql:",notnull,unique"`
Tags []string `json:"tags"`
OwnerID uint64 `json:"owner_id" sql:",notnull"`
Published bool `json:"published" sql:",default:false"`
Editors []uint64 `json:"editors"`
Metadata map[string]string `json:"metadata"`
Languages []string `json:"languages" sql:",notnull"`
CreatedOn time.Time `json:"created_on" sql:",default:now()"`
PublishedOn time.Time `json:"published_timestamp"`
LastEditedOn time.Time `json:"last_edited_on" sql:",default:now()"`
TextID string `json:"text_id"`
Open bool `json:"open" sql:",default:false"`
ImageURL string `json:"image_url"`
Visible bool `json:"-" sql:",default:true"`
Locked bool `json:"-" sql:",default:false"`
//MediaGroup represents an arbitrary grouping of Media. Has at least one parent.
type MediaGroup struct {
ID uint64 `json:"id" pg:",pk"`
Title string `json:"title" sql:",notnull"`
ParentID uint64 `json:"parent_id" sql:",default:1"`
Published bool `json:"published" sql:",default:false"`
Metadata map[string]string `json:"metadata"`
CreatedTimestamp time.Time `json:"created_on" sql:",default:now()"`
PublishedOn time.Time `json:"published_on"`
LastEditedOn time.Time `json:"last_edited_on" sql:",default:now()"`
ImageURL string `json:"image_url"`
Visible bool `json:"-" sql:",default:true"`
Locked bool `json:"-" sql:",default:false"`
//Tag defiles a tag name/value pair
type Tag struct {
Name string `json:"tag_name" sql:"unique, notnull"`
Value string `json:"tag_value" sql:"uniqu,notnull"`