Skip to content

Commit

Permalink
Merge pull request #110 from varianter/employee/remove-unnecessary-en…
Browse files Browse the repository at this point in the history
…dpoints

Employee/remove unnecessary endpoints
  • Loading branch information
jonasbrunvoll authored Nov 7, 2023
2 parents d829d2d + ba7d79a commit 57a21e3
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 92 deletions.
3 changes: 0 additions & 3 deletions src/ApplicationCore/Interfaces/IEmployeesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public interface IEmployeesRepository
Task<Employee?> GetEmployeeAsync(string alias, string country);
Task AddOrUpdateEmployeeInformation(Employee employee);

Task<bool> UpdateEmployeeInformation(string alias, string country,
UpdateEmployeeInformation employeeInformation);

/// <summary>
/// Deletes the employee from the database, if they exist, and returns the image url to the employees image blob that needs to be cleaned up
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions src/ApplicationCore/Services/EmployeesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ public Task AddOrUpdateEmployee(Employee employee)
return _employeesRepository.EnsureEmployeesWithEndDateBeforeTodayAreDeleted();
}

public async Task<bool> UpdateEmployeeInformationByAliasAndCountry(string alias, string country,
UpdateEmployeeInformation employeeInformation)
{
return await _employeesRepository.UpdateEmployeeInformation(alias, country, employeeInformation);
}

public async Task<EmergencyContact?> GetEmergencyContactByEmployee(string alias, string country)
{
return await _emergencyContactRepository.GetByEmployee(alias, country);
Expand Down
20 changes: 0 additions & 20 deletions src/Infrastructure/Repositories/EmployeeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,6 @@ await _db.AddAsync(new EmployeeEntity
await _db.SaveChangesAsync();
}

public async Task<bool> UpdateEmployeeInformation(string alias, string country,
UpdateEmployeeInformation employeeInformation)
{
var employee = await GetEmployeeEntity(alias, country);

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

employee.Telephone = employeeInformation.Phone;
employee.AccountNumber = employeeInformation.AccountNumber;
employee.Address = employeeInformation.Address;
employee.ZipCode = employeeInformation.ZipCode;
employee.City = employeeInformation.City;

var changes = await _db.SaveChangesAsync();
return changes > 0;
}

/// <summary>
/// Deletes the employee from the database, if they exist, and returns the image url to the employees image blob that needs to be cleaned up
/// </summary>
Expand Down
19 changes: 0 additions & 19 deletions src/Web/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,6 @@ public async Task<ActionResult<EmployeeExtendedJson>> GetExtendedByAlias(string
return ModelConverters.ToEmployeeExtendedJson(employee);
}

[EnableCors("DashCorsPolicy")]
[HttpPost("information/{country}/{alias}")]
public async Task<ActionResult> UpdateEmployeeInformation(string alias, string country,
[FromBody] UpdateEmployeeInformation employeeInformation)
{
var updateSuccess =
await _employeeService.UpdateEmployeeInformationByAliasAndCountry(alias, country, employeeInformation);
if (updateSuccess)
{
return NoContent();
}

_logger.LogError(
"Can't update EmployeeInformation because there is no matching Employee to alias {alias} and country {country}",
alias, country);
return NotFound();
}


[EnableCors("DashCorsPolicy")]
[HttpPost("emergencyContact/{country}/{alias}")]
public async Task<ActionResult> UpdateEmergencyContact(string alias, string country,

Check warning on line 103 in src/Web/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EmployeesController.UpdateEmergencyContact(string, string, EmergencyContact)'

Check warning on line 103 in src/Web/Controllers/EmployeesController.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EmployeesController.UpdateEmergencyContact(string, string, EmergencyContact)'
Expand Down
44 changes: 0 additions & 44 deletions tests/ComponentTests/Tests/EmployeeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,50 +125,6 @@ public async void Given_EmployeeDoesNotExists_When_CallingEmployeeControllerGETE
employeeResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}

[Fact]
public async void Given_EmployeeExists_When_CallingEmployeeControllerPOSTInformation_Then_UpdateDatabase()
{
// Arrange
var firstSeededEmployee = Seed.GetSeedingEmployees()[0];
var firstSeededEmployeeAlias = firstSeededEmployee!.Email.Split("@").First();
var firstSeededEmployeeCountry = firstSeededEmployee!.Email.Split(".").Last();

const string json = """
{
"Phone": "11223344",
"AccountNumber": "12341234123",
"Address": "Et annet sted",
"ZipCode": "7000",
"City": "Trondheim"
}
""";

// Act
var response =
await _client.PostAsync($"/employees/information/{firstSeededEmployeeCountry}/{firstSeededEmployeeAlias}",
new StringContent(json, Encoding.UTF8, "application/json"));

// Assert
response.StatusCode.Should().Be(HttpStatusCode.NoContent);

var employeeResponse =
await _client.GetAsync(
$"/employees/{firstSeededEmployeeAlias}/extended?country={firstSeededEmployeeCountry}");
var employee =
JsonConvert.DeserializeObject<EmployeeExtendedJson>(await employeeResponse.Content
.ReadAsStringAsync());

employee!.Name.Should().BeEquivalentTo(firstSeededEmployee.Name);
employee!.OfficeName.Should().BeEquivalentTo(firstSeededEmployee.OfficeName);
employee!.Telephone.Should().BeEquivalentTo("11223344");
employee.AccountNumber.Should()
.BeEquivalentTo("12341234123");
employee!.Address.Should()
.BeEquivalentTo("Et annet sted");
employee!.ZipCode.Should().BeEquivalentTo("7000");
employee!.City.Should().BeEquivalentTo("Trondheim");
}

[Fact]
public async void
Given_EmployeeExists_When_CallingEmployeeControllerPOSTEmergencyContact_Then_UpdateDatabase()
Expand Down

0 comments on commit 57a21e3

Please sign in to comment.