dela
dela
CC#
Created by dela on 8/28/2023 in #help
❔ I don't know where to put handle error in my project
I use DDD in my project and this project makes CRUD. In infrastructure, there are a logic to call a database and I thiking it's a good idea to put a handle error. For example:
public Task<Employee> GetEmployeeById (int id) {
var employee = await _employee.Find(x => x.Id == id).FirstOrDefaultAsync();

if(employee == null){
return NotFound();
}
}
public Task<Employee> GetEmployeeById (int id) {
var employee = await _employee.Find(x => x.Id == id).FirstOrDefaultAsync();

if(employee == null){
return NotFound();
}
}
But I think is a bad practice do that. It's a good practice do that but in a controller?. For example:
[HttpGet("{id}")]
public Task<IActionResult> GetEmployeeById(int id){
var employee = await _employeeRepository.GetEmployee(id);

if(employee == null){
return NotFound();
}

return employee;
}
[HttpGet("{id}")]
public Task<IActionResult> GetEmployeeById(int id){
var employee = await _employeeRepository.GetEmployee(id);

if(employee == null){
return NotFound();
}

return employee;
}
2 replies
CC#
Created by dela on 6/2/2023 in #help
❔ OpenAPI add TAG swagger
Hi, I have an api with two controllers and I'm using swashbuckle to generate the swaggers. What I do is later get the json from the swagger and export it to docusaurus so that the documentation is generated automatically. The problem is that within docusaurus it is not shown divided by tags. For example. I have the controller named "pets" and another controller called "users" I want their respective endpoints to be seen within pets and the same with users. Is there some configuration of swashbuckle or something else that can divide each controller by tags? Thanks
3 replies