Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions asker-analytics/backend/src/commands/post-question.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Command } from '@boostercloud/framework-core'
import { Register, UUID } from '@boostercloud/framework-types'
import { QuestionCreated } from '../events/question-created';

@Command({
authorize: 'all' // Specify authorized roles here. Use 'all' to authorize anyone
})
export class PostQuestion {
public constructor(
readonly conferenceId: UUID,
readonly text: string,
) {}

public static async handle(command: PostQuestion , register: Register): Promise<void> {
register.events(new QuestionCreated(command.text, UUID.generate(), command.conferenceId))
}
}
21 changes: 21 additions & 0 deletions asker-analytics/backend/src/entities/word.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Entity, Reduces } from '@boostercloud/framework-core'
import { UUID } from '@boostercloud/framework-types'
import { WordPicked } from '../events/word-picked'

@Entity
export class Word {
public constructor(
public id: UUID,
readonly name: string,
readonly questionId: UUID,
readonly conferenceId: UUID,
readonly type: string,
) {}

@Reduces(WordPicked)
public static reduceWordPicked(event: WordPicked, currentWord?: Word): Word {
const type: string = 'TODO'
return new Word(event.id, event.name, event.questionId, event.conferenceId, type)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { QuestionCreated } from '../events/question-created'
import { WordPicked } from '../events/word-picked'
import { EventHandler } from '@boostercloud/framework-core'
import { Register, UUID } from '@boostercloud/framework-types'

@EventHandler(QuestionCreated)
export class SplitQuestionsIntoWords {
public static async handle(event: QuestionCreated, register: Register): Promise<void> {
const words = event.text.split(' ')
for (const word in words) {
register.events(new WordPicked(word, UUID.generate(), event.id, event.conferenceId))
}
}
}
15 changes: 15 additions & 0 deletions asker-analytics/backend/src/events/question-created.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Event } from '@boostercloud/framework-core'
import { UUID } from '@boostercloud/framework-types'

@Event
export class QuestionCreated {
public constructor(
readonly text: string,
readonly id: UUID,
readonly conferenceId: UUID,
) {}

public entityID(): UUID {
return this.id
}
}
16 changes: 16 additions & 0 deletions asker-analytics/backend/src/events/word-picked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Event } from '@boostercloud/framework-core'
import { UUID } from '@boostercloud/framework-types'

@Event
export class WordPicked {
public constructor(
readonly name: string,
readonly id: UUID,
readonly questionId: UUID,
readonly conferenceId: UUID,
) {}

public entityID(): UUID {
return this.id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ReadModel, Projects } from '@boostercloud/framework-core'
import { UUID, ProjectionResult } from '@boostercloud/framework-types'
import { Word } from '../entities/word'

@ReadModel({
authorize: 'all' // Specify authorized roles here. Use 'all' to authorize anyone
})
export class ConferenceStatisticsReadModel {
public constructor(
public id: UUID,
readonly verbs: number,
readonly noums: number,
readonly adjectives: number,
readonly interjections: number,
readonly pronouns: number,
readonly conjuctionPrepositions: number,
readonly spokenContractions: number,
) {}

@Projects(Word, "conferenceId")
public static projectWord(entity: Word, currentConferenceStatisticsReadModel?: ConferenceStatisticsReadModel): ProjectionResult<ConferenceStatisticsReadModel> {
if (!currentConferenceStatisticsReadModel) {
currentConferenceStatisticsReadModel = new ConferenceStatisticsReadModel(entity.conferenceId,0,0,0,0,0,0,0)
}
let verbs = currentConferenceStatisticsReadModel.verbs
let noums = currentConferenceStatisticsReadModel.noums
let adjectives = currentConferenceStatisticsReadModel.adjectives
let interjections = currentConferenceStatisticsReadModel.interjections
let pronouns = currentConferenceStatisticsReadModel.pronouns
let conjuctionPrepositions = currentConferenceStatisticsReadModel.conjuctionPrepositions
let spokenContractions = currentConferenceStatisticsReadModel.spokenContractions
if (entity.type === 'TODO') {
verbs += 1
}
return new ConferenceStatisticsReadModel(
entity.conferenceId,
verbs,
noums,
adjectives,
interjections,
pronouns,
conjuctionPrepositions,
spokenContractions
)
}

}