Skip to content

Commit

Permalink
Merge pull request #374 from gordon-cs/s20-master-candidate
Browse files Browse the repository at this point in the history
S20 master candidate
  • Loading branch information
russtuck authored Jul 17, 2020
2 parents 0271755 + c951ded commit 48a56ca
Show file tree
Hide file tree
Showing 88 changed files with 10,497 additions and 2,936 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## From Github /~https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Avoid database files
*.edmx
*/Metadata.cs
*/ModelPartialClasses.cs

Expand Down Expand Up @@ -271,6 +270,7 @@ paket-files/
## Secret Files
secrets.config
test_credentials.py
credentials.py


## Python
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ os: windows
mono: none

# Install NuGet, then build the solution
script:
script:
- choco install nuget.commandline
- choco install visualstudio2017-workload-manageddesktop
- choco install visualstudio2017-workload-netweb
Expand All @@ -34,4 +34,4 @@ deploy:
# Only send notification emails on build failure
notifications:
email:
on_success: never
on_success: never
288 changes: 287 additions & 1 deletion Gordon360/ApiControllers/JobsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Newtonsoft.Json.Linq;
using Gordon360.AuthorizationFilters;
using Gordon360.Static.Names;
using Gordon360.Exceptions.CustomExceptions;

namespace Gordon360.ApiControllers
{
Expand Down Expand Up @@ -76,7 +77,7 @@ public IHttpActionResult getJobsForUser([FromBody] ActiveJobSelectionParametersM
public HttpResponseMessage getSavedShiftsForUser()
{
int userID = GetCurrentUserID();

IEnumerable<StudentTimesheetsViewModel> result = null;

try
Expand Down Expand Up @@ -139,6 +140,8 @@ public HttpResponseMessage editShiftForUser([FromBody] ShiftViewModel shiftDetai
int userID = -1;
var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;
var id = _accountService.GetAccountByUsername(username).GordonID;
userID = Convert.ToInt32(id);

try
{
Expand Down Expand Up @@ -230,5 +233,288 @@ public IHttpActionResult getSupervisorName(int supervisorID)
}
return Ok(result);
}

/// <summary>
/// sends the current clock in status to the back end
/// true if user is clocked in and false if clocked out
/// </summary>
/// <param name="state">detail to be saved in the back end, true if user just clocked in</param>
/// <returns>returns confirmation that the answer was recorded </returns>
[HttpPost]
[Route("clockIn")]
public IHttpActionResult ClockIn([FromBody] bool state)
{

if (!ModelState.IsValid || state == null)
{
string errors = "";
foreach (var modelstate in ModelState.Values)
{
foreach (var error in modelstate.Errors)
{
errors += "|" + error.ErrorMessage + "|" + error.Exception;
}

}
throw new BadInputException() { ExceptionMessage = errors };
}

var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

var id = _accountService.GetAccountByUsername(username).GordonID;

var result = _jobsService.ClockIn(state, id);

if (result == null)
{
return NotFound();
}


return Created("Recorded answer :", result);

}

/// <summary>
/// gets the the clock in status from the back end
/// true if user is clocked in and false if clocked out
/// </summary>
/// <returns>ClockInViewModel</returns>
[HttpGet]
[Route("clockOut")]
public IHttpActionResult ClockOut()
{
var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

var id = _accountService.GetAccountByUsername(username).GordonID;

var result = _jobsService.ClockOut(id);

if (result == null)
{
return NotFound();
}

return Ok(result);
}

/// <summary>
/// deletes the last clocked in status of a user
/// </summary>
/// <returns>returns confirmation that clock in status was deleted</returns>
[HttpPut]
[Route("deleteClockIn")]
public IHttpActionResult DeleteClockIn()
{
var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

var id = _accountService.GetAccountByUsername(username).GordonID;

var result = _jobsService.DeleteClockIn(id);

if (result == null)
{
return NotFound();
}

return Ok(result);
}

//staff routes


/// <summary>
/// Get a user's active jobs
/// </summary>
/// <param name="details"> deatils of the current Staff</param>
/// <returns>The Staff's active jobs</returns>
[HttpPost]
[Route("getJobsStaff")]
public IHttpActionResult getJobsForStaff([FromBody] ActiveJobSelectionParametersModel details)
{
IEnumerable<ActiveJobViewModel> result = null;
int userID = GetCurrentUserID();
try
{
result = _jobsService.getActiveJobsStaff(details.SHIFT_START_DATETIME, details.SHIFT_END_DATETIME, userID);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return InternalServerError();
}
return Ok(result);
}

/// <summary>
/// Get a user's saved shifts
/// </summary>
/// <returns>The staff's saved shifts</returns>
[HttpGet]
[Route("getSavedShiftsStaff")]
public HttpResponseMessage getSavedShiftsForStaff()
{
int userID = GetCurrentUserID();

IEnumerable<StaffTimesheetsViewModel> result = null;

try
{
result = _jobsService.getSavedShiftsForStaff(userID);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
}
return Request.CreateResponse(HttpStatusCode.OK, result);
}

/// <summary>
/// Get a user's active jobs
/// </summary>
/// <param name="shiftDetails">The details that will be changed</param>
/// <returns>The result of saving a shift for a staff</returns>
[HttpPost]
[Route("saveShiftStaff")]
[StateYourBusiness(operation = Operation.ADD, resource = Resource.SHIFT)]
public HttpResponseMessage saveShiftForStaff([FromBody] ShiftViewModel shiftDetails)
{
IEnumerable<StaffTimesheetsViewModel> result = null;
IEnumerable<OverlappingShiftIdViewModel> overlapCheckResult = null;

int userID = GetCurrentUserID();
var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

try
{
overlapCheckResult = _jobsService.checkForOverlappingShiftStaff(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME);
if (overlapCheckResult.Count() > 0)
{
return Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected");
}
result = _jobsService.saveShiftForStaff(userID, shiftDetails.EML, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, shiftDetails.SHIFT_NOTES, username);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
}
return Request.CreateResponse(HttpStatusCode.OK, result);
}

/// <summary>
/// Edit a shift for staff
/// <param name="shiftDetails">The details that will be changed</param>
/// </summary>
[HttpPut]
[Route("editShiftStaff")]
public HttpResponseMessage editShiftForStaff([FromBody] ShiftViewModel shiftDetails)
{
IEnumerable<StaffTimesheetsViewModel> result = null;
IEnumerable<OverlappingShiftIdViewModel> overlapCheckResult = null;

int userID = -1;
var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;
var id = _accountService.GetAccountByUsername(username).GordonID;
userID = Convert.ToInt32(id);

try
{
overlapCheckResult = _jobsService.editShiftOverlapCheck(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.ID);
if (overlapCheckResult.Count() > 0)
{
return Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected");
}
result = _jobsService.editShiftStaff(shiftDetails.ID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, username);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return Request.CreateResponse(HttpStatusCode.InternalServerError, e);
}
return Request.CreateResponse(HttpStatusCode.OK, result);
}

/// <summary>
/// Get a user's active jobs
/// </summary>
/// <returns>The result of deleting the shift for a Staff</returns>
[HttpDelete]
[Route("deleteShiftStaff/{rowID}")]
[StateYourBusiness(operation = Operation.DELETE, resource = Resource.SHIFT)]
public IHttpActionResult deleteShiftForStaff(int rowID)
{
IEnumerable<StaffTimesheetsViewModel> result = null;
int userID = GetCurrentUserID();

try
{
result = _jobsService.deleteShiftForStaff(rowID, userID);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return InternalServerError();
}
return Ok(result);
}

/// <summary>
/// Submit shift for staff
/// </summary>
/// <returns>The result of submitting the shifts for staff</returns>
[HttpPost]
[Route("submitShiftsStaff")]
[StateYourBusiness(operation = Operation.UPDATE, resource = Resource.SHIFT)]
public IHttpActionResult submitShiftsForStaff([FromBody] IEnumerable<ShiftToSubmitViewModel> shifts)
{
IEnumerable<StaffTimesheetsViewModel> result = null;
int userID = GetCurrentUserID();

try
{
foreach (ShiftToSubmitViewModel shift in shifts)
{
result = _jobsService.submitShiftForStaff(userID, shift.EML, shift.SHIFT_END_DATETIME, shift.SUBMITTED_TO, shift.LAST_CHANGED_BY);
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return InternalServerError();
}
return Ok(result);
}

/// <summary>
/// Gets the name of a supervisor based on their ID number for Staff
/// </summary>
/// <returns>The name of the supervisor</returns>
[HttpGet]
[Route("supervisorNameStaff/{supervisorID}")]
[StateYourBusiness(operation = Operation.UPDATE, resource = Resource.SHIFT)]
public IHttpActionResult getSupervisorNameStaff(int supervisorID)
{
IEnumerable<SupervisorViewModel> result = null;

try
{
result = _jobsService.getStaffSupervisorNameForJob(supervisorID);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return InternalServerError();
}
return Ok(result);
}

}

}
6 changes: 3 additions & 3 deletions Gordon360/ApiControllers/MembershipRequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public IHttpActionResult ApproveRequest(int id)
/// <summary>
/// Sets the membership request to Denied
/// </summary>
/// <param name="id">The id of the membership reuqest in question.</param>
/// <returns>If successful: THe updated membership request wrapped in an OK Http status code.</returns>
/// <param name="id">The id of the membership request in question.</param>
/// <returns>If successful: The updated membership request wrapped in an OK Http status code.</returns>
[HttpPost]
[Route("{id}/deny")]
[StateYourBusiness(operation = Operation.DENY_ALLOW, resource = Resource.MEMBERSHIP_REQUEST)]
Expand Down Expand Up @@ -290,7 +290,7 @@ public IHttpActionResult DenyRequest(int id)
return Ok(result);
}
/// <summary>
/// Delets a membership request
/// Deletes a membership request
/// </summary>
/// <param name="id">The id of the membership request to delete</param>
/// <returns>The deleted object</returns>
Expand Down
Loading

0 comments on commit 48a56ca

Please sign in to comment.