Skip to content

Commit

Permalink
Merge pull request #117 from Yorubaname/main
Browse files Browse the repository at this point in the history
Release to production
  • Loading branch information
Zifah authored Dec 24, 2024
2 parents 1852181 + 089f15d commit 70701e3
Show file tree
Hide file tree
Showing 134 changed files with 383 additions and 1,636 deletions.
9 changes: 4 additions & 5 deletions Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="4.6.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Ardalis.GuardClauses" Version="5.0.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.10.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Infrastructure.MongoDB\Infrastructure.MongoDB.csproj" />
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Api/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Api.Utilities;
using Application.Services;
using Core.Dto.Request;
using Core.Dto.Response;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using YorubaOrganization.Core.Dto.Request;
using YorubaOrganization.Core.Dto.Response;

namespace Api.Controllers
{
Expand Down
4 changes: 2 additions & 2 deletions Api/Controllers/EtymologyController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Core.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using YorubaOrganization.Core.Repositories;

namespace Api.Controllers
{
Expand Down
16 changes: 7 additions & 9 deletions Api/Controllers/FeedbacksController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Api.Model.Request;
using Application.Domain;
using Application.Services;
using Application.Services;
using Core.Dto.Request;
using Core.Dto.Response;
using Core.Entities.NameEntry.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
Expand All @@ -27,7 +25,7 @@ public FeedbacksController(NameEntryFeedbackService nameEntryFeedbackService, Na

[HttpGet]
[Route("{id}")]
[ProducesResponseType(typeof(FeedbackDto), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(NameFeedbackDto), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetById(string id)
{
var feedback = await _nameEntryFeedbackService.GetFeedbackByIdAsync(id);
Expand All @@ -46,7 +44,7 @@ public async Task<IActionResult> GetById(string id)
/// <param name="name">Optional name parameter</param>
/// <returns>A list of all feedback (or just feedback for a given name)</returns>
[HttpGet]
[ProducesResponseType(typeof(List<FeedbackDto>), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(List<NameFeedbackDto>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetFeedback([FromQuery] string? name = null)
{
var feedbacks = string.IsNullOrWhiteSpace(name) ? await _nameEntryFeedbackService.FindAllAsync() :
Expand All @@ -64,7 +62,7 @@ public async Task<IActionResult> GetFeedback([FromQuery] string? name = null)
[ProducesResponseType(typeof(Dictionary<string, string>), (int)HttpStatusCode.Created)]
public async Task<IActionResult> Create([FromBody] CreateNameFeedbackDto model)
{
var nameEntry = await _nameEntryService.LoadName(model.Name);
var nameEntry = await _nameEntryService.LoadEntry(model.Name);

if (nameEntry == null)
{
Expand All @@ -91,7 +89,7 @@ public async Task<IActionResult> Delete(string name, string feedbackId)
return BadRequest("Name parameter is required.");
}

var nameEntry = await _nameEntryService.LoadName(name);
var nameEntry = await _nameEntryService.LoadEntry(name);

if (nameEntry == null)
{
Expand Down Expand Up @@ -122,7 +120,7 @@ public async Task<IActionResult> DeleteAll([FromQuery][Required] string name)
return BadRequest("Name parameter is required.");
}

var nameEntry = await _nameEntryService.LoadName(name);
var nameEntry = await _nameEntryService.LoadEntry(name);

if (nameEntry == null)
{
Expand Down
6 changes: 3 additions & 3 deletions Api/Controllers/GeoLocationsController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Api.Utilities;
using Application.Services;
using Core.Dto.Request;
using Core.Dto.Response;
using Core.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using YorubaOrganization.Core.Dto.Request;
using YorubaOrganization.Core.Dto.Response;
using YorubaOrganization.Core.Entities;

namespace Api.Controllers
{
Expand Down
35 changes: 20 additions & 15 deletions Api/Controllers/NamesController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Api.Model.In;
using Api.Utilities;
using Application.Domain;
using Api.Utilities;
using Application.Mappers;
using Application.Services;
using Core.Dto.Request;
using Core.Dto.Response;
using Core.Entities.NameEntry;
using Core.Enums;
using Core.Entities;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Driver;
using System.Net;
using YorubaOrganization.Core.Enums;

namespace Api.Controllers
{
Expand Down Expand Up @@ -63,13 +63,18 @@ public async Task<IActionResult> Post([FromBody] CreateNameDto request)
/// </summary>
/// <returns></returns>
[HttpGet("meta")]
[ProducesResponseType(typeof(NamesMetadataDto[]), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(NamesMetadataDto), (int)HttpStatusCode.OK)]
[AllowAnonymous]
public async Task<IActionResult> GetMetaData()
{
var metaData = await _nameEntryService.GetMetadata();

return Ok(metaData);
return Ok(new NamesMetadataDto
{
TotalNames = metaData.TotalEntries,
TotalPublishedNames = metaData.TotalPublishedEntries,
TotalModifiedNames = metaData.TotalModifiedEntries,
TotalNewNames = metaData.TotalNewEntries
});
}

/// <summary>
Expand All @@ -96,7 +101,7 @@ public async Task<IActionResult> GetAllNames(
IEnumerable<NameEntry> names;
if (all.HasValue && all.Value)
{
names = await _nameEntryService.GetAllNames(state, submittedBy);
names = await _nameEntryService.GetAllEntries(state, submittedBy);
return Ok(names.MapToDtoCollectionMini());
}

Expand All @@ -116,7 +121,7 @@ public async Task<IActionResult> GetAllNames(
[AllowAnonymous]
public async Task<IActionResult> GetName([FromRoute] string name)
{
var nameEntry = await _nameEntryService.LoadName(name);
var nameEntry = await _nameEntryService.LoadEntry(name);

if (nameEntry == null)
{
Expand Down Expand Up @@ -146,22 +151,22 @@ public async Task<IActionResult> UpdateName(string name, [FromBody] UpdateNameDt
return BadRequest(ModelState);
}

var oldNameEntry = await _nameEntryService.LoadName(name);
var oldNameEntry = await _nameEntryService.LoadEntry(name);

if (oldNameEntry == null)
{
return NotFound($"{name} not in database");
}

_ = await _nameEntryService.UpdateName(oldNameEntry, updated.MapToEntity());
_ = await _nameEntryService.Update(oldNameEntry, updated.MapToEntity());
return Ok(new { Message = "Name successfully updated" });
}

[HttpDelete("{name}")]
[Authorize(Policy = "AdminOnly")]
public async Task<IActionResult> DeleteName(string name)
{
var nameEntry = await _nameEntryService.LoadName(name);
var nameEntry = await _nameEntryService.LoadEntry(name);
if (nameEntry == null)
{
return NotFound($"{name} not found in the system so cannot be deleted");
Expand All @@ -177,7 +182,7 @@ public async Task<IActionResult> DeleteName(string name)
public async Task<IActionResult> DeleteNamesBatch(string[] names)
{

var foundNames = (await _nameEntryService.LoadNames(names))?.Select(f => f.Name)?.ToArray();
var foundNames = (await _nameEntryService.LoadEntries(names))?.Select(f => f.Title)?.ToArray();

if (foundNames is null || foundNames.Length == 0)
{
Expand All @@ -186,7 +191,7 @@ public async Task<IActionResult> DeleteNamesBatch(string[] names)

var notFoundNames = names.Where(d => !foundNames.Contains(d)).ToList();

await _nameEntryService.DeleteNamesBatch(foundNames);
await _nameEntryService.DeleteEntriesBatch(foundNames);

string responseMessage = string.Join(", ", foundNames) + " deleted";
if (notFoundNames.Any())
Expand Down
38 changes: 19 additions & 19 deletions Api/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Api.Utilities;
using Application.Domain;
using Application.Mappers;
using Application.Services;
using Core.Cache;
using Core.Dto.Response;
using Core.Entities.NameEntry;
using Core.Enums;
using Core.Events;
using Core.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Net;
using YorubaOrganization.Core.Cache;
using YorubaOrganization.Core.Dto.Response;
using YorubaOrganization.Core.Enums;
using YorubaOrganization.Core.Events;

namespace Api.Controllers
{
Expand Down Expand Up @@ -55,9 +55,9 @@ public async Task<IActionResult> Search([FromQuery(Name = "q"), Required] string
var matches = await _searchService.Search(searchTerm);

// TODO: Check if the comparison here removes takes diacrits into consideration
if (matches.Count() == 1 && matches.First().Name.Equals(searchTerm, StringComparison.CurrentCultureIgnoreCase))
if (matches.Count() == 1 && matches.First().Title.Equals(searchTerm, StringComparison.CurrentCultureIgnoreCase))
{
await _eventPubService.PublishEvent(new ExactNameSearched(matches.First().Name));
await _eventPubService.PublishEvent(new ExactEntrySearched(matches.First().Title));
}

return Ok(matches.MapToDtoCollection());
Expand Down Expand Up @@ -92,11 +92,11 @@ public async Task<IActionResult> SearchByStartsWith(string searchTerm)
[ProducesResponseType(typeof(NameEntryDto), (int)HttpStatusCode.OK)]
public async Task<IActionResult> SearchOne(string searchTerm)
{
NameEntryDto nameEntry = await _searchService.GetName(searchTerm);
var nameEntry = await _searchService.GetName(searchTerm);

if(nameEntry != null)
{
await _eventPubService.PublishEvent(new ExactNameSearched(nameEntry.Name));
await _eventPubService.PublishEvent(new ExactEntrySearched(nameEntry.Name));
}

return Ok(nameEntry);
Expand Down Expand Up @@ -158,7 +158,7 @@ public async Task<IActionResult> GetRecentStats()
[Authorize(Policy = "AdminAndProLexicographers")]
public async Task<IActionResult> PublishName([FromRoute] string name)
{
var nameEntry = await _nameEntryService.LoadName(name);
var nameEntry = await _nameEntryService.LoadEntry(name);
if (nameEntry == null)
{
return BadRequest(ResponseHelper.GetResponseDict($"{name} not found in the repository so not indexed"));
Expand All @@ -170,7 +170,7 @@ public async Task<IActionResult> PublishName([FromRoute] string name)
return BadRequest(ResponseHelper.GetResponseDict($"{name} is already indexed"));
}

await _nameEntryService.PublishName(nameEntry, User!.Identity!.Name!);
await _nameEntryService.PublishEntry(nameEntry, User!.Identity!.Name!);
return StatusCode((int)HttpStatusCode.Created, ResponseHelper.GetResponseDict($"{name} has been published"));
}

Expand All @@ -189,7 +189,7 @@ public async Task<IActionResult> PublishNames([FromBody] string[] names)
// TODO Later: Optimize by fetching all names in one database call instead of one-by-one.
foreach (var name in names)
{
var entry = await _nameEntryService.LoadName(name);
var entry = await _nameEntryService.LoadEntry(name);
if (entry != null && entry.State != State.PUBLISHED)
{
entriesToIndex.Add(entry);
Expand All @@ -204,10 +204,10 @@ public async Task<IActionResult> PublishNames([FromBody] string[] names)
foreach (var nameEntry in entriesToIndex)
{
// TODO Later: The names should be updated in one batch instead of one-by-one.
await _nameEntryService.PublishName(nameEntry, User!.Identity!.Name!);
await _nameEntryService.PublishEntry(nameEntry, User!.Identity!.Name!);
}

var successMessage = $"The following names were successfully indexed: {string.Join(',', entriesToIndex.Select(x => x.Name))}";
var successMessage = $"The following names were successfully indexed: {string.Join(',', entriesToIndex.Select(x => x.Title))}";
return StatusCode((int)HttpStatusCode.Created, ResponseHelper.GetResponseDict(successMessage));
}

Expand All @@ -220,15 +220,15 @@ public async Task<IActionResult> PublishNames([FromBody] string[] names)
[Authorize(Policy = "AdminAndProLexicographers")]
public async Task<IActionResult> UnpublishName([FromRoute] string name)
{
var entry = await _nameEntryService.FindByNameAndState(name, State.PUBLISHED);
var entry = await _nameEntryService.FindByTitleAndState(name, State.PUBLISHED);

if (entry == null)
{
return StatusCode((int)HttpStatusCode.BadRequest, ResponseHelper.GetResponseDict("Published name not found."));
}

entry.State = State.NEW;
await _nameEntryService.UpdateName(entry);
await _nameEntryService.Update(entry);
return Ok(ResponseHelper.GetResponseDict($"{name} removed from index."));
}

Expand All @@ -245,7 +245,7 @@ public async Task<IActionResult> UnpublishNames([FromBody] string[] names)

foreach (var name in names)
{
var entry = await _nameEntryService.FindByNameAndState(name, State.PUBLISHED);
var entry = await _nameEntryService.FindByTitleAndState(name, State.PUBLISHED);

if (entry == null)
{
Expand All @@ -254,8 +254,8 @@ public async Task<IActionResult> UnpublishNames([FromBody] string[] names)
else
{
entry.State = State.UNPUBLISHED;
await _nameEntryService.UpdateName(entry);
unpublishedNames.Add(entry.Name);
await _nameEntryService.Update(entry);
unpublishedNames.Add(entry.Title);
}
}

Expand Down
1 change: 0 additions & 1 deletion Api/Controllers/SuggestedNameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Net;
using Application.Mappers;
using Application.Validation;
using FluentValidation;

namespace Api.Controllers;
Expand Down
2 changes: 1 addition & 1 deletion Api/ExceptionHandler/GlobalExceptionHandling.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Api.ExceptionHandler
{
using Api.Utilities;
using Application.Exceptions;
using System.Net;
using System.Text.Json;
using YorubaOrganization.Application.Exceptions;

public class GlobalExceptionHandlingMiddleware
{
Expand Down
Loading

0 comments on commit 70701e3

Please sign in to comment.