Skip to content

Commit

Permalink
Merge pull request #156 from careerfairsystems/timeslotsFilter
Browse files Browse the repository at this point in the history
Added filter to check studentsessions have not expired
  • Loading branch information
LeoFjatstrom authored Apr 18, 2024
2 parents e47e3fe + 11b1e41 commit 2158fda
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
23 changes: 16 additions & 7 deletions Nexpo.Tests/Controllers/StudentSessionTimeslotControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Nexpo.Tests.Controllers
{
public class StudentSessionTimeslotControllerTest
{
private int currentYear = DateTime.Now.Year + 1;
[Fact]
public async Task GetAllByCompanyId()
{
Expand Down Expand Up @@ -47,7 +48,7 @@ public async Task Get()
var app = JsonConvert.DeserializeObject<StudentSessionTimeslot>(await response.Content.ReadAsStringAsync());

Assert.True(response.StatusCode.Equals(HttpStatusCode.OK), "Wrong status code. Expected: OK. Received: " + response.StatusCode.ToString());
Assert.True(app.Start.Equals(DateTime.Parse("2021-11-21 10:00")), "Wrong time. Expected: 2021-11-21 10:00. Received: " + app.Start);
Assert.True(app.Start.Equals(DateTime.Parse($"{currentYear}-11-21 10:00")), $"Wrong time. Expected: {currentYear}-11-21 10:00. Received: " + app.Start);
}

[Fact]
Expand Down Expand Up @@ -427,8 +428,8 @@ public async Task CreateNewTimeslotAndDelete()
//Add new timeslot
var json = new JsonObject
{
{ "start", DateTime.Parse("2021-11-15 12:45") },
{ "end", DateTime.Parse("2021-11-15 13:15") },
{ "start", DateTime.Parse($"{currentYear}-11-15 12:45") },
{ "end", DateTime.Parse($"{currentYear}-11-15 13:15") },
{ "companyid", "-3" },
{ "location", "At home" }
};
Expand Down Expand Up @@ -500,13 +501,13 @@ public async Task UpdateLocation()

Assert.True(responseObject1.Location.Equals("E:A"), "Wrong location. Expected: E:A. Received: " + responseObject1.Location.ToString());
Assert.True(responseObject1.CompanyId == -3, "Wrong CompandyId. Expected: -3. Received: " + responseObject1.CompanyId.ToString());
Assert.True(responseObject1.Start.Equals(DateTime.Parse("2021-11-23 12:00")), "Wrong start time. Expected: 2021-11-23 12:00. Received: " + responseObject1.Start);
Assert.True(responseObject1.Start.Equals(DateTime.Parse($"{currentYear}-11-23 12:00")), $"Wrong start time. Expected: {currentYear}-11-23 12:00. Received: " + responseObject1.Start);

var responseObject2 = JsonConvert.DeserializeObject<StudentSessionTimeslot>(await response2.Content.ReadAsStringAsync());

Assert.True(responseObject2.Location.Equals("Zoom"), "Wrong location. Expected: Zoom. Received: " + responseObject2.Location.ToString());
Assert.True(responseObject2.CompanyId == -3, "Wrong CompandyId. Expected: -3. Received: " + responseObject2.CompanyId.ToString());
Assert.True(responseObject2.Start.Equals(DateTime.Parse("2021-11-23 12:00")), "Wrong start time. Expected: 2021-11-23 12:00. Received: " + responseObject2.Start);
Assert.True(responseObject2.Start.Equals(DateTime.Parse($"{currentYear}-11-23 12:00")), $"Wrong start time. Expected: {currentYear}-11-23 12:00. Received: " + responseObject2.Start);
}

[Fact]
Expand All @@ -533,8 +534,8 @@ public async Task CreateAndDelete()
//Add new timeslot
var json = new JsonObject
{
{ "start", DateTime.Parse("2021-11-15 12:45") },
{ "end", DateTime.Parse("2021-11-15 13:15") },
{ "start", DateTime.Parse($"{currentYear}-11-15 12:45") },
{ "end", DateTime.Parse($"{currentYear}-11-15 13:15") },
{ "companyid", "-3" },
{ "location", "At home" }
};
Expand Down Expand Up @@ -567,5 +568,13 @@ public async Task CreateAndDelete()
var responseList2 = JsonConvert.DeserializeObject<List<StudentSessionTimeslot>>(await response4.Content.ReadAsStringAsync());
Assert.True(responseList2.Count == 2, "Wrong number of timeslots. Expected: 1. Received: " + responseList2.Count.ToString());
}
[Fact]

public async Task TestTimedOut()
{
var client = await TestUtils.Login("student1");
var response = await client.GetAsync("/api/timeslots/-8");
Assert.True(response.StatusCode.Equals(HttpStatusCode.NotFound), "Timed out test should not be returned " + response.ToString());
}
}
}
20 changes: 12 additions & 8 deletions Nexpo/Models/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ public void Seed()
SaveChanges();

// StudentSessionTimeslots
var session1 = new StudentSessionTimeslot { Id = -1, Start = DateTime.Parse("2021-11-21 10:00"), End = DateTime.Parse("2021-11-21 10:15"), Location = "Zoom", CompanyId = company1.Id.Value };
var session2 = new StudentSessionTimeslot { Id = -2, Start = DateTime.Parse("2021-11-21 10:15"), End = DateTime.Parse("2021-11-21 10:30"), Location = "Zoom", CompanyId = company1.Id.Value };
var session3 = new StudentSessionTimeslot { Id = -3, Start = DateTime.Parse("2021-11-21 10:30"), End = DateTime.Parse("2021-11-21 10:45"), Location = "Zoom", CompanyId = company1.Id.Value };
int currentYear = DateTime.Now.Year;
var session1 = new StudentSessionTimeslot { Id = -1, Start = DateTime.Parse($"{currentYear+1}-11-21 10:00"), End = DateTime.Parse($"{currentYear+1}-11-21 10:15"), Location = "Zoom", CompanyId = company1.Id.Value };
var session2 = new StudentSessionTimeslot { Id = -2, Start = DateTime.Parse($"{currentYear+1}-11-21 10:15"), End = DateTime.Parse($"{currentYear+1}-11-21 10:30"), Location = "Zoom", CompanyId = company1.Id.Value };
var session3 = new StudentSessionTimeslot { Id = -3, Start = DateTime.Parse($"{currentYear+1}-11-21 10:30"), End = DateTime.Parse($"{currentYear+1}-11-21 10:45"), Location = "Zoom", CompanyId = company1.Id.Value };

var session4 = new StudentSessionTimeslot { Id = -4, Start = DateTime.Parse("2021-11-22 11:00"), End = DateTime.Parse("2021-11-22 11:15"), Location = "Zoom", CompanyId = company2.Id.Value };
var session5 = new StudentSessionTimeslot { Id = -5, Start = DateTime.Parse("2021-11-22 11:15"), End = DateTime.Parse("2021-11-22 11:30"), Location = "Zoom", CompanyId = company2.Id.Value };
var session4 = new StudentSessionTimeslot { Id = -4, Start = DateTime.Parse($"{currentYear+1}-11-22 11:00"), End = DateTime.Parse($"{currentYear+1}-11-22 11:15"), Location = "Zoom", CompanyId = company2.Id.Value };
var session5 = new StudentSessionTimeslot { Id = -5, Start = DateTime.Parse($"{currentYear+1}-11-22 11:15"), End = DateTime.Parse($"{currentYear+1}-11-22 11:30"), Location = "Zoom", CompanyId = company2.Id.Value };

var session6 = new StudentSessionTimeslot { Id = -6, Start = DateTime.Parse("2021-11-23 12:00"), End = DateTime.Parse("2021-11-22 12:15"), Location = "Zoom", CompanyId = company3.Id.Value };
var session7 = new StudentSessionTimeslot { Id = -7, Start = DateTime.Parse("2021-11-23 12:15"), End = DateTime.Parse("2021-11-22 12:30"), Location = "Zoom", CompanyId = company3.Id.Value };
StudentSessionTimeslots.AddRange(session1, session2, session3, session4, session5, session6, session7);
var session6 = new StudentSessionTimeslot { Id = -6, Start = DateTime.Parse($"{currentYear+1}-11-23 12:00"), End = DateTime.Parse($"{currentYear+1}-11-22 12:15"), Location = "Zoom", CompanyId = company3.Id.Value };
var session7 = new StudentSessionTimeslot { Id = -7, Start = DateTime.Parse($"{currentYear+1}-11-23 12:15"), End = DateTime.Parse($"{currentYear+1}-11-22 12:30"), Location = "Zoom", CompanyId = company3.Id.Value };

var session8 = new StudentSessionTimeslot { Id = -8, Start = DateTime.Parse($"{currentYear-1}-11-21 10:00"), End = DateTime.Parse($"{currentYear-1}-11-21 10:15"), Location = "Zoom", CompanyId = company1.Id.Value };

StudentSessionTimeslots.AddRange(session1, session2, session3, session4, session5, session6, session7, session8);
SaveChanges();

// StudentSessionApplications
Expand Down
7 changes: 4 additions & 3 deletions Nexpo/Repositories/StudentSessionTimeslotRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nexpo.Models;
using System;
using Nexpo.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -27,12 +28,12 @@ public StudentSessionTimeslotRepository(ApplicationDbContext context)

public async Task<IEnumerable<StudentSessionTimeslot>> GetAllForCompany(int companyId)
{
return await _context.StudentSessionTimeslots.Where(timeslot => timeslot.CompanyId == companyId).ToListAsync();
return await _context.StudentSessionTimeslots.Where(timeslot => timeslot.CompanyId == companyId && timeslot.Start > DateTime.Now).ToListAsync();
}

public async Task<StudentSessionTimeslot> Get(int id)
{
return await _context.StudentSessionTimeslots.Where(timeslot => timeslot.Id == id).FirstOrDefaultAsync();
return await _context.StudentSessionTimeslots.Where(timeslot => timeslot.Id == id && timeslot.Start > DateTime.Now).FirstOrDefaultAsync();
}

public async Task Add(StudentSessionTimeslot timeslot)
Expand Down

0 comments on commit 2158fda

Please sign in to comment.