Skip to content
Snippets Groups Projects
Commit 50a067f9 authored by Enzo Santangelo Dodera's avatar Enzo Santangelo Dodera
Browse files

Merge branch 'feature/course-password' into 'develop'

course passwords

See merge request !42
parents 977a469c 33ef0c6a
No related branches found
No related tags found
1 merge request!42course passwords
Pipeline #10644 passed
Showing
with 1161 additions and 8 deletions
......@@ -60,8 +60,8 @@ namespace Tsi1.Api.Controllers
}
[Authorize(Roles = UserTypes.Student)]
[HttpPost("Matriculate/{courseId}")]
public async Task<IActionResult> Matriculate(int courseId)
[HttpPost("Matriculate")]
public async Task<IActionResult> Matriculate(CourseMatriculateDto courseMatriculateDto)
{
try
{
......@@ -74,7 +74,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(response.Message);
}
var result = await _courseService.Matriculate(userId, courseId);
var result = await _courseService.Matriculate(userId, courseMatriculateDto);
if (result.HasError)
{
return BadRequest(result.Message);
......
......@@ -9,6 +9,8 @@ namespace Tsi1.BusinessLayer.Dtos
{
public string Name { get; set; }
public bool IsTemplate { get; set; }
public bool HasPassword { get; set; }
public string Password { get; set; }
public List<SectionCreateDto> Sections { get; set; }
[JsonIgnore]
......
......@@ -9,6 +9,8 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; }
public string Name { get; set; }
public int TenantId { get; set; }
public bool HasPassword { get; set; }
public string Password { get; set; }
public List<SectionDetailDto> Sections { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class CourseMatriculateDto
{
public int CourseId { get; set; }
public string Password { get; set; }
}
}
......@@ -6,6 +6,8 @@ namespace Tsi1.BusinessLayer.Dtos
{
public string Name { get; set; }
public bool IsTemplate { get; set; }
public bool HasPassword { get; set; }
public string Password { get; set; }
[JsonIgnore]
public int TenantId { get; set; }
......
......@@ -35,6 +35,7 @@ namespace Tsi1.BusinessLayer.Helpers
public const string DuplicateCourseName = "Ya existe un curso con nombre '{0}'";
public const string CourseIsTemplate = "El curso con id '{0}' es un template";
public const string CourseHasNoStudents = "El curso con id '{0}' no tiene estudiantes";
public const string CourseInvalidPassword = "Clave de matriculación incorrecta para el curso {0}";
public const string TenantDoesNotExist = "La Facultad '{0}' no existe";
public const string DuplicateTenantName = "Ya existe una Facultad con nombre '{0}'";
......
......@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<int>> Create(CourseCreateDto newCourse);
Task<ServiceResult<bool>> Matriculate(int userId, int courseId);
Task<ServiceResult<bool>> Matriculate(int userId, CourseMatriculateDto courseMatriculateDto);
Task<ServiceResult<bool>> AddProfessorToCourse(ProfessorCourseDto professorCourseDto, int userId, string userType);
......
......@@ -93,7 +93,7 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<bool>> Matriculate(int userId, int courseId)
public async Task<ServiceResult<bool>> Matriculate(int userId, CourseMatriculateDto courseMatriculateDto)
{
var result = new ServiceResult<bool>();
......@@ -114,19 +114,19 @@ namespace Tsi1.BusinessLayer.Services
.ThenInclude(x => x.SectionItemType)
.ThenInclude(x => x.SectionItems)
.ThenInclude(x => x.Forum)
.FirstOrDefaultAsync(x => x.Id == courseId);
.FirstOrDefaultAsync(x => x.Id == courseMatriculateDto.CourseId);
if (course == null)
{
result.HasError = true;
result.Message = string.Format(ErrorMessages.CourseDoesNotExist, courseId);
result.Message = string.Format(ErrorMessages.CourseDoesNotExist, courseMatriculateDto.CourseId);
return result;
}
if (course.IsTemplate)
{
result.HasError = true;
result.AddMessage(string.Format(ErrorMessages.CourseIsTemplate, courseId));
result.AddMessage(string.Format(ErrorMessages.CourseIsTemplate, courseMatriculateDto.CourseId));
return result;
}
......@@ -140,6 +140,13 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
if (course.HasPassword && (course.Password != courseMatriculateDto.Password))
{
result.HasError = true;
result.Message = string.Format(ErrorMessages.CourseInvalidPassword, course.Name);
return result;
}
var automaticSubscriptionForums = course.Sections
.SelectMany(x => x.SectionItems)
.Where(x => x.SectionItemType.Name == SectionItemTypes.Forum)
......
......@@ -19,6 +19,8 @@ namespace Tsi1.DataLayer.Entities
public string Name { get; set; }
public int TenantId { get; set; }
public bool IsTemplate { get; set; }
public bool HasPassword { get; set; }
public string Password { get; set; }
public Tenant Tenant { get; set; }
public ICollection<StudentCourse> StudentCourses { get; set; }
......
......@@ -23,6 +23,13 @@ namespace Tsi1.DataLayer.EntityConfiguration
builder.Property(x => x.IsTemplate)
.IsRequired();
builder.Property(x => x.HasPassword)
.IsRequired();
builder.Property(x => x.Password)
.IsRequired()
.HasColumnType("character varying(200)");
builder.HasOne(x => x.Tenant)
.WithMany(x => x.Courses)
.HasForeignKey(x => x.TenantId);
......
This diff is collapsed.
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tsi1.DataLayer.Migrations
{
public partial class coursepassword : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "HasPassword",
table: "Courses",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "Password",
table: "Courses",
type: "character varying(200)",
nullable: false,
defaultValue: "");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HasPassword",
table: "Courses");
migrationBuilder.DropColumn(
name: "Password",
table: "Courses");
}
}
}
......@@ -154,6 +154,9 @@ namespace Tsi1.DataLayer.Migrations
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<bool>("HasPassword")
.HasColumnType("boolean");
b.Property<bool>("IsTemplate")
.HasColumnType("boolean");
......@@ -161,6 +164,10 @@ namespace Tsi1.DataLayer.Migrations
.IsRequired()
.HasColumnType("character varying(50)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("character varying(200)");
b.Property<int>("TenantId")
.HasColumnType("integer");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment