-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Lov controller, added ListID selection in the property editor, …
…added pagination Lov data
- Loading branch information
Showing
17 changed files
with
367 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using FormBuilder.API.Data; | ||
using FormBuilder.API.Mappers; | ||
using FormBuilder.Shared.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace FormBuilder.API.Controllers; | ||
|
||
[Route("api/lov")] | ||
[ApiController] | ||
public class LovController : ControllerBase | ||
{ | ||
private readonly ApplicationDbContext _context; | ||
|
||
public LovController(ApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
/// <summary> | ||
/// Gets a paged list of List IDs. | ||
/// </summary> | ||
/// <param name="pagedQuery">Paged query</param> | ||
[HttpGet] | ||
[ProducesResponseType(typeof(PagedResult<int?>), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(Result), StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> GetListIdPaged([FromQuery] PagedQuery pagedQuery) | ||
{ | ||
var listIds = await _context.LovMaster | ||
.Select(i => i.ListId) | ||
.Distinct() | ||
.Skip((pagedQuery.Page - 1) * pagedQuery.PageSize) | ||
.Take(pagedQuery.PageSize) | ||
.ToArrayAsync(); | ||
|
||
return Ok(PagedResult<int?>.Succeed(listIds)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets list of values filtered by ListId | ||
/// </summary> | ||
[HttpGet("{listId:int}")] | ||
[ProducesResponseType(typeof(Result<LovDto[]>), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(Result), StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> GetLov(int listId) | ||
{ | ||
var lovs = await _context.LovMaster | ||
.Where(i => i.ListId == listId) | ||
.Select(i => i.ToDto()) | ||
.ToArrayAsync(); | ||
|
||
return Ok(Result<LovDto[]>.Succeed(lovs)); | ||
} | ||
|
||
/// <summary> | ||
/// Batch add list of values | ||
/// </summary> | ||
/// <param name="batchAddLovCommand">The form data.</param> | ||
[HttpPost] | ||
[ProducesResponseType(typeof(Result), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(Result), StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> AddListOfValues(BatchAddLovCommand batchAddLovCommand) | ||
{ | ||
var lovs = batchAddLovCommand.Lovs.Select(i => i.ToEntity()); | ||
|
||
await _context.LovMaster.AddRangeAsync(lovs); | ||
await _context.SaveChangesAsync(); | ||
return Ok(Result.Succeed()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/FormBuilder.API/Entities/LovMaster.cs → src/FormBuilder.API/Entities/Lov.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FormBuilder.API.Entities; | ||
using FormBuilder.Shared.Models; | ||
|
||
namespace FormBuilder.API.Mappers; | ||
|
||
public static class FormMapper | ||
{ | ||
public static FormDto ToDto(this Form entity) | ||
{ | ||
return new FormDto | ||
{ | ||
Id = entity.Id, | ||
FormName = entity.FormName, | ||
FormDesign = entity.FormDesign | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FormBuilder.API.Entities; | ||
using FormBuilder.Shared.Models; | ||
|
||
namespace FormBuilder.API.Mappers; | ||
|
||
public static class LovMapper | ||
{ | ||
public static LovDto ToDto(this Lov entity) | ||
{ | ||
return new LovDto | ||
{ | ||
ListId = entity.ListId, | ||
ListValue = entity.ListValue | ||
}; | ||
} | ||
|
||
public static Lov ToEntity(this LovDto dto) | ||
{ | ||
return new Lov | ||
{ | ||
ListId = dto.ListId, | ||
ListValue = dto.ListValue | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace FormBuilder.Shared.Models; | ||
|
||
public record BatchAddLovCommand | ||
{ | ||
public IEnumerable<LovDto> Lovs { get; set; } = []; | ||
} |
2 changes: 1 addition & 1 deletion
2
...ormBuilder.Shared/Models/CreateFormDto.cs → ...uilder.Shared/Models/CreateFormCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace FormBuilder.Shared.Models; | ||
|
||
public record LovDto | ||
{ | ||
public int? ListId { get; set; } | ||
public string? ListValue { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ormBuilder.Shared/Models/UpdateFormDto.cs → ...uilder.Shared/Models/UpdateFormCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.