Skip to content

Commit

Permalink
Revert "Semantic domain model/type update (#1718)" (#1732)
Browse files Browse the repository at this point in the history
This reverts commit 991a877.
That commit was not compatible with the data in the database.
  • Loading branch information
imnasnainaec authored Sep 13, 2022
1 parent b5a4fec commit 65b8c4d
Show file tree
Hide file tree
Showing 46 changed files with 341 additions and 1,096 deletions.
17 changes: 16 additions & 1 deletion Backend.Tests/Controllers/ProjectControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BackendFramework.Controllers;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using BackendFramework.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
Expand All @@ -16,6 +17,7 @@ public class ProjectControllerTests
private IUserRepository _userRepo = null!;
private UserRoleRepositoryMock _userRoleRepo = null!;
private IPermissionService _permissionService = null!;
private ISemanticDomainService _semDomService = null!;
private ProjectController _projController = null!;

private User _jwtAuthenticatedUser = null!;
Expand All @@ -27,7 +29,9 @@ public void Setup()
_userRepo = new UserRepositoryMock();
_userRoleRepo = new UserRoleRepositoryMock();
_permissionService = new PermissionServiceMock(_userRepo);
_projController = new ProjectController(_projRepo, _userRoleRepo, _userRepo, _permissionService)
_semDomService = new SemanticDomainService();
_projController = new ProjectController(_projRepo, _semDomService, _userRoleRepo,
_userRepo, _permissionService)
{
// Mock the Http Context because this isn't an actual call avatar controller
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }
Expand Down Expand Up @@ -111,6 +115,17 @@ public void TestDeleteAllProjects()
Assert.That(_projRepo.GetAllProjects().Result, Has.Count.EqualTo(0));
}

[Test]
public void TestParseSemanticDomains()
{
var project = _projRepo.Create(Util.RandomProject()).Result;
var sdList = (List<SemanticDomainWithSubdomains>)(
(ObjectResult)_projController.GetSemDoms(project!.Id).Result).Value!;
Assert.That(sdList, Has.Count.EqualTo(3));
Assert.That(sdList[0].Subdomains, Has.Count.EqualTo(3));
Assert.That(sdList[0].Subdomains[0].Subdomains, Has.Count.EqualTo(3));
}

[Test]
public void TestProjectDuplicateCheck()
{
Expand Down
56 changes: 0 additions & 56 deletions Backend.Tests/Controllers/SemanticDomainControllerTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Backend.Tests/Models/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void TestClone()
{
var system = new WritingSystem { Name = "WritingSystemName", Bcp47 = "en", Font = "calibri" };
var project = new Project { Name = "ProjectName", VernacularWritingSystem = system };
var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1" };
var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1", Description = "text" };
project.SemanticDomains.Add(domain);

var customField = new CustomField { Name = "CustomFieldName", Type = "type" };
Expand Down
131 changes: 0 additions & 131 deletions Backend.Tests/Models/SemanticDomainTest.cs

This file was deleted.

19 changes: 19 additions & 0 deletions Backend.Tests/Models/WordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,23 @@ public void TestHashCode()
);
}
}

public class SemanticDomainTests
{
private const string Name = "Home";

[Test]
public void TestEquals()
{
var domain = new SemanticDomain { Name = Name };
Assert.That(domain.Equals(new SemanticDomain { Name = Name }));
}

[Test]
public void TestEqualsNull()
{
var domain = new SemanticDomain { Name = Name };
Assert.IsFalse(domain.Equals(null));
}
}
}
1 change: 1 addition & 0 deletions Backend.Tests/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static SemanticDomain RandomSemanticDomain(string? id = null)
{
Name = RandString(),
Id = id ?? RandString(),
Description = RandString()
};
}

Expand Down
28 changes: 26 additions & 2 deletions Backend/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ public class ProjectController : Controller
private readonly IUserRepository _userRepo;
private readonly IUserRoleRepository _userRoleRepo;
private readonly IPermissionService _permissionService;
private readonly ISemanticDomainService _semDomService;

public ProjectController(IProjectRepository projRepo, IUserRoleRepository userRoleRepo,
IUserRepository userRepo, IPermissionService permissionService)
public ProjectController(IProjectRepository projRepo, ISemanticDomainService semDomService,
IUserRoleRepository userRoleRepo, IUserRepository userRepo, IPermissionService permissionService)
{
_projRepo = projRepo;
_userRepo = userRepo;
_userRoleRepo = userRoleRepo;
_permissionService = permissionService;
_semDomService = semDomService;
}

/// <summary> Returns all <see cref="Project"/>s </summary>
Expand Down Expand Up @@ -206,6 +208,28 @@ public async Task<IActionResult> DeleteProject(string projectId)
return NotFound();
}

/// <summary>
/// UNUSED: Returns tree of <see cref="SemanticDomainWithSubdomains"/> for specified <see cref="Project"/>
/// </summary>
[AllowAnonymous]
[HttpGet("{projectId}/semanticdomains", Name = "GetSemDoms")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SemanticDomainWithSubdomains>))]
public async Task<IActionResult> GetSemDoms(string projectId)
{
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
{
return Forbid();
}

var proj = await _projRepo.GetProject(projectId);
if (proj is null)
{
return NotFound(projectId);
}
var result = _semDomService.ParseSemanticDomains(proj);
return Ok(result);
}

[HttpGet("duplicate/{projectName}", Name = "ProjectDuplicateCheck")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))]
public async Task<IActionResult> ProjectDuplicateCheck(string projectName)
Expand Down
67 changes: 0 additions & 67 deletions Backend/Controllers/SemanticDomainController.cs

This file was deleted.

Loading

0 comments on commit 65b8c4d

Please sign in to comment.