Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultData() (User, []Program)
- type Class
- type Connection
- type DB
- func (d *DB) AddClassToUser(ctx context.Context, uid string, cid string) error
- func (d *DB) AddUserToClass(ctx context.Context, uid string, cid string) error
- func (d *DB) CreateClass(c echo.Context) error
- func (d *DB) CreateCollab(c echo.Context) error
- func (d *DB) CreateProgram(ctx context.Context, p Program) (Program, error)
- func (d *DB) CreateUser(ctx context.Context, u User) (User, error)
- func (d *DB) DeleteClass(ctx context.Context, cid string) error
- func (d *DB) DeleteUser(ctx context.Context, uid string) error
- func (d *DB) ForkProgram(c echo.Context) error
- func (d *DB) GetID(ctx context.Context, path string) (int64, error)
- func (d *DB) GetUIDFromWID(ctx context.Context, wid string, path string) (string, error)
- func (d *DB) InitShards(ctx context.Context, path string) error
- func (d *DB) JoinCollab(c echo.Context) error
- func (d *DB) LeaveClass(c echo.Context) error
- func (d *DB) LoadClass(ctx context.Context, cid string) (Class, error)
- func (d *DB) LoadProgram(ctx context.Context, pid string) (Program, error)
- func (d *DB) LoadUser(ctx context.Context, uid string) (User, error)
- func (d *DB) MakeAlias(ctx context.Context, uid string, path string) (string, error)
- func (d *DB) RemoveClassFromUser(ctx context.Context, uid string, cid string) error
- func (d *DB) RemoveProgram(ctx context.Context, pid string) error
- func (d *DB) RemoveUserFromClass(ctx context.Context, uid string, cid string) error
- func (d *DB) StoreClass(ctx context.Context, c Class) error
- func (d *DB) StoreProgram(ctx context.Context, p Program) error
- func (d *DB) StoreUser(ctx context.Context, u User) error
- func (d *DB) UpdateProgram(c echo.Context) error
- func (d *DB) UpdateUser(c echo.Context) error
- type DBContext
- type Message
- type MockDB
- func (d *MockDB) CreateProgram(_ context.Context, p Program) (Program, error)
- func (d *MockDB) CreateUser(_ context.Context, u User) (User, error)
- func (d *MockDB) DeleteClass(_ context.Context, cid string) error
- func (d *MockDB) DeleteUser(_ context.Context, uid string) error
- func (d *MockDB) GetUIDFromWID(ctx context.Context, wid string, path string) (string, error)
- func (d *MockDB) LoadClass(_ context.Context, cid string) (c Class, err error)
- func (d *MockDB) LoadProgram(_ context.Context, pid string) (Program, error)
- func (d *MockDB) LoadUser(_ context.Context, uid string) (u User, err error)
- func (d *MockDB) MakeAlias(ctx context.Context, uid string, path string) (string, error)
- func (d *MockDB) RemoveProgram(_ context.Context, pid string) error
- func (d *MockDB) StoreClass(_ context.Context, c Class) error
- func (d *MockDB) StoreProgram(_ context.Context, p Program) error
- func (d *MockDB) StoreUser(_ context.Context, u User) error
- type Program
- type Session
- func (s *Session) AddConn(uid string, conn *websocket.Conn) error
- func (s *Session) BroadcastAll(msg Message) (lastErr error)
- func (s *Session) BroadcastError(uid string, err string) error
- func (s *Session) BroadcastTo(msg Message, uids ...string) (lastErr error)
- func (s *Session) BroadcastToSet(msg Message, uids stringSet) (lastErr error)
- func (s *Session) RemoveConn(uid string) error
- func (s *Session) RequestAccess(uid string, msg Message) error
- type Shard
- type TLADB
- type User
Constants ¶
const ( // DefaultEnvVar describes the default environment // variable used to open a connection to the database. DefaultEnvVar = "TLACFG" // the number of program thumbnails available to choose from. ThumbnailCount = 58 // classesAliasPath describes the path to the collection with 3 word id => hash mapping for classes ClassesAliasPath = "classes_alias" )
Variables ¶
var EnableBetaFeatures = os.Getenv("ENABLE_BETA_FEATURES")
Functions ¶
func DefaultData ¶
defaultData is the factory function for constructing default UserData structs and its associated Programs. Associations between said UserData and Programs are not automatically applied in the database.
Types ¶
type Class ¶
type Class struct { Thumbnail int64 `firestore:"thumbnail" json:"thumbnail"` Name string `firestore:"name" json:"name"` Creator string `firestore:"creator" json:"creator"` Instructors []string `firestore:"instructors" json:"instructors"` Members []string `firestore:"members" json:"members"` Programs []string `firestore:"programs" json:"programs"` CID string `firestore:"CID" json:"cid"` WID string `firestore:"WID" json:"wid"` Description string `firestore:"description" json:"description"` }
Class is a struct representation of a class document. It provides functions for converting the struct to firebase-digestible types.
type Connection ¶
type DB ¶
DB implements the TLADB interface on a Firestore database.
func Open ¶
Open returns a pointer to a new database client based on JSON credentials given by the environment variable. Returns an error if it fails at any point.
func OpenFromJSON ¶
OpenFromJSON returns a pointer to a new database client based on a JSON file given by the provided path. Returns an error if it fails at any point.
func (*DB) AddClassToUser ¶
AddClassToUser takes a uid and a pid, and adds the pid to the user's list of programs
func (*DB) AddUserToClass ¶
AddUserToClass add an uid to a given class
func (*DB) CreateClass ¶
CreateClass is the handler for creating a new class. It takes the UID of the creator, the name of the class, and a thumbnail id.
func (*DB) CreateCollab ¶
CreateCollab creates a collaborative session, setting up the session's websocket. Request Body:
{ uid: UID for the user the program belongs to name: optional name identifier for the session, defaults to random UUID. }
Returns status 201 created on success.
func (*DB) CreateProgram ¶
func (*DB) ForkProgram ¶
ForkProgram forks a program `pid` to the user `uid`.
Request Body:
{ uid string pid string }
Returns status 201 created on success.
func (*DB) GetUIDFromWID ¶
GetUIDFromWID returns the UID given a WID
func (*DB) InitShards ¶
InitShards takes the path to the class_alias collection (path) and initializes the shard
func (*DB) JoinCollab ¶
func (*DB) LeaveClass ¶
LeaveClass takes a UID and CID through the request body, and attempts to remove user UID from the provided class CID.
func (*DB) MakeAlias ¶
MakeAlias takes an id (usually pid or cid), generates a 3 word id(wid), and stores it in Firebase. The generated wid is returned as a string, with words comma seperated
func (*DB) RemoveClassFromUser ¶
RemoveClassFromUser removes a class from a given user
func (*DB) RemoveUserFromClass ¶
RemoveUserFromClass removes an uid from a given class
func (*DB) UpdateProgram ¶
UpdateProgram expects an array of partial Program structs and a UID of the user they belong to. If the user pointed to by UID does not own the programs passed to update, no programs are updated.
Request Body:
{ "uid": [REQUIRED], "programs": [array of partial program objects as indexed in user] }
Returns status 200 OK on nominal request.
func (*DB) UpdateUser ¶
UpdateUser updates the doc with specified UID's fields to match those of the request body.
Request Body:
{ "uid": [REQUIRED] [User object fields] }
Returns: Status 200 on success.
type DBContext ¶
type DBContext struct { echo.Context TLADB }
DBContext describes the basic echo context required by handlers.
type MockDB ¶
type MockDB struct {
// contains filtered or unexported fields
}
func (*MockDB) CreateProgram ¶
func (*MockDB) GetUIDFromWID ¶
func (*MockDB) LoadProgram ¶
type Program ¶
type Program struct { Code string `firestore:"code" json:"code"` DateCreated string `firestore:"dateCreated" json:"dateCreated"` Language string `firestore:"language" json:"language"` Name string `firestore:"name" json:"name"` Thumbnail int64 `firestore:"thumbnail" json:"thumbnail"` UID string `json:"uid"` WID string `json:"wid"` // Optional WID of class associated with program }
Program is a representation of a program document.
func DefaultProgram ¶
defaultProgram returns a Program struct initialized to default values for a given Language. if the language does not exist, it returns nil.
func (*Program) ToFirestoreUpdate ¶
ToFirestoreUpdate returns the []firestore.Update representation of this struct. Any fields that are non-zero valued are included in the update, save for the date of creation.
type Session ¶
type Session struct { *sync.Mutex // Map UIDs to their websocket.Conn Conns map[string]*Connection Teacher string }
Session describes a collaborative coding environment.
func (*Session) BroadcastAll ¶
BroadcastAll sends a message to all active connections
func (*Session) BroadcastError ¶
BroadcastError creates and sends an Error message given a string err to a given uid
func (*Session) BroadcastTo ¶
BroadcastTo sends a Message msg to the connections associated with the provided uids
func (*Session) BroadcastToSet ¶
BroadcastToSet sends a Message msg to the connections associated with the provided uids in a stringSet
func (*Session) RemoveConn ¶
type Shard ¶
type Shard struct {
Count int64
}
Shard class Currently all it does is store the number of shards
type TLADB ¶
type TLADB interface { LoadProgram(context.Context, string) (Program, error) StoreProgram(context.Context, Program) error // Rename to DeleteProgram after moving API handler out of db/program.go RemoveProgram(context.Context, string) error LoadClass(context.Context, string) (Class, error) StoreClass(context.Context, Class) error DeleteClass(context.Context, string) error LoadUser(context.Context, string) (User, error) StoreUser(context.Context, User) error DeleteUser(context.Context, string) error CreateUser(context.Context, User) (User, error) CreateProgram(context.Context, Program) (Program, error) MakeAlias(context.Context, string, string) (string, error) GetUIDFromWID(context.Context, string, string) (string, error) }
TLADB describes the basic set of operations required by backend handlers. Atomicity of operations on a TLADB are implementation-dependent.
type User ¶
type User struct { Classes []string `firestore:"classes" json:"classes"` DisplayName string `firestore:"displayName" json:"displayName"` MostRecentProgram string `firestore:"mostRecentProgram" json:"mostRecentProgram"` PhotoName string `firestore:"photoName" json:"photoName"` Programs []string `firestore:"programs" json:"programs"` UID string `json:"uid"` DeveloperAcc bool `firestore:"developerAcc" json:"developerAcc"` }
User is a struct representation of a user document. It provides functions for converting the struct to firebase-digestible types.
func (*User) ToFirestoreUpdate ¶
ToFirestoreUpdate returns the database update representation of its UserData struct.