prjseal / Umbraco-Community-Quiz

Source code for the Community Quiz website
https://communityquiz.net
Other
8 stars 17 forks source link

Create a badging engine #14

Closed prjseal closed 1 year ago

prjseal commented 1 year ago

Currently the badges are awarded in the code on submit of a form. It would be good to create some sort of badging engine. Perhaps it can raise an event and we hook into those events, check for the badge types for that type of event and then check if the data associated with this event matches the criteria for the badge and then award the badge.

cornehoskam commented 1 year ago

That sounds like a good addition! There would be many ways to setup such a system, but a more event driven notification & notificationHandler based system with a Badge Service to process the various notifications could make it quite flexible! 🤔

prjseal commented 1 year ago

Yes definitely. We want to raise event when things happen. Then hook into those notifications to consult with the badge engine to see if a badge is required and then apply it

cornehoskam commented 1 year ago

Would you be ok with me giving a go at this when I have the time? 🙂

prjseal commented 1 year ago

Yeah sure. Go for it. Please can you split it into separate PRs though. 1 for raising notifications throughout the site. Then one that consumes those notifications and works out which badges to give if any

I'd like to manage the rules of what badges to give for what using Umbraco

cornehoskam commented 1 year ago

Sure thing! I'll start with raising notifications at the locations the application currently hands out badges, and once that one is approved, we can get working on processing those notifications to hand out badges and removing the old badging code in the process!

prjseal commented 1 year ago

Brilliant. Thank you so much for joining in with this and helping make it a reality

prjseal commented 1 year ago

@cornehoskam please can you add an event for member logged in

cornehoskam commented 1 year ago

Sure thing @prjseal, will work on that next!

prjseal commented 1 year ago

Excellent, would you mind creating events for failed registration, failed edit profile and failed submit survey and failed submit question? If you have time?

cornehoskam commented 1 year ago

Sure! By Survey, do you mean a Quiz, or is a survey a new feature you have in mind?

prjseal commented 1 year ago

Yeah I meant quiz. Don't know why I said survey 🤣

cornehoskam commented 1 year ago

There you go Paul! I also took the liberty to add a notification for Failed login too, to stay consistent and have a failed counterpart for all the current Notifications!

prjseal commented 1 year ago

Brilliant. Thank you. I'll review it later

cornehoskam commented 1 year ago

Lovely! I'll do some thinking about a potential Badging Engine setup now that we have these notifications in place! I'd love to hear if you already have some idea's in mind @prjseal, otherwise I'll let my creativity go lose haha. I'll make sure to share some ideas with you before starting on any code either way 🙂

cornehoskam commented 1 year ago

Hi @prjseal, I've created a basic design of how I thought the assigning of badges using the new notifications could work, without trying to overcomplicate things too much! The essence would be that there is a Badge implementation for each badge in Umbraco, on which the logic for the condition resides. If that condition is met, the various notificationhandlers pass said badge to the badging service to assign the badge to the corresponding users! This would fully decouple the assigning of badges from any controllers, and have NotificationHandlers do the job for us, without having the handlers store the badging logic themselves! I'd love to hear your opinion on this before writing any code 🙂

CommunityQuiz

prjseal commented 1 year ago

This is great. How does the Umbraco badge in content map to the individual badge C# implementation?

cornehoskam commented 1 year ago

We could solve that with the alias property on a c# badge, which could be the unique alias of the Umbraco item as a constant/static! We could even reference the ModelsBuilder model from there if we want, but I think using the alias would make it a bit more generic and easier to work with.

prjseal commented 1 year ago

Yeah I like that idea. This way we can create as many badges as we want in the content and then when it comes to implementing the logic we can just look for the alias

cornehoskam commented 1 year ago

Because the logic of the badge can be very context dependend, and we only provide the necessary context through the notification itself (and we don't want make the IBadge implementation dependend on the notification), I opted to keep the logic for the badge condition in the notificationhandler for said specific badge to be the most logical place

prjseal commented 1 year ago

This is now live and is very exciting. Thank you so much. Fixed in #48