feat: ajuste dos contadores
This commit is contained in:
parent
5fc7eb5ad3
commit
9e7ea6ed9a
@ -56,6 +56,25 @@ public class AdminController : Controller
|
|||||||
var userPlanType = Enum.TryParse<PlanType>(user.CurrentPlan, true, out var planType) ? planType : PlanType.Trial;
|
var userPlanType = Enum.TryParse<PlanType>(user.CurrentPlan, true, out var planType) ? planType : PlanType.Trial;
|
||||||
var userPages = await _userPageService.GetUserPagesAsync(user.Id);
|
var userPages = await _userPageService.GetUserPagesAsync(user.Id);
|
||||||
|
|
||||||
|
var listCounts = new Dictionary<string, dynamic>();
|
||||||
|
|
||||||
|
// Atualizar status das baseado nas livepasges
|
||||||
|
foreach (var page in userPages)
|
||||||
|
{
|
||||||
|
if (page.Status == ViewModels.PageStatus.Active)
|
||||||
|
{
|
||||||
|
var livePage = await _livePageService.GetLivePageFromUserPageId(page.Id);
|
||||||
|
if (livePage != null)
|
||||||
|
{
|
||||||
|
listCounts.Add(page.Id, new { TotalViews = livePage.Analytics?.TotalViews ?? 0 , TotalClicks = livePage.Analytics?.TotalClicks ?? 0 });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listCounts.Add(page.Id, new { TotalViews = (long)(page.Analytics?.TotalViews ?? 0), TotalClicks = (long)(page.Analytics?.TotalClicks ?? 0) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var dashboardModel = new DashboardViewModel
|
var dashboardModel = new DashboardViewModel
|
||||||
{
|
{
|
||||||
CurrentUser = user,
|
CurrentUser = user,
|
||||||
@ -66,8 +85,8 @@ public class AdminController : Controller
|
|||||||
Slug = p.Slug,
|
Slug = p.Slug,
|
||||||
Category = p.Category,
|
Category = p.Category,
|
||||||
Status = p.Status,
|
Status = p.Status,
|
||||||
TotalClicks = p.Analytics?.TotalClicks ?? 0,
|
TotalClicks = listCounts[p.Id].TotalClicks ?? 0,
|
||||||
TotalViews = p.Analytics?.TotalViews ?? 0,
|
TotalViews = listCounts[p.Id].TotalViews ?? 0,
|
||||||
PreviewToken = p.PreviewToken,
|
PreviewToken = p.PreviewToken,
|
||||||
CreatedAt = p.CreatedAt,
|
CreatedAt = p.CreatedAt,
|
||||||
LastModerationStatus = p.ModerationHistory == null || p.ModerationHistory.Count == 0 || p.ModerationHistory.Last().Status == "rejected"
|
LastModerationStatus = p.ModerationHistory == null || p.ModerationHistory.Count == 0 || p.ModerationHistory.Last().Status == "rejected"
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class LivePageController : Controller
|
|||||||
|
|
||||||
// Configurar ViewBag para indicar que é uma live page
|
// Configurar ViewBag para indicar que é uma live page
|
||||||
ViewBag.IsLivePage = true;
|
ViewBag.IsLivePage = true;
|
||||||
ViewBag.PageUrl = $"https://vcart.me/page/{category}/{slug}";
|
ViewBag.PageUrl = $"https://bcards.site/page/{category}/{slug}";
|
||||||
ViewBag.Title = $"{livePage.DisplayName} - {livePage.Category} | BCards";
|
ViewBag.Title = $"{livePage.DisplayName} - {livePage.Category} | BCards";
|
||||||
|
|
||||||
_logger.LogInformation("Serving LivePage {LivePageId} for {Category}/{Slug}", livePage.Id, category, slug);
|
_logger.LogInformation("Serving LivePage {LivePageId} for {Category}/{Slug}", livePage.Id, category, slug);
|
||||||
|
|||||||
@ -87,12 +87,18 @@ public class UserPageController : Controller
|
|||||||
var seoSettings = _seoService.GenerateSeoSettings(userPage, categoryObj);
|
var seoSettings = _seoService.GenerateSeoSettings(userPage, categoryObj);
|
||||||
|
|
||||||
// Record page view (async, don't wait) - only for non-preview requests
|
// Record page view (async, don't wait) - only for non-preview requests
|
||||||
|
Console.WriteLine($"DEBUG VIEW COUNT - Page: {userPage.Slug}, Status: {userPage.Status}, IsPreview: {isPreview}, PreviewToken: {previewToken}");
|
||||||
if (!isPreview)
|
if (!isPreview)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine($"DEBUG: Recording view for page {userPage.Slug}");
|
||||||
var referrer = Request.Headers["Referer"].FirstOrDefault();
|
var referrer = Request.Headers["Referer"].FirstOrDefault();
|
||||||
var userAgent = Request.Headers["User-Agent"].FirstOrDefault();
|
var userAgent = Request.Headers["User-Agent"].FirstOrDefault();
|
||||||
_ = Task.Run(() => _userPageService.RecordPageViewAsync(userPage.Id, referrer, userAgent));
|
_ = Task.Run(() => _userPageService.RecordPageViewAsync(userPage.Id, referrer, userAgent));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"DEBUG: NOT recording view - isPreview = true");
|
||||||
|
}
|
||||||
|
|
||||||
ViewBag.SeoSettings = seoSettings;
|
ViewBag.SeoSettings = seoSettings;
|
||||||
ViewBag.Category = categoryObj;
|
ViewBag.Category = categoryObj;
|
||||||
|
|||||||
@ -6,6 +6,7 @@ public interface ILivePageRepository
|
|||||||
{
|
{
|
||||||
Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug);
|
Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug);
|
||||||
Task<LivePage?> GetByOriginalPageIdAsync(string originalPageId);
|
Task<LivePage?> GetByOriginalPageIdAsync(string originalPageId);
|
||||||
|
Task<LivePage?> GetByIdAsync(string pageId);
|
||||||
Task<List<LivePage>> GetAllActiveAsync();
|
Task<List<LivePage>> GetAllActiveAsync();
|
||||||
Task<LivePage> CreateAsync(LivePage livePage);
|
Task<LivePage> CreateAsync(LivePage livePage);
|
||||||
Task<LivePage> UpdateAsync(LivePage livePage);
|
Task<LivePage> UpdateAsync(LivePage livePage);
|
||||||
|
|||||||
@ -43,6 +43,11 @@ public class LivePageRepository : ILivePageRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<LivePage?> GetByIdAsync(string pageId)
|
||||||
|
{
|
||||||
|
return await _collection.Find(x => x.Id == pageId).FirstOrDefaultAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug)
|
public async Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug)
|
||||||
{
|
{
|
||||||
return await _collection.Find(x => x.Category == category && x.Slug == slug).FirstOrDefaultAsync();
|
return await _collection.Find(x => x.Category == category && x.Slug == slug).FirstOrDefaultAsync();
|
||||||
|
|||||||
@ -6,6 +6,7 @@ public interface ILivePageService
|
|||||||
{
|
{
|
||||||
Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug);
|
Task<LivePage?> GetByCategoryAndSlugAsync(string category, string slug);
|
||||||
Task<List<LivePage>> GetAllActiveAsync();
|
Task<List<LivePage>> GetAllActiveAsync();
|
||||||
|
Task<LivePage?> GetLivePageFromUserPageId(string userPageId);
|
||||||
Task<LivePage> SyncFromUserPageAsync(string userPageId);
|
Task<LivePage> SyncFromUserPageAsync(string userPageId);
|
||||||
Task<bool> DeleteByOriginalPageIdAsync(string originalPageId);
|
Task<bool> DeleteByOriginalPageIdAsync(string originalPageId);
|
||||||
Task IncrementViewAsync(string livePageId);
|
Task IncrementViewAsync(string livePageId);
|
||||||
|
|||||||
@ -30,6 +30,11 @@ public class LivePageService : ILivePageService
|
|||||||
return await _livePageRepository.GetAllActiveAsync();
|
return await _livePageRepository.GetAllActiveAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<LivePage?> GetLivePageFromUserPageId(string userPageId)
|
||||||
|
{
|
||||||
|
return await _livePageRepository.GetByOriginalPageIdAsync(userPageId);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<LivePage> SyncFromUserPageAsync(string userPageId)
|
public async Task<LivePage> SyncFromUserPageAsync(string userPageId)
|
||||||
{
|
{
|
||||||
var userPage = await _userPageRepository.GetByIdAsync(userPageId);
|
var userPage = await _userPageRepository.GetByIdAsync(userPageId);
|
||||||
|
|||||||
@ -12,15 +12,18 @@ public class UserPageService : IUserPageService
|
|||||||
private readonly IUserPageRepository _userPageRepository;
|
private readonly IUserPageRepository _userPageRepository;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly ISubscriptionRepository _subscriptionRepository;
|
private readonly ISubscriptionRepository _subscriptionRepository;
|
||||||
|
private readonly ILivePageRepository _livePageRepository;
|
||||||
|
|
||||||
public UserPageService(
|
public UserPageService(
|
||||||
IUserPageRepository userPageRepository,
|
IUserPageRepository userPageRepository,
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
ISubscriptionRepository subscriptionRepository)
|
ISubscriptionRepository subscriptionRepository,
|
||||||
|
ILivePageRepository livePageRepository)
|
||||||
{
|
{
|
||||||
_userPageRepository = userPageRepository;
|
_userPageRepository = userPageRepository;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_subscriptionRepository = subscriptionRepository;
|
_subscriptionRepository = subscriptionRepository;
|
||||||
|
_livePageRepository = livePageRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserPage?> GetPageAsync(string category, string slug)
|
public async Task<UserPage?> GetPageAsync(string category, string slug)
|
||||||
@ -148,14 +151,21 @@ public class UserPageService : IUserPageService
|
|||||||
|
|
||||||
public async Task RecordLinkClickAsync(string pageId, int linkIndex)
|
public async Task RecordLinkClickAsync(string pageId, int linkIndex)
|
||||||
{
|
{
|
||||||
var page = await _userPageRepository.GetByIdAsync(pageId);
|
var livePageExists = await _livePageRepository.GetByIdAsync(pageId);
|
||||||
if (page?.PlanLimitations.AllowAnalytics != true) return;
|
if (livePageExists == null) return;
|
||||||
|
|
||||||
if (linkIndex >= 0 && linkIndex < page.Links.Count)
|
var page = await _userPageRepository.GetByIdAsync(livePageExists.OriginalPageId);
|
||||||
|
var livepage = (LivePage)livePageExists;
|
||||||
|
|
||||||
|
if (linkIndex >= 0 && linkIndex < livepage.Links.Count)
|
||||||
{
|
{
|
||||||
|
livepage.Links[linkIndex].Clicks++;
|
||||||
page.Links[linkIndex].Clicks++;
|
page.Links[linkIndex].Clicks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var analyticsLive = livepage.Analytics;
|
||||||
|
analyticsLive.TotalClicks++;
|
||||||
|
|
||||||
var analytics = page.Analytics;
|
var analytics = page.Analytics;
|
||||||
analytics.TotalClicks++;
|
analytics.TotalClicks++;
|
||||||
|
|
||||||
@ -166,6 +176,7 @@ public class UserPageService : IUserPageService
|
|||||||
else
|
else
|
||||||
analytics.MonthlyClicks[monthKey] = 1;
|
analytics.MonthlyClicks[monthKey] = 1;
|
||||||
|
|
||||||
|
await _livePageRepository.UpdateAsync(livepage);
|
||||||
await _userPageRepository.UpdateAsync(page);
|
await _userPageRepository.UpdateAsync(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -97,8 +97,8 @@ public class UserPageSummary
|
|||||||
public string Slug { get; set; } = string.Empty;
|
public string Slug { get; set; } = string.Empty;
|
||||||
public string Category { get; set; } = string.Empty;
|
public string Category { get; set; } = string.Empty;
|
||||||
public PageStatus Status { get; set; } = PageStatus.Active;
|
public PageStatus Status { get; set; } = PageStatus.Active;
|
||||||
public int TotalClicks { get; set; } = 0;
|
public long TotalClicks { get; set; } = 0;
|
||||||
public int TotalViews { get; set; } = 0;
|
public long TotalViews { get; set; } = 0;
|
||||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
public string? PreviewToken { get; set; } = string.Empty;
|
public string? PreviewToken { get; set; } = string.Empty;
|
||||||
public string PublicUrl => $"/page/{Category.ToLower()}/{Slug.ToLower()}?preview={PreviewToken}";
|
public string PublicUrl => $"/page/{Category.ToLower()}/{Slug.ToLower()}?preview={PreviewToken}";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user