-
Notifications
You must be signed in to change notification settings - Fork 4
homework #2
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?
homework #2
Conversation
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.
一些反馈
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<List<ParkingLot>>> GetAllAsync(int? pageIndex, 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.
pageSize 暂时没有需要更新的需求,可以定义为常量,不暴露给客户,允许其修改
} | ||
public async Task<ParkingLot> CreateAsync( ParkingLotDto parkingLotDto) | ||
{ | ||
if (parkingLotDto.Capacity < 10) throw new InvaildCapacityException(); |
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.
定义常量
{ | ||
var skip = (pageIndex - 1) * pageSize; | ||
var query = _parkingLotCollection.Find(a => true); | ||
var parkinglots = await query.Skip(skip).Limit(pageSize).ToListAsync(); |
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.
好,没有在内存中分页
} | ||
|
||
[HttpPut("{id}")] | ||
public async Task<ActionResult> UpdateAsync(string id, [FromBody] ParkingLotDto 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.
Probably you could define a new DTO with capacity only since we only modify capacity.
|
||
internal async Task<ParkingLot> UpdateAsync(string id, ParkingLotDto parkingLotDto) | ||
{ | ||
return await _parkingLotRepository.Update(id, parkingLotDto.ToModel()); |
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.
Probably could check capacity is less than 10
Well:
Less well:
|
No description provided.