Skip to content

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sjin9
Copy link

@sjin9 sjin9 commented Nov 8, 2023

No description provided.

//try
//{
return StatusCode(StatusCodes.Status201Created, await _parkingLotsService.AddAsync(parkingLotDto));
//}

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)

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();

Choose a reason for hiding this comment

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

Suggestion: use FirstOrDefaultAsync instead.

@jingwang315
Copy link

Good points:

  1. Good implementation for all ACs and sad paths included.
  2. Use 3-layer-architecture and connect to MongoDB.
  3. API are Restful.

To be improved:

  1. Need to check not found case when get by id.

[HttpPost]
public async Task<ActionResult<ParkingLotDto>> AddParkingLotAsync([FromBody] ParkingLotDto parkingLotDto)
{
//try

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

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)

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());

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;

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

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