Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
220 lines
9.6 KiB
C#
220 lines
9.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using DNTPersianUtils.Core;
|
|
using DivanRazor.Utils;
|
|
using GSpotifyProxy.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
using RSecurityBackend.Models.Auth.ViewModels;
|
|
using RSecurityBackend.Models.Generic;
|
|
|
|
namespace DivanRazor.Areas.User.Pages
|
|
{
|
|
public class MyCommentsModel : PageModel
|
|
{
|
|
/// <summary>
|
|
/// constructor
|
|
/// </summary>
|
|
public MyCommentsModel()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Last Error
|
|
/// </summary>
|
|
public string LastError { get; set; }
|
|
|
|
/// <summary>
|
|
/// comments
|
|
/// </summary>
|
|
public List<DivanCommentFullViewModel> Comments { get; set; }
|
|
|
|
/// <summary>
|
|
/// pagination links
|
|
/// </summary>
|
|
public List<NameIdUrlImage> PaginationLinks { get; set; }
|
|
|
|
public RegisterRAppUser UserInfo { get; set; }
|
|
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
|
|
return Redirect("/");
|
|
|
|
LastError = "";
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
{
|
|
var userInfoResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/users/{Request.Cookies["UserId"]}");
|
|
if (userInfoResponse.IsSuccessStatusCode)
|
|
{
|
|
PublicRAppUser userInfo = JsonConvert.DeserializeObject<PublicRAppUser>(await userInfoResponse.Content.ReadAsStringAsync());
|
|
|
|
UserInfo = new RegisterRAppUser()
|
|
{
|
|
Id = userInfo.Id,
|
|
Username = userInfo.Username,
|
|
FirstName = userInfo.FirstName,
|
|
SurName = userInfo.SurName,
|
|
NickName = userInfo.NickName,
|
|
PhoneNumber = userInfo.PhoneNumber,
|
|
Email = userInfo.Email,
|
|
Website = userInfo.Website,
|
|
Bio = userInfo.Bio,
|
|
RImageId = userInfo.RImageId,
|
|
Status = userInfo.Status,
|
|
IsAdmin = false,
|
|
Password = ""
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LastError = await userInfoResponse.Content.ReadAsStringAsync();
|
|
}
|
|
|
|
int pageNumber = 1;
|
|
if (!string.IsNullOrEmpty(Request.Query["page"]))
|
|
{
|
|
pageNumber = int.Parse(Request.Query["page"]);
|
|
}
|
|
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/divan/comments/mine?PageNumber={pageNumber}&PageSize=20");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
|
return Page();
|
|
}
|
|
|
|
Comments = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<DivanCommentFullViewModel>>();
|
|
|
|
string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(paginnationMetadata))
|
|
{
|
|
PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject<PaginationMetadata>(paginnationMetadata);
|
|
PaginationLinks = new List<NameIdUrlImage>();
|
|
if (paginationMetadata.totalPages > 1)
|
|
{
|
|
if (paginationMetadata.currentPage > 3)
|
|
{
|
|
PaginationLinks.Add
|
|
(
|
|
new NameIdUrlImage()
|
|
{
|
|
Name = "صفحهٔ اول",
|
|
Url = "/User/MyComments/?page=1"
|
|
}
|
|
);
|
|
}
|
|
for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++)
|
|
{
|
|
if (i >= 1 && i <= paginationMetadata.totalPages)
|
|
{
|
|
if (i == paginationMetadata.currentPage)
|
|
{
|
|
|
|
PaginationLinks.Add
|
|
(
|
|
new NameIdUrlImage()
|
|
{
|
|
Name = i.ToPersianNumbers(),
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
|
|
PaginationLinks.Add
|
|
(
|
|
new NameIdUrlImage()
|
|
{
|
|
Name = i.ToPersianNumbers(),
|
|
Url = $"/User/MyComments/?page={i}"
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
|
|
{
|
|
|
|
PaginationLinks.Add
|
|
(
|
|
new NameIdUrlImage()
|
|
{
|
|
Name = "... ",
|
|
}
|
|
);
|
|
|
|
PaginationLinks.Add
|
|
(
|
|
new NameIdUrlImage()
|
|
{
|
|
Name = "صفحهٔ آخر",
|
|
Url = $"/User/MyComments/?page={paginationMetadata.totalPages}"
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LastError = "لطفاً از دیوان خارج و مجددا به آن وارد شوید.";
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> OnDeleteMyComment(int id)
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
var response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/divan/comment?id={id}");
|
|
|
|
if (response.StatusCode != HttpStatusCode.OK)
|
|
{
|
|
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return new BadRequestObjectResult("لطفاً از دیوان خارج و مجددا به آن وارد شوید.");
|
|
}
|
|
}
|
|
return new JsonResult(true);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPutMyComment(int id, string comment)
|
|
{
|
|
using (HttpClient secureClient = new HttpClient(new DivanReloginHandler(Request, Response)))
|
|
{
|
|
if (await DivanSessionChecker.PrepareClient(secureClient, Request, Response))
|
|
{
|
|
var response = await secureClient.PutAsync($"{APIRoot.Url}/api/divan/comment/{id}", new StringContent(JsonConvert.SerializeObject(comment), Encoding.UTF8, "application/json"));
|
|
if (response.StatusCode != HttpStatusCode.OK)
|
|
{
|
|
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return new BadRequestObjectResult("لطفاً از دیوان خارج و مجددا به آن وارد شوید.");
|
|
}
|
|
}
|
|
return new JsonResult(true);
|
|
}
|
|
}
|
|
}
|