-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
to test the virtual machine from senior project branch
change column name
…ordon-360-api into housing-add-roommate
…ordon-360-api into housing-add-roommate
…ordon-360-api into housing-add-roommate
Housing Lottery Add Applicants and Preferred Hall
hl-update-database
update string to Json array
update and get due date
Here is the API code for the Housing Lottery Senior Project. In this project, we created five tables and referenced them mainly in the |
There was a problem hiding this 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.
if (viewerGroups.Contains(AuthGroup.HousingAdmin)) | ||
{ | ||
await _housingService.UpdateDueDateAsync(dueDate); | ||
return Ok(); | ||
} | ||
return BadRequest(); |
There was a problem hiding this comment.
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:
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(); | |
There was a problem hiding this comment.
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?
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); |
There was a problem hiding this comment.
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:
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 | |
}); |
There was a problem hiding this comment.
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:
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); |
if (viewerGroups.Contains(AuthGroup.HousingAdmin)) | ||
{ | ||
await _housingService.UpdateDueDateAsync(dueDate); | ||
return Ok(); | ||
} | ||
return BadRequest(); |
There was a problem hiding this comment.
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?
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(); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
add routes to send particular user data to frontend
This PR is to code review and release the senior project branch.