Skip to content

Commit

Permalink
fix(API): update api
Browse files Browse the repository at this point in the history
* fix(User) : update api

* fix(User) : get pagination of user ao=pi

* fix(Graph) : Pagination

* feat(User) :add logout api for user
  • Loading branch information
mahdijafariii authored Aug 19, 2024
1 parent 6b6d2da commit 25f8d6a
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 214 deletions.
4 changes: 2 additions & 2 deletions AnalysisData/AnalysisData/Graph/Controller/GraphController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AnalysisData.Graph.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnalysisData.Graph.Controller;
Expand All @@ -13,9 +14,8 @@ public GraphController(IGraphUtility graphUtility, IGraphService graphService)
_graphUtility = graphUtility;
_graphService = graphService;
}

[HttpGet("pagination")]
public async Task<IActionResult> GetGraph([FromQuery] int page)
public async Task<IActionResult> GetGraph([FromQuery] int page = 1)
{
var result = await _graphService.GetAllAccountPagination(page);
return Ok(new
Expand Down
6 changes: 3 additions & 3 deletions AnalysisData/AnalysisData/Graph/Services/GraphServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public GraphServices(IGraphUtility graphUtility, IAccountRepository accountRepos
_transactionRepository = transactionRepository;
}

public async Task<(List<PaginationDto>,int,int)> GetAllAccountPagination(int page = 0)
public async Task<(List<PaginationDto>,int,int)> GetAllAccountPagination(int page = 1)
{
var count = await _accountRepository.GetCountNodes();
var accounts = await _accountRepository.GetAllAccountPagination(page);
var count = await _accountRepository.GetCountNodes();
var accounts = await _accountRepository.GetAllAccountPagination(page - 1);
var paginationData = accounts.Select(x => new PaginationDto()
{ AccountID = x.AccountID, OwnerName = x.OwnerName, OwnerLastName = x.OwnerLastName }).ToList();
return (paginationData,page,count);
Expand Down
2 changes: 1 addition & 1 deletion AnalysisData/AnalysisData/Graph/Services/IGraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AnalysisData.Graph.Services;

public interface IGraphService
{
Task<(List<PaginationDto>, int, int)> GetAllAccountPagination(int page = 0);
Task<(List<PaginationDto>, int, int)> GetAllAccountPagination(int page = 1);
Task<Account> GetSpecialNode(string id);

Task<(IEnumerable<AccountContractDto> accounts, IEnumerable<TransactionsContractDto> transactions)>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

Expand Down Expand Up @@ -31,19 +31,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
table.PrimaryKey("PK_Accounts", x => x.AccountID);
});

migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleName = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Transactions",
columns: table => new
Expand All @@ -64,32 +51,20 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Id = table.Column<Guid>(type: "uuid", nullable: false),
Username = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
FirstName = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
PhoneNumber = table.Column<string>(type: "text", nullable: false),
ImageURL = table.Column<string>(type: "text", nullable: true),
RoleId = table.Column<int>(type: "integer", nullable: false)
Role = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_Users_RoleId",
table: "Users",
column: "RoleId");
}

/// <inheritdoc />
Expand All @@ -103,9 +78,6 @@ protected override void Down(MigrationBuilder migrationBuilder)

migrationBuilder.DropTable(
name: "Users");

migrationBuilder.DropTable(
name: "Roles");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using AnalysisData.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -21,7 +22,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("AnalysisData.DataManage.Model.Account", b =>
modelBuilder.Entity("AnalysisData.Graph.DataManage.Model.Account", b =>
{
b.Property<string>("AccountID")
.HasColumnType("text");
Expand Down Expand Up @@ -67,7 +68,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Accounts");
});

modelBuilder.Entity("AnalysisData.DataManage.Model.Transaction", b =>
modelBuilder.Entity("AnalysisData.Graph.DataManage.Model.Transaction", b =>
{
b.Property<string>("TransactionID")
.HasColumnType("text");
Expand Down Expand Up @@ -96,30 +97,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Transactions");
});

modelBuilder.Entity("Role", b =>
modelBuilder.Entity("AnalysisData.UserManage.Model.User", b =>
{
b.Property<int>("Id")
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));

b.Property<string>("RoleName")
.IsRequired()
.HasColumnType("text");

b.HasKey("Id");

b.ToTable("Roles");
});

modelBuilder.Entity("User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
.HasColumnType("uuid");

b.Property<string>("Email")
.IsRequired()
Expand All @@ -144,30 +126,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("text");

b.Property<int>("RoleId")
.HasColumnType("integer");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("text");

b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");

b.HasKey("Id");

b.HasIndex("RoleId");

b.ToTable("Users");
});

modelBuilder.Entity("User", b =>
{
b.HasOne("Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Role");
});
#pragma warning restore 612, 618
}
}
Expand Down
65 changes: 32 additions & 33 deletions AnalysisData/AnalysisData/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
builder.Services.AddScoped<IRegexService, RegexService>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IDataProcessor, DataReadProcessor>();
builder.Services.AddScoped<IAdminService, AdminService>();
builder.Services.AddScoped<IAccountRepository, AccountRepository>();
builder.Services.AddScoped<ITransactionRepository, TransactionRepository>();
builder.Services.AddScoped<IGraphUtility, GraphUtility>();
builder.Services.AddScoped<IAccountRepository, AccountRepository>();
builder.Services.AddScoped<ITransactionRepository, TransactionRepository>();
builder.Services.AddScoped<IGraphService, GraphServices>();
// builder.Services.AddDbContext<ApplicationDbContext>(options =>
// options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")),
ServiceLifetime.Scoped);
Expand All @@ -58,37 +57,37 @@
.AllowAnyHeader()
.AllowCredentials());
});
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(builder.Configuration["Jwt:Key"])),
};
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var cookie = context.Request.Cookies["AuthToken"];
if (!string.IsNullOrEmpty(cookie))
{
context.Token = cookie;
}

return Task.CompletedTask;
}
};
});
// builder.Services.AddAuthentication(options =>
// {
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
// })
// .AddJwtBearer(options =>
// {
// options.RequireHttpsMetadata = false;
// options.SaveToken = true;
// options.TokenValidationParameters = new TokenValidationParameters
// {
// ValidateIssuer = false,
// ValidateAudience = false,
// ValidateLifetime = true,
// ValidateIssuerSigningKey = true,
// IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(builder.Configuration["Jwt:Key"])),
// };
// options.Events = new JwtBearerEvents
// {
// OnMessageReceived = context =>
// {
// var cookie = context.Request.Cookies["AuthToken"];
// if (!string.IsNullOrEmpty(cookie))
// {
// context.Token = cookie;
// }
//
// return Task.CompletedTask;
// }
// };
// });

var app = builder.Build();

Expand Down
Loading

0 comments on commit 25f8d6a

Please sign in to comment.