Skip to content

Conversation

@sharpey-mis
Copy link

No description provided.

Task<IEnumerable<T>> GetAllAsync();

Task<T> GetByIdAsync(Guid id);
Task AddAsync(T entity);

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; }

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

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)

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

Choose a reason for hiding this comment

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

Параметром (Id) передаем уже идентификатор записи для обновления и newEmloyee как модель без идентификатора, но с обновляемыми данными. Исправим?

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.

2 participants