Skip to content

Commit af599ea

Browse files
committed
mass refactoring and code cleanup
1 parent 56efd1c commit af599ea

32 files changed

+629
-887
lines changed

HAC.API/Controllers/AttendanceController.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/attendance")]
87
[ApiController]
9-
public class AttendanceController : ControllerBase
10-
{
8+
public class AttendanceController : ControllerBase {
119
private readonly ILogger<AttendanceController> _logger;
1210

13-
public AttendanceController(ILogger<AttendanceController> logger)
14-
{
11+
public AttendanceController(ILogger<AttendanceController> logger) {
1512
_logger = logger;
1613
}
1714

1815

1916
// GET: api/<AttendanceController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);

HAC.API/Controllers/ControllerUtils.cs

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,55 @@
1-
using System.Net;
1+
using HAC.API.Data;
22
using HAC.API.Data.Objects;
33
using Microsoft.AspNetCore.Http;
44
using Microsoft.Extensions.Logging;
55

6-
namespace HAC.API.Controllers
7-
{
8-
public static class Utils
9-
{
10-
public static Response GetResponse<T>(HttpContext context, ILogger<T> logger)
11-
{
6+
namespace HAC.API.Controllers {
7+
public static class Utils {
8+
public static Response GetResponse<T>(HttpContext context, ILogger<T> logger) {
129
string hacLink = context.Request.Query["hacLink"];
1310
string username = context.Request.Query["username"];
1411
string password = context.Request.Query["password"];
15-
16-
if (string.IsNullOrEmpty(hacLink))
17-
return new Response { Message = "Error 404: Empty hacLink parameter." };
18-
if (string.IsNullOrEmpty(username))
19-
return new Response { Message = "Error 404: Empty username parameter." };
12+
13+
if (string.IsNullOrEmpty(hacLink))
14+
return new Response {Message = "Error 404: Empty hacLink parameter."};
15+
if (string.IsNullOrEmpty(username))
16+
return new Response {Message = "Error 404: Empty username parameter."};
2017
if (string.IsNullOrEmpty(password))
21-
return new Response { Message = "Error 404: Empty password parameter." };
22-
18+
return new Response {Message = "Error 404: Empty password parameter."};
19+
2320
logger.LogInformation("Received a request.\n" +
24-
$"Link: {hacLink}\n" +
25-
$"Username: {username}\n" +
26-
$"Password: {password}");
27-
28-
var hac = new Data.Hac();
29-
HttpWebResponse response = hac.Login(hacLink, username, password, out var container);
21+
$"Link: {hacLink}\n" +
22+
$"Username: {username}\n" +
23+
$"Password: {password}");
24+
25+
var response = Hac.Login(hacLink, username, password);
26+
var container = response.Result.CookieContainer;
27+
var uri = response.Result.RequestUri;
3028

31-
if (!hac.IsValidLogin(response)) //checks if login creds are true
29+
if (!Hac.IsValidLogin(response.Result.ResponseBody)) //checks if login credentials are true
3230
{
3331
const string errorText = "Either the HAC username or password is incorrect.";
34-
return new Response
35-
{
32+
return new Response {
3633
Message = errorText
3734
};
3835
}
3936

4037
var result = new Response();
4138
var type = logger.GetType().GenericTypeArguments[0];
42-
39+
4340
if (type == typeof(HacController))
44-
{
45-
result = hac.GetAll(container, response.ResponseUri, hacLink);
46-
}
41+
result = Hac.GetAll(container, uri, hacLink);
4742
else if (type == typeof(StudentController))
48-
{
49-
result = hac.GetStudentInfo(container, response.ResponseUri, hacLink);
50-
}
43+
result = Hac.GetStudentInfo(container, uri, hacLink);
5144
else if (type == typeof(CourseController))
52-
{
53-
result = hac.GetCourses(container, response.ResponseUri, hacLink);
54-
}
45+
result = Hac.GetCourses(container, uri, hacLink);
5546
else if (type == typeof(IprController))
56-
{
57-
result = hac.GetIpr(container, response.ResponseUri, hacLink);
58-
}
47+
result = Hac.GetIpr(container, uri, hacLink);
5948
else if (type == typeof(ReportCardController))
60-
{
61-
result = hac.GetReportCard(container, response.ResponseUri, hacLink);
62-
}
49+
result = Hac.GetReportCard(container, uri, hacLink);
6350
else if (type == typeof(TranscriptController))
64-
{
65-
result = hac.GetTranscript(container, response.ResponseUri, hacLink);
66-
}
67-
else if (type == typeof(AttendanceController))
68-
{
69-
result = hac.GetAttendance(container, response.ResponseUri, hacLink);
70-
}
51+
result = Hac.GetTranscript(container, uri, hacLink);
52+
else if (type == typeof(AttendanceController)) result = Hac.GetAttendance(container, uri, hacLink);
7153

7254
return result;
7355
}

HAC.API/Controllers/CourseController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/courses")]
87
[ApiController]
9-
public class CourseController : ControllerBase
10-
{
8+
public class CourseController : ControllerBase {
119
private readonly ILogger<CourseController> _logger;
1210

13-
public CourseController(ILogger<CourseController> logger)
14-
{
11+
public CourseController(ILogger<CourseController> logger) {
1512
_logger = logger;
1613
}
1714

1815

19-
// GET: api/<HacController>
16+
// GET: api/<CourseController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);

HAC.API/Controllers/HacController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/hac")]
87
[ApiController]
9-
public class HacController : ControllerBase
10-
{
8+
public class HacController : ControllerBase {
119
private readonly ILogger<HacController> _logger;
1210

13-
public HacController(ILogger<HacController> logger)
14-
{
11+
public HacController(ILogger<HacController> logger) {
1512
_logger = logger;
1613
}
1714

1815

1916
// GET: api/<HacController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);
2622

2723
return result;
2824
}
2925
}
30-
}
26+
}

HAC.API/Controllers/IprController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/ipr")]
87
[ApiController]
9-
public class IprController : ControllerBase
10-
{
8+
public class IprController : ControllerBase {
119
private readonly ILogger<IprController> _logger;
1210

13-
public IprController(ILogger<IprController> logger)
14-
{
11+
public IprController(ILogger<IprController> logger) {
1512
_logger = logger;
1613
}
1714

1815

19-
// GET: api/<HacController>
16+
// GET: api/<IprController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);

HAC.API/Controllers/ReportCardController.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
7-
5+
namespace HAC.API.Controllers {
86
[Route("api/reportCard")]
97
[ApiController]
10-
public class ReportCardController : ControllerBase
11-
{
8+
public class ReportCardController : ControllerBase {
129
private readonly ILogger<ReportCardController> _logger;
1310

14-
public ReportCardController(ILogger<ReportCardController> logger)
15-
{
11+
public ReportCardController(ILogger<ReportCardController> logger) {
1612
_logger = logger;
1713
}
1814

1915

20-
// GET: api/<HacController>
16+
// GET: api/<ReportCardController>
2117
[HttpGet]
22-
public Response Get()
23-
{
18+
public Response Get() {
2419
// Retrieves the username, password, and hacLink values from the URL Request.
2520
// Then logs in and fetches the result
2621
var result = Utils.GetResponse(HttpContext, _logger);

HAC.API/Controllers/StudentController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/student")]
87
[ApiController]
9-
public class StudentController : ControllerBase
10-
{
8+
public class StudentController : ControllerBase {
119
private readonly ILogger<StudentController> _logger;
1210

13-
public StudentController(ILogger<StudentController> logger)
14-
{
11+
public StudentController(ILogger<StudentController> logger) {
1512
_logger = logger;
1613
}
1714

1815

19-
// GET: api/<HacController>
16+
// GET: api/<StudentController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);

HAC.API/Controllers/TranscriptController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Logging;
44

5-
namespace HAC.API.Controllers
6-
{
5+
namespace HAC.API.Controllers {
76
[Route("api/transcript")]
87
[ApiController]
9-
public class TranscriptController : ControllerBase
10-
{
8+
public class TranscriptController : ControllerBase {
119
private readonly ILogger<TranscriptController> _logger;
1210

13-
public TranscriptController(ILogger<TranscriptController> logger)
14-
{
11+
public TranscriptController(ILogger<TranscriptController> logger) {
1512
_logger = logger;
1613
}
1714

1815

19-
// GET: api/<HacController>
16+
// GET: api/<TranscriptController>
2017
[HttpGet]
21-
public Response Get()
22-
{
18+
public Response Get() {
2319
// Retrieves the username, password, and hacLink values from the URL Request.
2420
// Then logs in and fetches the result
2521
var result = Utils.GetResponse(HttpContext, _logger);

0 commit comments

Comments
 (0)