-
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.
Merge pull request #13 from Nesteo/inspection-retrieval
Inspection and species retrieval implemented
- Loading branch information
Showing
9 changed files
with
169 additions
and
90 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 |
---|---|---|
@@ -1,33 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Nesteo.Server.Models; | ||
using Nesteo.Server.Services; | ||
|
||
namespace Nesteo.Server.Controllers.Api | ||
{ | ||
[Route("api/v1/species")] | ||
public class SpeciesController : ApiControllerBase | ||
{ | ||
private readonly ISpeciesService _speciesService; | ||
|
||
public SpeciesController(ISpeciesService speciesService) | ||
{ | ||
_speciesService = speciesService ?? throw new ArgumentNullException(nameof(speciesService)); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve all species | ||
/// </summary> | ||
// TODO: Use IAsyncEnumerable<> | ||
[HttpGet] | ||
public Task<ActionResult<ICollection<Species>>> GetSpeciesAsync() | ||
public IAsyncEnumerable<Species> GetSpeciesAsync() | ||
{ | ||
return Task.FromResult<ActionResult<ICollection<Species>>>(new List<Species> { new Species { Id = 0, Name = "Dodo" } }); | ||
return _speciesService.GetAllAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve a species by id | ||
/// </summary> | ||
[HttpGet("{id}")] | ||
public Task<ActionResult<Species>> GetSpeciesByIdAsync(int id) | ||
public async Task<ActionResult<Species>> GetSpeciesByIdAsync(int id) | ||
{ | ||
if (id != 0) | ||
return Task.FromResult<ActionResult<Species>>(NotFound()); | ||
// Retrieve species | ||
Species species = await _speciesService.FindByIdAsync(id, HttpContext.RequestAborted).ConfigureAwait(false); | ||
if (species == null) | ||
return NotFound(); | ||
|
||
return Task.FromResult<ActionResult<Species>>(new Species { Id = 0, Name = "Dodo" }); | ||
return species; | ||
} | ||
} | ||
} |
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,43 @@ | ||
using System; | ||
using Nesteo.Server.Data.Enums; | ||
|
||
namespace Nesteo.Server.Models | ||
{ | ||
public class InspectionPreview | ||
{ | ||
/// <summary> | ||
/// Inspection-ID | ||
/// </summary> | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// The id of the inspected nesting box | ||
/// </summary> | ||
public string NestingBoxId { get; set; } | ||
|
||
/// <summary> | ||
/// Date and time of the inspection | ||
/// </summary> | ||
public DateTime InspectionDate { get; set; } | ||
|
||
/// <summary> | ||
/// The condition in which the nesting box has been found | ||
/// </summary> | ||
public Condition Condition { get; set; } | ||
|
||
/// <summary> | ||
/// Number of ringed chicks | ||
/// </summary> | ||
public int RingedChickCount { get; set; } | ||
|
||
/// <summary> | ||
/// Information about the presence of the female parent bird | ||
/// </summary> | ||
public ParentBirdDiscovery FemaleParentBirdDiscovery { get; set; } | ||
|
||
/// <summary> | ||
/// Information about the presence of the male parent bird | ||
/// </summary> | ||
public ParentBirdDiscovery MaleParentBirdDiscovery { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Nesteo.Server.Models; | ||
|
||
namespace Nesteo.Server.Services | ||
{ | ||
public interface IInspectionService: ICrudService<Inspection, int> | ||
{ | ||
IAsyncEnumerable<InspectionPreview> GetAllPreviewsAsync(); | ||
|
||
Task<InspectionPreview> FindPreviewByIdAsync(int id, CancellationToken cancellationToken = default); | ||
} | ||
} |
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 @@ | ||
using Nesteo.Server.Models; | ||
|
||
namespace Nesteo.Server.Services | ||
{ | ||
public interface ISpeciesService : ICrudService<Species, int> { } | ||
} |
31 changes: 31 additions & 0 deletions
31
Nesteo.Server/Services/Implementations/InspectionService.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using AutoMapper.QueryableExtensions; | ||
using Microsoft.EntityFrameworkCore; | ||
using Nesteo.Server.Data; | ||
using Nesteo.Server.Data.Entities; | ||
using Nesteo.Server.Models; | ||
|
||
namespace Nesteo.Server.Services.Implementations | ||
{ | ||
public class InspectionService : CrudServiceBase<InspectionEntity, Inspection, int>, IInspectionService | ||
{ | ||
protected override DbSet<InspectionEntity> Entities => DbContext.Inspections; | ||
|
||
public InspectionService(NesteoDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { } | ||
|
||
public IAsyncEnumerable<InspectionPreview> GetAllPreviewsAsync() | ||
{ | ||
return Entities.ProjectTo<InspectionPreview>(Mapper.ConfigurationProvider).AsAsyncEnumerable(); | ||
} | ||
|
||
public Task<InspectionPreview> FindPreviewByIdAsync(int id, CancellationToken cancellationToken = default) | ||
{ | ||
return Entities.Where(entity => entity.Id.Equals(id)).ProjectTo<InspectionPreview>(Mapper.ConfigurationProvider).FirstOrDefaultAsync(cancellationToken); | ||
} | ||
} | ||
} |
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,15 @@ | ||
using AutoMapper; | ||
using Microsoft.EntityFrameworkCore; | ||
using Nesteo.Server.Data; | ||
using Nesteo.Server.Data.Entities; | ||
using Nesteo.Server.Models; | ||
|
||
namespace Nesteo.Server.Services.Implementations | ||
{ | ||
public class SpeciesService : CrudServiceBase<SpeciesEntity, Species, int>, ISpeciesService | ||
{ | ||
protected override DbSet<SpeciesEntity> Entities => DbContext.Species; | ||
|
||
public SpeciesService(NesteoDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { } | ||
} | ||
} |
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