Skip to content

Commit

Permalink
Merge pull request #650 from gordon-cs/release
Browse files Browse the repository at this point in the history
RELEASE: S21 Academic Check-In
  • Loading branch information
cpabbot authored Jul 23, 2021
2 parents f3bef08 + e76844c commit 96bba35
Show file tree
Hide file tree
Showing 14 changed files with 1,322 additions and 778 deletions.
177 changes: 177 additions & 0 deletions Gordon360/ApiControllers/AcademicCheckInController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using Gordon360.Exceptions.CustomExceptions;
using Gordon360.Exceptions.ExceptionFilters;
using Gordon360.Models;
using Gordon360.Models.ViewModels;
using Gordon360.Repositories;
using Gordon360.Services;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Web.Http;

namespace Gordon360.Controllers.Api
{
[RoutePrefix("api/checkIn")]
[Authorize]
[CustomExceptionFilter]
public class AcademicCheckInController : ApiController
{
private IAcademicCheckInService _checkInService;
private IAccountService _accountService;

public AcademicCheckInController()
{
IUnitOfWork _unitOfWork = new UnitOfWork();
_checkInService = new AcademicCheckInService(_unitOfWork);
_accountService = new AccountService(_unitOfWork);
}

/// <summary>Set emergency contacts for student</summary>
/// <param name="data"> The contact data to be stored </param>
/// <returns> The data stored </returns>
[HttpPost]
[Route("emergencycontact")]
public IHttpActionResult PutEmergencyContact([FromBody] EmergencyContact data)
{
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;

try {
var result = _checkInService.PutEmergencyContact(data, id, username);
return Created("Emergency Contact", result);
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error setting the check in data.");
return NotFound();
}

}



/// <summary> Sets the students cell phone number</summary>
/// <param name="data"> The phone number object to be added to the database </param>
/// <returns> The data stored </returns>
[HttpPut]
[Route("cellphone")]
public IHttpActionResult PutCellPhone([FromBody] AcademicCheckInViewModel data)
{
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;

try {
var result = _checkInService.PutCellPhone(id, data);
return Ok(result);
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error setting the check in data.");
return NotFound();
}

}

/// <summary>Sets the students race and ethinicity</summary>
/// <param name="data"> The object containing the race numbers of the users </param>
/// <returns> The data stored </returns>
[HttpPut]
[Route("demographic")]
public IHttpActionResult PutDemographic([FromBody] AcademicCheckInViewModel data)
{
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;

try
{
var result = _checkInService.PutDemographic(id, data);
return Ok(result);
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error setting the check in data.");
return NotFound();
}

}

/// <summary> Gets and returns the user's holds </summary>
/// <returns> The user's stored holds </returns>
[HttpGet]
[Route("holds")]
public IHttpActionResult GetHolds()
{
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;

try
{
var result = (_checkInService.GetHolds(id)).First();
return Ok(result);
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error finding the check in data");
return NotFound();
}

}

/// <summary> Sets the user as having completed Academic Checkin </summary>
/// <returns> The HTTP status indicating whether the request was completed or not</returns>
[HttpPut]
[Route("status")]
public IHttpActionResult SetStatus()
{
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;

try
{
_checkInService.SetStatus(id);
return Ok();
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error finding the check in data");
return NotFound();
}
}

/// <summary> Gets whether the user has checked in or not. True if they have checked in, false if they have not checked in </summary>
/// <returns> The HTTP status indicating whether the request was completed and returns the check in status of the student </returns>
[HttpGet]
[Route("status")]
public IHttpActionResult GetStatus()
{
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;

try
{
var result = _checkInService.GetStatus(id);
return Ok(result);
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "There was an error finding the check in data");
return NotFound();
}
}

}
}
1 change: 1 addition & 0 deletions Gordon360/ApiControllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ public IHttpActionResult GetEmergencyContact(string username)


}


/// <summary>Gets the mailbox information of currently logged in user</summary>
/// <returns></returns>
Expand Down
14 changes: 13 additions & 1 deletion Gordon360/AuthorizationFilters/StateYourBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ private bool canReadOne(string resource)
case Resource.EMERGENCY_CONTACT:
if (user_position == Position.POLICE)
return true;
return false;
else
{
var username = (string)context.ActionArguments["username"];
var isSelf = username.Equals(user_name.ToLower());
return isSelf;
}
case Resource.MEMBERSHIP:
return true;
case Resource.MEMBERSHIP_REQUEST:
Expand Down Expand Up @@ -643,6 +648,13 @@ private bool canUpdate(string resource)

return false;
}
case Resource.EMERGENCY_CONTACT:
{
var username = (string)context.ActionArguments["username"];
var isSelf = username.Equals(user_name);
return isSelf;
}

case Resource.NEWS:
var newsID = context.ActionArguments["newsID"];
var newsService = new NewsService(new UnitOfWork());
Expand Down
Loading

0 comments on commit 96bba35

Please sign in to comment.