feat: Implement database schema, relationships and models for survey application
- Designed an ERD (Entity-Relationship Diagram) for the survey system. - Defined entities: User, Survey, Question, Choice, Response, and Answer. - Established relationships: - Users can author multiple surveys. - Surveys contain multiple questions. - Questions have multiple choices. - Surveys can have multiple responses from participants. - Responses are linked to answers, questions, and choices. - Ensured compliance with best practices for relational database design. Note : no migration yet
This commit is contained in:
25
survey-beta.sln
Normal file
25
survey-beta.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35312.102
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "survey-beta", "survey-beta\survey-beta.csproj", "{7A5087A4-5EFE-49C8-AD7A-A2AC9F815C32}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7A5087A4-5EFE-49C8-AD7A-A2AC9F815C32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7A5087A4-5EFE-49C8-AD7A-A2AC9F815C32}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7A5087A4-5EFE-49C8-AD7A-A2AC9F815C32}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7A5087A4-5EFE-49C8-AD7A-A2AC9F815C32}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {AD3F914F-11E0-46E6-A86F-6C7743255DC4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
56
survey-beta/DataBaseContext/AppDbContext.cs
Normal file
56
survey-beta/DataBaseContext/AppDbContext.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using survey_beta.Models;
|
||||
namespace survey_beta.DataBaseContext
|
||||
{
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Survey> Surveys { get; set; }
|
||||
public DbSet<Question> Questions { get; set; }
|
||||
public DbSet<Choice> Choices { get; set; }
|
||||
public DbSet<Response> Responses { get; set; }
|
||||
public DbSet<Answer> Answers { get; set; }
|
||||
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Survey>()
|
||||
.HasOne(s => s.Author)
|
||||
.WithMany(u => u.Surveys)
|
||||
.HasForeignKey(s => s.AuthorId);
|
||||
|
||||
modelBuilder.Entity<Question>()
|
||||
.HasOne(q => q.Survey)
|
||||
.WithMany(s => s.Questions)
|
||||
.HasForeignKey(q => q.SurveyId);
|
||||
|
||||
modelBuilder.Entity<Choice>()
|
||||
.HasOne(c => c.Question)
|
||||
.WithMany(q => q.Choices)
|
||||
.HasForeignKey(c => c.QuestionId);
|
||||
|
||||
modelBuilder.Entity<Response>()
|
||||
.HasOne(r => r.Survey)
|
||||
.WithMany(s => s.Responses)
|
||||
.HasForeignKey(r => r.SurveyId);
|
||||
|
||||
modelBuilder.Entity<Answer>()
|
||||
.HasOne(a => a.Response)
|
||||
.WithMany(r => r.Answers)
|
||||
.HasForeignKey(a => a.ResponseId);
|
||||
|
||||
modelBuilder.Entity<Answer>()
|
||||
.HasOne(a => a.Question)
|
||||
.WithMany()
|
||||
.HasForeignKey(a => a.QuestionId);
|
||||
|
||||
modelBuilder.Entity<Answer>()
|
||||
.HasOne(a => a.Choice)
|
||||
.WithMany()
|
||||
.HasForeignKey(a => a.ChoiceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
survey-beta/Models/Answer.cs
Normal file
13
survey-beta/Models/Answer.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class Answer
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string ResponseId { get; set; }
|
||||
public Response Response { get; set; }
|
||||
public string QuestionId { get; set; }
|
||||
public Question Question { get; set; }
|
||||
public string ChoiceId { get; set; }
|
||||
public Choice Choice { get; set; }
|
||||
}
|
||||
}
|
||||
11
survey-beta/Models/Choice.cs
Normal file
11
survey-beta/Models/Choice.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class Choice
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Letter { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string QuestionId { get; set; }
|
||||
public Question Question { get; set; }
|
||||
}
|
||||
}
|
||||
11
survey-beta/Models/Question.cs
Normal file
11
survey-beta/Models/Question.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class Question
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string SurveyId { get; set; }
|
||||
public Survey Survey { get; set; }
|
||||
public ICollection<Choice> Choices { get; set; }
|
||||
}
|
||||
}
|
||||
11
survey-beta/Models/Response.cs
Normal file
11
survey-beta/Models/Response.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class Response
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string IpAddress { get; set; }
|
||||
public string SurveyId { get; set; }
|
||||
public Survey Survey { get; set; }
|
||||
public ICollection<Answer> Answers { get; set; }
|
||||
}
|
||||
}
|
||||
16
survey-beta/Models/Survey.cs
Normal file
16
survey-beta/Models/Survey.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class Survey
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Category { get; set; }
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
public bool IsPublished { get; set; }
|
||||
public string AuthorId { get; set; }
|
||||
public User Author { get; set; }
|
||||
public ICollection<Question> Questions { get; set; }
|
||||
public ICollection<Response> Responses { get; set; }
|
||||
}
|
||||
}
|
||||
13
survey-beta/Models/User.cs
Normal file
13
survey-beta/Models/User.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace survey_beta.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Fullname { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? PasswordHash { get; set; }
|
||||
public ICollection<Survey> Surveys { get; set; } = new List<Survey>();
|
||||
|
||||
}
|
||||
}
|
||||
23
survey-beta/Program.cs
Normal file
23
survey-beta/Program.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using survey_beta.DataBaseContext;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
41
survey-beta/Properties/launchSettings.json
Normal file
41
survey-beta/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:5388",
|
||||
"sslPort": 44392
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"applicationUrl": "http://localhost:5036",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"applicationUrl": "https://localhost:7002;http://localhost:5036",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
survey-beta/appsettings.Development.json
Normal file
8
survey-beta/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
survey-beta/appsettings.json
Normal file
12
survey-beta/appsettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Database=SurveyDB;Username=postgre;Password=MAJEDali645"
|
||||
}
|
||||
}
|
||||
24
survey-beta/survey-beta.csproj
Normal file
24
survey-beta/survey-beta.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>survey_beta</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
survey-beta/survey-beta.csproj.user
Normal file
6
survey-beta/survey-beta.csproj.user
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
6
survey-beta/survey-beta.http
Normal file
6
survey-beta/survey-beta.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@survey_beta_HostAddress = http://localhost:5036
|
||||
|
||||
GET {{survey_beta_HostAddress}}/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
Reference in New Issue
Block a user