api

package
v0.0.0-...-48d6db3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockTypeExternal = "external"
	BlockTypeEmbed    = "embed"
	BlockTypeForm     = "form"
	BlockTypeText     = "text"
	BlockTypeFile     = "file"
)
View Source
const (
	BlockEmbedTypeExternalPDF = "external_pdf"
	BlockEmbedTypeInternalPDF = "internal_pdf"
	BlockEmbedTypeYoutube     = "youtube"
)
View Source
const (
	BlockFormTypeSurvey = "survey"
	BlockFormTypeQuiz   = "quiz"

	BlockFormQuestionTypeExplanation = "explanation" // just text, no response allowed
	BlockFormQuestionTypeMultiple    = "multiple"    // multiple choice
	BlockFormQuestionTypeSingle      = "single"      // single choice
	BlockFormQuestionTypeShort       = "short"       // short text
	BlockFormQuestionTypeLong        = "long"        // long text
	BlockFormQuestionTypeLikert5     = "likert5"     // likert5
	BlockFormQuestionTypeLikert7     = "likert7"     // likert7

	BlockFormSubmissionResultsNA         = "na"
	BlockFormSubmissionResultsNeedsInput = "needs_input"
	BlockFormSubmissionResultsPassed     = "passed"
	BlockFormSubmissionResultsFailed     = "failed"

	BlockFormSubmissionResponseIsCorrectNA      = "na"
	BlockFormSubmissionResponseIsCorrectPending = "pending"
	BlockFormSubmissionResponseIsCorrectYes     = "yes"
	BlockFormSubmissionResponseIsCorrectNo      = "no"
)
View Source
const (
	Yes      = "yes"
	No       = "no"
	SortASC  = "ASC"
	SortDESC = "DESC"
)
View Source
const (
	ConsentResponseStatusAccepted         = "accepted"
	ConsentResponseStatusAcceptedForOther = "accepted_for_other"
	ConsentResponseStatusDeclined         = "declined"
)
View Source
const (
	MaxFileSizeMB = 128

	FileVisibilityAdmin   = "admin"
	FileVisibilityUsers   = "users"
	FileVisibilityProject = "project"
	FileVisibilityPublic  = "public"

	FileLocationSourceAWS   = "aws"
	FileLocationSourceOther = "other"
)
View Source
const (
	BlockUserStatusNotStarted = "not_started"
	BlockUserStatusStarted    = "started"
	BlockUserStatusCompleted  = "completed"
)
View Source
const (
	LogLevelTrace = "TRACE"
	LogLevelDebug = "DEBUG"
	LogLevelInfo  = "INFO"
	LogLevelWarn  = "WARN"
	LogLevelError = "ERROR"
	LogLevelFatal = "FATAL"
	LogLevelPanic = "PANIC"
)
View Source
const (
	ModuleStatusActive   = "active"
	ModuleStatusPending  = "pending"
	ModuleStatusDisabled = "disabled"
)
View Source
const (
	NoteTypeJournal = "journal"
	NoteTypeProject = "project"

	NoteVisibilityPrivate = "private"
	NoteVisibilityAdmins  = "admins"
)
View Source
const (
	ProjectStatusPending   = "pending"
	ProjectStatusActive    = "active"
	ProjectStatusDisabled  = "disabled"
	ProjectStatusCompleted = "completed"

	ProjectUserLinkStatusNotStarted = "not_started"
	ProjectUserLinkStatusStarted    = "started"
	ProjectUserLinkStatusCompleted  = "completed"

	ProjectShowStatusSite   = "site"
	ProjectShowStatusDirect = "direct"
	ProjectShowStatusNo     = "no"

	ProjectSignupStatusOpen     = "open"
	ProjectSignupStatusWithCode = "with_code"
	ProjectSignupStatusClosed   = "closed"

	ProjectParticipantVisibilityCode  = "code"
	ProjectParticipantVisibilityEmail = "email"
	ProjectParticipantVisibilityFull  = "full"

	ProjectFlowRuleFree             = "free"                // no limitations
	ProjectFlowRuleInOrderInModule  = "in_order_in_module"  // must progress in module order but any module can be accessed
	ProjectFlowRuleInOrderInProject = "in_order_in_project" // must progress in project order

	ProjectCompleteRuleContinued = "continued_access" // continued access
	ProjectCompleteRuleBlocked   = "blocked"          // when complete or end, no more access

	ProjectStartRuleAny       = "any"       // begins when active
	ProjectStartRuleDate      = "date"      // begins on date
	ProjectStartRuleThreshold = "threshold" // begins when threshold hit
)
View Source
const (
	SiteStatusPending  = "pending"
	SiteStatusActive   = "active"
	SiteStatusDisabled = "disabled"

	SiteProjectListOptionsAll    = "show_all"
	SiteProjectListOptionsActive = "show_active"
	SiteProjectListOptionsNone   = "show_none"
)
View Source
const (
	UserStatusActive   = "active"
	UserStatusPending  = "pending"
	UserStatusLocked   = "locked"
	UserStatusDisabled = "disabled"

	UserSystemRoleUser        = "user"
	UserSystemRoleAdmin       = "admin"
	UserSystemRoleParticipant = "participant"
)

Variables

This section is empty.

Functions

func CalculateDuration

func CalculateDuration(input time.Time) (year, month, day, hour, min, sec int)

CalculateDuration gets the duration from a certain date time to now. Timezone is not important for this one and we always calculate from now. Shamelessly adapted from icza at https://stackoverflow.com/questions/36530251/golang-time-since-with-months-and-years. Support him through his profile: https://stackoverflow.com/users/1705598/icza

func CheckConfiguration

func CheckConfiguration()

func CheckProjectParticipantStatusForParticipant

func CheckProjectParticipantStatusForParticipant(participantID, projectID int64) (string, error)

CheckProjectParticipantStatusForParticipant checks the participant's status in a project

func CreateBlock

func CreateBlock(input *Block) error

CreateBlock creates a new block

func CreateBlockFormQuestion

func CreateBlockFormQuestion(input *BlockFormQuestion) error

CreateBlockFormQuestion creates a new question

func CreateBlockFormQuestionOption

func CreateBlockFormQuestionOption(input *BlockFormQuestionOption) error

CreateBlockFormQuestionOption creates a new option

func CreateBlockFormSubmission

func CreateBlockFormSubmission(input *BlockFormSubmission) error

CreateBlockFormSubmission creates a new submission to link in individual responses

func CreateBlockFormSubmissionResponse

func CreateBlockFormSubmissionResponse(input *BlockFormSubmissionResponse) error

CreateBlockFormSubmissionResponse creates a new individual question response

func CreateConsentResponse

func CreateConsentResponse(input *ConsentResponse) error

CreateConsentResponse creates a new response

func CreateFileInDB

func CreateFileInDB(input *File) error

CreateFileInDB creates a file entry in the DB

func CreateModule

func CreateModule(input *Module) error

CreateModule creates a module as a standalone "box"

func CreateNote

func CreateNote(input *Note) error

CreateNote creates a new note

func CreateProject

func CreateProject(input *Project) error

CreateProject creates a new project

func CreateSite

func CreateSite(input *Site) error

CreateSite creates a site; this should be called relatively infrequently

func CreateUser

func CreateUser(input *User) error

CreateUser creates a new user in the db

func DeleteBlock

func DeleteBlock(blockID int64) error

DeleteBlock deletes a block

func DeleteBlockEmbedByBlockID

func DeleteBlockEmbedByBlockID(blockID int64) error

DeleteBlockEmbedByBlockID deletes the block content

func DeleteBlockExternalByBlockID

func DeleteBlockExternalByBlockID(blockID int64) error

DeleteBlockExternalByBlockID deletes the block content

func DeleteBlockFileByBlockID

func DeleteBlockFileByBlockID(blockID int64) error

DeleteBlockFileByBlockID deletes the block content

func DeleteBlockFormByBlockID

func DeleteBlockFormByBlockID(blockID int64) error

DeleteBlockFormByBlockID deletes a form and all of the questions / options / responses

func DeleteBlockFormQuestion

func DeleteBlockFormQuestion(questionID int64) error

DeleteBlockFormQuestion deletes a question and all responses / options

func DeleteBlockFormQuestionOption

func DeleteBlockFormQuestionOption(id int64) error

DeleteBlockFormQuestionOption deletes an option

func DeleteBlockFormQuestionsForBlock

func DeleteBlockFormQuestionsForBlock(blockID int64) error

DeleteBlockFormQuestionsForBlock deletes all questions and all responses / options for a block

func DeleteBlockFormSubmission

func DeleteBlockFormSubmission(submissionID int64) error

DeleteBlockFormSubmission deletes a submission and connected responses

func DeleteBlockFormSubmissionResponses

func DeleteBlockFormSubmissionResponses(submissionID int64) error

DeleteBlockFormSubmissionResponses deletes all of the responses for a submission

func DeleteBlockTextByBlockID

func DeleteBlockTextByBlockID(blockID int64) error

DeleteBlockTextByBlockID deletes the block content

func DeleteConsentFormForProject

func DeleteConsentFormForProject(projectID int64) error

DeleteConsentFormForProject deletes the consent form for a project and all responses

func DeleteConsentResponsesForProject

func DeleteConsentResponsesForProject(projectID int64) error

DeleteConsentResponsesForProject deletes all responses for a project

func DeleteConsentesponse

func DeleteConsentesponse(responseID int64) error

DeleteConsentesponse deletes a single response

func DeleteConsentesponseForParticipant

func DeleteConsentesponseForParticipant(userID, projectID int64) error

DeleteConsentesponseForParticipant deletes a response for a specific participant; this could be dangerous depending on the study protocol!

func DeleteFileFromBucket

func DeleteFileFromBucket(key string) error

DeleteFileFromBucket deletes a file from a bucket

func DeleteFileFromDB

func DeleteFileFromDB(id int64) error

DeleteFileFromDB deletes a file's metadata from the DB

func DeleteJournalNotesForUser

func DeleteJournalNotesForUser(userID int64) error

DeleteJournalNotesForUser deletes all journal notes for a user

func DeleteModule

func DeleteModule(moduleID int64) error

DeleteModule removes a module from flows and then deletes the module

func DeleteNoteByID

func DeleteNoteByID(noteID int64) error

DeleteNoteByID deletes a single note

func DeleteNotesForUser

func DeleteNotesForUser(userID int64) error

DeleteNotesForUser deletes all notes tied to a user

func DeleteProject

func DeleteProject(projectID int64) error

DeleteProject deletes a project. Note that this probably

func DeleteProjectNotesForProject

func DeleteProjectNotesForProject(projectID int64) error

DeleteProjectNotesForProject deletes all notes on a project; should only be called if a project is deleted

func DeleteProjectNotesForUser

func DeleteProjectNotesForUser(userID, projectID int64) error

DeleteProjectNotesForUser deletes the notes for a user tied to a specific project

func DeleteSiteByID

func DeleteSiteByID(siteID int64) error

DeleteSiteByID deletes a site. WARNING: Think REALLY HARD before calling this, as the ramifications could be... difficult. It would be better to just drop the database if you are intentionally trying to delete a site and its data

func DeleteUser

func DeleteUser(userID int64) error

DeleteUser completely deletes a user, and should really only be used in tests

func GetFileFromBucket

func GetFileFromBucket(key string) ([]byte, error)

GetFileFromBucket gets the raw bytes of an object from a bucket

func HandleSaveBlockForm

func HandleSaveBlockForm(content *BlockForm) error

func IsBlockInModule

func IsBlockInModule(moduleID, blockID int64) bool

IsBlockInModule checks if a block is in a module for a flow

func IsModuleInProject

func IsModuleInProject(projectID, moduleID int64) bool

IsModuleInProject checks if a module is in a project flow

func IsUserInProject

func IsUserInProject(participantID, projectID int64) bool

IsUserInProject is a helper to determine if a user is in a project or not

func LinkBlockAndModule

func LinkBlockAndModule(moduleID int64, blockID int64, order int64) error

LinkBlockAndModule links a block and a module

func LinkModuleAndProject

func LinkModuleAndProject(projectID, moduleID, order int64) error

LinkModuleAndProject saves a connection between a module and a project

func LinkUserAndProject

func LinkUserAndProject(userID, projectID int64) error

LinkUserAndProject links a user to a project

func ListFilesInBucket

func ListFilesInBucket() ([]types.Object, error)

ListFilesInBucket will list the files in the bucket. Note that this isn't the ideal way to list all files for the account, as the files should be handled in the db

func Log

func Log(level string, key, message string, options *LogOptions)

Log sends a log to output

func LogOutUser

func LogOutUser(userID int64) error

func RemoveAllProgressForParticipantAndBlock

func RemoveAllProgressForParticipantAndBlock(participantID, blockID int64) error

RemoveAllProgressForParticipantAndBlock removes a participant's progress in a block

func RemoveAllProgressForParticipantAndFlow

func RemoveAllProgressForParticipantAndFlow(participantID, projectID int64) error

RemoveAllProgressForParticipantAndFlow removes all progress saved for a user in a project flow

func RemoveAllProgressForParticipantAndModule

func RemoveAllProgressForParticipantAndModule(participantID, moduleID int64) error

RemoveAllProgressForParticipantAndModule removes a participant's progress in a module

func RemoveUserFromProjectCompletely

func RemoveUserFromProjectCompletely(userID, projectID int64) error

func SaveBlockEmbed

func SaveBlockEmbed(input *BlockEmbed) error

SaveBlockEmbed saves the block content

func SaveBlockExternal

func SaveBlockExternal(input *BlockExternal) error

SaveBlockExternal saves the block content

func SaveBlockFile

func SaveBlockFile(input *BlockFile) error

SaveBlockFile saves the block content

func SaveBlockForm

func SaveBlockForm(input *BlockForm) error

SaveBlockForm creates or updates the limited sub-meta-data

func SaveBlockText

func SaveBlockText(input *BlockText) error

SaveBlockText saves the block content

func SaveBlockUserStatusForParticipant

func SaveBlockUserStatusForParticipant(input *BlockUserStatus) error

SaveBlockUserStatusForParticipant creates or updates a participant's block status in the flow

func SaveConsentFormForProject

func SaveConsentFormForProject(input *ConsentForm) error

SaveConsentFormForProject creates or updates a consent form for a project

func SetupAPI

func SetupAPI() *chi.Mux

SetupAPI sets up an API Mux for handling the calls

func SetupConfig

func SetupConfig() *apiConfig

SetupConfig is a call to configure the basic required configuration options for the API

func UnlinkAllBlocksFromModule

func UnlinkAllBlocksFromModule(moduleID int64) error

UnlinkAllBlocksFromModule unlinks all blocks from a module

func UnlinkAllModulesFromProject

func UnlinkAllModulesFromProject(projectID int64) error

UnlinkAllModulesFromProject removes all modules from a project

func UnlinkBlockAndModule

func UnlinkBlockAndModule(moduleID int64, blockID int64) error

UnlinkBlockAndModule unlinks a block and a module

func UnlinkModuleAndProject

func UnlinkModuleAndProject(projectID, moduleID int64) error

UnlinkModuleAndProject removes the module from a project

func UnlinkUserAndProject

func UnlinkUserAndProject(userID, projectID int64) error

UnlinkUserAndProject unlinks a user and a project

func UpdateBlock

func UpdateBlock(input *Block) error

UpdateBlock updates a block

func UpdateBlockFormQuestion

func UpdateBlockFormQuestion(input *BlockFormQuestion) error

UpdateBlockFormQuestion updates most fields in the question

func UpdateBlockFormQuestionOption

func UpdateBlockFormQuestionOption(input *BlockFormQuestionOption) error

UpdateBlockFormQuestionOption updates most fields for an option

func UpdateBlockFormSubmission

func UpdateBlockFormSubmission(input *BlockFormSubmission) error

UpdateBlockFormSubmission updates a submission's information; note that we allow changing most of the fields, but really the only fields that should change it the results field

func UpdateBlockFormSubmissionResponse

func UpdateBlockFormSubmissionResponse(input *BlockFormSubmissionResponse) error

UpdateBlockFormSubmissionResponse updates an individual response; note that we allow changing most of the fields, but really the only fields that should change are the isCorrect and text fields

func UpdateFileInDB

func UpdateFileInDB(input *File) error

UpdateFileInDB updates a file's metadata in the DB

func UpdateFileVisibilityFromAdminOnly

func UpdateFileVisibilityFromAdminOnly(fileID int64, visibility string) error

UpdateFileVisibilityFromAdminOnly is a simple helper for when a block saves with a file; only the file id is set, so if the file visibility is set to admin, we need to set it to project; if it's not admin only, then we don't change it (we don't want to make it more restrictive)

func UpdateModule

func UpdateModule(input *Module) error

UpdateModule updates a single module

func UpdateNote

func UpdateNote(input *Note) error

UpdateNote updates a single note

func UpdateProject

func UpdateProject(input *Project) error

UpdateProject updates an existing project

func UpdateSite

func UpdateSite(input *Site) error

UpdateSite updates a site

func UpdateUser

func UpdateUser(input *User) error

UpdateUser updates a user

func UpdateUserAndProjectStatus

func UpdateUserAndProjectStatus(userID, projectID int64, status string) error

UpdateUserAndProjectStatus updates the project status for a user

func UploadFileToBucket

func UploadFileToBucket(key string, data []byte) error

UploadFileToBucket uploads a file to a bucket

Types

type Block

type Block struct {
	ID           int64       `json:"id" db:"id"`
	Name         string      `json:"name" db:"name"`
	Summary      string      `json:"summary" db:"summary"`
	BlockType    string      `json:"blockType" db:"blockType"`
	Content      interface{} `json:"content,omitempty"`
	FoundInFlows int64       `json:"foundInFlows" db:"foundInFlows"`
	AllowReset   string      `json:"allowReset" db:"allowReset"`

	UserStatus    string `json:"userStatus,omitempty" db:"userStatus"`
	LastUpdatedOn string `json:"lastUpdatedOn,omitempty" db:"lastUpdatedOn"`
	ProjectID     int64  `json:"projectId,omitempty" db:"projectId"`
	ProjectName   string `json:"projectName,omitempty" db:"projectName"`
	ModuleID      int64  `json:"moduleId,omitempty" db:"moduleId"`
	ModuleName    string `json:"moduleName,omitempty" db:"moduleName"`
}

Block is a block of content, which has the details filled out in linked tables

func GetBlockByID

func GetBlockByID(blockID int64) (*Block, error)

GetBlockByID gets a single block by id

func GetBlocksForModule

func GetBlocksForModule(moduleID int64) ([]Block, error)

GetBlocksForModule gets all of the blocks for a module

func GetBlocksForSite

func GetBlocksForSite() ([]Block, error)

GetBlocksForSite gets the blocks for the site, usually used in admin views for linking and setting up flows

func GetModuleBlockForParticipant

func GetModuleBlockForParticipant(participantID, projectID, moduleID, blockID int64) (*Block, error)

GetModuleBlockForParticipant gets a single block for a participant; we take in all three levels to ensure that the permissions are correct

func (*Block) Bind

func (data *Block) Bind(r *http.Request) error

Bind binds the data for the HTTP

type BlockEmbed

type BlockEmbed struct {
	BlockID   int64  `json:"blockId" db:"blockId"`
	EmbedLink string `json:"embedLink" db:"embedLink"`
	EmbedType string `json:"embedType" db:"embedType"`
	FileID    int64  `json:"fileId" db:"fileId"`
}

BlockEmbed is the `presentation` block type

func GetBlockEmbedByBlockID

func GetBlockEmbedByBlockID(blockID int64) (*BlockEmbed, error)

GetBlockEmbedByBlockID gets the block content

func GetBlockFileByBlockID

func GetBlockFileByBlockID(blockID int64) (*BlockEmbed, error)

GetBlockFileByBlockID gets the block content

type BlockExternal

type BlockExternal struct {
	BlockID      int64  `json:"blockId" db:"blockId"`
	ExternalLink string `json:"externalLink" db:"externalLink"`
}

BlockExternal is the `external` block type

func GetBlockExternalByBlockID

func GetBlockExternalByBlockID(blockID int64) (*BlockExternal, error)

GetBlockExternalByBlockID gets the block content

type BlockFile

type BlockFile struct {
	BlockID int64 `json:"blockId" db:"blockId"`
	FileID  int64 `json:"fileId" db:"fileId"`
}

BlockFile is the `file` block type

type BlockForm

type BlockForm struct {
	BlockID       int64               `json:"blockId" db:"blockId"`
	FormType      string              `json:"formType" db:"formType"`
	AllowResubmit string              `json:"allowResubmit" db:"allowResubmit"`
	Questions     []BlockFormQuestion `json:"questions"`
}

BlockForm is a form block, such as a survey or quiz for a check on learning

func GetBlockFormByBlockID

func GetBlockFormByBlockID(blockID int64) (*BlockForm, error)

GetBlockFormByBlockID gets the form metadata but not the rest of the data

type BlockFormQestionResponseInput

type BlockFormQestionResponseInput struct {
	Responses []BlockFormSubmissionResponse `json:"responses"`
}

BlockFormQestionResponseInput is a helper input for sending many responses at once to the API

func (*BlockFormQestionResponseInput) Bind

Bind binds the data for the HTTP

type BlockFormQuestion

type BlockFormQuestion struct {
	ID           int64  `json:"id" db:"id"`
	BlockID      int64  `json:"blockId" db:"blockId"`
	QuestionType string `json:"questionType" db:"questionType"`
	Question     string `json:"question" db:"question"`
	FormOrder    int64  `json:"formOrder" db:"formOrder"`

	// needed for the return
	Options []BlockFormQuestionOption `json:"options"`
}

BlockFormQuestion is a question in a form

func GetBlockFormQuestionsForBlockID

func GetBlockFormQuestionsForBlockID(blockID int64) ([]BlockFormQuestion, error)

GetBlockFormQuestionsForBlockID gets the questions and options for a block

type BlockFormQuestionOption

type BlockFormQuestionOption struct {
	ID              int64  `json:"id" db:"id"`
	QuestionID      int64  `json:"questionId" db:"questionId"`
	OptionText      string `json:"optionText" db:"optionText"`
	OptionOrder     int64  `json:"optionOrder" db:"optionOrder"`
	OptionIsCorrect string `json:"optionIsCorrect" db:"optionIsCorrect"`
}

BlockFormQuestionOption are the options for a single or multiple choice question

func GetBlockFormQuestionOptionForQuestion

func GetBlockFormQuestionOptionForQuestion(questionID int64) ([]BlockFormQuestionOption, error)

GetBlockFormQuestionOptionForQuestion gets the options for a question

type BlockFormSubmission

type BlockFormSubmission struct {
	ID          int64  `json:"id" db:"id"`
	BlockID     int64  `json:"blockId" db:"blockId"`
	UserID      int64  `json:"userId" db:"userId"`
	SubmittedOn string `json:"submittedOn" db:"submittedOn"`
	Results     string `json:"results" db:"results"`
	// needed for the return
	Responses []BlockFormSubmissionResponse `json:"responses"`
}

BlockFormSubmission is a completed submission which will like in responses

func GetBlockFormSubmissionByID

func GetBlockFormSubmissionByID(id int64) (*BlockFormSubmission, error)

GetBlockFormSubmissionByID gets a specific response

func GetBlockFormSubmissionsForBlock

func GetBlockFormSubmissionsForBlock(blockID int64) ([]BlockFormSubmission, error)

GetBlockFormSubmissionsForBlock gets all submissions for a block

func GetBlockFormSubmissionsForUser

func GetBlockFormSubmissionsForUser(userID, blockID int64) ([]BlockFormSubmission, error)

GetBlockFormSubmissionByID gets submissions for a user

type BlockFormSubmissionResponse

type BlockFormSubmissionResponse struct {
	ID           int64  `json:"id" db:"id"`
	SubmissionID int64  `json:"submissionId" db:"submissionId"`
	QuestionID   int64  `json:"questionId" db:"questionId"`
	OptionID     int64  `json:"optionId" db:"optionId"`
	TextResponse string `json:"textResponse" db:"textResponse"`
	IsCorrect    string `json:"isCorrect" db:"isCorrect"`
	QuestionText string `json:"questionText" db:"questionText"`
	QuestionType string `json:"questionType" db:"questionType"`
}

BlockFormSubmissionResponse is a user's response to a question in a form; it can be either an option (single/multi) or text (optionId is 0 and question type is short/long)

func GetBlockFormSubmissionResponsesForBlock

func GetBlockFormSubmissionResponsesForBlock(blockID int64) ([]BlockFormSubmissionResponse, error)

GetBlockFormSubmissionResponsesForBlock gets all submissions for a block without being tied to a user

func GetBlockFormSubmissionResponsesForSubmission

func GetBlockFormSubmissionResponsesForSubmission(submissionID int64) ([]BlockFormSubmissionResponse, error)

GetBlockFormSubmissionResponsesForSubmission gets all of the responses for a submission

type BlockText

type BlockText struct {
	BlockID int64  `json:"blockId" db:"blockId"`
	Text    string `json:"text" db:"text"`
}

BlockText is the `text` block type

func GetBlockTextByBlockID

func GetBlockTextByBlockID(blockID int64) (*BlockText, error)

GetBlockTextByBlockID gets the block content

type BlockUserStatus

type BlockUserStatus struct {
	UserID        int64  `json:"userId" db:"userId"`
	ProjectID     int64  `json:"projectId" db:"projectId"`
	ModuleID      int64  `json:"moduleId" db:"moduleId"`
	BlockID       int64  `json:"blockId" db:"blockId"`
	UserStatus    string `json:"userStatus" db:"userStatus"`
	LastUpdatedOn string `json:"lastUpdatedOn" db:"lastUpdatedOn"`

	// these are needed for the save
	ProjectUserStatus      string `json:"projectUserStatus,omitempty" db:"projectUserStatus"`
	ProjectCompleteMessage string `json:"projectCompleteMessage,omitempty" db:"projectCompleteMessage"`
}

BlockUserStatus represents a specific block/status entry

func (*BlockUserStatus) Bind

func (data *BlockUserStatus) Bind(r *http.Request) error

Bind binds the data for the HTTP

type ConsentForm

type ConsentForm struct {
	ProjectID                     int64  `json:"projectId" db:"projectId"`
	ContentInMarkdown             string `json:"contentInMarkdown" db:"contentInMarkdown"`
	ContactInformationDisplay     string `json:"contactInformationDisplay" db:"contactInformationDisplay"`
	InstitutionInformationDisplay string `json:"institutionInformationDisplay" db:"institutionInformationDisplay"`

	OverrideSaveIfParticipants bool `json:"overrideSaveIfParticipants,omitempty"` // used to allow updating a consent form after the project started
}

ConsentForm is the consent form for a project

func GetConsentFormForProject

func GetConsentFormForProject(projectID int64) (*ConsentForm, error)

GetConsentFormForProject gets the project's consent form

func (*ConsentForm) Bind

func (data *ConsentForm) Bind(r *http.Request) error

Bind binds the data for the HTTP

type ConsentResponse

type ConsentResponse struct {
	ID                                    int64  `json:"id" db:"id"`
	ProjectID                             int64  `json:"projectId" db:"projectId"`
	SubmittedOn                           string `json:"submittedOn" db:"submittedOn"`
	ConsentStatus                         string `json:"consentStatus" db:"consentStatus"`
	ParticipantComments                   string `json:"participantComments" db:"participantComments"`
	ResearcherComments                    string `json:"researcherComments" db:"researcherComments"`
	ParticipantProvidedFirstName          string `json:"participantProvidedFirstName" db:"participantProvidedFirstName"`
	ParticipantProvidedLastName           string `json:"participantProvidedLastName" db:"participantProvidedLastName"`
	ParticipantProvidedContactInformation string `json:"participantProvidedContactInformation" db:"participantProvidedContactInformation"`
	ParticipantID                         int64  `json:"participantId" db:"participantId"` // will be 0 if the project specifies to not link them

	ProjectCode string `json:"projectCode,omitempty"` // used for signup when the project needs a code

	// these are used when the project must be anonymous, so a new account is created during consent
	// and tied to a participant code
	User *User `json:"user"`
}

ConsentResponse is the response to a consent form

func GetConsentResponseByID

func GetConsentResponseByID(responseID int64) (*ConsentResponse, error)

GetConsentResponseByID gets a single response

func GetConsentResponsesForProject

func GetConsentResponsesForProject(projectID int64) ([]ConsentResponse, error)

GetConsentResponsesForProject gets all of the responses for a project

func (*ConsentResponse) Bind

func (data *ConsentResponse) Bind(r *http.Request) error

Bind binds the data for the HTTP

type CountReturn

type CountReturn struct {
	Count int64 `json:"count" db:"count"`
}

CountReturn is a helpers for DB calls that just need a count

type File

type File struct {
	ID             int64  `json:"id" db:"id"`
	RemoteKey      string `json:"remoteKey" db:"remoteKey"`
	Display        string `json:"display" db:"display"`
	Description    string `json:"description" db:"description"`
	FileType       string `json:"fileType" db:"fileType"`
	UploadedOn     string `json:"uploadedOn" db:"uploadedOn"`
	UploadedBy     int64  `json:"uploadedBy" db:"uploadedBy"`
	Visibility     string `json:"visibility" db:"visibility"`
	FileSize       int64  `json:"fileSize" db:"fileSize"`
	LocationSource string `json:"locationSource" db:"locationSource"`
}

File is a DB entry for a file that is hosted somewhere

func GetFileFromDB

func GetFileFromDB(id int64) (*File, error)

GetFileFromDB gets a file's metadata from the DB

func GetFilesFromDB

func GetFilesFromDB(sortBy, sortDir string, count, offset int64) ([]File, error)

GetFilesFromDB gets a list of files from the DB; since this can be pretty large, we add sort and offset

func (*File) Bind

func (data *File) Bind(r *http.Request) error

Bind binds the data for the HTTP

type Flow

type Flow struct {
	UserID            int64  `json:"userId" db:"userId"`
	ProjectID         int64  `json:"projectId" db:"projectId"`
	FlowOrder         int64  `json:"flowOrder" db:"flowOrder"`
	ModuleID          int64  `json:"moduleId" db:"moduleId"`
	ModuleName        string `json:"moduleName" db:"moduleName"`
	ModuleDescription string `json:"moduleDescription" db:"moduleDescription"`
	BlockID           int64  `json:"blockId" db:"blockId"`
	BlockName         string `json:"blockName" db:"blockName"`
	BlockSummary      string `json:"blockSummary" db:"blockSummary"`
	BlockType         string `json:"blockType" db:"blockType"`
	UserStatus        string `json:"userStatus" db:"userStatus"`
	LastUpdatedOn     string `json:"lastUpdatedOn" db:"lastUpdatedOn"`
}

Flow represents the flow of a project from a participant's viewpoint; keep in mind this is not a direct translation of the Flows table; it needs to support the joins that come from the Flows, Links, and Status tables

func GetProjectFlowForParticipant

func GetProjectFlowForParticipant(participantID, projectID int64) ([]Flow, error)

GetProjectFlowForParticipant gets the entire flow for a project for a participant to lay out the flow and status for each section. Note the explicit lack of a module or project status; that can be calculated based upon this data.

func (*Flow) Bind

func (data *Flow) Bind(r *http.Request) error

Bind binds the data for the HTTP

type LogOptions

type LogOptions struct {
	ExtraData map[string]interface{}

	// the two can be helpful when things are tough to debug, but shouldn't be required
	CallingFile string
	CallingFunc string
}

LogOptions are optional options and fields for logging

type Module

type Module struct {
	ID            int64  `json:"id" db:"id"`
	Name          string `json:"name" db:"name"`
	Status        string `json:"status" db:"status"`
	Description   string `json:"description" db:"description"`
	FlowOrder     int64  `json:"flowOrder" db:"flowOrder"`         // used in getting for a project
	ProjectsCount int64  `json:"projectsCount" db:"projectsCount"` // used in getting for platform to identify if it's in a project
}

Module is a module that contains Blocks and are organized into Flows for a Project

func GetAllModulesForSite

func GetAllModulesForSite() ([]Module, error)

GetAllModulesForSite gets all the modules on the site, needed for the building of the flows interface

func GetModuleByID

func GetModuleByID(moduleID int64) (*Module, error)

GetModuleByID gets a single module

func GetModulesForProject

func GetModulesForProject(projectID int64) ([]Module, error)

GetModulesForProject gets all of the modules for a project

func (*Module) Bind

func (data *Module) Bind(r *http.Request) error

Bind binds the data for the HTTP

type Note

type Note struct {
	ID         int64  `json:"id" db:"id"`
	UserID     int64  `json:"userId" db:"userId"`
	CreatedOn  string `json:"createdOn" db:"createdOn"`
	NoteType   string `json:"noteType" db:"noteType"`
	ProjectID  int64  `json:"projectId" db:"projectId"`
	ModuleID   int64  `json:"moduleId" db:"moduleId"`
	BlockID    int64  `json:"blockId" db:"blockId"`
	Visibility string `json:"visibility" db:"visibility"`
	Title      string `json:"title" db:"title"`
	Body       string `json:"body" db:"body"`

	// needed for the gets
	ProjectName string `json:"projectName" db:"projectName"`
	ModuleName  string `json:"moduleName" db:"moduleName"`
	BlockName   string `json:"blockName" db:"blockName"`
}

Note represents a note that a user can enter into the system, often as a part of a training or project

func GetAllNotesForUser

func GetAllNotesForUser(userID int64, noteType string, filter *NoteSelectOptions) ([]Note, error)

GetAllNotesForUser gets non-project notes for a user

func GetNote

func GetNote(noteID int64) (*Note, error)

GetNote gets a single note by its id

func (*Note) Bind

func (data *Note) Bind(r *http.Request) error

Bind binds the data for the HTTP

type NoteSelectOptions

type NoteSelectOptions struct {
	NoteType  string `json:"noteType"`
	ProjectID int64  `json:"projectId"`
	ModuleID  int64  `json:"moduleId"`
	BlockID   int64  `json:"blockId"`
}

NoteSelectOptions is a helper to store all the possible combinations of values in a selector rather than building a whole bunch of strings or funcs

type Project

type Project struct {
	ID                              int64  `json:"id" db:"id"`
	SiteID                          int64  `json:"siteId" db:"siteId"`
	Name                            string `json:"name" db:"name"`
	ShortCode                       string `json:"shortCode" db:"shortCode"`
	ShortDescription                string `json:"shortDescription" db:"shortDescription"`
	Description                     string `json:"description" db:"description"`
	Status                          string `json:"status" db:"status"`
	ShowStatus                      string `json:"showStatus" db:"showStatus"`
	SignupStatus                    string `json:"signupStatus" db:"signupStatus"`
	MaxParticipants                 int64  `json:"maxParticipants" db:"maxParticipants"`
	ParticipantVisibility           string `json:"participantVisibility" db:"participantVisibility"`
	ParticipantMinimumAge           int64  `json:"participantMinimumAge" db:"participantMinimumAge"`
	ConnectParticipantToConsentForm string `json:"connectParticipantToConsentForm" db:"connectParticipantToConsentForm"`
	ParticipantCount                int64  `json:"participantCount" db:"participantCount"`
	CompleteMessage                 string `json:"completeMessage" db:"completeMessage"`
	FlowRule                        string `json:"flowRule" db:"flowRule"`
	CompleteRule                    string `json:"completeRule" db:"completeRule"`
	StartRule                       string `json:"startRule" db:"startRule"`
	StartDate                       string `json:"startDate" db:"startDate"`
	EndDate                         string `json:"endDate" db:"endDate"`

	// needed for the participant and admin views
	ParticipantID     int64  `json:"participantId,omitempty" db:"participantId"`
	ParticipantStatus string `json:"participantStatus,omitempty" db:"participantStatus"`
}

Project is a major research project, which will have flows associated with it. Participants work through the project flows. Projects can be viewed as meta-info about the activities conducted in the project. The shortCode is used with the `SignupStatus` field and should NOT be returned in GETs for non-admins

func GetProjectByID

func GetProjectByID(projectID int64) (*Project, error)

GetProjectByID gets a single project by its id

func GetProjectForParticipantByID

func GetProjectForParticipantByID(participantID, projectID int64) (*Project, error)

GetProjectForParticipantByID gets a project along with the user's project status

func GetProjectsForParticipant

func GetProjectsForParticipant(participantID int64) ([]Project, error)

GetProjectsForParticipant gets the lis of projects for a participant

func GetProjectsForSite

func GetProjectsForSite(siteID int64, status string) ([]Project, error)

GetProjectsForSite gets all of the projects for a site, optionally filtered by status

func (*Project) Bind

func (data *Project) Bind(r *http.Request) error

Bind binds the data for the HTTP

type ProjectAPIReturnNonAdmin

type ProjectAPIReturnNonAdmin struct {
	ID                    int64  `json:"id" db:"id"`
	Name                  string `json:"name" db:"name"`
	ShortDescription      string `json:"shortDescription" db:"shortDescription"`
	Description           string `json:"description" db:"description"`
	Status                string `json:"status" db:"status"`
	SignupStatus          string `json:"signupStatus" db:"signupStatus"`
	ParticipantMinimumAge int64  `json:"participantMinimumAge" db:"participantMinimumAge"`
	ParticipantVisibility string `json:"participantVisibility" db:"participantVisibility"`
	ParticipantStatus     string `json:"participantStatus,omitempty" db:"participantStatus"`
}

ProjectAPIReturnNonAdmin is a much-reduced project return struct for non-admins

type ProjectUserLinkRequest

type ProjectUserLinkRequest struct {
	Code string `json:"code"`
}

ProjectUserLinkRequest holds extra request options for joining a project, such as if a code is needed

func (*ProjectUserLinkRequest) Bind

func (data *ProjectUserLinkRequest) Bind(r *http.Request) error

Bind binds the data for the HTTP

type ReportBlockStatusCount

type ReportBlockStatusCount struct {
	ModuleID        int64  `json:"moduleId" db:"moduleId"`
	ModuleName      string `json:"moduleName" db:"moduleName"`
	BlockID         int64  `json:"blockId" db:"blockId"`
	BlockName       string `json:"blockName" db:"blockName"`
	CompletedCount  int64  `json:"completedCount" db:"completedCount"`
	NotStartedCount int64  `json:"notStartedCount" db:"notStartedCount"`
	StartedCount    int64  `json:"startedCount" db:"startedCount"`
}

ReportBlockStatusCount is a report on a user's status in a block

func ReportGetCountOfStatusForProject

func ReportGetCountOfStatusForProject(projectID int64) ([]ReportBlockStatusCount, error)

ReportGetCountOfStatusForProject gets the status of the users grouped for a project

type ReportSubmissionCount

type ReportSubmissionCount struct {
	ModuleID   int64  `json:"moduleId" db:"moduleId"`
	ModuleName string `json:"moduleName" db:"moduleName"`
	BlockID    int64  `json:"blockId" db:"blockId"`
	BlockName  string `json:"blockName" db:"blockName"`
	BlockType  string `json:"blockType" db:"blockType"`
	Count      int64  `json:"count" db:"count"`
}

ReportSubmissionCount is the count of number of submissions

func ReportGetSubmissionCountForProject

func ReportGetSubmissionCountForProject(projectID int64) ([]ReportSubmissionCount, error)

ReportGetSubmissionCountForProject gets the count of submissions for a project

type ReportSubmissionResponses

type ReportSubmissionResponses struct {
	BlockID         int64                               `json:"blockId" db:"blockId"`
	BlockName       string                              `json:"blockName" db:"blockName"`
	SubmissionCount int64                               `json:"submissionCount" db:"submissionCount"`
	Questions       []ReportSubmissionResponsesQuestion `json:"questions" db:"questions"`
}

ReportSubmissionResponses is the responses

type ReportSubmissionResponsesQuestion

type ReportSubmissionResponsesQuestion struct {
	QuestionID   int64                               `json:"questionId" db:"questionId"`
	QuestionText string                              `json:"questionText" db:"questionText"`
	QuestionType string                              `json:"questionType" db:"questionType"`
	Responses    []ReportSubmissionResponsesResponse `json:"responses" db:"responses"`
}

ReportSubmissionResponsesQuestion is a question in the response report

type ReportSubmissionResponsesResponse

type ReportSubmissionResponsesResponse struct {
	OptionID     int64  `json:"optionId" db:"optionId"`
	TextResponse string `json:"textResponse" db:"textResponse"`
	Count        int64  `json:"count" db:"count"`
}

ReportSubmissionResponsesResponse is a response to a question in the report

type ReportUserLastUpdatedAgo

type ReportUserLastUpdatedAgo struct {
	DaysAgo int64 `json:"daysAgo" db:"daysAgo"`
	UserID  int64 `json:"userId" db:"userId"`
}

ReportUserLastUpdatedAgo holds the days ago versus the user

func ReportGetCountOfLastUpdatedForProject

func ReportGetCountOfLastUpdatedForProject(projectID int64) ([]ReportUserLastUpdatedAgo, error)

ReportGetCountOfLastUpdatedForProject gets the report of users in a project by their last updated status

type ReportValueCount

type ReportValueCount struct {
	Value string `json:"value" db:"value"`
	Count int64  `json:"count" db:"count"`
}

ReportValueCount is a generic report count holder

func ReportGetCountOfUsersOnProjectByStatus

func ReportGetCountOfUsersOnProjectByStatus(projectID int64) ([]ReportValueCount, error)

ReportGetCountOfUsersOnProjectByStatus gets the users on a project by their status

type Site

type Site struct {
	ID                   int64  `json:"id" db:"id"` // in the current set up, there should only be one site
	CreatedOn            string `json:"createdOn" db:"createdOn"`
	ShortName            string `json:"shortName" db:"shortName"`
	Name                 string `json:"name" db:"name"`
	Description          string `json:"description" db:"description"`
	Domain               string `json:"domain" db:"domain"`
	Status               string `json:"status" db:"status"`                         // pending, active, disabled
	ProjectListOptions   string `json:"projectListOptions" db:"projectListOptions"` // show_all, show_active, show_none
	SiteTechnicalContact string `json:"siteTechnicalContact" db:"siteTechnicalContact"`
}

Site is an available location or installation

func GetSite

func GetSite() (*Site, error)

GetSite gets the site from the DB

func GetSiteByID

func GetSiteByID(id int64) (*Site, error)

GetSiteByID gets the site by the id

func GetSiteFromContext

func GetSiteFromContext(ctx context.Context) (*Site, error)

GetSiteFromContext is a helper to try to get the site from the context and, if it's not there, get it from the Cache or DB

func (*Site) Bind

func (data *Site) Bind(r *http.Request) error

Bind binds the data for the HTTP

type Token

type Token struct {
	UserID    int64  `json:"userId" db:"userId"`
	TokenType string `json:"tokenType" db:"tokenType"`
	CreatedOn string `json:"createdOn" db:"createdOn"`
	ExpiresOn string `json:"expiresOn" db:"expiresOn"`
	Token     string `json:"token" db:"token"`
}

Token is a token struct that holds information about various token needs, including password reset, email verification, and refresh

type User

type User struct {
	ID              int64  `json:"id" db:"id"`
	Title           string `json:"title" db:"title"`
	FirstName       string `json:"firstName" db:"firstName"`
	LastName        string `json:"lastName" db:"lastName"`
	Pronouns        string `json:"pronouns" db:"pronouns"`
	Email           string `json:"email" db:"email"`
	Password        string `json:"password,omitempty" db:"password"`
	DateOfBirth     string `json:"dateOfBirth" db:"dateOfBirth"`
	ParticipantCode string `json:"participantCode" db:"participantCode"`
	Status          string `json:"status" db:"status"`
	SystemRole      string `json:"systemRole" db:"systemRole"`
	CreatedOn       string `json:"createdOn" db:"createdOn"`
	LastLoginOn     string `json:"lastLoginOn" db:"lastLoginOn"`
	Access          string `json:"access,omitempty"`
	Refresh         string `json:"refresh,omitempty"` // web clients should not store this in local storage and should instead use the cookies!
	Expires         string `json:"expires,omitempty"`

	// these are used for the admin reports
	ProjectCount  int64     `json:"projectCount,omitempty" db:"projectCount"`
	Projects      []Project `json:"projects,omitempty" db:"projects"`
	ProjectStatus string    `json:"projectStatus,omitempty" db:"projectStatus"`
}

User is a person with a login that has permission to "do stuff". This is for researchers, site admins, and participants

func AttemptLoginForUser

func AttemptLoginForUser(emailOrCode, password string) (*User, error)

func GetAllUsersInProject

func GetAllUsersInProject(projectID int64) ([]User, error)

GetAllUsersInProject gets all the users in a project along with their status

func GetAllUsersOnPlatform

func GetAllUsersOnPlatform() ([]User, error)

GetAllUsersOnPlatform gets all the users on the platform

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail gets a user by an email

func GetUserByID

func GetUserByID(userID int64) (*User, error)

GetUserByID gets a user by the id

func GetUserByParticipantCode

func GetUserByParticipantCode(participantCode string) (*User, error)

GetUserByParticipantCode gets a user by the participant code

func (*User) Bind

func (data *User) Bind(r *http.Request) error

Bind binds the data for the HTTP

Jump to

Keyboard shortcuts

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