Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<ActionResult<AuthDto>> Login([FromQuery] AuthCreateCommand cmd
};
}

logger.LogInformation("User {UserId} Logined", result.Data!.UserId);
logger.LogInformation("User {UserId} Logined", result.Data!.UserDto.Id);

this.CraeteTokensInCookies(result.Data.Token, result.Data.RefreshToken);

Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task<ActionResult<AuthDto>> RefreshToken()
};
}

logger.LogInformation("User {UserId} Refreshed Token", result.Data!.UserId);
logger.LogInformation("User {UserId} Refreshed Token", result.Data!.UserDto.Id);

this.CraeteTokensInCookies(result.Data.Token, result.Data.RefreshToken);

Expand Down
8 changes: 4 additions & 4 deletions src/API/Controllers/ChannelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public ChannelController(IMediator mediator)

[HttpPost]
[Authorize(Policy = nameof(UserRole.Creator))]
public async Task<ActionResult<ChannelDto>> CreateChannel(ChannelCreateRequest request)
public async Task<ActionResult<ChannelDto>> CreateChannel([FromForm] ChannelCreateRequest request)
{
ChannelCreateCommand cmd = new(
this.GetIDFromClaim(), request.Name, request.AvatarPhoto);
this.GetIDFromClaim(), request.Name, request.IconPhoto);

Result<ChannelDto> result = await mediator.Send(cmd);

Expand Down Expand Up @@ -125,10 +125,10 @@ public async Task<ActionResult<ChannelDto[]>> GetChannels()

[HttpPut("{ChannelId}")]
[Authorize(Policy = nameof(UserRole.Creator))]
public async Task<ActionResult<ChannelDto>> UpdateChannel(Guid ChannelId, ChannelUpdateRequest request)
public async Task<ActionResult<ChannelDto>> UpdateChannel([FromRoute] Guid ChannelId, [FromForm] ChannelUpdateRequest request)
{
ChannelUpdateCommand cmd = new(
this.GetIDFromClaim(), ChannelId, request.Name, request.Description);
this.GetIDFromClaim(), ChannelId, request.Name, request.Description, request.IconPhoto);

Result<ChannelDto> result = await mediator.Send(cmd);

Expand Down
22 changes: 16 additions & 6 deletions src/API/Controllers/ChannelOwnersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Application.Utilities;
using Domain.Common.Enums;
using Domain.Entities;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand Down Expand Up @@ -115,12 +117,20 @@ public async Task<ActionResult<ChannelDto>> CreateChannelOwner(Guid ChannelId, G
currentUserId, UserId, ChannelId);

return Created($"api/ChannelOwners/user/{UserId}/Channel/{ChannelId}",
context.Channels.Select(Channel => new ChannelDto(
Channel.Id, Channel.Name, "@" + Channel.Slug,
Channel.Description ?? "", Channel.CreatedDate,
Channel.AvatarPhotoUrl, Channel.Subscribers.Count,
Channel.Contents.Count, Channel.Owners.Count,
Channel.TotalLikes, Channel.TotalViews))
await context.Channels.Select(channel => new ChannelDto(
channel.Id, channel.Name, "@" + channel.Slug,
channel.Description ?? "", channel.CreatedDate,
new PhotoDto(
new PhotoVariants(
channel.ChannelMeta.IconBase,
channel.ChannelMeta.Small,
channel.ChannelMeta.Medium,
channel.ChannelMeta.Large),
channel.ChannelMeta.R,
channel.ChannelMeta.G,
channel.ChannelMeta.B),
0,0, channel.Owners.Count,
channel.TotalLikes, channel.TotalViews))
.FirstAsync(Channel => Channel.Id == ChannelId));
}

Expand Down
33 changes: 25 additions & 8 deletions src/API/Controllers/CommentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Domain.Entities;
using API.Extensions;
using Application.Comments.Update;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand All @@ -29,7 +31,7 @@ public CommentController(IAppDbContext context, ILogger<CommentController> logge
}

[HttpGet("content/{ContentId}")]
public async Task<ActionResult<CommentSendedDto[]>> GetCommentWithContnet(Guid ContentId)
public async Task<ActionResult<CommentSendedDto[]>> GetCommentByContentId(Guid ContentId)
{
bool hasContent = await context.Contents
.AsNoTracking().AnyAsync(content => content.Id == ContentId);
Expand All @@ -39,18 +41,25 @@ public async Task<ActionResult<CommentSendedDto[]>> GetCommentWithContnet(Guid C

var comments = await context.Comments
.Where(comment => comment.ContentId == ContentId)
.Include(comment => comment.Commentator)
.Select(comment => new CommentSendedDto(
new CommentDto(
comment.Id, comment.Text,
comment.PublicatedDate, comment.Likers.Count,
comment.DisLikers.Count, comment.ViewsCount),
new UserDto(
comment.Commentator!.Id, comment.Commentator!.Name, "@" + comment.Commentator!.Slug,
comment.Commentator!.Description ?? "", comment.Commentator!.RegistryData, comment.Commentator!.Email,
comment.Commentator!.Role.ToString(), comment.Commentator!.AvatarPhotoUrl, comment.Commentator!.TotalLikes,
comment.Commentator!.Comments.Count, comment.Commentator!.Contents.Count, comment.Commentator!.Followers.Count,
comment.Commentator!.Following.Count, comment.Commentator!.OwnedChannels.Count, comment.Commentator!.SubscripedChannels.Count)))
comment.Commentator.Id, comment.Commentator.Name, "@" + comment.Commentator.Slug,
comment.Commentator.Description ?? "", comment.Commentator.RegistryData, comment.Commentator.Email,
comment.Commentator.Role.ToString(), new PhotoDto(
new PhotoVariants(
comment.Commentator.UserMeta.IconBase,
comment.Commentator.UserMeta.Small,
comment.Commentator.UserMeta.Medium,
comment.Commentator.UserMeta.Large),
comment.Commentator.UserMeta.R,
comment.Commentator.UserMeta.G,
comment.Commentator.UserMeta.B), comment.Commentator.TotalLikes,
comment.Commentator.Comments.Count, comment.Commentator.Contents.Count, comment.Commentator.Followers.Count,
comment.Commentator.Following.Count, comment.Commentator.OwnedChannels.Count, comment.Commentator.SubscripedChannels.Count)))
.ToArrayAsync();

logger.LogInformation("Returned {Count} comment in content {ContentId}",
Expand Down Expand Up @@ -78,7 +87,15 @@ public async Task<ActionResult<CommentSendedDto>> SendComment(Guid ContentId, [F
uResponse = new UserDto(
user.Id, user.Name, "@" + user.Slug,
user.Description ?? "", user.RegistryData, user.Email,
user.Role.ToString(), user.AvatarPhotoUrl, user.TotalLikes,
user.Role.ToString(), new PhotoDto(
new PhotoVariants(
user.UserMeta.IconBase,
user.UserMeta.Small,
user.UserMeta.Medium,
user.UserMeta.Large),
user.UserMeta.R,
user.UserMeta.G,
user.UserMeta.B), user.TotalLikes,
user.Comments.Count, user.Contents.Count, user.Followers.Count,
user.Following.Count, user.OwnedChannels.Count, user.SubscripedChannels.Count)
})
Expand Down
8 changes: 4 additions & 4 deletions src/API/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ public async Task<ActionResult<ContentUrlDto>> GetContentUrlById(Guid ContentId)
}

[HttpGet("random")]
public async Task<ActionResult<ContentRecoDto[]>> GetRandomContent()
public async Task<ActionResult<ContentFeedDto[]>> GetRandomContent()
{
Result<ContentDto[]> randomContents = await mediator.Send(
Result<ContentFeedDto[]> randomContents = await mediator.Send(
new ContentRandomQuery());

return Ok(randomContents);
}

[HttpGet("recommendation")]
[Authorize(Policy = nameof(UserRole.User))]
public async Task<ActionResult<ContentRecoDto[]>> GetContentForRecommendation()
public async Task<ActionResult<ContentFeedDto[]>> GetContentForRecommendation()
{
Result<ContentRecoDto[]> result = await mediator.Send(new
Result<ContentFeedDto[]> result = await mediator.Send(new
ContentRecommendationQuery(this.GetIDFromClaim()));

if (!result.IsSuccess || result.Data == null)
Expand Down
11 changes: 10 additions & 1 deletion src/API/Controllers/DisLikingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Domain.Common.Enums;
using Domain.Entities;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand Down Expand Up @@ -43,7 +44,15 @@ public async Task<ActionResult<ContentDto>> DisLikeContent(Guid ContentId)
content.Title, content.Slug, content.Description,
content.CreatedDate, content.ContentType.ToString(),
content.VideoMeta.DurationSeconds, content.VideoMeta.VideoUrl,
new PreviewPhotoDto(content.VideoMeta.GetPhotoVariants(), content.VideoMeta.R, content.VideoMeta.G, content.VideoMeta.B),
new PhotoDto(
new PhotoVariants(
content.VideoMeta.PhotoBase,
content.VideoMeta.Small,
content.VideoMeta.Medium,
content.VideoMeta.Large),
content.VideoMeta.R,
content.VideoMeta.G,
content.VideoMeta.B),
content.Savers.Count, content.Likers.Count, content.Comments.Count, content.DisLikers.Count, content.ViewsCount)
})
.FirstOrDefaultAsync(content => content.c.Id == ContentId);
Expand Down
14 changes: 12 additions & 2 deletions src/API/Controllers/FollowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Application.Utilities;
using Domain.Common.Enums;
using Domain.Entities;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand Down Expand Up @@ -45,8 +47,16 @@ public async Task<ActionResult<UserDto>> Following(Guid UserId)
uResponse = new UserDto(
user.Id, user.Name, "@" + user.Slug,
user.Description ?? "", user.RegistryData, user.Email,
user.Role.ToString(), user.AvatarPhotoUrl, user.TotalLikes,
user.Comments.Count, user.Contents.Count, user.Followers.Count,
user.Role.ToString(), new PhotoDto(
new PhotoVariants(
user.UserMeta.IconBase,
user.UserMeta.Small,
user.UserMeta.Medium,
user.UserMeta.Large),
user.UserMeta.R,
user.UserMeta.G,
user.UserMeta.B),
user.TotalLikes, user.Comments.Count, user.Contents.Count, user.Followers.Count,
user.Following.Count, user.OwnedChannels.Count, user.SubscripedChannels.Count)
})
.AsNoTracking()
Expand Down
11 changes: 10 additions & 1 deletion src/API/Controllers/LikingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Domain.Common.Enums;
using Domain.Entities;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand Down Expand Up @@ -43,7 +44,15 @@ public async Task<ActionResult<ContentDto>> LikeContent(Guid ContentId)
content.Title, content.Slug, content.Description,
content.CreatedDate, content.ContentType.ToString(),
content.VideoMeta.DurationSeconds, content.VideoMeta.VideoUrl,
new PreviewPhotoDto(content.VideoMeta.GetPhotoVariants(), content.VideoMeta.R, content.VideoMeta.G, content.VideoMeta.B),
new PhotoDto(
new PhotoVariants(
content.VideoMeta.PhotoBase,
content.VideoMeta.Small,
content.VideoMeta.Medium,
content.VideoMeta.Large),
content.VideoMeta.R,
content.VideoMeta.G,
content.VideoMeta.B),
content.Savers.Count, content.Likers.Count, content.Comments.Count, content.DisLikers.Count,
content.ViewsCount)
})
Expand Down
11 changes: 10 additions & 1 deletion src/API/Controllers/SavingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Domain.Common.Enums;
using Domain.Entities;
using Application.Dtos;
using Domain.Rows.Contents;

namespace API.Controllers;

Expand Down Expand Up @@ -42,7 +43,15 @@ public async Task<ActionResult<ContentDto>> SaveContent(Guid ContentId)
content.Title, content.Slug, content.Description,
content.CreatedDate, content.ContentType.ToString(),
content.VideoMeta.DurationSeconds, content.VideoMeta.VideoUrl,
new PreviewPhotoDto(content.VideoMeta.GetPhotoVariants(), content.VideoMeta.R, content.VideoMeta.G, content.VideoMeta.B),
new PhotoDto(
new PhotoVariants(
content.VideoMeta.PhotoBase,
content.VideoMeta.Small,
content.VideoMeta.Medium,
content.VideoMeta.Large),
content.VideoMeta.R,
content.VideoMeta.G,
content.VideoMeta.B),
content.Savers.Count, content.Likers.Count, content.Comments.Count, content.DisLikers.Count, content.ViewsCount)
})
.FirstOrDefaultAsync(content => content.c.Id == ContentId);
Expand Down
53 changes: 30 additions & 23 deletions src/API/Controllers/SubscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Application.Utilities;
using Domain.Common.Enums;
using Domain.Entities;
using Domain.Rows.Contents;
using Application.Dtos;

namespace API.Controllers;

Expand All @@ -24,31 +26,38 @@ public SubscriptionController(IAppDbContext context, ILogger<SubscriptionControl
this.logger = logger;
}

[HttpPost("Channel/{ChannelId}")]
[HttpPost("channel/{ChannelId}")]
[Authorize(Policy = nameof(UserRole.User))]
public async Task<ActionResult<ChannelDto>> Subscription(Guid ChannelId)
{
Guid currentUserId = this.GetIDFromClaim();

User? currentUser = await context.Users.FindAsync(currentUserId);
var Channel = await context.Channels
.Select(Channel => new
var channel = await context.Channels
.Select(channel => new
{
d = Channel,
dResponse = new ChannelDto(
Channel.Id, Channel.Name, "@" + Channel.Slug,
Channel.Description ?? "", Channel.CreatedDate,
Channel.AvatarPhotoUrl, Channel.Subscribers.Count,
Channel.Contents.Count, Channel.Owners.Count,
Channel.TotalLikes, Channel.TotalViews)
c = channel,
dto = new ChannelDto(
channel.Id, channel.Name, "@" + channel.Slug,
channel.Description ?? "", channel.CreatedDate,
new PhotoDto(
new PhotoVariants(
channel.ChannelMeta.IconBase,
channel.ChannelMeta.Small,
channel.ChannelMeta.Medium,
channel.ChannelMeta.Large),
channel.ChannelMeta.R,
channel.ChannelMeta.G,
channel.ChannelMeta.B), channel.Subscribers.Count,
0,0, channel.TotalLikes, channel.TotalViews)
})
.AsNoTracking()
.FirstOrDefaultAsync(Channel => Channel.d.Id == ChannelId);
.FirstOrDefaultAsync(channel => channel.c.Id == ChannelId);

if (currentUser is null)
return NotFound("User not found");
if (Channel is null || Channel is null)
return NotFound("Channel not found");
if (channel is null || channel.c is null)
return NotFound("channel not found");

ChannelSubscription ChannelSubscription = new()
{
Expand All @@ -62,48 +71,46 @@ public async Task<ActionResult<ChannelDto>> Subscription(Guid ChannelId)

await context.SaveChangesAsync();

logger.LogInformation("User {UserId} subscriped Channel {ChannelId}",
logger.LogInformation("User {UserId} subscriped channel {ChannelId}",
currentUserId, ChannelId);

return Created($"api/subscription/user/{currentUserId}/Channel/{ChannelId}",
Channel.dResponse);
return Created($"api/subscription/user/{currentUserId}/channel/{ChannelId}",
channel.dto);
}

[HttpGet("user/{UserId}/Channel/{ChannelId}")]
[HttpGet("user/{UserId}/channel/{ChannelId}")]
[Authorize(Policy = nameof(UserRole.User))]
public async Task<ActionResult> GetSubscribedChannels(Guid UserId, Guid ChannelId)
{
return NotFound("Dont released this end point");
}

[HttpGet("Channel/{ChannelId}")]
[HttpGet("channel/{ChannelId}")]
[Authorize(Policy = nameof(UserRole.User))]
public async Task<ActionResult> GetCurrentUserSubscribedChannels(Guid ChannelId)
{
return NotFound("Dont released this end point");
}

[HttpDelete("Channel/{ChannelId}")]
[HttpDelete("channel/{ChannelId}")]
[Authorize(Policy = nameof(UserRole.User))]
public async Task<IActionResult> ReSubscription(Guid ChannelId)
{
Guid currentUserId = this.GetIDFromClaim();

ChannelSubscription? ChannelSubscription = await context.ChannelSubscriptions
.Include(ChannelSubscription => ChannelSubscription.Subscriber)
.Include(ChannelSubscription => ChannelSubscription.Channel)
.FirstOrDefaultAsync(ChannelSubscription =>
ChannelSubscription.SubscriberId == currentUserId &&
ChannelSubscription.ChannelId == ChannelId);

if (ChannelSubscription is null)
return NotFound("Subscriped Channel not found");
return NotFound("Subscriped channel not found");

context.ChannelSubscriptions.Remove(ChannelSubscription);

await context.SaveChangesAsync();

logger.LogInformation("User {UserId} re subscriped Channel {ChannelId}",
logger.LogInformation("User {UserId} re subscriped channel {ChannelId}",
currentUserId, ChannelId);

return NoContent();
Expand Down
Loading
Loading