Skip to content

Commit da546e4

Browse files
committed
Return a different error code for deactivated records
1 parent 7027a22 commit da546e4

File tree

25 files changed

+154
-23
lines changed

25 files changed

+154
-23
lines changed

TeachingRecordSystem/src/TeachingRecordSystem.Api/ApiError.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static class ErrorCodes
3636
public static int UnableToChangeFailProfessionalStatusStatus => 10055;
3737
public static int UnableToChangeWithdrawnProfessionalStatusStatus => 10056;
3838
public static int PiiUpdatesForbiddenPersonHasEyts => 10057;
39+
public static int PersonInactive => 10058;
3940
}
4041

4142
public static ApiError PersonNotFound(string trn, DateOnly? dateOfBirth = null, string? nationalInsuranceNumber = null)
@@ -55,6 +56,13 @@ public static ApiError PersonNotFound(string trn, DateOnly? dateOfBirth = null,
5556
return new ApiError(ErrorCodes.PersonNotFound, title, detail);
5657
}
5758

59+
public static ApiError PersonInactive(string trn)
60+
{
61+
var title = $"Person is inactive.";
62+
63+
return new ApiError(ErrorCodes.PersonInactive, title);
64+
}
65+
5866
public static ApiError SpecifiedResourceUrlDoesNotExist(string url) =>
5967
new(ErrorCodes.SpecifiedResourceUrlDoesNotExist, "The specified resource does not exist.", $"URL: '{url}'");
6068

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/GetPerson.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public async Task<ApiResult<GetPersonResult>> HandleAsync(GetPersonCommand comma
178178
}
179179

180180
var contactDetail = await crmQueryDispatcher.ExecuteQueryAsync(
181-
new GetActiveContactDetailByTrnQuery(
181+
new GetContactDetailByTrnQuery(
182182
command.Trn,
183183
new ColumnSet(
184184
Contact.Fields.FirstName,
@@ -203,6 +203,11 @@ public async Task<ApiResult<GetPersonResult>> HandleAsync(GetPersonCommand comma
203203
return ApiError.PersonNotFound(command.Trn);
204204
}
205205

206+
if (contactDetail.Contact.StateCode is ContactState.Inactive)
207+
{
208+
return ApiError.PersonInactive(command.Trn);
209+
}
210+
206211
// If a DateOfBirth or NationalInsuranceNumber was provided, ensure the record we've retrieved with the TRN matches
207212
if (command.DateOfBirth is DateOnly dateOfBirth &&
208213
contactDetail.Contact.BirthDate.ToDateOnlyWithDqtBstFix(isLocalTime: false) != dateOfBirth)

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240101/Controllers/TeacherController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public async Task<IActionResult> GetAsync(
3535
var result = await handler.HandleAsync(command);
3636

3737
return result.ToActionResult(r => Ok(mapper.Map<GetTeacherResponse>(r)))
38+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden)
3839
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden);
3940
}
4041
}

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240101/Controllers/TeachersController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public async Task<IActionResult> GetAsync(
3636
var result = await handler.HandleAsync(command);
3737

3838
return result.ToActionResult(r => Ok(mapper.Map<GetTeacherResponse>(r)))
39-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound);
39+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound)
40+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status404NotFound);
4041
}
4142

4243
[HttpPost("name-changes")]

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240416/Controllers/TeacherController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public async Task<IActionResult> GetAsync(
3535
var result = await handler.HandleAsync(command);
3636

3737
return result.ToActionResult(r => Ok(mapper.Map<GetTeacherResponse>(r)))
38-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden);
38+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden)
39+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status403Forbidden);
3940
}
4041
}

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240416/Controllers/TeachersController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public async Task<IActionResult> GetAsync(
3737
var result = await handler.HandleAsync(command);
3838

3939
return result.ToActionResult(r => Ok(mapper.Map<GetTeacherResponse>(r)))
40-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound);
40+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound)
41+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status404NotFound);
4142
}
4243
}

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240606/Controllers/PersonController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public async Task<IActionResult> GetAsync(
3535
var result = await handler.HandleAsync(command);
3636

3737
return result.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r)))
38-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden);
38+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden)
39+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status403Forbidden);
3940
}
4041

4142
[HttpPost("name-changes")]

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240606/Controllers/PersonsController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public async Task<IActionResult> GetAsync(
3737
var result = await handler.HandleAsync(command);
3838

3939
return result.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r)))
40-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound);
40+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound)
41+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status404NotFound);
4142
}
4243

4344
[HttpGet("")]

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240920/Controllers/PersonController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public async Task<IActionResult> GetAsync(
3535
var result = await handler.HandleAsync(command);
3636

3737
return result.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r)))
38-
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden);
38+
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status403Forbidden)
39+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status403Forbidden);
3940
}
4041
}

TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240920/Controllers/PersonsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async Task<IActionResult> GetAsync(
4040

4141
return result.ToActionResult(r => Ok(mapper.Map<GetPersonResponse>(r)))
4242
.MapErrorCode(ApiError.ErrorCodes.PersonNotFound, StatusCodes.Status404NotFound)
43+
.MapErrorCode(ApiError.ErrorCodes.PersonInactive, StatusCodes.Status404NotFound)
4344
.MapErrorCode(ApiError.ErrorCodes.ForbiddenForAppropriateBody, StatusCodes.Status403Forbidden);
4445
}
4546

0 commit comments

Comments
 (0)