add missing fields
This commit is contained in:
@@ -8,6 +8,7 @@ using weddingapi.Repositories;
|
||||
using weddingapi.Dtos;
|
||||
using weddingapi.Converters;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
namespace weddingapi.Controllers
|
||||
{
|
||||
@@ -22,6 +23,15 @@ namespace weddingapi.Controllers
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
// GET /familyCount
|
||||
[HttpGet("FamilyCount")]
|
||||
public async Task<int> GetFamilyCountAsync()
|
||||
{
|
||||
int totalCount = 0;
|
||||
(await repository.GetFamiliesAsync()).ToList().ForEach(family => totalCount += family.Members.Count());
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
// GET /family
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
||||
@@ -55,6 +65,8 @@ namespace weddingapi.Controllers
|
||||
CreatedDate = DateTimeOffset.UtcNow,
|
||||
Name = familyDto.Name,
|
||||
Overnight = familyDto.Overnight,
|
||||
Email = familyDto.EMail,
|
||||
Telephonenumber = familyDto.Telephonenumber,
|
||||
Members = familyDto.Members.Select(person => new Person() {
|
||||
IsChild = person.IsChild,
|
||||
Name = person.Name,
|
||||
@@ -84,6 +96,8 @@ namespace weddingapi.Controllers
|
||||
IsChild = person.IsChild,
|
||||
}).ToList(),
|
||||
Overnight = familyDto.Overnight,
|
||||
Email = familyDto.Email,
|
||||
Telephonenumber = familyDto.Telephonenumber,
|
||||
Name = familyDto.Name,
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace weddingapi.Converters
|
||||
{
|
||||
Id = family.Id,
|
||||
CreatedDate = family.CreatedDate,
|
||||
Overnight = family.Overnight,
|
||||
Email = family.Email,
|
||||
Telephonenumber = family.Telephonenumber,
|
||||
Members = family.Members.Select(person => person.AsDto()).ToList(),
|
||||
Name = family.Name,
|
||||
};
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace weddingapi.Dtos
|
||||
[Required]
|
||||
public bool Overnight { get; set; }
|
||||
[Required]
|
||||
public string EMail { get; set; }
|
||||
[Required]
|
||||
public string Telephonenumber { get; set; }
|
||||
[Required]
|
||||
public IList<PersonDto> Members { get; init;}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@ namespace weddingapi.Dtos
|
||||
|
||||
public bool Overnight { get; init; }
|
||||
|
||||
public string Email { get; init; }
|
||||
|
||||
public string Telephonenumber { get; init; }
|
||||
|
||||
public DateTimeOffset CreatedDate { get; set; }
|
||||
|
||||
public IList<PersonDto> Members { get; init;}
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace weddingapi.Dtos
|
||||
[Required]
|
||||
public IList<PersonDto> Members { get; init;}
|
||||
[Required]
|
||||
public bool Overnight { get; set; }
|
||||
public bool Overnight { get; init; }
|
||||
[Required]
|
||||
public string Email { get; init; }
|
||||
[Required]
|
||||
public string Telephonenumber { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@ namespace weddingapi.Models
|
||||
|
||||
public string Name { get; init; }
|
||||
|
||||
public string Email { get; init; }
|
||||
|
||||
public string Telephonenumber { get; init; }
|
||||
|
||||
public DateTimeOffset CreatedDate { get; set; }
|
||||
|
||||
public IList<Person> Members { get; init; }
|
||||
|
||||
15
Startup.cs
15
Startup.cs
@@ -23,6 +23,8 @@ namespace weddingapi
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
private string MyAllowSpecificOrigins = "defaultCors";
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
@@ -57,6 +59,17 @@ namespace weddingapi
|
||||
timeout: TimeSpan.FromSeconds(3),
|
||||
tags: new[] { "ready" });
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(name: MyAllowSpecificOrigins,
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@@ -76,6 +89,8 @@ namespace weddingapi
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCors(MyAllowSpecificOrigins);
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
|
||||
Reference in New Issue
Block a user