-
Notifications
You must be signed in to change notification settings - Fork 3
Shuhan Jin-homework with adult step commit #5
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
base: main
Are you sure you want to change the base?
Conversation
//try | ||
//{ | ||
return StatusCode(StatusCodes.Status201Created, await _parkingLotsService.AddAsync(parkingLotDto)); | ||
//} |
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.
Suggestion:
Remove unused comment
[HttpGet] | ||
public async Task<ActionResult<List<ParkingLot>>> GetOnePageAsync([FromQuery] int? pageIndex) | ||
{ | ||
if (pageIndex == null) |
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.
Good job to check the sad path
|
||
public async Task<ParkingLot> GetById(string ParkingLotId) | ||
{ | ||
return await _parkingLotCollection.Find(p => p.Id == ParkingLotId).FirstAsync(); |
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.
Suggestion: use FirstOrDefaultAsync instead.
Good points:
To be improved:
|
[HttpPost] | ||
public async Task<ActionResult<ParkingLotDto>> AddParkingLotAsync([FromBody] ParkingLotDto parkingLotDto) | ||
{ | ||
//try |
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.
suggestion: remove dead code
pageIndex = 1; | ||
return Ok(await _parkingLotsService.GetOnePageAsync((int)pageIndex)); | ||
} | ||
else |
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.
suggestion: else can be removed, since there is no other branch
public async Task<ActionResult> GetParkingLotByIdAsync(string id) | ||
{ | ||
var parkingLot = await _parkingLotsService.GetByIdAsync(id); | ||
if (parkingLot == null) |
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.
suggestion: avoid return null from method, since it's hard to understand the meaning
throw new InvalidCapacityException(); | ||
} | ||
|
||
return await parkingLotsRepository.CreateParkingLot(parkingLotDto.ToEntity()); |
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.
well: hold transfer to entity logic in DTO
public async Task<List<ParkingLot>> GetOnePageAsync(int pageIndex) | ||
{ | ||
List<ParkingLot> allParkingLots = await parkingLotsRepository.GetAllParkingLots(); | ||
int pageSize = 15; |
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.
suggestion: extract this variable to a constant
No description provided.