Skip to content

Commit 30e5998

Browse files
committed
Revert out-of-scope controller/frontend API change
1 parent 1ad4951 commit 30e5998

5 files changed

Lines changed: 34 additions & 23 deletions

File tree

Backend.Tests/Controllers/WordControllerTests.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,26 @@ public async Task TestRestoreWord()
385385

386386
var result = await _wordController.RestoreWord(ProjId, word.Id);
387387

388-
Assert.That(result, Is.InstanceOf<OkResult>());
388+
Assert.That(result, Is.InstanceOf<OkObjectResult>());
389+
Assert.That(((OkObjectResult)result).Value, Is.True);
390+
Assert.That(await _wordRepo.GetAllWords(ProjId), Does.Contain(word).UsingPropertiesComparer());
391+
Assert.That(await _wordRepo.GetAllFrontier(ProjId), Does.Contain(word).UsingPropertiesComparer());
392+
}
393+
394+
[Test]
395+
public async Task TestRestoreWordAlreadyInFrontier()
396+
{
397+
var word = await _wordRepo.Create(Util.RandomWord(ProjId));
398+
389399
Assert.That(await _wordRepo.GetAllWords(ProjId), Does.Contain(word).UsingPropertiesComparer());
390400
Assert.That(await _wordRepo.GetAllFrontier(ProjId), Does.Contain(word).UsingPropertiesComparer());
401+
var frontierCount = await _wordRepo.GetFrontierCount(ProjId);
402+
403+
var result = await _wordController.RestoreWord(ProjId, word.Id);
404+
405+
Assert.That(result, Is.InstanceOf<OkObjectResult>());
406+
Assert.That(((OkObjectResult)result).Value, Is.False);
407+
Assert.That(await _wordRepo.GetFrontierCount(ProjId), Is.EqualTo(frontierCount));
391408
}
392409

393410
[Test]
@@ -404,20 +421,7 @@ public async Task TestRestoreWordNoPermission()
404421
public async Task TestRestoreWordMissingWord()
405422
{
406423
var wordResult = await _wordController.RestoreWord(ProjId, MissingId);
407-
Assert.That(wordResult, Is.InstanceOf<BadRequestResult>());
408-
}
409-
410-
[Test]
411-
public async Task TestRestoreWordAlreadyInFrontier()
412-
{
413-
var word = await _wordRepo.Create(Util.RandomWord(ProjId));
414-
415-
Assert.That(await _wordRepo.GetAllWords(ProjId), Does.Contain(word).UsingPropertiesComparer());
416-
Assert.That(await _wordRepo.GetAllFrontier(ProjId), Does.Contain(word).UsingPropertiesComparer());
417-
418-
var result = await _wordController.RestoreWord(ProjId, word.Id);
419-
420-
Assert.That(result, Is.InstanceOf<BadRequestResult>());
424+
Assert.That(wordResult, Is.InstanceOf<NotFoundResult>());
421425
}
422426

423427
[Test]

Backend/Controllers/WordController.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ public async Task<IActionResult> UpdateWord(
248248
}
249249

250250
/// <summary> Restore a deleted <see cref="Word"/>. </summary>
251+
/// <returns> bool: true if restored; false if already in frontier. </returns>
251252
[HttpGet("restore/{wordId}", Name = "RestoreWord")]
252-
[ProducesResponseType(StatusCodes.Status200OK)]
253-
[ProducesResponseType(StatusCodes.Status400BadRequest)]
253+
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
254254
[ProducesResponseType(StatusCodes.Status403Forbidden)]
255+
[ProducesResponseType(StatusCodes.Status404NotFound)]
256+
255257
public async Task<IActionResult> RestoreWord(string projectId, string wordId)
256258
{
257259
using var activity = OtelService.StartActivityWithTag(otelTagName, "restoring a word");
@@ -260,8 +262,12 @@ public async Task<IActionResult> RestoreWord(string projectId, string wordId)
260262
{
261263
return Forbid();
262264
}
265+
if (await _wordRepo.GetWord(projectId, wordId) is null)
266+
{
267+
return NotFound();
268+
}
263269

264-
return await _wordService.RestoreFrontierWords(projectId, [wordId]) ? Ok() : BadRequest();
270+
return Ok(await _wordService.RestoreFrontierWords(projectId, [wordId]));
265271
}
266272

267273
/// <summary> Revert words from a dictionary of word ids (key: to revert to; value: from frontier). </summary>

Backend/Models/Sense.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,6 @@ public enum Status
243243
Active,
244244
Deleted,
245245
Duplicate,
246-
Protected,
246+
Protected
247247
}
248248
}

src/api/api/word-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ export const WordApiFp = function (configuration?: Configuration) {
10411041
wordId: string,
10421042
options?: any
10431043
): Promise<
1044-
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>
1044+
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<boolean>
10451045
> {
10461046
const localVarAxiosArgs = await localVarAxiosParamCreator.restoreWord(
10471047
projectId,
@@ -1315,7 +1315,7 @@ export const WordApiFactory = function (
13151315
projectId: string,
13161316
wordId: string,
13171317
options?: any
1318-
): AxiosPromise<void> {
1318+
): AxiosPromise<boolean> {
13191319
return localVarFp
13201320
.restoreWord(projectId, wordId, options)
13211321
.then((request) => request(axios, basePath));

src/backend/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,10 @@ export async function isInFrontier(
959959
export async function restoreWord(
960960
wordId: string,
961961
projectId?: string
962-
): Promise<void> {
962+
): Promise<boolean> {
963963
projectId ||= LocalStorage.getProjectId();
964-
await wordApi.restoreWord({ projectId, wordId }, defaultOptions());
964+
const params = { projectId, wordId };
965+
return (await wordApi.restoreWord(params, defaultOptions())).data;
965966
}
966967

967968
/** Revert word updates given in dictionary of word ids:

0 commit comments

Comments
 (0)