Skip to content

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

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

Conversation

BenfenYU
Copy link

@BenfenYU BenfenYU commented Nov 8, 2023

No description provided.

Copy link

@JCLTW JCLTW left a 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)
Copy link

Choose a reason for hiding this comment

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

这里ParkingLot 是数据的实体,传入和返回的传输对象是DTO对象

Copy link

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

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)
Copy link

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

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)
Copy link

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

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
Copy link

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)
Copy link

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 =>
Copy link

Choose a reason for hiding this comment

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

注释没用就删了吧


namespace ParkingLotApi.DTOs
{
public class ParkingLotDto

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

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;

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 _))

Choose a reason for hiding this comment

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

check id invalid, nb

@XinwenXiang
Copy link

XinwenXiang commented Nov 9, 2023

Well:

  • Baby step commit message, make good progress.
  • Clear exception definition and project structure.
  • Handle repeat name situation

May can do better:

  • dto, models name in code.

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