InternshipTypeNextFixes #57

Manually merged
Zonar merged 2 commits from InternshipTypeNextFixes into master 2020-10-03 22:33:22 +02:00
8 changed files with 55 additions and 53 deletions

View File

@ -79,8 +79,9 @@ namespace InternshipSystem.Api.Controllers
public async Task<ActionResult<IEnumerable<InternshipType>>> SearchInternshipTypes([FromQuery] InternshipTypeSearchQuery searchQuery, CancellationToken cancellationToken) public async Task<ActionResult<IEnumerable<InternshipType>>> SearchInternshipTypes([FromQuery] InternshipTypeSearchQuery searchQuery, CancellationToken cancellationToken)
{ {
return await Context.InternshipTypes return await Context.InternshipTypes
.Where(t => string.IsNullOrEmpty(searchQuery.Type) || t.Type.Contains(searchQuery.Type)) .Where(t => string.IsNullOrEmpty(searchQuery.Label) || t.Label.Contains(searchQuery.Label))
.OrderBy(t => t.Type) .Where(t => string.IsNullOrEmpty(searchQuery.LabelEng) || t.Label.Contains(searchQuery.LabelEng))
.OrderBy(t => t.Label)
.Skip(searchQuery.Page * searchQuery.PerPage) .Skip(searchQuery.Page * searchQuery.PerPage)
.Take(searchQuery.PerPage) .Take(searchQuery.PerPage)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
@ -118,7 +119,8 @@ namespace InternshipSystem.Api.Controllers
return NotFound($"Internship type with id {internshipTypeFrom.Id} not found"); return NotFound($"Internship type with id {internshipTypeFrom.Id} not found");
} }
internshipType.Type = string.IsNullOrEmpty(internshipTypeFrom.Type) ? internshipType.Type : internshipTypeFrom.Type; internshipType.Label = string.IsNullOrEmpty(internshipTypeFrom.Label) ? internshipType.Label : internshipTypeFrom.Label;
internshipType.LabelEng = string.IsNullOrEmpty(internshipTypeFrom.LabelEng) ? internshipType.LabelEng : internshipTypeFrom.LabelEng;
internshipType.Description = string.IsNullOrEmpty(internshipTypeFrom.Description) ? internshipType.Description : internshipTypeFrom.Description; internshipType.Description = string.IsNullOrEmpty(internshipTypeFrom.Description) ? internshipType.Description : internshipTypeFrom.Description;
internshipType.DescriptionEng = string.IsNullOrEmpty(internshipTypeFrom.DescriptionEng) ? internshipType.DescriptionEng : internshipTypeFrom.DescriptionEng; internshipType.DescriptionEng = string.IsNullOrEmpty(internshipTypeFrom.DescriptionEng) ? internshipType.DescriptionEng : internshipTypeFrom.DescriptionEng;
} }
@ -126,7 +128,8 @@ namespace InternshipSystem.Api.Controllers
{ {
var newInternshipType = new InternshipType var newInternshipType = new InternshipType
{ {
Type = internshipTypeFrom.Type, Label = internshipTypeFrom.Label,
LabelEng = internshipTypeFrom.LabelEng,
Description = internshipTypeFrom.Description, Description = internshipTypeFrom.Description,
DescriptionEng = internshipTypeFrom.DescriptionEng, DescriptionEng = internshipTypeFrom.DescriptionEng,
}; };

View File

@ -5,7 +5,8 @@ namespace InternshipSystem.Api.Queries
public class InternshipTypeFrom public class InternshipTypeFrom
{ {
public long? Id { get; set; } public long? Id { get; set; }
public string Type { get; set; } public string Label { get; set; }
public string LabelEng { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string DescriptionEng { get; set; } public string DescriptionEng { get; set; }
@ -15,12 +16,10 @@ namespace InternshipSystem.Api.Queries
{ {
RuleFor(t => t.Id).NotNull() RuleFor(t => t.Id).NotNull()
.When(t => .When(t =>
string.IsNullOrEmpty(t.Description) || string.IsNullOrEmpty(t.Type) || string.IsNullOrEmpty(t.DescriptionEng)); string.IsNullOrEmpty(t.Label) || string.IsNullOrEmpty(t.LabelEng));
RuleFor(t => t.Type).NotEmpty() RuleFor(t => t.Label).NotEmpty()
.When(t => !t.Id.HasValue); .When(t => !t.Id.HasValue);
RuleFor(t => t.Description).NotEmpty() RuleFor(t => t.LabelEng).NotEmpty()
.When(t => !t.Id.HasValue);
RuleFor(t => t.DescriptionEng).NotEmpty()
.When(t => !t.Id.HasValue); .When(t => !t.Id.HasValue);
} }
} }

View File

@ -4,6 +4,7 @@ namespace InternshipSystem.Api.Controllers
{ {
public class InternshipTypeSearchQuery : SearchQuery public class InternshipTypeSearchQuery : SearchQuery
{ {
public string Type { get; set; } = ""; public string Label { get; set; } = "";
public string LabelEng { get; set; } = "";
} }
} }

View File

@ -3,7 +3,8 @@
public class InternshipType public class InternshipType
{ {
public long Id { get; set; } public long Id { get; set; }
public string Type { get; set; } public string Label { get; set; }
public string LabelEng { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string DescriptionEng { get; set; } public string DescriptionEng { get; set; }
} }

View File

@ -114,51 +114,40 @@ namespace InternshipSystem.Repository
{ {
new InternshipType new InternshipType
{ {
Type = "FreeInternship", Label = "Praktyka bezpłatna",
Description = "Praktyka bezpłatna", LabelEng = "Free internship",
DescriptionEng = "Free internship",
}, },
new InternshipType new InternshipType
{ {
Type = "GraduateInternship", Label = "Praktyka absolwencka",
Description = "Praktyka absolwencka", LabelEng = "Graduate internship",
DescriptionEng = "Graduate internship",
}, },
new InternshipType new InternshipType
{ {
Type = "FreeApprenticeship", Label = "Praktyka bezpłatna",
Description = "Praktyka bezpłatna", LabelEng = "Free apprenticeship",
DescriptionEng = "Free apprenticeship",
}, },
new InternshipType new InternshipType
{ {
Type = "PaidApprenticeship", Label = "Praktyka Zagraniczna",
Description = "np. przemysłowy", LabelEng = "Foreign Internship",
DescriptionEng = "Paid apprenticeship", Description = "IAESTE, ERASMUS",
DescriptionEng = "IAESTE, ERASMUS",
}, },
new InternshipType new InternshipType
{ {
Type = "ForeignInternship", Label = "Umowa o pracę",
Description = "np. IAESTE, ERASMUS", LabelEng = "contract of employment",
DescriptionEng = "Foreign internship",
}, },
new InternshipType new InternshipType
{ {
Type = "UOP", Label = "Umowa o dzieło",
Description = "umowa o pracę", LabelEng = "contract work",
DescriptionEng = "contract of employment",
}, },
new InternshipType new InternshipType
{ {
Type = "UD", Label = "Umowa zlecenie",
Description = "umowa o dzieło", LabelEng = "contract of mandate"
DescriptionEng = "contract work",
},
new InternshipType
{
Type = "UZ",
Description = "umowa zlecenie",
DescriptionEng = "contract of mandate"
}, },
}; };
await Context.InternshipTypes.AddRangeAsync(internshipTypes); await Context.InternshipTypes.AddRangeAsync(internshipTypes);
@ -210,19 +199,19 @@ namespace InternshipSystem.Repository
{ {
new EditionInternshipType new EditionInternshipType
{ {
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UOP")) InternshipType = Context.InternshipTypes.First(t => t.Label.Equals("Umowa o pracę"))
}, },
new EditionInternshipType new EditionInternshipType
{ {
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UZ")) InternshipType = Context.InternshipTypes.First(t => t.Label.Equals("Umowa zlecenie"))
}, },
new EditionInternshipType new EditionInternshipType
{ {
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("UD")) InternshipType = Context.InternshipTypes.First(t => t.Label.Equals("Umowa o dzieło"))
}, },
new EditionInternshipType new EditionInternshipType
{ {
InternshipType = Context.InternshipTypes.First(t => t.Type.Equals("FreeInternship")) InternshipType = Context.InternshipTypes.First(t => t.Label.Equals("Praktyka bezpłatna"))
} }
}, },
Internships = new List<Internship>(), Internships = new List<Internship>(),
@ -245,7 +234,7 @@ namespace InternshipSystem.Repository
InternshipRegistration = new InternshipRegistration InternshipRegistration = new InternshipRegistration
{ {
Company = Context.Companies.First(c => c.Name.Equals("Intel")), Company = Context.Companies.First(c => c.Name.Equals("Intel")),
Type = Context.InternshipTypes.First(t => t.Type.Equals("UOP")), Type = Context.InternshipTypes.First(t => t.Label.Equals("Umowa o pracę")),
Start = new DateTime(2000, 7, 1), Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30), End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted, State = DocumentState.Submitted,
@ -291,7 +280,7 @@ namespace InternshipSystem.Repository
InternshipRegistration = new InternshipRegistration InternshipRegistration = new InternshipRegistration
{ {
Company = Context.Companies.First(c => c.Name.Equals("Asseco Poland")), Company = Context.Companies.First(c => c.Name.Equals("Asseco Poland")),
Type = Context.InternshipTypes.First(t => t.Type.Equals("UZ")), Type = Context.InternshipTypes.First(t => t.Label.Equals("Umowa zlecenie")),
Start = new DateTime(2000, 7, 1), Start = new DateTime(2000, 7, 1),
End = new DateTime(2000, 8, 30), End = new DateTime(2000, 8, 30),
State = DocumentState.Submitted, State = DocumentState.Submitted,

View File

@ -10,8 +10,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace InternshipSystem.Repository.Migrations namespace InternshipSystem.Repository.Migrations
{ {
[DbContext(typeof(InternshipDbContext))] [DbContext(typeof(InternshipDbContext))]
[Migration("20201002222652_Initial")] [Migration("20201003202928_init")]
partial class Initial partial class init
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@ -301,8 +301,12 @@ namespace InternshipSystem.Repository.Migrations
.HasColumnName("description_eng") .HasColumnName("description_eng")
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Type") b.Property<string>("Label")
.HasColumnName("type") .HasColumnName("label")
.HasColumnType("text");
b.Property<string>("LabelEng")
.HasColumnName("label_eng")
.HasColumnType("text"); .HasColumnType("text");
b.HasKey("Id") b.HasKey("Id")

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace InternshipSystem.Repository.Migrations namespace InternshipSystem.Repository.Migrations
{ {
public partial class Initial : Migration public partial class init : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
@ -56,7 +56,8 @@ namespace InternshipSystem.Repository.Migrations
{ {
id = table.Column<long>(nullable: false) id = table.Column<long>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
type = table.Column<string>(nullable: true), label = table.Column<string>(nullable: true),
label_eng = table.Column<string>(nullable: true),
description = table.Column<string>(nullable: true), description = table.Column<string>(nullable: true),
description_eng = table.Column<string>(nullable: true) description_eng = table.Column<string>(nullable: true)
}, },

View File

@ -299,8 +299,12 @@ namespace InternshipSystem.Repository.Migrations
.HasColumnName("description_eng") .HasColumnName("description_eng")
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Type") b.Property<string>("Label")
.HasColumnName("type") .HasColumnName("label")
.HasColumnType("text");
b.Property<string>("LabelEng")
.HasColumnName("label_eng")
.HasColumnType("text"); .HasColumnType("text");
b.HasKey("Id") b.HasKey("Id")