Доработан UI
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using AutoMapper;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.Auth;
|
||||
using PlaylistShared.Shared.Shared;
|
||||
|
||||
namespace PlaylistShared.Api.Mapping;
|
||||
|
||||
public class AppMappingProfile : Profile
|
||||
{
|
||||
public AppMappingProfile()
|
||||
{
|
||||
CreateMap<SharedPlaylist, SharedPlaylistDto>()
|
||||
.ForMember(dest => dest.Creator, opt => opt.MapFrom(src => src.Creator));
|
||||
CreateMap<ApplicationUser, ApplicationUserDto>();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="16.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.5" />
|
||||
|
||||
@@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using PlaylistShared.Api.Data;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Api.Mapping;
|
||||
using PlaylistShared.Api.Services;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Text;
|
||||
@@ -89,7 +88,6 @@ public class Program
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAutoMapper(t => t.AddProfile<AppMappingProfile>());
|
||||
builder.Services.AddScoped<JwtService>();
|
||||
builder.Services.AddScoped<UserSessionService>();
|
||||
builder.Services.AddScoped<YandexMusicService>();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlaylistShared.Api.Data;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.Auth;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Playlist;
|
||||
using PlaylistShared.Shared.Shared;
|
||||
@@ -11,13 +11,11 @@ namespace PlaylistShared.Api.Services;
|
||||
public class SharedPlaylistService
|
||||
{
|
||||
private readonly ApplicationDbContext _db;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly TrackAdditionLogService _trackLogService;
|
||||
|
||||
public SharedPlaylistService(ApplicationDbContext db, IMapper mapper, TrackAdditionLogService trackLogService)
|
||||
public SharedPlaylistService(ApplicationDbContext db, TrackAdditionLogService trackLogService)
|
||||
{
|
||||
_db = db;
|
||||
_mapper = mapper;
|
||||
_trackLogService = trackLogService;
|
||||
}
|
||||
|
||||
@@ -42,7 +40,7 @@ public class SharedPlaylistService
|
||||
};
|
||||
_db.SharedPlaylists.Add(entity);
|
||||
await _db.SaveChangesAsync();
|
||||
return _mapper.Map<SharedPlaylistDto>(entity);
|
||||
return MapToDto(entity);
|
||||
}
|
||||
|
||||
public async Task<SharedPlaylistDto?> GetByTokenAsync(string token)
|
||||
@@ -50,7 +48,7 @@ public class SharedPlaylistService
|
||||
var entity = await _db.SharedPlaylists
|
||||
.Include(sp => sp.Creator)
|
||||
.FirstOrDefaultAsync(sp => sp.ShareToken == token && !sp.IsDeleted);
|
||||
return entity == null ? null : _mapper.Map<SharedPlaylistDto>(entity);
|
||||
return entity == null ? null : MapToDto(entity);
|
||||
}
|
||||
|
||||
public async Task<SharedPlaylist?> GetEntityByTokenAsync(string token)
|
||||
@@ -70,7 +68,7 @@ public class SharedPlaylistService
|
||||
entity.RemovePermission = dto.RemovePermission;
|
||||
entity.UpdatedAt = DateTime.UtcNow;
|
||||
await _db.SaveChangesAsync();
|
||||
return _mapper.Map<SharedPlaylistDto>(entity);
|
||||
return MapToDto(entity);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(Guid playlistId)
|
||||
@@ -144,4 +142,36 @@ public class SharedPlaylistService
|
||||
.Where(sp => sp.CreatorUserId == userId && !sp.IsDeleted)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
// Ручное маппинг сущности в DTO
|
||||
private SharedPlaylistDto MapToDto(SharedPlaylist entity)
|
||||
{
|
||||
return new SharedPlaylistDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
CreatorUserId = entity.CreatorUserId,
|
||||
YandexPlaylistUuid = entity.YandexPlaylistUuid,
|
||||
YandexPlaylistKind = entity.YandexPlaylistKind,
|
||||
YandexPlaylistOwnerUid = entity.YandexPlaylistOwnerUid,
|
||||
Title = entity.Title,
|
||||
Description = entity.Description,
|
||||
CoverUrl = entity.CoverUrl,
|
||||
CreatedAt = entity.CreatedAt,
|
||||
UpdatedAt = entity.UpdatedAt,
|
||||
IsDeleted = entity.IsDeleted,
|
||||
ShareToken = entity.ShareToken,
|
||||
ViewPermission = entity.ViewPermission,
|
||||
PlayPermission = entity.PlayPermission,
|
||||
AddPermission = entity.AddPermission,
|
||||
RemovePermission = entity.RemovePermission,
|
||||
Creator = entity.Creator != null ? new ApplicationUserDto
|
||||
{
|
||||
Id = entity.Creator.Id,
|
||||
UserName = entity.Creator.UserName ?? string.Empty,
|
||||
Email = entity.Creator.Email,
|
||||
YandexId = entity.Creator.YandexId,
|
||||
DisplayName = entity.Creator.UserName
|
||||
} : null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user