Skip to content

Kailin company api #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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lklgithub
Copy link

No description provided.

{
// Given
Company companyGiven = new Company("slb");
HttpResponseMessage httpResponseMessage = await httpClient.PostAsJsonAsync("/api/companies",companyGiven);
Copy link

Choose a reason for hiding this comment

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

Good: Use one httpResponseMessage to handle all httpResponses. easy to read!👍

{
// Given
await ClearDataAsync();
Company companyGiven = new Company("slb");
Copy link

Choose a reason for hiding this comment

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

To Improve: Better use CreateCompanyRequest and CreateEmployeeRequest since FE doesn't provide ID


## AC9 Update Employee
PUT https://{{hostname}}:{{port}}/api/companies/{companyId}/employees/{employeeId}

Choose a reason for hiding this comment

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

suggestion: add request body for PUT

## DELETE /api/companies/companyID/employees/{employeeId}

## AC6 Create Employee API
PUT https://{{hostname}}:{{port}}/api/companies/{companyId}/employees

Choose a reason for hiding this comment

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

suggestion: use POST instead of PUT to create resource

}

var startIndex = (pageIndex - 1) * pageSize;
var pagedCompanies = companies.Skip(startIndex).Take(pageSize).ToList();

Choose a reason for hiding this comment

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

👍 nice to use Skip Take

var company = companies.Find(c => c.Id == companyId);
if (company is null)
{
return BadRequest();

Choose a reason for hiding this comment

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

suggestion: return 404 if the company can not be found

[HttpGet]
public ActionResult<List<Company>> GetAllByIndex([FromQuery] int pageSize = 0, [FromQuery] int pageIndex = 1)
{
if (pageSize <= 0 || pageIndex <= 0)
Copy link

Choose a reason for hiding this comment

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

Good: Give a init pageSize and pageIndex value. Stick with the rules!🤩

@celianiu
Copy link

celianiu commented Nov 7, 2023

Good: Smalls step & clear code logic easy to read;
To Improve: Write API doc before write 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