version: '3.9'
networks:
dev:
services:
#Nginx
proxy:
image: nginx:stable-alpine
ports:
- "80:80"
volumes:
- './nginx.conf:/etc/nginx/nginx.conf'
depends_on:
- server_app
- client_app
networks:
- dev
# ASP.NET Core application
server_app:
build:
context: ./server_app
dockerfile: Dockerfile
ports:
- "5183:5183"
depends_on:
- redis
- mongodb
- postgres
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=5183
networks:
- dev
#for windows: $APPDATA/Microsoft/UserSecrets/$USER_SECRETS_ID:/root/.microsoft/usersecrets/$USER_SECRETS_
volumes:
- /home/timur/.microsoft/usersecrets/bd1f8802-13a0-4b5f-891d-3be2cef1574c:/root/.microsoft/usersecrets/bd1f8802-13a0-4b5f-891d-3be2cef1574c
# React application
client_app:
build:
context: ./client_app
dockerfile: Dockerfile
ports:
- "3000:3000"
networks:
- dev
# Redis
redis:
image: redis:7.2.5
ports:
- "6370:6370"
networks:
- dev
# MongoDB
mongodb:
image: mongo:8.0.4
ports:
- "27010:27010"
networks:
- dev
# PostgreSQL
postgres:
image: postgres:latest
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: nigPostgres_Pas5432
POSTGRES_DB: marketplacedb
ports:
- '5432:5432'
networks:
- dev
public class UserEntityConfiguration : IEntityTypeConfiguration<UserEntity>
{
public void Configure(EntityTypeBuilder<UserEntity> builder)
{
builder.UseTpcMappingStrategy();
builder.HasKey(x => x.Id).HasName("id");
builder.Property(x => x.Name).HasMaxLength(25).IsRequired().HasColumnName("name");
builder.Property(x => x.Email).HasMaxLength(50).IsRequired().HasColumnName("email");
builder.Property(x => x.EmailVerify).IsRequired().HasColumnName("email_verify");
builder.Property(x => x.PasswordHash).IsRequired().HasColumnName("password_hash");
}
}
public class SellerEntityConfiguration : IEntityTypeConfiguration<SellerEntity>
{
public void Configure(EntityTypeBuilder<SellerEntity> builder)
{
builder.UseTpcMappingStrategy();
builder.ToTable("sellers");
builder.Property(x => x.Description).IsRequired().HasMaxLength(500).HasColumnName("description");
builder.HasMany(x => x.Products).WithOne().HasConstraintName("products_constraint");
}
}
public class CustomerEntityConfiguration : IEntityTypeConfiguration<CustomerEntity>
{
public void Configure(EntityTypeBuilder<CustomerEntity> builder)
{
builder.UseTpcMappingStrategy();
builder.ToTable("customers");
builder.Property(x => x.CreditCard).IsRequired().HasMaxLength(35).HasColumnName("credit_card");
builder.HasMany(x => x.Purchases)
.WithOne().HasConstraintName("purchases_constraint");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new UserEntityConfiguration());
modelBuilder.ApplyConfiguration(new RefreshTokenEntityConfigurations());
modelBuilder.ApplyConfiguration(new CustomerEntityConfiguration());
modelBuilder.ApplyConfiguration(new SellerEntityConfiguration());
modelBuilder.ApplyConfiguration(new ProductEntityCongurations());
}
public class SellerLoginController : BaseLoginController
{
public SellerLoginController(SellerService sellerService, IServiceProvider provider) : base(provider)
{
_sellerService = sellerService;
}
private readonly SellerService _sellerService;
protected override IUserService<UserEntity> _userService { get => _sellerService; }
//Место где и возникает проблема(Cannot implicitly convert type 'SellerService' to 'IUserService'. An explicit conversion exists (are you missing a cast?)
public abstract class BaseLoginController : ControllerBase
{
protected abstract IUserService<UserEntity> _userService { get; }
...
}
[ApiController]
[Route("/api/notes")]
[ValidationFilter]
[Authorize]
public class NoteController : ControllerBase
{
private readonly ILogger<NoteController> _logger;
private readonly string _authorId;
public NoteController(ILogger<NoteController> logger)
{
_logger = logger;
var id = User?.Claims?.GetIdValue();
_authorId = id is not null ? id : default;
_logger.LogCritical("Author: \t n:");
_logger.LogCritical(_authorId);
}
...
}
public static class ClaimsExtension
{
private static string GetValue(Claim[] claims, string selectType) => claims.FirstOrDefault(c => c.Type == selectType).Value;
private static string GetValue(IEnumerable<Claim> claims, string selectType) => claims.FirstOrDefault(c => c.Type == selectType).Value;
public static string GetIdValue(this Claim[] claims) => GetValue(claims, "userId");
public static string GetIdValue(this IEnumerable<Claim> claims) => GetValue(claims, "userId");
}