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

Feature/save graph #14

Merged
merged 40 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8a94407
initial commit for saving graph feature
Ftm-Sayadzadeh Aug 17, 2024
329b9bf
skelt of the proj
mahdizahedii2005 Aug 17, 2024
5da747f
build : some service added
Aug 18, 2024
5fd9a09
build : database models built
Aug 18, 2024
6d003eb
refactor : class arrangement refactored
Aug 18, 2024
c1b8ff2
fix : add some class
mahdizahedii2005 Aug 18, 2024
5a6df9f
fix : nothing
mahdizahedii2005 Aug 18, 2024
82c88b8
fix : fix EAV bugs and added extra models
Ftm-Sayadzadeh Aug 18, 2024
e3deca3
fix : want to switch between Branch
mahdizahedii2005 Aug 19, 2024
7b2332c
fetch : push
mahdizahedii2005 Aug 19, 2024
d920cad
fix : fix the model input
mahdizahedii2005 Aug 19, 2024
6b5f56b
fix : fix the model long and in and del the value from entity
mahdizahedii2005 Aug 19, 2024
32cdaa4
fix : push for update
mahdizahedii2005 Aug 19, 2024
876a23a
fix : code th Update code
mahdizahedii2005 Aug 19, 2024
1e829f1
feat : add the test
mahdizahedii2005 Aug 20, 2024
c086f04
feat : add servise
mahdizahedii2005 Aug 20, 2024
6fe5492
feat : fix the program cs
mahdizahedii2005 Aug 20, 2024
683b304
fix : make the api rest
mahdizahedii2005 Aug 20, 2024
79ec5c4
fix : save the file
mahdizahedii2005 Aug 20, 2024
5f25302
build : display graph added
Aug 20, 2024
ca4e014
fix : fix the format
mahdizahedii2005 Aug 20, 2024
ef2fed2
merge : merge
mahdizahedii2005 Aug 20, 2024
387b918
fix : fix the counstructor
mahdizahedii2005 Aug 20, 2024
9067847
Merge branch 'main' into feature/save-graph
Ftm-Sayadzadeh Aug 20, 2024
9e669de
fix : just miner changes
Ftm-Sayadzadeh Aug 20, 2024
bb4f330
fix :
mahdizahedii2005 Aug 20, 2024
6c717af
merge
mahdizahedii2005 Aug 20, 2024
e359ae8
refactor : some refactor
Aug 20, 2024
c1ec3c0
Merge remote-tracking branch 'origin/feature/save-graph' into feature…
Aug 20, 2024
a14477f
fix : push
mahdizahedii2005 Aug 20, 2024
03ca7d6
fix : merge
mahdizahedii2005 Aug 20, 2024
1308511
fix :
mahdizahedii2005 Aug 20, 2024
a51a7a5
Merge remote-tracking branch 'origin/feature/save-graph' into feature…
Aug 20, 2024
e80c94f
fix : merge
mahdizahedii2005 Aug 20, 2024
4bd231e
fix : fix te
mahdizahedii2005 Aug 20, 2024
804c564
fix : merge
mahdizahedii2005 Aug 20, 2024
a454850
refactor : just reformat
Ftm-Sayadzadeh Aug 21, 2024
2cbcc68
fix : change sln
Ftm-Sayadzadeh Aug 21, 2024
1f19b16
refactor : just for linting
Ftm-Sayadzadeh Aug 21, 2024
96f7dc2
refactor : just for linting
Ftm-Sayadzadeh Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mohaymen-codestar-Team02.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mohaymen-codestar-Team02", "mohaymen-codestar-Team02\mohaymen-codestar-Team02.csproj", "{4D1C173E-6901-406B-AF51-8272236E98FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mohaymen-codestar-Team02_XUnitTest", "mohaymen-codestar-Team02_XUnitTest\mohaymen-codestar-Team02_XUnitTest.csproj", "{DBCC3406-305C-4B21-AF94-8BF8B78D1040}"
Expand All @@ -18,5 +17,9 @@ Global
{DBCC3406-305C-4B21-AF94-8BF8B78D1040}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBCC3406-305C-4B21-AF94-8BF8B78D1040}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBCC3406-305C-4B21-AF94-8BF8B78D1040}.Release|Any CPU.Build.0 = Release|Any CPU
{28E49A9C-03AF-4843-9757-57D7E096B686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28E49A9C-03AF-4843-9757-57D7E096B686}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28E49A9C-03AF-4843-9757-57D7E096B686}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28E49A9C-03AF-4843-9757-57D7E096B686}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion mohaymen-codestar-Team02/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<IActionResult> Register([FromBody] RegisterUserDto request)
Username = request.Username,
FirstName = request.FirstName,
LastName = request.LastName,
Email = request.Email,
Email = request.Email
};

ServiceResponse<GetUserDto?> response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using mohaymen_codestar_Team02.Models;
using mohaymen_codestar_Team02.Services.Authenticatoin;


namespace mohaymen_codestar_Team02.Controllers;

[ApiController]
Expand Down
48 changes: 48 additions & 0 deletions mohaymen-codestar-Team02/Controllers/DataAdminController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Mvc;
using mohaymen_codestar_Team02.Dto.StoreDataDto;
using mohaymen_codestar_Team02.Services.DataAdminService;
using mohaymen_codestar_Team02.Services.FileReaderService;

namespace mohaymen_codestar_Team02.Controllers;

public class DataAdminController : ControllerBase
{

private readonly IDataAdminService _dataAdminService;
private readonly IFileReader _fileReader;
public DataAdminController(IDataAdminService dataAdminService, IFileReader fileReader)
{
_dataAdminService = dataAdminService;
_fileReader = fileReader;
}
[HttpPost("DataSets")]
public async Task<IActionResult> StoreNewDataSet([FromForm] StoreDataDto storeDataDto)
{
var edgeFile = _fileReader.Read(storeDataDto.EdgeFile);
var vertexFile = _fileReader.Read(storeDataDto.VertexFile);
var response = await _dataAdminService.StoreData(edgeFile, vertexFile, storeDataDto.DataName,
Path.GetFileName(storeDataDto.EdgeFile.FileName), Path.GetFileName(storeDataDto.VertexFile.FileName),
storeDataDto.CreatorUserName);
return StatusCode((int)response.Type, response);
}

[HttpGet("DataSets")]
public void GetDataSetsList()
{
}

[HttpGet("DataSets/{dataSetName}")]
public void DisplayDataSetAsGraph(string dataSetName)
{
}

[HttpGet("DataSets/{dataSetName}/Vertices/{vertexId}")]
public void DisplayVertexDetails(string datasetName, int vertexId)
{
}

[HttpGet("DataSets/{dataSetName}/Edges/{edgeId}")]
public void DisplayEdgeDetails(string datasetName, int edgeId)
{
}
}
10 changes: 10 additions & 0 deletions mohaymen-codestar-Team02/Data/DataContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;
using mohaymen_codestar_Team02.Models;
using mohaymen_codestar_Team02.Models.EdgeEAV;
using mohaymen_codestar_Team02.Models.VertexEAV;

namespace mohaymen_codestar_Team02.Data;

Expand All @@ -12,6 +14,14 @@ public DataContext(DbContextOptions<DataContext> options) : base(options)
public DbSet<User> Users { get; set; }
public DbSet<Role> Roles { get; set; }
public DbSet<UserRole> UserRoles { get; set; }
public DbSet<VertexEntity> VertexEntities { get; set; }
public DbSet<EdgeEntity> EdgeEntities { get; set; }
public DbSet<VertexAttribute> VertexAttributes { get; set; }
public DbSet<EdgeAttribute> EdgeAttributes { get; set; }
public DbSet<VertexValue> VertexValues { get; set; }
public DbSet<EdgeValue> EdgeValues { get; set; }
public DbSet<DataGroup> DataSets { get; set; }


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Expand Down
11 changes: 11 additions & 0 deletions mohaymen-codestar-Team02/Dto/StoreDataDto/StoreDataDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace mohaymen_codestar_Team02.Dto.StoreDataDto;

public class StoreDataDto
{
public IFormFile EdgeFile { get; set; }
public IFormFile VertexFile { get; set; }
public string FileType { get; set; }
public string DataName { get; set; }

public string CreatorUserName { get; set; }
}
28 changes: 28 additions & 0 deletions mohaymen-codestar-Team02/Models/DataGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using mohaymen_codestar_Team02.Models.EdgeEAV;
using mohaymen_codestar_Team02.Models.VertexEAV;

namespace mohaymen_codestar_Team02.Models;

public class DataGroup
{
public DataGroup(string name, long userId)
{
Name = name;
UserId = userId;
}
[Key] public long DataGroupId { get; set; }

public string Name { get; set; }
public DateTime CreateAt { get; set; } = DateTime.UtcNow;
public DateTime UpdateAt { get; set; } = DateTime.UtcNow;

public virtual EdgeEntity EdgeEntity { get; set; }
public virtual VertexEntity VertexEntity { get; set; }

public long UserId { get; set; }

[ForeignKey("UserId")] public virtual User? User { get; set; }
}
18 changes: 18 additions & 0 deletions mohaymen-codestar-Team02/Models/EdgeEAV/EdgeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace mohaymen_codestar_Team02.Models.EdgeEAV;

public class EdgeAttribute
{
public EdgeAttribute(string name, long edgeEntityId)
{
Name = name;
EdgeEntityId = edgeEntityId;
}
[Key] public long Id { get; set; }
public string Name { get; set; }
public long EdgeEntityId { get; set; }
[ForeignKey("EdgeEntityId")] public virtual EdgeEntity EdgeEntity { get; set; }
public virtual ICollection<EdgeValue> EdgeValues { get; set; } = new List<EdgeValue>();
}
34 changes: 34 additions & 0 deletions mohaymen-codestar-Team02/Models/EdgeEAV/EdgeEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.RegularExpressions;

namespace mohaymen_codestar_Team02.Models.EdgeEAV;

public class EdgeEntity
{
public EdgeEntity(string name, long dataGroupId)
{
_name = name + "!Edge" + "!" + Guid.NewGuid() + "!";
DataGroupId = dataGroupId;
}

[Key] public long Id { get; set; }
private string _name;

public string Name
{
get
{
var regex = new Regex(@"^(.+?)!");
var match = regex.Match(_name);
if (match.Success) return match.Groups[1].Value;

return null;
}
set => _name = value + "!Edge" + "!" + Guid.NewGuid() + "!";
}

public long DataGroupId { get; set; }
[ForeignKey("DataGroupId")] public virtual DataGroup? DataGroup { get; set; }
public virtual ICollection<EdgeAttribute> EdgeAttributes { get; set; } = new List<EdgeAttribute>();
}
19 changes: 19 additions & 0 deletions mohaymen-codestar-Team02/Models/EdgeEAV/EdgeValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace mohaymen_codestar_Team02.Models.EdgeEAV;

public class EdgeValue
{
public EdgeValue(string stringValue, long edgeAttributeId, string objectId)
{
StringValue = stringValue;
EdgeAttributeId = edgeAttributeId;
ObjectId = objectId;
}
[Key] public long Id { get; set; }
public string StringValue { get; set; }
public long EdgeAttributeId { get; set; }
[ForeignKey("EdgeAttributeId")] public virtual EdgeAttribute EdgeAttribute { get; set; }
public string ObjectId { get; set; }
}
4 changes: 2 additions & 2 deletions mohaymen-codestar-Team02/Models/ServiceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ namespace mohaymen_codestar_Team02.Models;

public class ServiceResponse<T>
{
public ServiceResponse(T data, ApiResponseType type, string message)
public ServiceResponse(T? data, ApiResponseType type, string message)
{
Data = data;
Type = type;
Message = message;
}

public T Data { get; set; }
public T? Data { get; set; }
public ApiResponseType Type { get; set; }
public string Message { get; set; }
}
1 change: 1 addition & 0 deletions mohaymen-codestar-Team02/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public class User
[Required][StringLength(256)] public byte[] PasswordHash { get; set; }

public virtual ICollection<UserRole> UserRoles { get; set; }
public virtual ICollection<DataGroup> DataSets { get; set; }
}
4 changes: 2 additions & 2 deletions mohaymen-codestar-Team02/Models/UserRole.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using mohaymen_codestar_Team02.Models;

namespace mohaymen_codestar_Team02.Models;

public class UserRole
{
Expand Down
19 changes: 19 additions & 0 deletions mohaymen-codestar-Team02/Models/VertexEAV/VertexAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using mohaymen_codestar_Team02.Models.EdgeEAV;

namespace mohaymen_codestar_Team02.Models.VertexEAV;

public class VertexAttribute
{
public VertexAttribute(string name, long vertexEntityId)
{
Name = name;
VertexEntityId = vertexEntityId;
}
[Key] public long Id { get; set; }
public string Name { get; set; }
public long VertexEntityId { get; set; }
[ForeignKey("VertexEntityId")] public virtual VertexEntity VertexEntity { get; set; }
public virtual ICollection<VertexValue> VertexValues { get; set; }
}
45 changes: 45 additions & 0 deletions mohaymen-codestar-Team02/Models/VertexEAV/VertexEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.RegularExpressions;
using mohaymen_codestar_Team02.Models.EdgeEAV;

namespace mohaymen_codestar_Team02.Models.VertexEAV;

public class VertexEntity
{
public VertexEntity(string name, long dataGroupId)
{
if (!name.Contains("!"))
{
_name = name + "!vertex" + "!" + Guid.NewGuid() + "!";
DataGroupId = dataGroupId;
}
else
{
throw new ArgumentException("your name contain !");
}
}

[Key] public long Id { get; set; }
private string _name;

public string Name
{
get
{
var regex = new Regex(@"^(.+?)!");
var match = regex.Match(_name);
if (match.Success) return match.Groups[1].Value;

return null;
}
set
{
if (!value.Contains("!")) _name = value + "!vertex" + "!" + Guid.NewGuid() + "!";
}
}

public long DataGroupId { get; set; }
[ForeignKey("DataGroupId")] public virtual DataGroup DataGroup { get; set; }
public virtual ICollection<VertexAttribute> VertexAttributes { get; set; } = new List<VertexAttribute>();
}
22 changes: 22 additions & 0 deletions mohaymen-codestar-Team02/Models/VertexEAV/VertexValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using mohaymen_codestar_Team02.Models.EdgeEAV;

namespace mohaymen_codestar_Team02.Models.VertexEAV;

public class VertexValue
{

public VertexValue(string stringValue, long vertexAttributeId, string objectId)
{
StringValue = stringValue;
VertexAttributeId = vertexAttributeId;
ObjectId = objectId;
}
[Key] public long Id { get; set; }
public string StringValue { get; set; }

public long VertexAttributeId { get; set; }
[ForeignKey("VertexAttributeId")] public virtual VertexAttribute VertexAttribute { get; set; }
public string ObjectId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task<ServiceResponse<List<GetRoleDto>>> GetAllRoles()
if (await UserExists(user.Username))
return new ServiceResponse<GetUserDto?>(null, ApiResponseType.Conflict, Resources.UserAlreadyExistsMessage);

_passwordService.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
_passwordService.CreatePasswordHash(password, out var passwordHash, out var passwordSalt);
user.PasswordHash = passwordHash;
user.Salt = passwordSalt;

Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task<ServiceResponse<List<GetRoleDto>>> GetAllRoles()
if (await GetUserRole(foundRole, foundUser) is not null)
return new ServiceResponse<GetUserDto?>(null, ApiResponseType.BadRequest, Resources.RoleAlreadyAssigned);

UserRole userRole = new UserRole
var userRole = new UserRole
{
Role = foundRole,
User = foundUser,
Expand Down Expand Up @@ -238,7 +238,6 @@ private Task<bool> IsAdmin(User? user)
return await _context.Roles.FirstOrDefaultAsync(x => x.RoleType.ToLower() == roleType.ToLower());
}


private async Task<UserRole?> GetUserRole(Role foundRole, User foundUser) =>
await _context.UserRoles.FirstOrDefaultAsync(x =>
x.User.Username != null && foundUser.Username != null && x.RoleId == foundRole.RoleId &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public AuthenticationService(DataContext context, ICookieService cookieService,

Claim[] claims = new[]
{
new Claim(ClaimTypes.Name, user.Username),
new Claim(ClaimTypes.Name, user.Username)
};

_cookieService.CreateCookie(_tokenService.CreateToken(claims));
Expand Down
Loading
Loading