add missing fields
This commit is contained in:
@@ -8,6 +8,7 @@ using weddingapi.Repositories;
|
|||||||
using weddingapi.Dtos;
|
using weddingapi.Dtos;
|
||||||
using weddingapi.Converters;
|
using weddingapi.Converters;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Cors;
|
||||||
|
|
||||||
namespace weddingapi.Controllers
|
namespace weddingapi.Controllers
|
||||||
{
|
{
|
||||||
@@ -22,6 +23,15 @@ namespace weddingapi.Controllers
|
|||||||
this.repository = repository;
|
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
|
// GET /family
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
||||||
@@ -55,6 +65,8 @@ namespace weddingapi.Controllers
|
|||||||
CreatedDate = DateTimeOffset.UtcNow,
|
CreatedDate = DateTimeOffset.UtcNow,
|
||||||
Name = familyDto.Name,
|
Name = familyDto.Name,
|
||||||
Overnight = familyDto.Overnight,
|
Overnight = familyDto.Overnight,
|
||||||
|
Email = familyDto.EMail,
|
||||||
|
Telephonenumber = familyDto.Telephonenumber,
|
||||||
Members = familyDto.Members.Select(person => new Person() {
|
Members = familyDto.Members.Select(person => new Person() {
|
||||||
IsChild = person.IsChild,
|
IsChild = person.IsChild,
|
||||||
Name = person.Name,
|
Name = person.Name,
|
||||||
@@ -84,6 +96,8 @@ namespace weddingapi.Controllers
|
|||||||
IsChild = person.IsChild,
|
IsChild = person.IsChild,
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
Overnight = familyDto.Overnight,
|
Overnight = familyDto.Overnight,
|
||||||
|
Email = familyDto.Email,
|
||||||
|
Telephonenumber = familyDto.Telephonenumber,
|
||||||
Name = familyDto.Name,
|
Name = familyDto.Name,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ namespace weddingapi.Converters
|
|||||||
{
|
{
|
||||||
Id = family.Id,
|
Id = family.Id,
|
||||||
CreatedDate = family.CreatedDate,
|
CreatedDate = family.CreatedDate,
|
||||||
|
Overnight = family.Overnight,
|
||||||
|
Email = family.Email,
|
||||||
|
Telephonenumber = family.Telephonenumber,
|
||||||
Members = family.Members.Select(person => person.AsDto()).ToList(),
|
Members = family.Members.Select(person => person.AsDto()).ToList(),
|
||||||
Name = family.Name,
|
Name = family.Name,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ namespace weddingapi.Dtos
|
|||||||
[Required]
|
[Required]
|
||||||
public bool Overnight { get; set; }
|
public bool Overnight { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
public string EMail { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string Telephonenumber { get; set; }
|
||||||
|
[Required]
|
||||||
public IList<PersonDto> Members { get; init;}
|
public IList<PersonDto> Members { get; init;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,10 @@ namespace weddingapi.Dtos
|
|||||||
|
|
||||||
public bool Overnight { get; init; }
|
public bool Overnight { get; init; }
|
||||||
|
|
||||||
|
public string Email { get; init; }
|
||||||
|
|
||||||
|
public string Telephonenumber { get; init; }
|
||||||
|
|
||||||
public DateTimeOffset CreatedDate { get; set; }
|
public DateTimeOffset CreatedDate { get; set; }
|
||||||
|
|
||||||
public IList<PersonDto> Members { get; init;}
|
public IList<PersonDto> Members { get; init;}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ namespace weddingapi.Dtos
|
|||||||
[Required]
|
[Required]
|
||||||
public IList<PersonDto> Members { get; init;}
|
public IList<PersonDto> Members { get; init;}
|
||||||
[Required]
|
[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 Name { get; init; }
|
||||||
|
|
||||||
|
public string Email { get; init; }
|
||||||
|
|
||||||
|
public string Telephonenumber { get; init; }
|
||||||
|
|
||||||
public DateTimeOffset CreatedDate { get; set; }
|
public DateTimeOffset CreatedDate { get; set; }
|
||||||
|
|
||||||
public IList<Person> Members { get; init; }
|
public IList<Person> Members { get; init; }
|
||||||
|
|||||||
15
Startup.cs
15
Startup.cs
@@ -23,6 +23,8 @@ namespace weddingapi
|
|||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
private string MyAllowSpecificOrigins = "defaultCors";
|
||||||
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
@@ -57,6 +59,17 @@ namespace weddingapi
|
|||||||
timeout: TimeSpan.FromSeconds(3),
|
timeout: TimeSpan.FromSeconds(3),
|
||||||
tags: new[] { "ready" });
|
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.
|
// 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.UseRouting();
|
||||||
|
|
||||||
|
app.UseCors(MyAllowSpecificOrigins);
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
|
|||||||
Reference in New Issue
Block a user