Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Senior Project Release: 02/10/2024 #1021

Merged
merged 32 commits into from
Apr 3, 2024
Merged

Senior Project Release: 02/10/2024 #1021

merged 32 commits into from
Apr 3, 2024

Conversation

ArabellaJi
Copy link
Contributor

This PR is to code review and release the senior project branch.

ArabellaJi and others added 29 commits October 4, 2023 23:13
to test the virtual machine from senior project branch
Housing Lottery Add Applicants and Preferred Hall
@ArabellaJi
Copy link
Contributor Author

ArabellaJi commented Feb 21, 2024

Here is the API code for the Housing Lottery Senior Project. In this project, we created five tables and referenced them mainly in the HousingController and HousingService files.
I may remove the Housing.Year table and make some changes to the Housing.Applicant table in the near future, but we'd love to start our code review process on other parts of the code so that we have a better chance to launch our project on time. Thank you very much!!

Copy link
Contributor

@EjPlatzer EjPlatzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Arabella,

The code looks correct from a behavioral standpoint, although I don't know your requirements. Great work!

I have left some initial comments about changes to improve the expressiveness, performance, and readability of your code. Let me know if you have questions on any of those comments.

I know you said you're planning to re-design the database layout somewhat, which I think is good. I didn't leave any comments about that for now, although I do have some thoughts about how you could improve it.

I do have some concerns about design, especially in terms of database design and the Type of data the API is working with. I think it would be worthwhile to meet together and discuss those design aspects if you would like to.

Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Outdated Show resolved Hide resolved
Comment on lines +320 to +325
if (viewerGroups.Contains(AuthGroup.HousingAdmin))
{
await _housingService.UpdateDueDateAsync(dueDate);
return Ok();
}
return BadRequest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of BadRequest, you should return Unauthorized here. Also, you can reduce the nesting here and make the successful path more prominent by inverting the condition. In my opinion, this makes the logic easier to understand and follow:

Suggested change
if (viewerGroups.Contains(AuthGroup.HousingAdmin))
{
await _housingService.UpdateDueDateAsync(dueDate);
return Ok();
}
return BadRequest();
if (!viewerGroups.Contains(AuthGroup.HousingAdmin))
{
return Unauthorized();
}
await _housingService.UpdateDueDateAsync(dueDate);
return Ok();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be done in StateYourBusiness.cs instead of in the controller. Is that possible here?

Gordon360/Services/HousingService.cs Show resolved Hide resolved
Gordon360/Services/HousingService.cs Show resolved Hide resolved
Comment on lines +587 to +611
List<string> yearList = new List<string>();
foreach (string e in emailList)
{
if (e != "")
{
var newApplicant = new Applicant
{
ApplicationID = applicantion_id,
Applicant1 = e
}; ;
await _context.Applicant.AddAsync(newApplicant);

var student = _context.Student.FirstOrDefault(x => x.Email == e);
if (student != null)
{
yearList.Add(student.Class);
}
}
}
var newMaxYear = new Year
{
ApplicationID = applicantion_id,
Year1 = yearList.Max()
}; ;
await _context.Year.AddAsync(newMaxYear);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify the logic for getting the max class year of all applicants, and also make it much more performant, by getting all rows from the Student table in one query:

Suggested change
List<string> yearList = new List<string>();
foreach (string e in emailList)
{
if (e != "")
{
var newApplicant = new Applicant
{
ApplicationID = applicantion_id,
Applicant1 = e
}; ;
await _context.Applicant.AddAsync(newApplicant);
var student = _context.Student.FirstOrDefault(x => x.Email == e);
if (student != null)
{
yearList.Add(student.Class);
}
}
}
var newMaxYear = new Year
{
ApplicationID = applicantion_id,
Year1 = yearList.Max()
}; ;
await _context.Year.AddAsync(newMaxYear);
var maxYear = _context.Student.Where(s => emailList.Contains(s.Email)).Select(s => s.Class).Max();
await _context.Year.AddAsync(new Year
{
ApplicationID = applicantion_id,
Year1 = maxYear
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, we can use a bit of LINQ to simplify the Applicant code:

Suggested change
List<string> yearList = new List<string>();
foreach (string e in emailList)
{
if (e != "")
{
var newApplicant = new Applicant
{
ApplicationID = applicantion_id,
Applicant1 = e
}; ;
await _context.Applicant.AddAsync(newApplicant);
var student = _context.Student.FirstOrDefault(x => x.Email == e);
if (student != null)
{
yearList.Add(student.Class);
}
}
}
var newMaxYear = new Year
{
ApplicationID = applicantion_id,
Year1 = yearList.Max()
}; ;
await _context.Year.AddAsync(newMaxYear);
var newApplicants = emailList
.Where(e => String.IsNullOrWhiteSpace(e))
.Select(email => new Applicant
{
ApplicationID = applicantion_id,
Applicant1 = email
});
_context.Applicant.AddRange(newApplicants);

Gordon360/Services/HousingService.cs Show resolved Hide resolved
Gordon360/Services/HousingService.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Gordon360/Controllers/HousingController.cs Show resolved Hide resolved
Comment on lines +320 to +325
if (viewerGroups.Contains(AuthGroup.HousingAdmin))
{
await _housingService.UpdateDueDateAsync(dueDate);
return Ok();
}
return BadRequest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be done in StateYourBusiness.cs instead of in the controller. Is that possible here?

Gordon360/Models/CCT/Housing/Applicant.cs Show resolved Hide resolved
Gordon360/Models/CCT/Housing/Applicant.cs Show resolved Hide resolved
Gordon360/Models/CCT/Housing/DueDate.cs Show resolved Hide resolved
Gordon360/Models/CCT/Housing/DueDate.cs Show resolved Hide resolved
Gordon360/Models/CCT/Housing/Preference.cs Show resolved Hide resolved
Gordon360/Services/HousingService.cs Show resolved Hide resolved
Gordon360/Services/HousingService.cs Show resolved Hide resolved
Gordon360/Services/HousingService.cs Show resolved Hide resolved
Comment on lines +691 to +701
var existDueDate = _context.DueDate.FirstOrDefault();
if (existDueDate != null)
{
_context.DueDate.Remove(existDueDate);
}
var newDueDate = new DueDate
{
DueDate1 = dueDate
}; ;
await _context.DueDate.AddAsync(newDueDate);
_context.SaveChanges();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use update logic instead of delete and readd.

///Gets an array of school years
/// </summary>
/// <returns> AN array of school years </returns>
public Year[] GetAllSchoolYear()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these Class Years? School years are a different thing.

@ArabellaJi ArabellaJi merged commit 85928c9 into sp-release Apr 3, 2024
4 checks passed
This was referenced Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants