-
Notifications
You must be signed in to change notification settings - Fork 3
feat: event support #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: event support #380
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2755892
#373: first draft with in-memory implementation and tests
petermasking d12a189
#373: added event broker as resource
petermasking 7cbcd10
#373: implemented post count related events
petermasking 351eef3
#373: second draft (pub/sub)
petermasking 7ba49dd
#373: implemented first notifications events (and refactored the rest)
petermasking 05336c5
#373: added remaining events
petermasking e32edd5
#373 removed obsolete test cases
petermasking c2e0686
#373: removed kafka references
petermasking 691cc25
Merge branch 'main' into 373-event-support
petermasking 2d12e0d
#373: merged reactions into posts
petermasking 213b8dc
#373: refactored rating system
petermasking f161ba3
#373: made publications a part of the SAGAs
petermasking 47b809c
#373: split off metrics
petermasking 906eaae
#373: refactored tests
petermasking 791eaa1
#373: renamed post getAll feature (it doesn't get all)
petermasking 81b3728
#373: refactored post metrics
petermasking e7fcd60
#373: refactored creator metrics
petermasking e36b32e
#373: fixed Firefox compatibility issue
petermasking f2f6dbe
#373: fixed subscription issues
petermasking a4d4e9b
#373: added back row to post details
petermasking b02e345
#373: cleanups
petermasking 231716a
#373: increased body limit for services behind the proxy
petermasking cdc5a33
#373: solved sonar issues
petermasking 0a1a010
#373: processed feedback
petermasking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| import createData from './createData'; | ||
| import insertData from './insertData'; | ||
|
|
||
| export default async function create(creatorId: string): Promise<string> | ||
| { | ||
| const data = createData(creatorId); | ||
|
|
||
| return insertData(data); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
|
|
||
| import { generateId } from '^/integrations/utilities/crypto'; | ||
|
|
||
| import type { DataModel } from '../types'; | ||
|
|
||
| export default function createData(creatorId: string): DataModel | ||
| { | ||
| return { | ||
| id: generateId(), | ||
| creatorId, | ||
| posts: 0, | ||
| followers: 0, | ||
| following: 0, | ||
| popularity: 0 | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { default } from './create'; | ||
|
|
||
| export { default as subscriptions } from './subscriptions'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
|
|
||
| import { subscribe as subscribeToCreatorRegistered } from '^/domain/creator/register'; | ||
|
|
||
| import create from './create'; | ||
|
|
||
| async function subscribe(): Promise<void> | ||
| { | ||
| await Promise.all([ | ||
| subscribeToCreatorRegistered(({ creatorId }) => create(creatorId)), | ||
| ]); | ||
| } | ||
|
|
||
| export default subscribe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
|
|
||
| export const RECORD_TYPE = 'creator.metrics'; | ||
| export const EVENT_CHANNEL = 'creator.metrics'; |
10 changes: 10 additions & 0 deletions
10
src/domain/creator.metrics/getByCreator/CreatorMetricsNotFound.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| import { NotFound } from '^/integrations/runtime'; | ||
|
|
||
| export default class CreatorMetricsNotFound extends NotFound | ||
| { | ||
| constructor() | ||
| { | ||
| super('Creator metrics not found'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
|
|
||
| import database from '^/integrations/database'; | ||
|
|
||
| import { RECORD_TYPE } from '../definitions'; | ||
| import type { DataModel } from '../types'; | ||
|
|
||
| import CreatorMetricsNotFound from './CreatorMetricsNotFound'; | ||
|
|
||
| export default async function getByCreator(creatorId: string): Promise<DataModel> | ||
| { | ||
| const query = { creatorId: { EQUALS: creatorId } }; | ||
|
|
||
| const data = database.findRecord(RECORD_TYPE, query) as Promise<DataModel>; | ||
|
|
||
| if (data === undefined) | ||
| { | ||
| throw new CreatorMetricsNotFound(); | ||
| } | ||
|
|
||
| return data; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { default } from './getByCreator'; | ||
|
|
||
| export { default as CreatorMetricsNotFound } from './CreatorMetricsNotFound'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
|
|
||
| import { BaseDataModel, CountOperation } from '../types'; | ||
|
|
||
| type DataModel = BaseDataModel & | ||
| { | ||
| readonly creatorId: string; | ||
| readonly posts: number; | ||
| readonly followers: number; | ||
| readonly following: number; | ||
| readonly popularity: number; | ||
| }; | ||
|
|
||
| export type { CountOperation, DataModel }; |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { default } from './updateFollowers'; | ||
|
|
||
| export { default as subscriptions } from './subscriptions'; |
13 changes: 13 additions & 0 deletions
13
src/domain/creator.metrics/updateFollowers/subscriptions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
|
|
||
| import { subscribe as subscribeToRelationEstablished } from '^/domain/relation/establish'; | ||
|
|
||
| import updateFollowerCount from './updateFollowers'; | ||
|
|
||
| async function subscribe(): Promise<void> | ||
| { | ||
| await Promise.all([ | ||
| subscribeToRelationEstablished(({ followingId }) => updateFollowerCount(followingId, 'increase')) | ||
| ]); | ||
| } | ||
|
|
||
| export default subscribe(); |
18 changes: 18 additions & 0 deletions
18
src/domain/creator.metrics/updateFollowers/updateFollowers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
|
|
||
| import getByCreator from '../getByCreator'; | ||
| import update from '../update'; | ||
|
|
||
| import type { CountOperation } from '../types'; | ||
|
|
||
| export default async function updateFollowers(creatorId: string, operation: CountOperation): Promise<number> | ||
| { | ||
| const data = await getByCreator(creatorId); | ||
|
|
||
| const followers = operation === 'increase' | ||
| ? data.followers + 1 | ||
| : data.followers - 1; | ||
|
|
||
| await update(data.id, { followers }); | ||
|
|
||
| return followers; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { default } from './updateFollowing'; | ||
|
|
||
| export { default as subscriptions } from './subscriptions'; |
13 changes: 13 additions & 0 deletions
13
src/domain/creator.metrics/updateFollowing/subscriptions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
|
|
||
| import { subscribe as subscribeToRelationEstablished } from '^/domain/relation/establish'; | ||
|
|
||
| import updateFollowing from './updateFollowing'; | ||
|
|
||
| async function subscribe(): Promise<void> | ||
| { | ||
| await Promise.all([ | ||
| subscribeToRelationEstablished(({ followerId }) => updateFollowing(followerId, 'increase')) | ||
| ]); | ||
| } | ||
|
|
||
| export default subscribe(); |
18 changes: 18 additions & 0 deletions
18
src/domain/creator.metrics/updateFollowing/updateFollowing.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
|
|
||
| import getByCreator from '../getByCreator'; | ||
| import update from '../update'; | ||
|
|
||
| import type { CountOperation } from '../types'; | ||
|
|
||
| export default async function updateFollowing(creatorId: string, operation: CountOperation): Promise<number> | ||
| { | ||
| const data = await getByCreator(creatorId); | ||
|
|
||
| const following = operation === 'increase' | ||
| ? data.following + 1 | ||
| : data.following - 1; | ||
|
|
||
| await update(data.id, { following }); | ||
|
|
||
| return following; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| export { default } from './updatePosts'; | ||
|
|
||
| export { default as subscriptions } from './subscriptions'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| import { subscribe as subscribeToPostCreated } from '^/domain/post/create'; | ||
| import { subscribe as subscribeToPostRemoved } from '^/domain/post/remove'; | ||
|
|
||
| import updatePosts from './updatePosts'; | ||
|
|
||
| async function subscribe(): Promise<void> | ||
| { | ||
| await Promise.all([ | ||
|
|
||
| subscribeToPostCreated(({ creatorId, parentId }) => | ||
| { | ||
| if (parentId !== undefined) return; | ||
|
|
||
| return updatePosts(creatorId, 'increase'); | ||
| }), | ||
|
|
||
| subscribeToPostRemoved(({ creatorId, parentId }) => | ||
| { | ||
| if (parentId !== undefined) return; | ||
|
|
||
| return updatePosts(creatorId, 'decrease'); | ||
| }) | ||
|
|
||
| ]); | ||
| } | ||
|
|
||
| export default subscribe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
|
|
||
| import getByCreator from '../getByCreator'; | ||
| import update from '../update'; | ||
|
|
||
| import type { CountOperation } from '../types'; | ||
|
|
||
| export default async function updatePosts(creatorId: string, operation: CountOperation): Promise<number> | ||
| { | ||
| const data = await getByCreator(creatorId); | ||
|
|
||
| const posts = operation === 'increase' | ||
| ? data.posts + 1 | ||
| : data.posts - 1; | ||
|
|
||
| await update(data.id, { posts }); | ||
|
|
||
| return posts; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should await the promise to be able to check the data itself