Skip to content

Commit e927e5b

Browse files
committed
Add domain entities
1 parent 8f6c494 commit e927e5b

File tree

12 files changed

+217
-29
lines changed

12 files changed

+217
-29
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
namespace Quizzer.Domain.Entities
22
{
3+
/// <summary>
4+
/// Entity for the question answer
5+
/// </summary>
36
public record Answer
47
{
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>
516
public string Description { get; init; }
17+
18+
/// <summary>
19+
/// Whether is correct or not
20+
/// </summary>
621
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; }
727
}
828
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
using System.Collections.Generic;
2+
using System.ComponentModel.DataAnnotations;
23

34
namespace Quizzer.Domain.Entities
45
{
6+
/// <summary>
7+
/// Entity for the quiz question
8+
/// </summary>
59
public record Question
610
{
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>
719
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>
825
public int Timeout { get; init; }
26+
27+
/// <summary>
28+
/// List of possible answer, MIN 0 and MAX 4
29+
/// </summary>
30+
[Range(0, 4)]
931
public IList<Answer> Answer { get; init; }
1032
}
1133
}

server/src/Services/Quizer/Quiz.Domain/Entities/Quiz.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,35 @@
22

33
namespace Quizzer.Domain.Entities
44
{
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>
59
public record Quiz
610
{
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>
719
public string Title { get; init; }
20+
21+
/// <summary>
22+
/// Description of the quiz
23+
/// </summary>
824
public string Description { get; init; }
25+
26+
/// <summary>
27+
/// Image Url in future can be used as a banner
28+
/// </summary>
929
public string ImageUrl { get; init; }
30+
31+
/// <summary>
32+
/// List of available questions in the quiz
33+
/// </summary>
1034
public IList<Question> Questions { get; init; }
11-
public IList<string> Users { get; init; }
1235
}
1336
}
Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
3+
using Quizzer.Domain.Enums;
64

75
namespace Quizzer.Domain.Entities
86
{
7+
/// <summary>
8+
/// Entity used for the game
9+
/// </summary>
910
public record QuizGame
1011
{
12+
/// <summary>
13+
/// Unique identifier for the game
14+
/// </summary>
1115
public ulong Id { get; init; }
16+
17+
/// <summary>
18+
/// The Quiz entity, this should probably just use a quiz id
19+
/// </summary>
1220
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>
1431
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
1550
}
1651
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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;
62

73
namespace Quizzer.Domain.Events
84
{
5+
/// <summary>
6+
/// Event fired once the game ended
7+
/// </summary>
98
public class GameEndedEvent
109
{
11-
public ulong GameId { get; init; }
10+
public QuizGame Game { get; init; }
1211
}
1312
}
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
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;
63

74
namespace Quizzer.Domain.Events
85
{
6+
/// <summary>
7+
/// Event fired once the game owner press start
8+
/// </summary>
99
public record GameStartedEvent
1010
{
11+
/// <summary>
12+
/// The game id or room id
13+
/// </summary>
1114
public ulong GameId { get; init; }
15+
16+
/// <summary>
17+
/// The participants users
18+
/// </summary>
1219
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; }
1330
}
1431
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
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;
63

74
namespace Quizzer.Domain.Events
85
{
6+
/// <summary>
7+
/// Event fired when the timeout of the question has been reached
8+
/// </summary>
99
public class QuestionEndedEvent
1010
{
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; }
1217
}
1318
}
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63

74
namespace Quizzer.Domain.Events
85
{
6+
/// <summary>
7+
/// Event fired when the user click on game start or when he clicks on next question
8+
/// </summary>
99
public record QuestionStartedEvent
1010
{
11+
public ulong GameId { get; init; }
12+
13+
/// <summary>
14+
/// The given question based on the game CurrentQuestion
15+
/// </summary>
1116
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>
1228
public IList<string> Answers { get; init; }
1329
}
1430
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

server/src/Services/Quizer/Quiz.Domain/Exceptions/GameNotFoundException.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62

73
namespace Quizzer.Domain.Exceptions
84
{
5+
/// <summary>
6+
/// Exception thrown when the game was not found
7+
/// </summary>
98
public class GameNotFoundException : Exception
109
{
1110
public GameNotFoundException(ulong id) : base($"Game {id} not found")

0 commit comments

Comments
 (0)