File tree Expand file tree Collapse file tree 12 files changed +217
-29
lines changed
server/src/Services/Quizer/Quiz.Domain Expand file tree Collapse file tree 12 files changed +217
-29
lines changed Original file line number Diff line number Diff line change 1
1
namespace Quizzer . Domain . Entities
2
2
{
3
+ /// <summary>
4
+ /// Entity for the question answer
5
+ /// </summary>
3
6
public record Answer
4
7
{
8
+ /// <summary>
9
+ /// The id of the answer
10
+ /// </summary>
11
+ public ulong Id { get ; init ; }
12
+
13
+ /// <summary>
14
+ /// The description illustrated to the user
15
+ /// </summary>
5
16
public string Description { get ; init ; }
17
+
18
+ /// <summary>
19
+ /// Whether is correct or not
20
+ /// </summary>
6
21
public bool IsCorrect { get ; init ; }
22
+
23
+ /// <summary>
24
+ /// How many points does the answer give once the user has got it right
25
+ /// </summary>
26
+ public uint Points { get ; init ; }
7
27
}
8
28
}
Original file line number Diff line number Diff line change
1
+ namespace Quizzer . Domain . Entities
2
+ {
3
+ public record Player
4
+ {
5
+ public string Id { get ; set ; }
6
+
7
+ public int Score { get ; set ; }
8
+ }
9
+ }
Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
+ using System . ComponentModel . DataAnnotations ;
2
3
3
4
namespace Quizzer . Domain . Entities
4
5
{
6
+ /// <summary>
7
+ /// Entity for the quiz question
8
+ /// </summary>
5
9
public record Question
6
10
{
11
+ /// <summary>
12
+ /// The id of the question
13
+ /// </summary>
14
+ public ulong Id { get ; set ; }
15
+
16
+ /// <summary>
17
+ /// The question title or the question itself
18
+ /// </summary>
7
19
public string Title { get ; init ; }
20
+
21
+ /// <summary>
22
+ /// The time given to the user to answer the question, this not handled by the server and client
23
+ /// TODO decide which measurement unit use and integrate with the frontend
24
+ /// </summary>
8
25
public int Timeout { get ; init ; }
26
+
27
+ /// <summary>
28
+ /// List of possible answer, MIN 0 and MAX 4
29
+ /// </summary>
30
+ [ Range ( 0 , 4 ) ]
9
31
public IList < Answer > Answer { get ; init ; }
10
32
}
11
33
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Quizzer . Domain . Entities
4
4
{
5
+ /// <summary>
6
+ /// Immutable quiz entity that contains necessary information to start a game
7
+ /// This in future will be saved in a database
8
+ /// </summary>
5
9
public record Quiz
6
10
{
11
+ /// <summary>
12
+ /// The id of the quiz
13
+ /// </summary>
14
+ public ulong Id { get ; init ; }
15
+
16
+ /// <summary>
17
+ /// Title of the quiz
18
+ /// </summary>
7
19
public string Title { get ; init ; }
20
+
21
+ /// <summary>
22
+ /// Description of the quiz
23
+ /// </summary>
8
24
public string Description { get ; init ; }
25
+
26
+ /// <summary>
27
+ /// Image Url in future can be used as a banner
28
+ /// </summary>
9
29
public string ImageUrl { get ; init ; }
30
+
31
+ /// <summary>
32
+ /// List of available questions in the quiz
33
+ /// </summary>
10
34
public IList < Question > Questions { get ; init ; }
11
- public IList < string > Users { get ; init ; }
12
35
}
13
36
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
3
+ using Quizzer . Domain . Enums ;
6
4
7
5
namespace Quizzer . Domain . Entities
8
6
{
7
+ /// <summary>
8
+ /// Entity used for the game
9
+ /// </summary>
9
10
public record QuizGame
10
11
{
12
+ /// <summary>
13
+ /// Unique identifier for the game
14
+ /// </summary>
11
15
public ulong Id { get ; init ; }
16
+
17
+ /// <summary>
18
+ /// The Quiz entity, this should probably just use a quiz id
19
+ /// </summary>
12
20
public Quiz Quiz { get ; init ; }
13
- public DateTime ? Started { get ; init ; }
21
+
22
+ /// <summary>
23
+ /// When the game started, null when it hasn't started yet
24
+ /// </summary>
25
+ public DateTime ? Started { get ; set ; }
26
+
27
+ /// <summary>
28
+ /// Indicate the current active question
29
+ /// </summary>
30
+ /// <remarks>Cannot be less than 0</remarks>
14
31
public int CurrentQuestion { get ; set ; }
32
+
33
+ /// <summary>
34
+ /// List of users who are participating to the quiz
35
+ /// </summary>
36
+ public IList < Player > Users { get ; set ; }
37
+
38
+ /// <summary>
39
+ /// Indicate the current state of the game
40
+ /// </summary>
41
+ public GameStatus Status { get ; set ; }
42
+
43
+ /// <summary>
44
+ /// Id of the user who started the game
45
+ /// </summary>
46
+ public string OwnerId { get ; set ; }
47
+
48
+ // TODO
49
+ // Store user answer so that score can be calculated at the end
15
50
}
16
51
}
Original file line number Diff line number Diff line change
1
+ namespace Quizzer . Domain . Enums
2
+ {
3
+ public enum GameStatus
4
+ {
5
+ /// <summary>
6
+ /// Indicates that the game hasn't started yet
7
+ /// </summary>
8
+ Idle = 0 ,
9
+
10
+ /// <summary>
11
+ /// Indicates that the game is currently running
12
+ /// </summary>
13
+ Running = 1 ,
14
+
15
+ /// <summary>
16
+ /// Indicate that the game has been stopped
17
+ /// This is not integrated yet
18
+ /// </summary>
19
+ Stopped = 2 ,
20
+
21
+ /// <summary>
22
+ /// Indicate that the game has ended
23
+ /// </summary>
24
+ Ended = 3
25
+ }
26
+ }
Original file line number Diff line number Diff line change 1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
1
+ using Quizzer . Domain . Entities ;
6
2
7
3
namespace Quizzer . Domain . Events
8
4
{
5
+ /// <summary>
6
+ /// Event fired once the game ended
7
+ /// </summary>
9
8
public class GameEndedEvent
10
9
{
11
- public ulong GameId { get ; init ; }
10
+ public QuizGame Game { get ; init ; }
12
11
}
13
12
}
Original file line number Diff line number Diff line change 1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
1
+ using System . Collections . Generic ;
2
+ using Quizzer . Domain . Enums ;
6
3
7
4
namespace Quizzer . Domain . Events
8
5
{
6
+ /// <summary>
7
+ /// Event fired once the game owner press start
8
+ /// </summary>
9
9
public record GameStartedEvent
10
10
{
11
+ /// <summary>
12
+ /// The game id or room id
13
+ /// </summary>
11
14
public ulong GameId { get ; init ; }
15
+
16
+ /// <summary>
17
+ /// The participants users
18
+ /// </summary>
12
19
public IList < string > Users { get ; init ; }
20
+
21
+ /// <summary>
22
+ /// Status of the game, should be running
23
+ /// </summary>
24
+ public GameStatus Status { get ; init ; }
25
+
26
+ /// <summary>
27
+ /// Starting question
28
+ /// </summary>
29
+ public int CurrentQuestion { get ; init ; }
13
30
}
14
31
}
Original file line number Diff line number Diff line change 1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
1
+ using System . Collections . Generic ;
2
+ using Quizzer . Domain . Entities ;
6
3
7
4
namespace Quizzer . Domain . Events
8
5
{
6
+ /// <summary>
7
+ /// Event fired when the timeout of the question has been reached
8
+ /// </summary>
9
9
public class QuestionEndedEvent
10
10
{
11
- public IList < string > CorrectAnswer { get ; init ; }
11
+ public ulong GameId { get ; init ; }
12
+
13
+ /// <summary>
14
+ /// The list of correct answer
15
+ /// </summary>
16
+ public IList < Answer > Answers { get ; init ; }
12
17
}
13
18
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
6
3
7
4
namespace Quizzer . Domain . Events
8
5
{
6
+ /// <summary>
7
+ /// Event fired when the user click on game start or when he clicks on next question
8
+ /// </summary>
9
9
public record QuestionStartedEvent
10
10
{
11
+ public ulong GameId { get ; init ; }
12
+
13
+ /// <summary>
14
+ /// The given question based on the game CurrentQuestion
15
+ /// </summary>
11
16
public string Question { get ; init ; }
17
+
18
+ /// <summary>
19
+ /// Current question position
20
+ /// </summary>
21
+ public int CurrentQuestion { get ; init ; }
22
+
23
+ public DateTimeOffset EndAt { get ; init ; }
24
+
25
+ /// <summary>
26
+ /// List of possible answer for he given question
27
+ /// </summary>
12
28
public IList < string > Answers { get ; init ; }
13
29
}
14
30
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace Quizzer . Domain . Events
8
+ {
9
+ /// <summary>
10
+ /// Event fired when a user joins a game
11
+ /// </summary>
12
+ public record UserJoinedGameEvent
13
+ {
14
+ public string UserId { get ; set ; }
15
+ public ulong GameId { get ; set ; }
16
+ }
17
+ }
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
6
2
7
3
namespace Quizzer . Domain . Exceptions
8
4
{
5
+ /// <summary>
6
+ /// Exception thrown when the game was not found
7
+ /// </summary>
9
8
public class GameNotFoundException : Exception
10
9
{
11
10
public GameNotFoundException ( ulong id ) : base ( $ "Game { id } not found")
You can’t perform that action at this time.
0 commit comments