#104 page PUT api
This commit is contained in:
parent
44f4136020
commit
3c87afee61
@ -9,6 +9,7 @@ using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.GanjoorIntegration.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Auth.Memory;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Models.Image;
|
||||
@ -206,6 +207,34 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// modify page
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPut]
|
||||
[Route("page/{id}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPageCompleteViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> ModifyPage(int id, GanjoorModifyPageViewModel page)
|
||||
{
|
||||
Guid userId =
|
||||
new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
|
||||
RServiceResult<GanjoorPageCompleteViewModel> res =
|
||||
await _ganjoorService.ModifyPage(id, userId, page);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
if (res.Result == null)
|
||||
return NotFound();
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// page url by id
|
||||
/// </summary>
|
||||
|
||||
2284
RMuseum/Migrations/20210409053912_GanjoorPageSnapshot.Designer.cs
generated
Normal file
2284
RMuseum/Migrations/20210409053912_GanjoorPageSnapshot.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
64
RMuseum/Migrations/20210409053912_GanjoorPageSnapshot.cs
Normal file
64
RMuseum/Migrations/20210409053912_GanjoorPageSnapshot.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace RMuseum.Migrations
|
||||
{
|
||||
public partial class GanjoorPageSnapshot : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "GanjoorPageSnapshots",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
GanjoorPageId = table.Column<int>(nullable: false),
|
||||
MadeObsoleteByUserId = table.Column<Guid>(nullable: false),
|
||||
RecordDate = table.Column<DateTime>(nullable: false),
|
||||
Note = table.Column<string>(nullable: true),
|
||||
Title = table.Column<string>(nullable: true),
|
||||
UrlSlug = table.Column<string>(nullable: true),
|
||||
HtmlText = table.Column<string>(nullable: true),
|
||||
Rhythm = table.Column<string>(nullable: true),
|
||||
RhymeLetters = table.Column<string>(nullable: true),
|
||||
SourceName = table.Column<string>(nullable: true),
|
||||
SourceUrlSlug = table.Column<string>(nullable: true),
|
||||
OldTag = table.Column<string>(nullable: true),
|
||||
OldTagPageUrl = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_GanjoorPageSnapshots", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_GanjoorPageSnapshots_GanjoorPages_GanjoorPageId",
|
||||
column: x => x.GanjoorPageId,
|
||||
principalTable: "GanjoorPages",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_GanjoorPageSnapshots_AspNetUsers_MadeObsoleteByUserId",
|
||||
column: x => x.MadeObsoleteByUserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GanjoorPageSnapshots_GanjoorPageId",
|
||||
table: "GanjoorPageSnapshots",
|
||||
column: "GanjoorPageId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GanjoorPageSnapshots_MadeObsoleteByUserId",
|
||||
table: "GanjoorPageSnapshots",
|
||||
column: "MadeObsoleteByUserId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "GanjoorPageSnapshots");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -534,6 +534,61 @@ namespace RMuseum.Migrations
|
||||
b.ToTable("GanjoorPages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorPageSnapshot", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<int>("GanjoorPageId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("HtmlText")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("MadeObsoleteByUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("Note")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("OldTag")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("OldTagPageUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("RecordDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("RhymeLetters")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Rhythm")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SourceName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SourceUrlSlug")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UrlSlug")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GanjoorPageId");
|
||||
|
||||
b.HasIndex("MadeObsoleteByUserId");
|
||||
|
||||
b.ToTable("GanjoorPageSnapshots");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorPoem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -1948,6 +2003,21 @@ namespace RMuseum.Migrations
|
||||
.HasForeignKey("SecondPoetId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorPageSnapshot", b =>
|
||||
{
|
||||
b.HasOne("RMuseum.Models.Ganjoor.GanjoorPage", "GanjoorPage")
|
||||
.WithMany()
|
||||
.HasForeignKey("GanjoorPageId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("RSecurityBackend.Models.Auth.Db.RAppUser", "MadeObsoleteByUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("MadeObsoleteByUserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RMuseum.Models.Ganjoor.GanjoorPoem", b =>
|
||||
{
|
||||
b.HasOne("RMuseum.Models.Ganjoor.GanjoorCat", "Cat")
|
||||
|
||||
@ -668,6 +668,14 @@
|
||||
<param name="catPoems"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.ModifyPage(System.Int32,RMuseum.Models.Ganjoor.ViewModels.GanjoorModifyPageViewModel)">
|
||||
<summary>
|
||||
modify page
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="page"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetPageUrlById(System.Int32)">
|
||||
<summary>
|
||||
page url by id
|
||||
@ -6593,6 +6601,15 @@
|
||||
<param name="poetId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.ModifyPage(System.Int32,System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorModifyPageViewModel)">
|
||||
<summary>
|
||||
modify page
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="editingUserId"></param>
|
||||
<param name="pageData"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.Faal">
|
||||
<summary>
|
||||
get a random poem from hafez
|
||||
|
||||
@ -242,6 +242,15 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId);
|
||||
|
||||
/// <summary>
|
||||
/// modify page
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="editingUserId"></param>
|
||||
/// <param name="pageData"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<GanjoorPageCompleteViewModel>> ModifyPage(int id, Guid editingUserId, GanjoorModifyPageViewModel pageData);
|
||||
|
||||
/// <summary>
|
||||
/// get a random poem from hafez
|
||||
/// </summary>
|
||||
|
||||
@ -1795,7 +1795,42 @@ namespace RMuseum.Services.Implementation
|
||||
_context.GanjoorPageSnapshots.Add(snapshot);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
//TODO actula modification goes here:
|
||||
dbPage.Title = pageData.Title;
|
||||
dbPage.UrlSlug = pageData.UrlSlug;
|
||||
dbPage.HtmlText = pageData.HtmlText;
|
||||
|
||||
_context.GanjoorPages.Update(dbPage);
|
||||
|
||||
if(dbPoem != null)
|
||||
{
|
||||
dbPoem.SourceName = pageData.SourceName;
|
||||
dbPoem.SourceUrlSlug = pageData.SourceUrlSlug;
|
||||
if(string.IsNullOrEmpty(pageData.Rhythm))
|
||||
{
|
||||
dbPoem.GanjoorMetreId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var metre = await _context.GanjoorMetres.Where(m => m.Rhythm == pageData.Rhythm).SingleOrDefaultAsync();
|
||||
if (metre == null)
|
||||
{
|
||||
metre = new GanjoorMetre()
|
||||
{
|
||||
Rhythm = pageData.Rhythm,
|
||||
VerseCount = 0
|
||||
};
|
||||
_context.GanjoorMetres.Add(metre);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
dbPoem.GanjoorMetreId = metre.Id;
|
||||
}
|
||||
dbPoem.RhymeLetters = pageData.RhymeLetters;
|
||||
dbPoem.OldTag = pageData.OldTag;
|
||||
dbPoem.OldTagPageUrl = pageData.OldTagPageUrl;
|
||||
_context.GanjoorPoems.Update(dbPoem);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
return await GetPageByUrl(dbPage.FullUrl);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user