|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Microsoft.AspNetCore.Http; |
| 5 | +using Microsoft.AspNetCore.Mvc; |
| 6 | +using Nesteo.Server.Data.Enums; |
| 7 | +using Nesteo.Server.Models; |
| 8 | + |
| 9 | +namespace Nesteo.Server.Controllers.Api |
| 10 | +{ |
| 11 | + [Route("api/v1/inspections")] |
| 12 | + public class InspectionsController : ApiControllerBase |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Retrieves all inspections |
| 16 | + /// </summary> |
| 17 | + // TODO: Use IAsyncEnumerable<> after EF Core upgrade |
| 18 | + [HttpGet] |
| 19 | + public Task<ActionResult<ICollection<Inspection>>> GetInspectionsAsync() |
| 20 | + { |
| 21 | + return Task.FromResult<ActionResult<ICollection<Inspection>>>(new List<Inspection> { |
| 22 | + new Inspection { |
| 23 | + Id = 0, |
| 24 | + NestingBox = |
| 25 | + new NestingBox { |
| 26 | + Id = "F000001", |
| 27 | + Region = new Region { Id = 0, Name = "The only forest in germany", NestingBoxIdPrefix = "F" }, |
| 28 | + OldId = null, |
| 29 | + ForeignId = "x234362", |
| 30 | + CoordinateLongitude = -97.142212, |
| 31 | + CoordinateLatitude = 30.081692, |
| 32 | + HangUpDate = new DateTime(2012, 12, 12, 12, 12, 12), |
| 33 | + HangUpUser = null, |
| 34 | + Owner = new Owner { Id = 0, Name = "He-who-must-not-be-named" }, |
| 35 | + Material = Material.TreatedWood, |
| 36 | + HoleSize = HoleSize.Large, |
| 37 | + ImageFileName = null, |
| 38 | + Comment = "This is a test", |
| 39 | + LastUpdated = DateTime.UtcNow |
| 40 | + }, |
| 41 | + InspectionDate = new DateTime(2013, 12, 12, 12, 12, 12), |
| 42 | + InspectedByUser = null, |
| 43 | + HasBeenCleaned = false, |
| 44 | + Condition = Condition.Good, |
| 45 | + JustRepaired = false, |
| 46 | + Occupied = true, |
| 47 | + ContainsEggs = true, |
| 48 | + EggCount = 0, |
| 49 | + ChickCount = 5, |
| 50 | + RingedChickCount = 4, |
| 51 | + AgeInDays = 6, |
| 52 | + FemaleParentBirdDiscovery = ParentBirdDiscovery.AlreadyRinged, |
| 53 | + MaleParentBirdDiscovery = ParentBirdDiscovery.NewlyRinged, |
| 54 | + Species = new Species { Id = 0, Name = "Dodo" }, |
| 55 | + ImageFileName = null, |
| 56 | + Comment = "It has been a great inspection! It's true! Trust me! It has been the greatest inspection ever! It's true!", |
| 57 | + LastUpdated = DateTime.UtcNow |
| 58 | + } |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Retrieves an inspection by id |
| 64 | + /// </summary> |
| 65 | + [HttpGet("{id}")] |
| 66 | + public Task<ActionResult<Inspection>> GetInspectionByIdAsync(int id) |
| 67 | + { |
| 68 | + if (id != 0) |
| 69 | + return Task.FromResult<ActionResult<Inspection>>(NotFound()); |
| 70 | + |
| 71 | + return Task.FromResult<ActionResult<Inspection>>(new Inspection { |
| 72 | + Id = 0, |
| 73 | + NestingBox = |
| 74 | + new NestingBox { |
| 75 | + Id = "F000001", |
| 76 | + Region = new Region { Id = 0, Name = "The only forest in germany", NestingBoxIdPrefix = "F" }, |
| 77 | + OldId = null, |
| 78 | + ForeignId = "x234362", |
| 79 | + CoordinateLongitude = -97.142212, |
| 80 | + CoordinateLatitude = 30.081692, |
| 81 | + HangUpDate = new DateTime(2012, 12, 12, 12, 12, 12), |
| 82 | + HangUpUser = null, |
| 83 | + Owner = new Owner { Id = 0, Name = "He-who-must-not-be-named" }, |
| 84 | + Material = Material.TreatedWood, |
| 85 | + HoleSize = HoleSize.Large, |
| 86 | + ImageFileName = null, |
| 87 | + Comment = "This is a test", |
| 88 | + LastUpdated = DateTime.UtcNow |
| 89 | + }, |
| 90 | + InspectionDate = new DateTime(2013, 12, 12, 12, 12, 12), |
| 91 | + InspectedByUser = null, |
| 92 | + HasBeenCleaned = false, |
| 93 | + Condition = Condition.Good, |
| 94 | + JustRepaired = false, |
| 95 | + Occupied = true, |
| 96 | + ContainsEggs = true, |
| 97 | + EggCount = 0, |
| 98 | + ChickCount = 5, |
| 99 | + RingedChickCount = 4, |
| 100 | + AgeInDays = 6, |
| 101 | + FemaleParentBirdDiscovery = ParentBirdDiscovery.AlreadyRinged, |
| 102 | + MaleParentBirdDiscovery = ParentBirdDiscovery.NewlyRinged, |
| 103 | + Species = new Species { Id = 0, Name = "Dodo" }, |
| 104 | + ImageFileName = null, |
| 105 | + Comment = "It has been a great inspection! It's true! Trust me! It has been the greatest inspection ever! It's true!", |
| 106 | + LastUpdated = DateTime.UtcNow |
| 107 | + }); |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments