added CreatedBy to surveys
This commit is contained in:
parent
3b6952364c
commit
dbcdfac698
7 changed files with 443 additions and 22 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SurveyBackend.Core.Services;
|
|
||||||
using SurveyBackend.DTOs;
|
using SurveyBackend.DTOs;
|
||||||
using SurveyBackend.Mappers.UserDTOs;
|
using SurveyBackend.Mappers.UserDTOs;
|
||||||
|
using IAuthorizationService = SurveyBackend.Core.Services.IAuthorizationService;
|
||||||
|
|
||||||
namespace SurveyBackend.Controllers;
|
namespace SurveyBackend.Controllers;
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ public class AuthController : ControllerBase
|
||||||
_authorizationService = authorizationService;
|
_authorizationService = authorizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
public async Task<IActionResult> LogIn([FromBody] UserLoginDto loginData)
|
public async Task<IActionResult> LogIn([FromBody] UserLoginDto loginData)
|
||||||
{
|
{
|
||||||
|
|
@ -23,10 +25,12 @@ public class AuthController : ControllerBase
|
||||||
return Ok(new { token = token });
|
return Ok(new { token = token });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
[HttpPost("register")]
|
[HttpPost("register")]
|
||||||
public async Task<IActionResult> Register([FromBody] UserRegistrationDto registerData)
|
public async Task<IActionResult> Register([FromBody] UserRegistrationDto registerData)
|
||||||
{
|
{
|
||||||
var token = await _authorizationService.RegisterUser(UserRegistrationMapper.UserRegistrationToModel(registerData));
|
var token = await _authorizationService.RegisterUser(
|
||||||
|
UserRegistrationMapper.UserRegistrationToModel(registerData));
|
||||||
return Ok(new { token = token });
|
return Ok(new { token = token });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SurveyBackend.DTOs.Survey;
|
using SurveyBackend.DTOs.Survey;
|
||||||
using SurveyLib.Core.Models;
|
using SurveyLib.Core.Models;
|
||||||
|
|
@ -17,6 +19,7 @@ public class SurveyController : ControllerBase
|
||||||
_surveyService = surveyService;
|
_surveyService = surveyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get()
|
public async Task<IActionResult> Get()
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +27,7 @@ public class SurveyController : ControllerBase
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
|
|
@ -31,18 +35,23 @@ public class SurveyController : ControllerBase
|
||||||
return result is not null ? Ok(result) : NotFound();
|
return result is not null ? Ok(result) : NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Post([FromBody] CreateSurveyDTO dto)
|
public async Task<IActionResult> Post([FromBody] CreateSurveyDTO dto)
|
||||||
{
|
{
|
||||||
|
var userId = Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);
|
||||||
|
|
||||||
var survey = new Survey
|
var survey = new Survey
|
||||||
{
|
{
|
||||||
Title = dto.Title,
|
Title = dto.Title,
|
||||||
Description = dto.Description,
|
Description = dto.Description,
|
||||||
|
CreatedBy = userId,
|
||||||
};
|
};
|
||||||
await _surveyService.AddSurveyAsync(survey);
|
await _surveyService.AddSurveyAsync(survey);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<IActionResult> Delete(int id)
|
public async Task<IActionResult> Delete(int id)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System.Text;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
using SurveyBackend.Core.Repositories;
|
using SurveyBackend.Core.Repositories;
|
||||||
using SurveyBackend.Core.Services;
|
using SurveyBackend.Core.Services;
|
||||||
using SurveyBackend.Infrastructure;
|
using SurveyBackend.Infrastructure;
|
||||||
|
|
@ -62,7 +63,32 @@ public class Program
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Scheme = "bearer",
|
||||||
|
BearerFormat = "JWT",
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Description = "JWT Authorization header using the Bearer scheme.",
|
||||||
|
Name = "Authorization",
|
||||||
|
Type = SecuritySchemeType.ApiKey
|
||||||
|
});
|
||||||
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Reference = new OpenApiReference
|
||||||
|
{
|
||||||
|
Type = ReferenceType.SecurityScheme,
|
||||||
|
Id = JwtBearerDefaults.AuthenticationScheme
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Array.Empty<string>()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,30 +13,16 @@ public class ApplicationDbContext : SurveyDbContext
|
||||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||||
: base(options)
|
: base(options)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
// Вызов конфигурации базового контекста для моделей библиотеки
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
// Здесь можно описывать конфигурацию дополнительных сущностей и связи между моделями библиотеки и моделями приложения.
|
modelBuilder.Entity<Survey>()
|
||||||
// Например, если Survey должен иметь связь с User (скажем, владелец опроса):
|
.HasOne<User>()
|
||||||
|
.WithMany()
|
||||||
// Допустим, Survey не имеет в исходной модели свойства UserId.
|
.HasForeignKey(s => s.CreatedBy)
|
||||||
// Можно использовать теневой ключ, или если ты готов расширить модель Survey в бэкенде.
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
// Пример с теневым ключом:
|
|
||||||
// modelBuilder.Entity<Survey>()
|
|
||||||
// .HasOne<User>() // тип связи: один пользователь
|
|
||||||
// .WithMany() // например, пользователь может владеть несколькими опросами
|
|
||||||
// .HasForeignKey("OwnerId"); // теневой ключ, который не прописан в модели Survey
|
|
||||||
|
|
||||||
// Или, если расширить Survey:
|
|
||||||
// public int? OwnerId { get; set; }
|
|
||||||
// modelBuilder.Entity<Survey>()
|
|
||||||
// .HasOne<User>()
|
|
||||||
// .WithMany(u => u.Surveys)
|
|
||||||
// .HasForeignKey(s => s.OwnerId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,334 @@
|
||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using SurveyBackend.Infrastructure.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SurveyBackend.Infrastructure.Data.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
|
[Migration("20250418190738_Add CreatedBy to Survey")]
|
||||||
|
partial class AddCreatedBytoSurvey
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.15");
|
||||||
|
|
||||||
|
modelBuilder.Entity("GroupUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("GroupsId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("UsersId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("GroupsId", "UsersId");
|
||||||
|
|
||||||
|
b.HasIndex("UsersId");
|
||||||
|
|
||||||
|
b.ToTable("GroupUser");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyBackend.Core.Models.Group", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Label")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Groups");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyBackend.Core.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Answer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("CompletionId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("QuestionId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("AnswerText")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("CompletionId", "QuestionId");
|
||||||
|
|
||||||
|
b.HasIndex("QuestionId");
|
||||||
|
|
||||||
|
b.ToTable("Answers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.AnswerVariant", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int?>("MultipleAnswerQuestionId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("QuestionId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int?>("SingleAnswerQuestionId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MultipleAnswerQuestionId");
|
||||||
|
|
||||||
|
b.HasIndex("QuestionId");
|
||||||
|
|
||||||
|
b.HasIndex("SingleAnswerQuestionId");
|
||||||
|
|
||||||
|
b.ToTable("AnswerVariant");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Completion", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("FinishedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("SurveyId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SurveyId");
|
||||||
|
|
||||||
|
b.ToTable("Completions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionBase", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Discriminator")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(34)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("SurveyId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SurveyId");
|
||||||
|
|
||||||
|
b.ToTable("Questions");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("QuestionBase");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Survey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int?>("CreatedBy")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CreatedBy");
|
||||||
|
|
||||||
|
b.ToTable("Surveys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionVariants.MultipleAnswerQuestion", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("SurveyLib.Core.Models.QuestionBase");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MultipleAnswerQuestion");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionVariants.SingleAnswerQuestion", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("SurveyLib.Core.Models.QuestionBase");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("SingleAnswerQuestion");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionVariants.TextQuestion", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("SurveyLib.Core.Models.QuestionBase");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("TextQuestion");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GroupUser", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyBackend.Core.Models.Group", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("GroupsId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SurveyBackend.Core.Models.User", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UsersId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Answer", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyLib.Core.Models.Completion", "Completion")
|
||||||
|
.WithMany("Answers")
|
||||||
|
.HasForeignKey("CompletionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SurveyLib.Core.Models.QuestionBase", "Question")
|
||||||
|
.WithMany("Answers")
|
||||||
|
.HasForeignKey("QuestionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Completion");
|
||||||
|
|
||||||
|
b.Navigation("Question");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.AnswerVariant", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyLib.Core.Models.QuestionVariants.MultipleAnswerQuestion", null)
|
||||||
|
.WithMany("AnswerVariants")
|
||||||
|
.HasForeignKey("MultipleAnswerQuestionId");
|
||||||
|
|
||||||
|
b.HasOne("SurveyLib.Core.Models.QuestionBase", "Question")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("QuestionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("SurveyLib.Core.Models.QuestionVariants.SingleAnswerQuestion", null)
|
||||||
|
.WithMany("AnswerVariants")
|
||||||
|
.HasForeignKey("SingleAnswerQuestionId");
|
||||||
|
|
||||||
|
b.Navigation("Question");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Completion", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyLib.Core.Models.Survey", "Survey")
|
||||||
|
.WithMany("Completions")
|
||||||
|
.HasForeignKey("SurveyId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Survey");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionBase", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyLib.Core.Models.Survey", "Survey")
|
||||||
|
.WithMany("Questions")
|
||||||
|
.HasForeignKey("SurveyId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Survey");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Survey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyBackend.Core.Models.User", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CreatedBy")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Completion", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Answers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionBase", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Answers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Survey", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Completions");
|
||||||
|
|
||||||
|
b.Navigation("Questions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionVariants.MultipleAnswerQuestion", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("AnswerVariants");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.QuestionVariants.SingleAnswerQuestion", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("AnswerVariants");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SurveyBackend.Infrastructure.Data.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddCreatedBytoSurvey : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "CreatedBy",
|
||||||
|
table: "Surveys",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Surveys_CreatedBy",
|
||||||
|
table: "Surveys",
|
||||||
|
column: "CreatedBy");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Surveys_Users_CreatedBy",
|
||||||
|
table: "Surveys",
|
||||||
|
column: "CreatedBy",
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.SetNull);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Surveys_Users_CreatedBy",
|
||||||
|
table: "Surveys");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Surveys_CreatedBy",
|
||||||
|
table: "Surveys");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CreatedBy",
|
||||||
|
table: "Surveys");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -177,6 +177,9 @@ namespace SurveyBackend.Infrastructure.Data.Migrations
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int?>("CreatedBy")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
@ -187,6 +190,8 @@ namespace SurveyBackend.Infrastructure.Data.Migrations
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CreatedBy");
|
||||||
|
|
||||||
b.ToTable("Surveys");
|
b.ToTable("Surveys");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -286,6 +291,14 @@ namespace SurveyBackend.Infrastructure.Data.Migrations
|
||||||
b.Navigation("Survey");
|
b.Navigation("Survey");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SurveyLib.Core.Models.Survey", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SurveyBackend.Core.Models.User", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CreatedBy")
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SurveyLib.Core.Models.Completion", b =>
|
modelBuilder.Entity("SurveyLib.Core.Models.Completion", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Answers");
|
b.Navigation("Answers");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue