Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/ASP.NET/v17/.wsuo
Binary file not shown.
139 changes: 139 additions & 0 deletions .vs/ASP.NET/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

.vs папку не нужно пушить в репозиторий

"Version": 1,
"WorkspaceRootPath": "C:\\Users\\\u041C\u0430\u0448\u0438\u043D\u0430\\Desktop\\OTUS_2025\\HomeWorks\\HW2\\ASP.NET\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": -1,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:131:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:132:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:133:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:133:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:134:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:135:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:139:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:138:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:141:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:143:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:140:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:142:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:147:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:149:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:148:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:151:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:152:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:153:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:154:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:155:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:157:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:158:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:159:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:160:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:161:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:162:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:163:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:156:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
},
{
"$type": "Bookmark",
"Name": "ST:129:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
},
{
"$type": "Bookmark",
"Name": "ST:130:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ public interface IRepository<T> where T: BaseEntity
Task<IEnumerable<T>> GetAllAsync();

Task<T> GetByIdAsync(Guid id);

Task<T> CreateAsync(T entity);

void Update(T entity);

void Delete(Guid id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public Task<T> GetByIdAsync(Guid id)
{
return Task.FromResult(Data.FirstOrDefault(x => x.Id == id));
}

public Task<T> CreateAsync(T entity)
{
Data = Data.Concat(new[] { entity });
return Task.FromResult(entity);
}

public void Update(T entity)
{
var dataList = Data.ToList();
var indexbyId = dataList.FindIndex(t => t.Id == entity.Id);
if (indexbyId == -1)
{
dataList[indexbyId] = entity;
}
Data = dataList.AsEnumerable();
}

public void Delete(Guid id)
{
Data = Data.Where(T => T.Id != id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using PromoCodeFactory.Core.Abstractions.Repositories;
using PromoCodeFactory.Core.Domain.Administration;
using PromoCodeFactory.WebHost.Models;
using PromoCodeFactory.WebHost.Request;

namespace PromoCodeFactory.WebHost.Controllers
{
Expand Down Expand Up @@ -70,5 +71,91 @@ public async Task<ActionResult<EmployeeResponse>> GetEmployeeByIdAsync(Guid id)

return employeeModel;
}

/// <summary>
/// Получить неполные данные сотрудника по Id
/// </summary>
/// <returns></returns>
[HttpGet("short/{id:guid}", Name = "GetEmployeeShort")]
[ProducesResponseType(typeof(EmployeeShortResponse), 200)]
[ProducesResponseType(404)]
public async Task<ActionResult<EmployeeShortResponse>> GetShortEmployeeByIdAsync(Guid id)
{
var employee = await _employeeRepository.GetByIdAsync(id);

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

var employeeModel = new EmployeeShortResponse()
{
Id = employee.Id,
Email = employee.Email,
FullName = employee.FullName,
};

return Ok(employeeModel);
}

/// <summary>
/// Добавить нового сотрудника
/// </summary>
/// <param name="employeeRequest"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType(typeof(EmployeeResponse), 201)]
[ProducesResponseType(400)]
public async Task<ActionResult> CreateEmployeeAsync(CreateEmployeeRequest employeeRequest)
{
var employee = new Employee()
{
Id = Guid.NewGuid(),
Email = employeeRequest.Email,
Roles = new List<Role>(),
FirstName = employeeRequest.FirstName,
LastName = employeeRequest.LastName,
AppliedPromocodesCount = employeeRequest.AppliedPromocodesCount
};
var createdEmployee = await _employeeRepository.CreateAsync(employee);
if (createdEmployee == null) return Problem("Не удалось создать сотрудника");
var employeeShortResponse = new EmployeeShortResponse()
{
Id = createdEmployee.Id,
Email = createdEmployee.Email,
FullName = createdEmployee.FullName,
};

return CreatedAtRoute("GetEmployeeShort", new { id = createdEmployee.Id }, employeeShortResponse);
}

[HttpPut("{id:guid}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public async Task<IActionResult> Update(Guid id, UpdateEmployeeRequest request)
{
var employeeExist = await _employeeRepository.GetByIdAsync(id);

if (employeeExist == null)
return NotFound();

employeeExist.Email = request.Email;
employeeExist.FirstName = request.FirstName;
employeeExist.LastName = request.LastName;
employeeExist.AppliedPromocodesCount = request.AppliedPromocodesCount;

_employeeRepository.Update(employeeExist);
return Ok(id);
}

[HttpDelete("{id:guid}")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult Delete(Guid id)
{
_employeeRepository.Delete(id);
return NoContent();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<ProjectReference Include="..\PromoCodeFactory.DataAccess\PromoCodeFactory.DataAccess.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace PromoCodeFactory.WebHost.Request
{
public class CreateEmployeeRequest
{
public string FirstName { get; set; }

public string LastName { get; set; }

public string Email { get; set; }

public int AppliedPromocodesCount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace PromoCodeFactory.WebHost.Request
{
public class UpdateEmployeeRequest
{
public string FirstName { get; set; }

public string LastName { get; set; }

public string Email { get; set; }

public int AppliedPromocodesCount { get; set; }
}
}
29 changes: 29 additions & 0 deletions Homeworks/Base/src/PromoCodeFactory.WebHost/wwwroot/Test_HTTP.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@baseURL = https://localhost:5001

###
GET {{baseURL}}/api/v1/Employees

###
POST {{baseURL}}/api/v1/Employees
Content-Type: application/json

{
"firstName": "Ivan",
"lastName": "Petrov",
"email": "[email protected]",
"appliedPromocodesCount": 0
}

###
PUT {{baseURL}}/api/v1/Employees/f766e2bf-340a-46ea-bff3-f1700b435895
Content-Type: application/json

{
"firstName": "����",
"lastName": "�������",
"email": "[email protected]",
"appliedPromocodesCount": 5
}

###
DELETE {{baseURL}}/api/v1/Employees/f766e2bf-340a-46ea-bff3-f1700b435895