Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Search and Filter & Refactor #30

Merged
merged 14 commits into from
Sep 7, 2024
2 changes: 1 addition & 1 deletion mohaymen-codestar-Team02/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
}

[HttpGet("users")]
public async Task<IActionResult> GetAllUsers([FromBody] int pageNumber)
public async Task<IActionResult> GetAllUsers([FromQuery] int pageNumber)
{
var response =
await _adminService.GetUsersPaginated(pageNumber);
return StatusCode((int)response.Type, response);

Check warning on line 28 in mohaymen-codestar-Team02/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / test

Nullable value type may be null.
}

[HttpGet("users/{username}")]
Expand All @@ -33,7 +33,7 @@
{
var response =
await _adminService.GetUserByUsername(username);
return StatusCode((int)response.Type, response);

Check warning on line 36 in mohaymen-codestar-Team02/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / test

Nullable value type may be null.
}

[HttpPost("users")]
Expand All @@ -50,7 +50,7 @@
var response =
await _adminService.CreateUser(user, request.Password, request.Roles);

return StatusCode((int)response.Type, response);

Check warning on line 53 in mohaymen-codestar-Team02/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / test

Nullable value type may be null.
}

[HttpDelete("users/{username}")]
Expand All @@ -64,7 +64,7 @@
var response =
await _adminService.DeleteUser(user);

return StatusCode((int)response.Type, response);

Check warning on line 67 in mohaymen-codestar-Team02/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / test

Nullable value type may be null.
}

[HttpPut("users/update/{username}")]
Expand All @@ -79,7 +79,7 @@
};

ServiceResponse<GetUserDto?> response = await _adminService.UpdateUser(updateUser);
return StatusCode((int)response.Type, response);

Check warning on line 82 in mohaymen-codestar-Team02/Controllers/AdminController.cs

View workflow job for this annotation

GitHub Actions / test

Nullable value type may be null.
}

[HttpGet("roles")]
Expand Down
29 changes: 28 additions & 1 deletion mohaymen-codestar-Team02/Controllers/AnalystController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using mohaymen_codestar_Team02.Dto;
using mohaymen_codestar_Team02.Dto.GraphDTO;
using mohaymen_codestar_Team02.Models;
using mohaymen_codestar_Team02.Services.AnalystService;
using mohaymen_codestar_Team02.Services.DataAdminService;

namespace mohaymen_codestar_Team02.Controllers;

public class AnalystController : ControllerBase
{
private readonly IAnalystService AnalystService;

public AnalystController(IAnalystService analystService)
public AnalystController(IAnalystService analystService, IDataAdminService dataAdminService)
{
AnalystService = analystService;
}
Expand All @@ -26,4 +29,28 @@ public async Task<IActionResult> ExpandVertex([FromQuery] GraphQueryInfoDto grap
var Response = await AnalystService.GetTheVertexNeighbor(graphQueryInfoDto, vertexId);
return StatusCode((int)Response.Type, Response);
}

[HttpPost("Analyst")]
public async Task<IActionResult> DisplayDataSetAsGraph([FromBody]FilterGraphDto filterGraphDto)
{
ServiceResponse<DisplayGraphDto> response =
await AnalystService.DisplayGeraphData(filterGraphDto.DatasetId, filterGraphDto.SourceIdentifier,
filterGraphDto.TargetIdentifier, filterGraphDto.VertexIdentifier, filterGraphDto.VertexAttributeValues, filterGraphDto.EdgeAttributeValues);
response.Data.GraphId = filterGraphDto.DatasetId;
return StatusCode((int)response.Type, response);
}

[HttpGet("Analyst/Vertex/{id}")]
public async Task<IActionResult> DisplayVertexAttributes(long id)
{
var response = AnalystService.GetVertexAttributes(id);
return StatusCode((int)response.Type, response);
}

[HttpGet("Analyst/Edge/{id}")]
public async Task<IActionResult> DisplayEdgeAttributes(long id)
{
var response = AnalystService.GetEdgeAttributes(id);
return StatusCode((int)response.Type, response);
}
}
33 changes: 9 additions & 24 deletions mohaymen-codestar-Team02/Controllers/DataAdminController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using mohaymen_codestar_Team02.Dto;
using mohaymen_codestar_Team02.Dto.GraphDTO;
using mohaymen_codestar_Team02.Dto.StoreDataDto;
using mohaymen_codestar_Team02.Models;
Expand All @@ -14,7 +15,7 @@ public class DataAdminController : ControllerBase
{
private readonly IDataAdminService _dataAdminService;
private readonly IFileReader _fileReader;

public DataAdminController(IDataAdminService dataAdminService,
IFileReader fileReader)
{
Expand Down Expand Up @@ -46,44 +47,28 @@ public IActionResult GetDataSetsList()
var response = _dataAdminService.DisplayDataSet();
return StatusCode((int)response.Type, response);
}

[HttpGet("DataSets/{dataSetId}")]
public async Task<IActionResult> DisplayDataSetAsGraph(long dataSetId, [FromQuery] string vertexIdentifier,
[FromQuery] string sourceIdentifier, [FromQuery] string targetIdentifier)

[HttpPost("DataSets/Graph")]
public async Task<IActionResult> DisplayDataSetAsGraph(GetGraphDto getGraphDto)
{
ServiceResponse<DisplayGraphDto> response =
await _dataAdminService.DisplayGeraphData(dataSetId, sourceIdentifier,
targetIdentifier, vertexIdentifier);
response.Data.GraphId = dataSetId;
await _dataAdminService.DisplayGeraphData(getGraphDto.DatasetId, getGraphDto.SourceIdentifier,
getGraphDto.TargetIdentifier, getGraphDto.VertexIdentifier);
response.Data.GraphId = getGraphDto.DatasetId;
return StatusCode((int)response.Type, response);
}


[HttpGet("DataSets/Vertices/{objectId}")]
public async Task<IActionResult> DisplayVertexDetails(string objectId)
{
var respond = _dataAdminService.GetVertexDetail(objectId);
return StatusCode((int)respond.Type, respond);
}
}

[HttpGet("DataSets/Edges/{objectId}")]
public async Task<IActionResult> DisplayEdgeDetails(string objectId)
{
var respond = _dataAdminService.GetEdgeDetail(objectId);
return StatusCode((int)respond.Type, respond);
}

[HttpGet("DataSets/Vertex/{id}")]
public async Task<IActionResult> DisplayVertexAttributes(long id)
{
var response = _dataAdminService.GetVertexAttributes(id);
return StatusCode((int)response.Type, response);
}

[HttpGet("DataSets/Edge/{id}")]
public async Task<IActionResult> DisplayEdgeAttributes(long id)
{
var response = _dataAdminService.GetEdgeAttributes(id);
return StatusCode((int)response.Type, response);
}
}
2 changes: 1 addition & 1 deletion mohaymen-codestar-Team02/Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
}

public DbSet<User> Users { get; set; }
public DbSet<User?> Users { get; set; }

Check warning on line 14 in mohaymen-codestar-Team02/Data/DataContext.cs

View workflow job for this annotation

GitHub Actions / test

The type 'mohaymen_codestar_Team02.Models.User?' cannot be used as type parameter 'TEntity' in the generic type or method 'DbSet<TEntity>'. Nullability of type argument 'mohaymen_codestar_Team02.Models.User?' doesn't match 'class' constraint.
public DbSet<Role> Roles { get; set; }
public DbSet<UserRole> UserRoles { get; set; }
public DbSet<VertexEntity> VertexEntities { get; set; }
Expand Down
11 changes: 11 additions & 0 deletions mohaymen-codestar-Team02/Dto/GraphDto/FilterGraphDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace mohaymen_codestar_Team02.Dto;

public class FilterGraphDto
{
public long DatasetId { get; set; }
public string SourceIdentifier { get; set; }
public string TargetIdentifier { get; set; }
public string VertexIdentifier { get; set; }
public Dictionary<string, string> VertexAttributeValues { get; set; }
public Dictionary<string, string> EdgeAttributeValues { get; set; }
}
9 changes: 9 additions & 0 deletions mohaymen-codestar-Team02/Dto/GraphDto/GetGraphDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace mohaymen_codestar_Team02.Dto;

public class GetGraphDto
{
public long DatasetId { get; set; }
public string SourceIdentifier { get; set; }
public string TargetIdentifier { get; set; }
public string VertexIdentifier { get; set; }
}
4 changes: 2 additions & 2 deletions mohaymen-codestar-Team02/Models/Auth/UserRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class UserRole
{
public long UserId { get; set; }

[ForeignKey("UserId")] public virtual User User { get; set; }
[ForeignKey("UserId")] public virtual User? User { get; set; }

public long RoleId { get; set; }
[ForeignKey("RoleId")] public virtual Role Role { get; set; }
[ForeignKey("RoleId")] public virtual Role? Role { get; set; }
}
4 changes: 2 additions & 2 deletions mohaymen-codestar-Team02/Models/Graph/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public class Edge : IEdge<string>
{
public string? Id { get; init; }
public string? Source { get; init; }
public string? Target { get; init; }
public string? Source { get; set; }

Check warning on line 8 in mohaymen-codestar-Team02/Models/Graph/Edge.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of reference types in return type of 'string? Edge.Source.get' doesn't match implicitly implemented member 'string IEdge<string>.Source.get' (possibly because of nullability attributes).
public string? Target { get; set; }

Check warning on line 9 in mohaymen-codestar-Team02/Models/Graph/Edge.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of reference types in return type of 'string? Edge.Target.get' doesn't match implicitly implemented member 'string IEdge<string>.Target.get' (possibly because of nullability attributes).
}
9 changes: 0 additions & 9 deletions mohaymen-codestar-Team02/Models/newModel/Tables.cs

This file was deleted.

2 changes: 1 addition & 1 deletion mohaymen-codestar-Team02/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
options.AddPolicy("AllowSpecificOrigins",
builder =>
{
builder.WithOrigins("http://localhost:4200")
builder.WithOrigins("http://localhost:4200", "https://codestar-g2.abriment.com/")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public interface IAdminService
{
Task<ServiceResponse<List<GetUserDto>?>> GetUsersPaginated(int pageNumber);
Task<ServiceResponse<GetUserDto?>> GetUserByUsername(string? username);
Task<ServiceResponse<GetUserDto?>> CreateUser(User user, string password, List<string> roles);
Task<ServiceResponse<GetUserDto?>> DeleteUser(User user);
Task<ServiceResponse<GetUserDto?>> UpdateUser(User user);
Task<ServiceResponse<GetUserDto?>> CreateUser(User? user, string password, List<string> roles);
Task<ServiceResponse<GetUserDto?>> DeleteUser(User? user);
Task<ServiceResponse<GetUserDto?>> UpdateUser(User? user);
Task<ServiceResponse<List<GetRoleDto>>> GetAllRoles();
Task<ServiceResponse<GetUserDto?>> AddRole(User user, Role role);
Task<ServiceResponse<GetUserDto?>> DeleteRole(User user, Role role);
Task<ServiceResponse<GetUserDto?>> AddRole(User? user, Role? role);
Task<ServiceResponse<GetUserDto?>> DeleteRole(User? user, Role? role);
}
10 changes: 5 additions & 5 deletions mohaymen-codestar-Team02/Services/Administration/AdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task<ServiceResponse<List<GetRoleDto>>> GetAllRoles()
return new ServiceResponse<List<GetRoleDto>>(roles, ApiResponseType.Success, Resources.UsersRetrievedMassage);
}

public async Task<ServiceResponse<GetUserDto?>> CreateUser(User user, string password, List<string> roles)
public async Task<ServiceResponse<GetUserDto?>> CreateUser(User? user, string password, List<string> roles)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
Expand Down Expand Up @@ -136,7 +136,7 @@ private bool IsRoleMatching(List<string> roles, DataContext context)
return matchingRoles;
}

public async Task<ServiceResponse<GetUserDto?>> DeleteUser(User user)
public async Task<ServiceResponse<GetUserDto?>> DeleteUser(User? user)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
Expand Down Expand Up @@ -166,7 +166,7 @@ private bool IsRoleMatching(List<string> roles, DataContext context)
Resources.UserDeletionSuccessfulMessage);
}

public async Task<ServiceResponse<GetUserDto?>> UpdateUser(User user)
public async Task<ServiceResponse<GetUserDto?>> UpdateUser(User? user)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
Expand Down Expand Up @@ -196,7 +196,7 @@ private bool IsRoleMatching(List<string> roles, DataContext context)
Resources.UserUpdateSuccessfulyMessage);
}

public async Task<ServiceResponse<GetUserDto?>> AddRole(User user, Role role)
public async Task<ServiceResponse<GetUserDto?>> AddRole(User? user, Role? role)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
Expand Down Expand Up @@ -237,7 +237,7 @@ private bool IsRoleMatching(List<string> roles, DataContext context)
Resources.RoleAddedSuccessfulyMassage);
}

public async Task<ServiceResponse<GetUserDto?>> DeleteRole(User user, Role role)
public async Task<ServiceResponse<GetUserDto?>> DeleteRole(User? user, Role? role)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
Expand Down
44 changes: 41 additions & 3 deletions mohaymen-codestar-Team02/Services/AnalystService/AnalystService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ namespace mohaymen_codestar_Team02.Services.AnalystService;
public class AnalystService : IAnalystService
{
private readonly IServiceProvider _serviceProvider;
private readonly IVertexService _vertexService;
private readonly IEdgeService _edgeService;
private readonly IGraphService _graphService;

public AnalystService(IServiceProvider serviceProvider)
public AnalystService(IServiceProvider serviceProvider, IVertexService vertexService, IEdgeService edgeService, IGraphService graphService)
{
_serviceProvider = serviceProvider;
_vertexService = vertexService;
_edgeService = edgeService;
_graphService = graphService;
}

private DataGroup JoinTheEdgeTable(IQueryable<DataGroup> validDataSetTable, GraphQueryInfoDto graphQueryInfoDto)
Expand Down Expand Up @@ -130,7 +136,7 @@ public async Task<ServiceResponse<DisplayGraphDto>> GetTheVertexNeighbor(GraphQu
validVertexLabel.Add(source.StringValue);
validVertexLabel.Add(target.StringValue);
validEdges.Add(new Edge()
{ Id = edgeValue.Id, Source = source.ObjectId, Target = target.ObjectId });
{ Id = edgeValue.Id, Source = source.ObjectId, Target = target.ObjectId });
}
}
}
Expand All @@ -151,10 +157,42 @@ public async Task<ServiceResponse<DisplayGraphDto>> GetTheVertexNeighbor(GraphQu

Console.WriteLine("finish the creating of vertex");
var responseData = new DisplayGraphDto()
{ GraphId = graphQueryInfoDto.datasetId, Edges = validEdges, Vertices = resultVertex };
{ GraphId = graphQueryInfoDto.datasetId, Edges = validEdges, Vertices = resultVertex };
time.Stop();
Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@ that take (" + time.ElapsedMilliseconds +
") milieSec to find the VertexNeighbor @@@@@@@@@@@@@@@@@@@@@@@@@@@@");
return new ServiceResponse<DisplayGraphDto>(responseData, ApiResponseType.Success, string.Empty);
}

public async Task<ServiceResponse<DisplayGraphDto>> DisplayGeraphData(long databaseId,
string sourceEdgeIdentifierFieldName,
string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName, Dictionary<string, string> vertexAttributeValus, Dictionary<string, string> edgeAttributeValues)
{
var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, vertexAttributeValus);
var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName,
destinationEdgeIdentifierFieldName, edgeAttributeValues);
var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName,
destinationEdgeIdentifierFieldName);

var dto = new DisplayGraphDto()
{
Vertices = graph.vertices,
Edges = graph.edges
};
return new ServiceResponse<DisplayGraphDto>(dto, ApiResponseType.Success,
Resources.GraphFetchedSuccessfullyMessage);
}

public ServiceResponse<List<GetAttributeDto>> GetVertexAttributes(long vertexEntityId)
{
var att = _vertexService.GetVertexAttributes(vertexEntityId);
return new ServiceResponse<List<GetAttributeDto>>(att, ApiResponseType.Success, "");
}

public ServiceResponse<List<GetAttributeDto>> GetEdgeAttributes(long edgeEntityId)
{
var att = _edgeService.GetEdgeAttributes(edgeEntityId);
return new ServiceResponse<List<GetAttributeDto>>(att, ApiResponseType.Success, "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ namespace mohaymen_codestar_Team02.Services.AnalystService;
public interface IAnalystService
{
Task<ServiceResponse<DisplayGraphDto>> GetTheVertexNeighbor(GraphQueryInfoDto graphQueryInfoDto, string vertexId);

Task<ServiceResponse<DisplayGraphDto>> DisplayGeraphData(long databaseId,
string sourceEdgeIdentifierFieldName,
string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName,
Dictionary<string, string> vertexAttributeValus, Dictionary<string, string> edgeAttributeValues);

ServiceResponse<List<GetAttributeDto>> GetVertexAttributes(long vertexEntityId);

ServiceResponse<List<GetAttributeDto>> GetEdgeAttributes(long edgeEntityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ Task<ServiceResponse<DisplayGraphDto>> DisplayGeraphData(long dataSetId, string

ServiceResponse<DetailDto> GetVertexDetail(string objectId);
ServiceResponse<DetailDto> GetEdgeDetail(string objectId);

ServiceResponse<List<GetAttributeDto>> GetVertexAttributes(long vertexEntityId);

ServiceResponse<List<GetAttributeDto>> GetEdgeAttributes(long edgeEntityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ public ServiceResponse<List<GetDataGroupDto>> DisplayDataSet()
return new ServiceResponse<List<GetDataGroupDto>>(dataGroupDtos, ApiResponseType.Success, "");
}

public async Task<ServiceResponse<DisplayGraphDto>> DisplayGeraphData(long databaseName,
public async Task<ServiceResponse<DisplayGraphDto>> DisplayGeraphData(long databaseId,
string sourceEdgeIdentifierFieldName,
string destinationEdgeIdentifierFieldName, string vertexIdentifierFieldName)
{
var graph = _graphService.GetGraph(databaseName, sourceEdgeIdentifierFieldName,
destinationEdgeIdentifierFieldName,
vertexIdentifierFieldName);
var vertices = _vertexService.GetAllVertices(databaseId, vertexIdentifierFieldName, new Dictionary<string, string>(){});
var edges = _edgeService.GetAllEdges(databaseId, sourceEdgeIdentifierFieldName,
destinationEdgeIdentifierFieldName, new Dictionary<string, string>(){});
var graph = _graphService.GetGraph(vertices, edges, vertexIdentifierFieldName, sourceEdgeIdentifierFieldName,
destinationEdgeIdentifierFieldName);

var dto = new DisplayGraphDto()
{
Expand All @@ -121,16 +123,4 @@ public ServiceResponse<DetailDto> GetEdgeDetail(string objectId)
return new ServiceResponse<DetailDto>(_edgeService.GetEdgeDetails(objectId), ApiResponseType.Success,
string.Empty);
}

public ServiceResponse<List<GetAttributeDto>> GetVertexAttributes(long vertexEntityId)
{
var att = _vertexService.GetVertexAttributes(vertexEntityId);
return new ServiceResponse<List<GetAttributeDto>>(att, ApiResponseType.Success, "");
}

public ServiceResponse<List<GetAttributeDto>> GetEdgeAttributes(long edgeEntityId)
{
var att = _edgeService.GetEdgeAttributes(edgeEntityId);
return new ServiceResponse<List<GetAttributeDto>>(att, ApiResponseType.Success, "");
}
}
Loading
Loading