-
Notifications
You must be signed in to change notification settings - Fork 4
20231108 ParkingLot Apis implemented #1
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
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 mongoDB = client.GetDatabase(dbOptions.Value.DatabaseName); | ||
collection = mongoDB.GetCollection<ParkingLotDto>(dbOptions.Value.CollectionName); | ||
} | ||
public async Task<ParkingLotDto> AddOneAsync(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.
这里ParkingLot 是数据的实体,传入和返回的传输对象是DTO对象
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.
命名需要调整一下
{ | ||
if (pageIndex < 1) | ||
{ | ||
throw new InvalidCapacityException(); |
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.
Page size 小于1的需求需要澄清,另外异常类型此处为什么需要跑出InvaliCapaciy
return await _parkingLotRepository.GetAllAsync(); | ||
} | ||
|
||
public async Task<List<ParkingLotDto>> GetByPageIndexAsync(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 目前需求为固定的15,可以定义为常量,不暴露给客户端
throw new InvalidCapacityException(); | ||
} | ||
var res = await GetAllAsync(); | ||
return res.Skip((pageIndex-1) * pageSize).Take(pageSize).ToList(); |
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.
GetAllAsync() 会读取全量数据,之后在内存中分页存在性能风险
|
||
private async Task ValidateCapacityAndName(int capacity, string name) | ||
{ | ||
if (capacity < 10) |
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.
可以定义为常量
{ | ||
if (!ObjectId.TryParse(id, out _)) | ||
{ | ||
throw new InvalidParkingLotNameOrIdException(); |
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.
ID 不合法抛出什么类型的异常,是一个需要和业务方澄清的需求
@@ -0,0 +1,71 @@ | |||
# For more info on HTTP files go to https://aka.ms/vs/httpfile |
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.
好啊,编写了文档
public class WeatherForecastControllerTest : TestBase | ||
{ | ||
|
||
public WeatherForecastControllerTest(WebApplicationFactory<Program> factory) : base(factory) |
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.
可以删了
protected HttpClient GetClient() | ||
{ | ||
return Factory.CreateClient(); | ||
//return Factory.WithWebHostBuilder(builder => |
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.
注释没用就删了吧
ParkingLotApi/DTOs/ParkingLotDto.cs
Outdated
|
||
namespace ParkingLotApi.DTOs | ||
{ | ||
public class 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.
May not named ParkingLotDto.
@@ -0,0 +1,13 @@ | |||
namespace ParkingLotApi.DTOs | |||
{ | |||
public class ParkingLotDtoRequest |
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.
May just named ParkingLotRequest
{ | ||
public class IdNotExistExceptionFilter : IActionFilter, IOrderedFilter | ||
{ | ||
public int Order => int.MaxValue - 10; |
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.
Actually, IOrderedFilter define exception throw order, you can adjust it according situation.
} | ||
public async Task<ParkingLotDto> AddOneAsync(ParkingLotDto parkingLotDto) | ||
{ | ||
if (parkingLotDto.Id == null || !ObjectId.TryParse(parkingLotDto.Id, out var _)) |
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.
check id invalid, nb
Well:
May can do better:
|
No description provided.