diff --git a/.vscode/launch.json b/.vscode/launch.json index 24df3ff..258ba73 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,9 +9,9 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/net7.0/GerbilManager.dll", + "program": "${workspaceFolder}GerbilManagerWebAPI/bin/Debug/net7.0/GerbilManager.dll", "args": [], - "cwd": "${workspaceFolder}", + "cwd": "${workspaceFolder}/GerbilManagerWebAPI", "stopAtEntry": false, "serverReadyAction": { "action": "openExternally", @@ -21,7 +21,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { - "/Views": "${workspaceFolder}/Views" + "/Views": "${workspaceFolder}/GerbilManagerWebAPI/Views" } }, { diff --git a/GerbilManager.sln b/GerbilManager.sln index d1bce9b..488d208 100644 --- a/GerbilManager.sln +++ b/GerbilManager.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerbilManager", "GerbilManager.csproj", "{48875578-7112-4F6F-A4C0-F1E7637B513D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerbilManager", "GerbilManagerWebAPI/GerbilManager.csproj", "{48875578-7112-4F6F-A4C0-F1E7637B513D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ApplicationContext.cs b/GerbilManagerWebAPI/ApplicationContext.cs similarity index 95% rename from ApplicationContext.cs rename to GerbilManagerWebAPI/ApplicationContext.cs index 0b5dcfa..24bc23c 100644 --- a/ApplicationContext.cs +++ b/GerbilManagerWebAPI/ApplicationContext.cs @@ -1,12 +1,12 @@ -using GerbilManager.Models; -using Microsoft.EntityFrameworkCore; - -public class ApplicationContext : DbContext -{ - public ApplicationContext(DbContextOptions options) - :base(options) - { - } - public DbSet Gerbils { get; set; } -} - +using GerbilManager.Models; +using Microsoft.EntityFrameworkCore; + +public class ApplicationContext : DbContext +{ + public ApplicationContext(DbContextOptions options) + :base(options) + { + } + public DbSet Gerbils { get; set; } +} + diff --git a/Controllers/BreedersController.cs b/GerbilManagerWebAPI/Controllers/BreedersController.cs similarity index 96% rename from Controllers/BreedersController.cs rename to GerbilManagerWebAPI/Controllers/BreedersController.cs index a81b07f..f3d4efe 100644 --- a/Controllers/BreedersController.cs +++ b/GerbilManagerWebAPI/Controllers/BreedersController.cs @@ -1,91 +1,91 @@ -using GerbilManager.Models; -using GerbilManager.Repositories; -using GerbilManager.Dtos; - -using GerbilManager.Converter; - -using Microsoft.AspNetCore.Mvc; -using System.Xml; - -namespace GerbilManager.Controllers -{ - [ApiController] - [Route("breeders")] - public class BreederController : ControllerBase - { - private readonly IGerbilRepository gerbilrepository; - private readonly IBreederRepository repository; - private readonly ILitterRepository litterRepository; - - public BreederController(IBreederRepository repo) - { - this.repository = repo; - } - - //GET /gerbils - [HttpGet] - public IEnumerable GetBreeders() - { - var items = repository.GetBreeders().Select( breeder => breeder.AsDto()); - return items; - } - - //GET /gerbils - [HttpGet("{id}")] - public ActionResult GetBreeder(Guid id) - { - var item = repository.GetBreeder(id).AsDto(); - - if(item is null) - { - return NotFound(); - } - return item; - } - - [HttpPost()] - public ActionResult CreateBreeder(CreateBreederDto dto) - { - Breeder breeder = new Breeder{ - Id = Guid.NewGuid(), - Name = dto.Name, - }; - - this.repository.CreateBreeder(breeder); - - return CreatedAtAction(nameof(GetBreeder), new { id = breeder.Id}, breeder.AsDto()); - } - - [HttpPut("{id}")] - public ActionResult UpdateBreeder(Guid id, UpdateBreederDto breederDto) - { - var existingItem = repository.GetBreeder(id); - if(existingItem is null) - { - return NotFound(); - } - - Breeder updatedBreeder = existingItem with{ - Name = breederDto.Name - }; - - repository.UpdateBreeder(updatedBreeder); - return NoContent(); - } - - [HttpDelete("{id}")] - public ActionResult DeleteBreeder(Guid id) - { - var existingLitter = repository.GetBreeder(id); - - if(existingLitter is null) - { - return NotFound(); - } - - repository.DeleteBreeder(existingLitter); - - return NoContent(); - } - } +using GerbilManager.Models; +using GerbilManager.Repositories; +using GerbilManager.Dtos; + +using GerbilManager.Converter; + +using Microsoft.AspNetCore.Mvc; +using System.Xml; + +namespace GerbilManager.Controllers +{ + [ApiController] + [Route("breeders")] + public class BreederController : ControllerBase + { + private readonly IGerbilRepository gerbilrepository; + private readonly IBreederRepository repository; + private readonly ILitterRepository litterRepository; + + public BreederController(IBreederRepository repo) + { + this.repository = repo; + } + + //GET /gerbils + [HttpGet] + public IEnumerable GetBreeders() + { + var items = repository.GetBreeders().Select( breeder => breeder.AsDto()); + return items; + } + + //GET /gerbils + [HttpGet("{id}")] + public ActionResult GetBreeder(Guid id) + { + var item = repository.GetBreeder(id).AsDto(); + + if(item is null) + { + return NotFound(); + } + return item; + } + + [HttpPost()] + public ActionResult CreateBreeder(CreateBreederDto dto) + { + Breeder breeder = new Breeder{ + Id = Guid.NewGuid(), + Name = dto.Name, + }; + + this.repository.CreateBreeder(breeder); + + return CreatedAtAction(nameof(GetBreeder), new { id = breeder.Id}, breeder.AsDto()); + } + + [HttpPut("{id}")] + public ActionResult UpdateBreeder(Guid id, UpdateBreederDto breederDto) + { + var existingItem = repository.GetBreeder(id); + if(existingItem is null) + { + return NotFound(); + } + + Breeder updatedBreeder = existingItem with{ + Name = breederDto.Name + }; + + repository.UpdateBreeder(updatedBreeder); + return NoContent(); + } + + [HttpDelete("{id}")] + public ActionResult DeleteBreeder(Guid id) + { + var existingLitter = repository.GetBreeder(id); + + if(existingLitter is null) + { + return NotFound(); + } + + repository.DeleteBreeder(existingLitter); + + return NoContent(); + } + } } \ No newline at end of file diff --git a/Controllers/GerbilsController.cs b/GerbilManagerWebAPI/Controllers/GerbilsController.cs similarity index 96% rename from Controllers/GerbilsController.cs rename to GerbilManagerWebAPI/Controllers/GerbilsController.cs index fad236b..0558733 100644 --- a/Controllers/GerbilsController.cs +++ b/GerbilManagerWebAPI/Controllers/GerbilsController.cs @@ -1,95 +1,95 @@ -using GerbilManager.Models; -using GerbilManager.Repositories; -using GerbilManager.Dtos; - -using Microsoft.AspNetCore.Mvc; -using GerbilManager.Converter; - -namespace GerbilManager.Controllers -{ - [ApiController] - [Route("gerbils")] - public class GerbilsController : ControllerBase - { - private readonly IGerbilRepository repository; - private readonly IBreederRepository breederRepository; - private readonly ILitterRepository litterRepository; - - public GerbilsController(IGerbilRepository repo) - { - this.repository = repo; - } - - //GET /gerbils - [HttpGet] - public IEnumerable GetGerbils() - { - var items = repository.GetGerbils().Select( gerbil => gerbil.AsDto()); - return items; - } - - //GET /gerbils - [HttpGet("{id}")] - public ActionResult GetGerbil(Guid id) - { - var item = repository.GetGerbil(id).AsDto(); - - if(item is null) - { - return NotFound(); - } - return item; - } - - [HttpPost()] - public ActionResult CreateGerbil(CreateGerbilDto dto) - { - Gerbil gerbil = new Gerbil{ - Id = Guid.NewGuid(), - Name = dto.Name, - Breeder = breederRepository.GetBreeder(dto.Breeder), - Litter = litterRepository.GetLitter(dto.Litter), - Gender = (Gender) (int) dto.Gender - }; - - this.repository.CreateGerbil(gerbil); - - return CreatedAtAction(nameof(GetGerbil), new { id = gerbil.Id}, gerbil.AsDto()); - } - - [HttpPut("{id}")] - public ActionResult UpdateGerbil(Guid id, UpdateGerbilDto gerbilDto) - { - var existingItem = repository.GetGerbil(id); - if(existingItem is null) - { - return NotFound(); - } - - Gerbil updatedGerbil = existingItem with{ - Breeder = breederRepository.GetBreeder(gerbilDto.Breeder.Id), - Litter = litterRepository.GetLitter(gerbilDto.Litter.Id), - Gender = (Gender) (int) gerbilDto.Gender, - Name = gerbilDto.Name - }; - - repository.UpdateGerbil(updatedGerbil); - return NoContent(); - } - - [HttpDelete("{id}")] - public ActionResult DeleteGerbil(Guid id) - { - var existingGerbil = repository.GetGerbil(id); - - if(existingGerbil is null) - { - return NotFound(); - } - - repository.DeleteGerbil(existingGerbil); - - return NoContent(); - } - } +using GerbilManager.Models; +using GerbilManager.Repositories; +using GerbilManager.Dtos; + +using Microsoft.AspNetCore.Mvc; +using GerbilManager.Converter; + +namespace GerbilManager.Controllers +{ + [ApiController] + [Route("gerbils")] + public class GerbilsController : ControllerBase + { + private readonly IGerbilRepository repository; + private readonly IBreederRepository breederRepository; + private readonly ILitterRepository litterRepository; + + public GerbilsController(IGerbilRepository repo) + { + this.repository = repo; + } + + //GET /gerbils + [HttpGet] + public IEnumerable GetGerbils() + { + var items = repository.GetGerbils().Select( gerbil => gerbil.AsDto()); + return items; + } + + //GET /gerbils + [HttpGet("{id}")] + public ActionResult GetGerbil(Guid id) + { + var item = repository.GetGerbil(id).AsDto(); + + if(item is null) + { + return NotFound(); + } + return item; + } + + [HttpPost()] + public ActionResult CreateGerbil(CreateGerbilDto dto) + { + Gerbil gerbil = new Gerbil{ + Id = Guid.NewGuid(), + Name = dto.Name, + Breeder = breederRepository.GetBreeder(dto.Breeder), + Litter = litterRepository.GetLitter(dto.Litter), + Gender = (Gender) (int) dto.Gender + }; + + this.repository.CreateGerbil(gerbil); + + return CreatedAtAction(nameof(GetGerbil), new { id = gerbil.Id}, gerbil.AsDto()); + } + + [HttpPut("{id}")] + public ActionResult UpdateGerbil(Guid id, UpdateGerbilDto gerbilDto) + { + var existingItem = repository.GetGerbil(id); + if(existingItem is null) + { + return NotFound(); + } + + Gerbil updatedGerbil = existingItem with{ + Breeder = breederRepository.GetBreeder(gerbilDto.Breeder.Id), + Litter = litterRepository.GetLitter(gerbilDto.Litter.Id), + Gender = (Gender) (int) gerbilDto.Gender, + Name = gerbilDto.Name + }; + + repository.UpdateGerbil(updatedGerbil); + return NoContent(); + } + + [HttpDelete("{id}")] + public ActionResult DeleteGerbil(Guid id) + { + var existingGerbil = repository.GetGerbil(id); + + if(existingGerbil is null) + { + return NotFound(); + } + + repository.DeleteGerbil(existingGerbil); + + return NoContent(); + } + } } \ No newline at end of file diff --git a/Controllers/LittersController.cs b/GerbilManagerWebAPI/Controllers/LittersController.cs similarity index 96% rename from Controllers/LittersController.cs rename to GerbilManagerWebAPI/Controllers/LittersController.cs index 79d410e..8d2c32c 100644 --- a/Controllers/LittersController.cs +++ b/GerbilManagerWebAPI/Controllers/LittersController.cs @@ -1,99 +1,99 @@ -using GerbilManager.Models; -using GerbilManager.Repositories; -using GerbilManager.Dtos; - -using GerbilManager.Converter; - -using Microsoft.AspNetCore.Mvc; -using System.Xml; - -namespace GerbilManager.Controllers -{ - [ApiController] - [Route("litters")] - public class LittersController : ControllerBase - { - private readonly IGerbilRepository gerbilrepository; - private readonly IBreederRepository breederRepository; - private readonly ILitterRepository repository; - - public LittersController(ILitterRepository repo) - { - this.repository = repo; - } - - //GET /gerbils - [HttpGet] - public IEnumerable GetLitters() - { - var items = repository.GetLitters().Select( litter => litter.AsDto()); - return items; - } - - //GET /gerbils - [HttpGet("{id}")] - public ActionResult GetLitter(Guid id) - { - var item = repository.GetLitter(id).AsDto(); - - if(item is null) - { - return NotFound(); - } - return item; - } - - [HttpPost()] - public ActionResult CreateLitter(CreateLitterDto dto) - { - Litter litter = new Litter{ - Id = Guid.NewGuid(), - Date = dto.Date, - Father = gerbilrepository.GetGerbil(dto.Father), - Mother = gerbilrepository.GetGerbil(dto.Mother), - Name = dto.Name, - Strength = dto.Strength - }; - - this.repository.CreateLitter(litter); - - return CreatedAtAction(nameof(GetLitter), new { id = litter.Id}, litter.AsDto()); - } - - [HttpPut("{id}")] - public ActionResult UpdateLitter(Guid id, UpdateLitterDto litterDto) - { - var existingItem = repository.GetLitter(id); - if(existingItem is null) - { - return NotFound(); - } - - Litter updatedLitter = existingItem with{ - Date = litterDto.Date, - Strength = litterDto.Strength, - Father = gerbilrepository.GetGerbil(litterDto.Father), - Mother = gerbilrepository.GetGerbil(litterDto.Mother), - Name = litterDto.Name - }; - - repository.UpdateLitter(updatedLitter); - return NoContent(); - } - - [HttpDelete("{id}")] - public ActionResult DeleteLitter(Guid id) - { - var existingLitter = repository.GetLitter(id); - - if(existingLitter is null) - { - return NotFound(); - } - - repository.DeleteLitter(existingLitter); - - return NoContent(); - } - } +using GerbilManager.Models; +using GerbilManager.Repositories; +using GerbilManager.Dtos; + +using GerbilManager.Converter; + +using Microsoft.AspNetCore.Mvc; +using System.Xml; + +namespace GerbilManager.Controllers +{ + [ApiController] + [Route("litters")] + public class LittersController : ControllerBase + { + private readonly IGerbilRepository gerbilrepository; + private readonly IBreederRepository breederRepository; + private readonly ILitterRepository repository; + + public LittersController(ILitterRepository repo) + { + this.repository = repo; + } + + //GET /gerbils + [HttpGet] + public IEnumerable GetLitters() + { + var items = repository.GetLitters().Select( litter => litter.AsDto()); + return items; + } + + //GET /gerbils + [HttpGet("{id}")] + public ActionResult GetLitter(Guid id) + { + var item = repository.GetLitter(id).AsDto(); + + if(item is null) + { + return NotFound(); + } + return item; + } + + [HttpPost()] + public ActionResult CreateLitter(CreateLitterDto dto) + { + Litter litter = new Litter{ + Id = Guid.NewGuid(), + Date = dto.Date, + Father = gerbilrepository.GetGerbil(dto.Father), + Mother = gerbilrepository.GetGerbil(dto.Mother), + Name = dto.Name, + Strength = dto.Strength + }; + + this.repository.CreateLitter(litter); + + return CreatedAtAction(nameof(GetLitter), new { id = litter.Id}, litter.AsDto()); + } + + [HttpPut("{id}")] + public ActionResult UpdateLitter(Guid id, UpdateLitterDto litterDto) + { + var existingItem = repository.GetLitter(id); + if(existingItem is null) + { + return NotFound(); + } + + Litter updatedLitter = existingItem with{ + Date = litterDto.Date, + Strength = litterDto.Strength, + Father = gerbilrepository.GetGerbil(litterDto.Father), + Mother = gerbilrepository.GetGerbil(litterDto.Mother), + Name = litterDto.Name + }; + + repository.UpdateLitter(updatedLitter); + return NoContent(); + } + + [HttpDelete("{id}")] + public ActionResult DeleteLitter(Guid id) + { + var existingLitter = repository.GetLitter(id); + + if(existingLitter is null) + { + return NotFound(); + } + + repository.DeleteLitter(existingLitter); + + return NoContent(); + } + } } \ No newline at end of file diff --git a/Converter/BreederConveter.cs b/GerbilManagerWebAPI/Converter/BreederConveter.cs similarity index 95% rename from Converter/BreederConveter.cs rename to GerbilManagerWebAPI/Converter/BreederConveter.cs index 25aea18..d975315 100644 --- a/Converter/BreederConveter.cs +++ b/GerbilManagerWebAPI/Converter/BreederConveter.cs @@ -1,18 +1,18 @@ -using GerbilManager.Dtos; -using GerbilManager.Models; - -namespace GerbilManager.Converter -{ - public static class BreederConverterExtension - { - public static BreederDto AsDto(this Breeder breeder) - { - return new BreederDto{ - Id = breeder.Id, - Name = breeder.Name - }; - } - - } -} - +using GerbilManager.Dtos; +using GerbilManager.Models; + +namespace GerbilManager.Converter +{ + public static class BreederConverterExtension + { + public static BreederDto AsDto(this Breeder breeder) + { + return new BreederDto{ + Id = breeder.Id, + Name = breeder.Name + }; + } + + } +} + diff --git a/Converter/GerbilConverter.cs b/GerbilManagerWebAPI/Converter/GerbilConverter.cs similarity index 96% rename from Converter/GerbilConverter.cs rename to GerbilManagerWebAPI/Converter/GerbilConverter.cs index 79f2f35..771cec6 100644 --- a/Converter/GerbilConverter.cs +++ b/GerbilManagerWebAPI/Converter/GerbilConverter.cs @@ -1,19 +1,19 @@ -using GerbilManager.Dtos; -using GerbilManager.Models; - -namespace GerbilManager.Converter -{ - public static class GerbilConverterExtension - { - public static GerbilDto AsDto(this Gerbil gerbil) - { - return new GerbilDto{ - Breeder = gerbil.Breeder.AsDto(), - Gender = (GenderDto) ((int) gerbil.Gender), - Name = gerbil.Name, - Litter = gerbil.Litter.AsDto() - }; - } - } -} - +using GerbilManager.Dtos; +using GerbilManager.Models; + +namespace GerbilManager.Converter +{ + public static class GerbilConverterExtension + { + public static GerbilDto AsDto(this Gerbil gerbil) + { + return new GerbilDto{ + Breeder = gerbil.Breeder.AsDto(), + Gender = (GenderDto) ((int) gerbil.Gender), + Name = gerbil.Name, + Litter = gerbil.Litter.AsDto() + }; + } + } +} + diff --git a/Converter/LitterConverter.cs b/GerbilManagerWebAPI/Converter/LitterConverter.cs similarity index 96% rename from Converter/LitterConverter.cs rename to GerbilManagerWebAPI/Converter/LitterConverter.cs index 0461851..e777a54 100644 --- a/Converter/LitterConverter.cs +++ b/GerbilManagerWebAPI/Converter/LitterConverter.cs @@ -1,21 +1,21 @@ -using GerbilManager.Dtos; -using GerbilManager.Models; - -namespace GerbilManager.Converter -{ - public static class LitterConverterExtension - { - public static LitterDto AsDto(this Litter litter) - { - return new LitterDto{ - Id = litter.Id, - Date = litter.Date, - Father = litter.Father.AsDto(), - Mother = litter.Mother.AsDto(), - Name = litter.Name, - Strength = litter.Strength - }; - } - } -} - +using GerbilManager.Dtos; +using GerbilManager.Models; + +namespace GerbilManager.Converter +{ + public static class LitterConverterExtension + { + public static LitterDto AsDto(this Litter litter) + { + return new LitterDto{ + Id = litter.Id, + Date = litter.Date, + Father = litter.Father.AsDto(), + Mother = litter.Mother.AsDto(), + Name = litter.Name, + Strength = litter.Strength + }; + } + } +} + diff --git a/Dtos/BreederDto.cs b/GerbilManagerWebAPI/Dtos/BreederDto.cs similarity index 95% rename from Dtos/BreederDto.cs rename to GerbilManagerWebAPI/Dtos/BreederDto.cs index 969b381..945e4d9 100644 --- a/Dtos/BreederDto.cs +++ b/GerbilManagerWebAPI/Dtos/BreederDto.cs @@ -1,8 +1,8 @@ -namespace GerbilManager.Dtos -{ - public record BreederDto - { - public Guid Id { get; init; } - public string Name { get; init; } - } +namespace GerbilManager.Dtos +{ + public record BreederDto + { + public Guid Id { get; init; } + public string Name { get; init; } + } } \ No newline at end of file diff --git a/Dtos/CreateBreederDto.cs b/GerbilManagerWebAPI/Dtos/CreateBreederDto.cs similarity index 95% rename from Dtos/CreateBreederDto.cs rename to GerbilManagerWebAPI/Dtos/CreateBreederDto.cs index a4616ae..f7e2719 100644 --- a/Dtos/CreateBreederDto.cs +++ b/GerbilManagerWebAPI/Dtos/CreateBreederDto.cs @@ -1,7 +1,7 @@ -namespace GerbilManager.Dtos -{ - public record CreateBreederDto - { - public string Name { get; init; } - } +namespace GerbilManager.Dtos +{ + public record CreateBreederDto + { + public string Name { get; init; } + } } \ No newline at end of file diff --git a/Dtos/CreateGerbilDto.cs b/GerbilManagerWebAPI/Dtos/CreateGerbilDto.cs similarity index 96% rename from Dtos/CreateGerbilDto.cs rename to GerbilManagerWebAPI/Dtos/CreateGerbilDto.cs index 8654756..3b99201 100644 --- a/Dtos/CreateGerbilDto.cs +++ b/GerbilManagerWebAPI/Dtos/CreateGerbilDto.cs @@ -1,11 +1,11 @@ -namespace GerbilManager.Dtos -{ - public record CreateGerbilDto - { - public string Name { get; init; } - public GenderDto Gender { get; init; } - public Guid Litter { get; init; } - public Guid Breeder { get; init; } - } - +namespace GerbilManager.Dtos +{ + public record CreateGerbilDto + { + public string Name { get; init; } + public GenderDto Gender { get; init; } + public Guid Litter { get; init; } + public Guid Breeder { get; init; } + } + } \ No newline at end of file diff --git a/Dtos/CreateLitterDto.cs b/GerbilManagerWebAPI/Dtos/CreateLitterDto.cs similarity index 96% rename from Dtos/CreateLitterDto.cs rename to GerbilManagerWebAPI/Dtos/CreateLitterDto.cs index 4465aa7..754a333 100644 --- a/Dtos/CreateLitterDto.cs +++ b/GerbilManagerWebAPI/Dtos/CreateLitterDto.cs @@ -1,11 +1,11 @@ -namespace GerbilManager.Dtos -{ - public record CreateLitterDto - { - public string Name { get; init; } - public DateTime Date { get; init; } - public int Strength { get; init; } - public Guid Father { get; init; } - public Guid Mother { get; init; } - } +namespace GerbilManager.Dtos +{ + public record CreateLitterDto + { + public string Name { get; init; } + public DateTime Date { get; init; } + public int Strength { get; init; } + public Guid Father { get; init; } + public Guid Mother { get; init; } + } } \ No newline at end of file diff --git a/Dtos/GenderDto.cs b/GerbilManagerWebAPI/Dtos/GenderDto.cs similarity index 94% rename from Dtos/GenderDto.cs rename to GerbilManagerWebAPI/Dtos/GenderDto.cs index 28e3dea..816bc54 100644 --- a/Dtos/GenderDto.cs +++ b/GerbilManagerWebAPI/Dtos/GenderDto.cs @@ -1,9 +1,9 @@ -namespace GerbilManager.Dtos -{ - public enum GenderDto - { - unknown = 0, - male = 1, - female = 2 - } +namespace GerbilManager.Dtos +{ + public enum GenderDto + { + unknown = 0, + male = 1, + female = 2 + } } \ No newline at end of file diff --git a/Dtos/GerbilDto.cs b/GerbilManagerWebAPI/Dtos/GerbilDto.cs similarity index 96% rename from Dtos/GerbilDto.cs rename to GerbilManagerWebAPI/Dtos/GerbilDto.cs index ef8ad8a..c5cdd4b 100644 --- a/Dtos/GerbilDto.cs +++ b/GerbilManagerWebAPI/Dtos/GerbilDto.cs @@ -1,11 +1,11 @@ -namespace GerbilManager.Dtos -{ - public record GerbilDto - { - public Guid Id { get; init; } - public string Name { get; init; } - public GenderDto Gender { get; init; } - public LitterDto Litter { get; init; } - public BreederDto Breeder { get; init; } - } +namespace GerbilManager.Dtos +{ + public record GerbilDto + { + public Guid Id { get; init; } + public string Name { get; init; } + public GenderDto Gender { get; init; } + public LitterDto Litter { get; init; } + public BreederDto Breeder { get; init; } + } } \ No newline at end of file diff --git a/Dtos/LitterDto.cs b/GerbilManagerWebAPI/Dtos/LitterDto.cs similarity index 96% rename from Dtos/LitterDto.cs rename to GerbilManagerWebAPI/Dtos/LitterDto.cs index 8b8a84a..74b9a5a 100644 --- a/Dtos/LitterDto.cs +++ b/GerbilManagerWebAPI/Dtos/LitterDto.cs @@ -1,12 +1,12 @@ -namespace GerbilManager.Dtos -{ - public record LitterDto - { - public Guid Id { get; init; } - public string Name { get; init; } - public DateTime Date { get; init; } - public int Strength { get; init; } - public GerbilDto Father { get; init; } - public GerbilDto Mother { get; init; } - } +namespace GerbilManager.Dtos +{ + public record LitterDto + { + public Guid Id { get; init; } + public string Name { get; init; } + public DateTime Date { get; init; } + public int Strength { get; init; } + public GerbilDto Father { get; init; } + public GerbilDto Mother { get; init; } + } } \ No newline at end of file diff --git a/Dtos/UpdateBreederDto.cs b/GerbilManagerWebAPI/Dtos/UpdateBreederDto.cs similarity index 94% rename from Dtos/UpdateBreederDto.cs rename to GerbilManagerWebAPI/Dtos/UpdateBreederDto.cs index bc98059..246fbe0 100644 --- a/Dtos/UpdateBreederDto.cs +++ b/GerbilManagerWebAPI/Dtos/UpdateBreederDto.cs @@ -1,8 +1,8 @@ - -namespace GerbilManager.Dtos -{ - public record UpdateBreederDto - { - public string Name { get; init; } - } + +namespace GerbilManager.Dtos +{ + public record UpdateBreederDto + { + public string Name { get; init; } + } } \ No newline at end of file diff --git a/Dtos/UpdateGerbilDto.cs b/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs similarity index 96% rename from Dtos/UpdateGerbilDto.cs rename to GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs index 8d68301..cf81d75 100644 --- a/Dtos/UpdateGerbilDto.cs +++ b/GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs @@ -1,10 +1,10 @@ -namespace GerbilManager.Dtos -{ - public record UpdateGerbilDto - { - public string Name { get; init; } - public GenderDto Gender { get; init; } - public LitterDto Litter { get; init; } - public BreederDto Breeder { get; init; } - } +namespace GerbilManager.Dtos +{ + public record UpdateGerbilDto + { + public string Name { get; init; } + public GenderDto Gender { get; init; } + public LitterDto Litter { get; init; } + public BreederDto Breeder { get; init; } + } } \ No newline at end of file diff --git a/Dtos/UpdateLitterDto.cs b/GerbilManagerWebAPI/Dtos/UpdateLitterDto.cs similarity index 96% rename from Dtos/UpdateLitterDto.cs rename to GerbilManagerWebAPI/Dtos/UpdateLitterDto.cs index b5e584e..00d94b1 100644 --- a/Dtos/UpdateLitterDto.cs +++ b/GerbilManagerWebAPI/Dtos/UpdateLitterDto.cs @@ -1,12 +1,12 @@ - -namespace GerbilManager.Dtos -{ - public record UpdateLitterDto - { - public string Name { get; init; } - public DateTime Date { get; init; } - public int Strength { get; init; } - public Guid Father { get; init; } - public Guid Mother { get; init; } - } + +namespace GerbilManager.Dtos +{ + public record UpdateLitterDto + { + public string Name { get; init; } + public DateTime Date { get; init; } + public int Strength { get; init; } + public Guid Father { get; init; } + public Guid Mother { get; init; } + } } \ No newline at end of file diff --git a/GerbilManager.csproj b/GerbilManagerWebAPI/GerbilManager.csproj similarity index 97% rename from GerbilManager.csproj rename to GerbilManagerWebAPI/GerbilManager.csproj index d6fce08..16f241e 100644 --- a/GerbilManager.csproj +++ b/GerbilManagerWebAPI/GerbilManager.csproj @@ -1,16 +1,16 @@ - - - - net7.0 - enable - enable - - - - - - - - - - + + + + net7.0 + enable + enable + + + + + + + + + + diff --git a/Models/Breeder.cs b/GerbilManagerWebAPI/Models/Breeder.cs similarity index 95% rename from Models/Breeder.cs rename to GerbilManagerWebAPI/Models/Breeder.cs index 9a67a0e..98f679d 100644 --- a/Models/Breeder.cs +++ b/GerbilManagerWebAPI/Models/Breeder.cs @@ -1,8 +1,8 @@ -namespace GerbilManager.Models -{ - public record Breeder - { - public Guid Id { get; init; } - public string Name { get; init; } - } +namespace GerbilManager.Models +{ + public record Breeder + { + public Guid Id { get; init; } + public string Name { get; init; } + } } \ No newline at end of file diff --git a/Models/Gender.cs b/GerbilManagerWebAPI/Models/Gender.cs similarity index 94% rename from Models/Gender.cs rename to GerbilManagerWebAPI/Models/Gender.cs index bcad74b..2b55c88 100644 --- a/Models/Gender.cs +++ b/GerbilManagerWebAPI/Models/Gender.cs @@ -1,9 +1,9 @@ -namespace GerbilManager.Models -{ - public enum Gender - { - unknown = 0, - male = 1, - female = 2 - } +namespace GerbilManager.Models +{ + public enum Gender + { + unknown = 0, + male = 1, + female = 2 + } } \ No newline at end of file diff --git a/Models/Gerbil.cs b/GerbilManagerWebAPI/Models/Gerbil.cs similarity index 96% rename from Models/Gerbil.cs rename to GerbilManagerWebAPI/Models/Gerbil.cs index 87c23d1..1893109 100644 --- a/Models/Gerbil.cs +++ b/GerbilManagerWebAPI/Models/Gerbil.cs @@ -1,11 +1,11 @@ -namespace GerbilManager.Models -{ - public record Gerbil - { - public Guid Id { get; init; } - public string Name { get; init; } - public Gender Gender { get; init; } - public Litter Litter { get; init; } - public Breeder Breeder { get; init; } - } +namespace GerbilManager.Models +{ + public record Gerbil + { + public Guid Id { get; init; } + public string Name { get; init; } + public Gender Gender { get; init; } + public Litter Litter { get; init; } + public Breeder Breeder { get; init; } + } } \ No newline at end of file diff --git a/Models/Litter.cs b/GerbilManagerWebAPI/Models/Litter.cs similarity index 96% rename from Models/Litter.cs rename to GerbilManagerWebAPI/Models/Litter.cs index 57c41e3..e2a29b0 100644 --- a/Models/Litter.cs +++ b/GerbilManagerWebAPI/Models/Litter.cs @@ -1,13 +1,13 @@ -namespace GerbilManager.Models -{ - public record Litter - { - public Guid Id { get; init; } - public string Name { get; init; } - public DateTime Date { get; init; } - public int Strength { get; init; } - public Gerbil Father { get; init; } - public Gerbil Mother { get; init; } - } -} - +namespace GerbilManager.Models +{ + public record Litter + { + public Guid Id { get; init; } + public string Name { get; init; } + public DateTime Date { get; init; } + public int Strength { get; init; } + public Gerbil Father { get; init; } + public Gerbil Mother { get; init; } + } +} + diff --git a/Program.cs b/GerbilManagerWebAPI/Program.cs similarity index 96% rename from Program.cs rename to GerbilManagerWebAPI/Program.cs index e5bf8b1..e733bd0 100644 --- a/Program.cs +++ b/GerbilManagerWebAPI/Program.cs @@ -1,33 +1,33 @@ -using GerbilManager.Repositories; -using Microsoft.EntityFrameworkCore; - -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -builder.Services.AddSingleton(); - -builder.Services.AddDbContext(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection"))); - -var app = builder.Build(); - - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); +using GerbilManager.Repositories; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.AddSingleton(); + +builder.Services.AddDbContext(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection"))); + +var app = builder.Build(); + + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Properties/launchSettings.json b/GerbilManagerWebAPI/Properties/launchSettings.json similarity index 96% rename from Properties/launchSettings.json rename to GerbilManagerWebAPI/Properties/launchSettings.json index bc52a00..49dc5c6 100644 --- a/Properties/launchSettings.json +++ b/GerbilManagerWebAPI/Properties/launchSettings.json @@ -1,41 +1,41 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:23762", - "sslPort": 44327 - } - }, - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5179", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7191;http://localhost:5179", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23762", + "sslPort": 44327 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5179", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7191;http://localhost:5179", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Repositories/IBreederRepository.cs b/GerbilManagerWebAPI/Repositories/IBreederRepository.cs similarity index 95% rename from Repositories/IBreederRepository.cs rename to GerbilManagerWebAPI/Repositories/IBreederRepository.cs index 64a1163..4c8bd51 100644 --- a/Repositories/IBreederRepository.cs +++ b/GerbilManagerWebAPI/Repositories/IBreederRepository.cs @@ -1,17 +1,17 @@ -using GerbilManager.Models; - -namespace GerbilManager.Repositories -{ - public interface IBreederRepository - { - IEnumerable GetBreeders(); - - Breeder GetBreeder(Guid id); - - void CreateBreeder(Breeder breeder); - - void UpdateBreeder(Breeder breeder); - - void DeleteBreeder(Breeder breeder); - } +using GerbilManager.Models; + +namespace GerbilManager.Repositories +{ + public interface IBreederRepository + { + IEnumerable GetBreeders(); + + Breeder GetBreeder(Guid id); + + void CreateBreeder(Breeder breeder); + + void UpdateBreeder(Breeder breeder); + + void DeleteBreeder(Breeder breeder); + } } \ No newline at end of file diff --git a/Repositories/IGerbilRepository.cs b/GerbilManagerWebAPI/Repositories/IGerbilRepository.cs similarity index 95% rename from Repositories/IGerbilRepository.cs rename to GerbilManagerWebAPI/Repositories/IGerbilRepository.cs index 320d09c..a4c3214 100644 --- a/Repositories/IGerbilRepository.cs +++ b/GerbilManagerWebAPI/Repositories/IGerbilRepository.cs @@ -1,17 +1,17 @@ -using GerbilManager.Models; - -namespace GerbilManager.Repositories -{ - public interface IGerbilRepository - { - IEnumerable GetGerbils(); - - Gerbil GetGerbil(Guid id); - - void CreateGerbil(Gerbil gerbil); - - void UpdateGerbil(Gerbil gerbil); - - void DeleteGerbil(Gerbil gerilb); - } +using GerbilManager.Models; + +namespace GerbilManager.Repositories +{ + public interface IGerbilRepository + { + IEnumerable GetGerbils(); + + Gerbil GetGerbil(Guid id); + + void CreateGerbil(Gerbil gerbil); + + void UpdateGerbil(Gerbil gerbil); + + void DeleteGerbil(Gerbil gerilb); + } } \ No newline at end of file diff --git a/Repositories/ILitterRepostitory.cs b/GerbilManagerWebAPI/Repositories/ILitterRepostitory.cs similarity index 95% rename from Repositories/ILitterRepostitory.cs rename to GerbilManagerWebAPI/Repositories/ILitterRepostitory.cs index d330098..2973e74 100644 --- a/Repositories/ILitterRepostitory.cs +++ b/GerbilManagerWebAPI/Repositories/ILitterRepostitory.cs @@ -1,15 +1,15 @@ -using GerbilManager.Models; - -namespace GerbilManager.Repositories -{ - public interface ILitterRepository - { - IEnumerable GetLitters(); - - Litter GetLitter(Guid id); - - void CreateLitter(Litter litter); - void UpdateLitter(Litter litter); - void DeleteLitter(Litter litter); - } +using GerbilManager.Models; + +namespace GerbilManager.Repositories +{ + public interface ILitterRepository + { + IEnumerable GetLitters(); + + Litter GetLitter(Guid id); + + void CreateLitter(Litter litter); + void UpdateLitter(Litter litter); + void DeleteLitter(Litter litter); + } } \ No newline at end of file diff --git a/Repositories/InMemGerbilRepository.cs b/GerbilManagerWebAPI/Repositories/InMemGerbilRepository.cs similarity index 97% rename from Repositories/InMemGerbilRepository.cs rename to GerbilManagerWebAPI/Repositories/InMemGerbilRepository.cs index d55bc5c..b81cafe 100644 --- a/Repositories/InMemGerbilRepository.cs +++ b/GerbilManagerWebAPI/Repositories/InMemGerbilRepository.cs @@ -1,39 +1,39 @@ -using GerbilManager.Models; - -namespace GerbilManager.Repositories -{ - public class InMemGerbilRepository : IGerbilRepository - { - private readonly List _gerbilList = new() - { - new Gerbil() {Id = Guid.NewGuid(), Name = "Blacky", Breeder = null, Litter = null, Gender = Gender.unknown}, - new Gerbil() {Id = Guid.NewGuid(), Name = "Coocky", Breeder = null, Litter = null, Gender = Gender.male}, - new Gerbil() {Id = Guid.NewGuid(), Name = "Lazy", Breeder = null, Litter = null, Gender = Gender.female} - }; - - public IEnumerable GetGerbils() - { - return _gerbilList; - } - - public Gerbil GetGerbil(Guid id) => _gerbilList.SingleOrDefault(x => x.Id == id); - - public void CreateGerbil(Gerbil gerbil) - { - _gerbilList.Add(gerbil); - } - - public void UpdateGerbil(Gerbil gerbil) - { - var index = this._gerbilList.FindIndex(existingGerbil => existingGerbil.Id == gerbil.Id); - _gerbilList[index] = gerbil; - } - - public void DeleteGerbil(Gerbil gerbil) - { - var index = this._gerbilList.FindIndex(existingGerbil => existingGerbil.Id == gerbil.Id); - _gerbilList.RemoveAt(index); - } - } - -} +using GerbilManager.Models; + +namespace GerbilManager.Repositories +{ + public class InMemGerbilRepository : IGerbilRepository + { + private readonly List _gerbilList = new() + { + new Gerbil() {Id = Guid.NewGuid(), Name = "Blacky", Breeder = null, Litter = null, Gender = Gender.unknown}, + new Gerbil() {Id = Guid.NewGuid(), Name = "Coocky", Breeder = null, Litter = null, Gender = Gender.male}, + new Gerbil() {Id = Guid.NewGuid(), Name = "Lazy", Breeder = null, Litter = null, Gender = Gender.female} + }; + + public IEnumerable GetGerbils() + { + return _gerbilList; + } + + public Gerbil GetGerbil(Guid id) => _gerbilList.SingleOrDefault(x => x.Id == id); + + public void CreateGerbil(Gerbil gerbil) + { + _gerbilList.Add(gerbil); + } + + public void UpdateGerbil(Gerbil gerbil) + { + var index = this._gerbilList.FindIndex(existingGerbil => existingGerbil.Id == gerbil.Id); + _gerbilList[index] = gerbil; + } + + public void DeleteGerbil(Gerbil gerbil) + { + var index = this._gerbilList.FindIndex(existingGerbil => existingGerbil.Id == gerbil.Id); + _gerbilList.RemoveAt(index); + } + } + +} diff --git a/appsettings.Development.json b/GerbilManagerWebAPI/appsettings.Development.json similarity index 95% rename from appsettings.Development.json rename to GerbilManagerWebAPI/appsettings.Development.json index 138e433..e0f2b5a 100644 --- a/appsettings.Development.json +++ b/GerbilManagerWebAPI/appsettings.Development.json @@ -1,11 +1,11 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "ConnectionStrings": { - "sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true" - } -} +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true" + } +} diff --git a/appsettings.json b/GerbilManagerWebAPI/appsettings.json similarity index 95% rename from appsettings.json rename to GerbilManagerWebAPI/appsettings.json index 77b42a0..ce86cda 100644 --- a/appsettings.json +++ b/GerbilManagerWebAPI/appsettings.json @@ -1,12 +1,12 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "ConnectionStrings": { - "sqlConnection": "server=.; database=GerbilManager; Integrated Security=true" - }, - "AllowedHosts": "*" -} +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "sqlConnection": "server=.; database=GerbilManager; Integrated Security=true" + }, + "AllowedHosts": "*" +}