diff --git a/Submission.Api/Controllers/DebugController.cs b/Submission.Api/Controllers/DebugController.cs index b6ae977..4e6a2eb 100644 --- a/Submission.Api/Controllers/DebugController.cs +++ b/Submission.Api/Controllers/DebugController.cs @@ -189,98 +189,6 @@ namespace Submission.Api.Controllers } } - // New endpoint: form-based petition upload - [HttpPost("upload-petition-form", Name = "UploadPetitionForm")] - public async Task UploadPetitionForm([FromForm] PetitionFormDto form) - { - // Check if petition creation is allowed - if (!_petitionSettings.AllowPetitionCreation) - { - return StatusCode(403, new { message = "Petition creation is disabled. Set 'PetitionSettings:AllowPetitionCreation' to true in appsettings.json" }); - } - - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - try - { - // Parse start date (format: dd-MM-yyyy) - DateOnly startDate; - try - { - startDate = DateOnly.ParseExact(form.StartDate, "dd-MM-yyyy", CultureInfo.InvariantCulture); - } - catch (FormatException) - { - return BadRequest(new { message = "StartDate must be in format dd-MM-yyyy" }); - } - - // Check for duplicate slug - var existingPetition = await _petitionRepository.FindOneAsync(x => x.Slug == form.Slug); - if (existingPetition != null) - { - return Conflict(new { message = $"A petition with slug '{form.Slug}' already exists" }); - } - - var petitionId = Guid.NewGuid(); - - // Create or get author - var author = await _authorRepository.FindOneAsync(x => x.NID == form.AuthorNid); - if (author == null) - { - author = new Author - { - Id = Guid.NewGuid(), - Name = form.AuthorName, - NID = form.AuthorNid - }; - await _authorRepository.InsertOneAsync(author); - } - - // Create petition - var petition = new PetitionDetail - { - Id = petitionId, - Slug = form.Slug, - StartDate = startDate, - NameDhiv = form.NameDhiv, - NameEng = form.NameEng, - AuthorId = author.Id, - PetitionBodyDhiv = form.PetitionBodyDhiv, - PetitionBodyEng = form.PetitionBodyEng, - SignatureCount = 0 - }; - - await _petitionRepository.InsertOneAsync(petition); - - // Build markdown file content and save to Petitions folder - var frontmatter = $"---\nslug: \"{EscapeYaml(form.Slug)}\"\nstartDate: {form.StartDate}\nnameDhiv: \"{EscapeYaml(form.NameDhiv)}\"\nnameEng: \"{EscapeYaml(form.NameEng)}\"\nauthor:\n name: \"{EscapeYaml(form.AuthorName)}\"\n nid: \"{EscapeYaml(form.AuthorNid)}\"\n---\n"; - var body = $"## Petition Body (Dhivehi)\n\n{form.PetitionBodyDhiv}\n\n## Petition Body (English)\n\n{form.PetitionBodyEng}\n"; - var fileContent = frontmatter + "\n" + body; - - Directory.CreateDirectory("Petitions"); - var newFileName = $"{Guid.NewGuid()}.md"; - var filePath = Path.Combine("Petitions", newFileName); - - await System.IO.File.WriteAllTextAsync(filePath, fileContent); - - return Ok(new - { - message = "Petition created successfully", - petitionId = petitionId, - slug = form.Slug, - fileName = newFileName, - filePath = filePath, - authorId = author.Id - }); - } - catch (Exception e) - { - return Problem(e.Message); - } - } [HttpPost("svg-debug", Name = "SvgDebug")] public async Task SVG_TEST([FromForm]string svg) @@ -356,10 +264,6 @@ namespace Submission.Api.Controllers return (dhivehiBody, englishBody); } - private static string EscapeYaml(string value) - { - if (string.IsNullOrEmpty(value)) return ""; - return value.Replace("\"", "\\\""); - } + } }