-
Notifications
You must be signed in to change notification settings - Fork 125
Homework CRUD Employee #84
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
| Task<IEnumerable<T>> GetAllAsync(); | ||
|
|
||
| Task<T> GetByIdAsync(Guid id); | ||
| Task AddAsync(T entity); |
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.
Желательно возвращать Task<Тип> для Add. Это повысит читабельность, и другой разработчик будет уверен что возвращаемый объект с уже с идентификатором
| public class InMemoryRepository<T>: IRepository<T> where T: BaseEntity | ||
| public class InMemoryRepository<T> : IRepository<T> where T : BaseEntity | ||
| { | ||
| protected IEnumerable<T> Data { get; set; } |
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.
Рекомендую, переменную сделать List<Tип>, чтоб исключить дальнейшую конвертацию в ToList() в CRUD методах
|
|
||
| public Task AddAsync(T entity) | ||
| { | ||
| var list = Data.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.
В начале метода рекомендую проверять параметр(ы) метода на null
Можно сделать ArgumentNullException.ThrowIfNull(<параметр>), это исключит возможные NullReferenceException-ы в дальнейшем
| /// Создать нового сотрудника | ||
| /// </summary> | ||
| [HttpPost] | ||
| public async Task<ActionResult<EmployeeResponse>> CreateEmployeeAsync([FromBody] Employee employee) |
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.
Для параметров controller-а, желательно объявлять специальные классы для запросов, с необходимым только для этого метода набор свойств
| public async Task<IActionResult> UpdateEmployeeAsync(Guid id, [FromBody] Employee newEmployee) | ||
| { | ||
|
|
||
| var employee = await _employeeRepository.GetByIdAsync(newEmployee.Id); |
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) передаем уже идентификатор записи для обновления и newEmloyee как модель без идентификатора, но с обновляемыми данными. Исправим?
No description provided.