Documentation ¶
Overview ¶
Package db provides functions and types relevant to the backend database for the article feed.
Package db provides functions and types relevant to the backend database for the article feed.
Package db provides functions and types relevant to the backend database for the article feed.
Package db provides functions and types relevant to the backend database for the article feed.
Index ¶
- func AppendArticle(ctx context.Context, article *Article) error
- func AppendArticleToOld(ctx context.Context, article *Article) error
- func AppendQuestion(ctx context.Context, qn Question) error
- func BackupArticles(ctx context.Context, database *ArticlesDBByDate) error
- func BackupQuestions(ctx context.Context, qnDB QuestionsDB) error
- func SendMail(from, to, replyTo, subject, msg string) error
- type Article
- func (a *Article) AddArticleToDB(db *ArticlesDBByDate, tm TopicsMap, qc QuestionCounter) error
- func (a *Article) SetDate(date string) error
- func (a *Article) SetQuestions(year, number string, qnDB QuestionsDB) error
- func (a *Article) SetQuestionsNewArticle(year, number string, qnDB QuestionsDB) (QuestionsDB, error)
- func (a *Article) SetTopics(topics ...string)
- type ArticlesDBByDate
- func NewArticlesDBByDate() *ArticlesDBByDate
- func Search(term string, database *ArticlesDBByDate) *ArticlesDBByDate
- func SearchAND(term string, database *ArticlesDBByDate) *ArticlesDBByDate
- func SearchAll(term string, database *ArticlesDBByDate) *ArticlesDBByDate
- func SearchNOT(term string, database *ArticlesDBByDate) *ArticlesDBByDate
- func SearchOR(term string, database *ArticlesDBByDate) *ArticlesDBByDate
- func (db ArticlesDBByDate) EditArticle(index string, article Article, tm TopicsMap, qc QuestionCounter) error
- func (db *ArticlesDBByDate) InitArticlesDB(ctx context.Context, qnDB QuestionsDB, tm TopicsMap, qc QuestionCounter) error
- func (db ArticlesDBByDate) Len() int
- func (db ArticlesDBByDate) Less(i, j int) bool
- func (db *ArticlesDBByDate) RemoveArticle(index int, tm TopicsMap, qc QuestionCounter)
- func (db ArticlesDBByDate) Swap(i, j int)
- type Question
- type QuestionCounter
- type QuestionObject
- type QuestionsByArticleCount
- type QuestionsDB
- type Topic
- type TopicObject
- type TopicsCount
- type TopicsMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendArticle ¶
AppendArticle appends a new article added to the web app database to a predefined, hard-coded Google Sheet.
func AppendArticleToOld ¶
AppendArticleToOld appends a new article added to the web app database to a predefined, hard-coded Google Sheet.
func AppendQuestion ¶
AppendQuestion appends a question to the initialised QuestionsDB.
func BackupArticles ¶
func BackupArticles(ctx context.Context, database *ArticlesDBByDate) error
BackupArticles backs up the articles database to a predefined, hard-coded Google Sheet.
func BackupQuestions ¶
func BackupQuestions(ctx context.Context, qnDB QuestionsDB) error
BackupQuestions backs up the questions database to a predefined, hard-coded Google Sheet.
Types ¶
type Article ¶
type Article struct { Title string URL string Topics []Topic Questions []Question DisplayDate string Date int64 }
Article is a struct representing a single entry in the articlesdb.
func NewArticle ¶
NewArticle returns an Article in order to populate fields for adding to the articles database.
func (*Article) AddArticleToDB ¶
func (a *Article) AddArticleToDB(db *ArticlesDBByDate, tm TopicsMap, qc QuestionCounter) error
AddArticleToDB takes a pointer to an article that has already had all its fields populated and adds it to the articles database, sorting by most recent published date.
func (*Article) SetDate ¶
SetDate is a wrapper around time.Parse to parse a date string to time.Time type, in order to call time.Unix() to return an int64 that makes the article sortable by date.
func (*Article) SetQuestions ¶
func (a *Article) SetQuestions(year, number string, qnDB QuestionsDB) error
SetQuestions sets the []Question for the given Article item.
func (*Article) SetQuestionsNewArticle ¶
func (a *Article) SetQuestionsNewArticle(year, number string, qnDB QuestionsDB) (QuestionsDB, error)
SetQuestionsNewArticle sets the []Question and increases the count for the question listing in the qnDB for the given Article item.
type ArticlesDBByDate ¶
type ArticlesDBByDate []Article
ArticlesDBByDate is the database of all entries in the articlesdb. Entries are sorted in reverse order of date, with the most recent at index 0.
func NewArticlesDBByDate ¶
func NewArticlesDBByDate() *ArticlesDBByDate
NewArticlesDBByDate makes a slice of Articles to initialise the articles database.
func Search ¶
func Search(term string, database *ArticlesDBByDate) *ArticlesDBByDate
Search implements a switch statement to check which kind of search to run.
func SearchAND ¶
func SearchAND(term string, database *ArticlesDBByDate) *ArticlesDBByDate
SearchAND runs an AND boolean search.
func SearchAll ¶
func SearchAll(term string, database *ArticlesDBByDate) *ArticlesDBByDate
SearchAll runs a search of the given term through all the items stored in the database.
func SearchNOT ¶
func SearchNOT(term string, database *ArticlesDBByDate) *ArticlesDBByDate
SearchNOT runs a NOT boolean search.
func SearchOR ¶
func SearchOR(term string, database *ArticlesDBByDate) *ArticlesDBByDate
SearchOR runs an OR boolean search.
func (ArticlesDBByDate) EditArticle ¶
func (db ArticlesDBByDate) EditArticle(index string, article Article, tm TopicsMap, qc QuestionCounter) error
EditArticle is a function that the admin can invoke from the live app to edit a specific article.
func (*ArticlesDBByDate) InitArticlesDB ¶
func (db *ArticlesDBByDate) InitArticlesDB(ctx context.Context, qnDB QuestionsDB, tm TopicsMap, qc QuestionCounter) error
InitArticlesDB initialises the articles database at first run. Data is downloaded from the incumbent Google Sheets and parsed into the app's data structure. This is meant to be executed only once.
func (ArticlesDBByDate) Less ¶
func (db ArticlesDBByDate) Less(i, j int) bool
func (*ArticlesDBByDate) RemoveArticle ¶
func (db *ArticlesDBByDate) RemoveArticle(index int, tm TopicsMap, qc QuestionCounter)
RemoveArticle is a function that the admin can invoke from the live app to remove any offending article.
func (ArticlesDBByDate) Swap ¶
func (db ArticlesDBByDate) Swap(i, j int)
type Question ¶
Question is a struct that represents the question object in each article entry in the ArticlesDBByDate.
type QuestionCounter ¶
QuestionCounter is an object to count number of articles per question.
func InitQuestionCounter ¶
func InitQuestionCounter() QuestionCounter
InitQuestionCounter returns an initialised QuestionCounter map.
func (QuestionCounter) Decrement ¶
func (qc QuestionCounter) Decrement(key string)
Decrement decreases the count for the question in the QuestionCounter map. Argument must be provided in the format qn.Year + " - Q" + qn.Number.
func (QuestionCounter) GetZeroArticleQns ¶
func (qc QuestionCounter) GetZeroArticleQns(qnDB QuestionsDB)
GetZeroArticleQns gets the questions that have zero articles tagged.
func (QuestionCounter) Increment ¶
func (qc QuestionCounter) Increment(key string)
Increment increases the count for the question in the QuestionCounter map. Argument must be provided in the format qn.Year + " - Q" + qn.Number.
type QuestionObject ¶
QuestionObject is an object to enable ranking of questions by number of articles tagged.
type QuestionsByArticleCount ¶
type QuestionsByArticleCount []QuestionObject
QuestionsByArticleCount is an object to rank questions by the number of articles tagged to each question.
func RankQuestionsByArticleCount ¶
func RankQuestionsByArticleCount(counter QuestionCounter) QuestionsByArticleCount
RankQuestionsByArticleCount converts a QuestionsDB into a slice of Article in order to count and rank questions by the numebr of articles tagged to each question.
func (QuestionsByArticleCount) Len ¶
func (q QuestionsByArticleCount) Len() int
Implement sort.Sort interface
func (QuestionsByArticleCount) Less ¶
func (q QuestionsByArticleCount) Less(i, j int) bool
func (QuestionsByArticleCount) Swap ¶
func (q QuestionsByArticleCount) Swap(i, j int)
type QuestionsDB ¶
QuestionsDB is a map of questions for quick searching.
func InitQuestionsDB ¶
func InitQuestionsDB(ctx context.Context) (QuestionsDB, error)
InitQuestionsDB maps a list of questions in a file named by filename and maps them to a questions database.
type TopicObject ¶
TopicObject provides an object to implement sorting by value in order to rank most and least tagged topics.
type TopicsCount ¶
type TopicsCount []TopicObject
TopicsCount provides a type to sort the TopicsMap.
func GetTopicsCount ¶
func GetTopicsCount(tm TopicsMap) TopicsCount
GetTopicsCount is a function to count topics on first initialisation of the Articles DB.
func (TopicsCount) Less ¶
func (tc TopicsCount) Less(i, j int) bool
func (TopicsCount) Swap ¶
func (tc TopicsCount) Swap(i, j int)