Compare commits
5 Commits
3e3ef39b80
...
489f0ee35a
| Author | SHA1 | Date | |
|---|---|---|---|
| 489f0ee35a | |||
| 8a2995302a | |||
| 7ee50442c5 | |||
| fc98f99eda | |||
| 707bfae2e3 |
12
ApplicationContext.cs
Normal file
12
ApplicationContext.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using GerbilManager.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
public class ApplicationContext : DbContext
|
||||||
|
{
|
||||||
|
public ApplicationContext(DbContextOptions options)
|
||||||
|
:base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public DbSet<Gerbil> Gerbils { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
91
Controllers/BreedersController.cs
Normal file
91
Controllers/BreedersController.cs
Normal file
@@ -0,0 +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<BreederDto> GetBreeders()
|
||||||
|
{
|
||||||
|
var items = repository.GetBreeders().Select( breeder => breeder.AsDto());
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
//GET /gerbils
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ActionResult<BreederDto> GetBreeder(Guid id)
|
||||||
|
{
|
||||||
|
var item = repository.GetBreeder(id).AsDto();
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost()]
|
||||||
|
public ActionResult<BreederDto> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
using GerbilManager.Models;
|
using GerbilManager.Models;
|
||||||
using GerbilManager.Repositories;
|
using GerbilManager.Repositories;
|
||||||
|
using GerbilManager.Dtos;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using GerbilManager.Converter;
|
||||||
|
|
||||||
namespace GerbilManager.Controllers
|
namespace GerbilManager.Controllers
|
||||||
{
|
{
|
||||||
@@ -8,19 +11,85 @@ namespace GerbilManager.Controllers
|
|||||||
[Route("gerbils")]
|
[Route("gerbils")]
|
||||||
public class GerbilsController : ControllerBase
|
public class GerbilsController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly InMemGerbilRepository repository;
|
private readonly IGerbilRepository repository;
|
||||||
|
private readonly IBreederRepository breederRepository;
|
||||||
|
private readonly ILitterRepository litterRepository;
|
||||||
|
|
||||||
public GerbilsController()
|
public GerbilsController(IGerbilRepository repo)
|
||||||
{
|
{
|
||||||
repository = new InMemGerbilRepository();
|
this.repository = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GET /gerbils
|
//GET /gerbils
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<Gerbil> GetGerbils()
|
public IEnumerable<GerbilDto> GetGerbils()
|
||||||
{
|
{
|
||||||
var items = repository.GetGerbils();
|
var items = repository.GetGerbils().Select( gerbil => gerbil.AsDto());
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GET /gerbils
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ActionResult<GerbilDto> GetGerbil(Guid id)
|
||||||
|
{
|
||||||
|
var item = repository.GetGerbil(id).AsDto();
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost()]
|
||||||
|
public ActionResult<GerbilDto> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
99
Controllers/LittersController.cs
Normal file
99
Controllers/LittersController.cs
Normal file
@@ -0,0 +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<LitterDto> GetLitters()
|
||||||
|
{
|
||||||
|
var items = repository.GetLitters().Select( litter => litter.AsDto());
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
//GET /gerbils
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ActionResult<LitterDto> GetLitter(Guid id)
|
||||||
|
{
|
||||||
|
var item = repository.GetLitter(id).AsDto();
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost()]
|
||||||
|
public ActionResult<LitterDto> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Converter/BreederConveter.cs
Normal file
18
Converter/BreederConveter.cs
Normal file
@@ -0,0 +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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
Converter/GerbilConverter.cs
Normal file
19
Converter/GerbilConverter.cs
Normal file
@@ -0,0 +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()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
21
Converter/LitterConverter.cs
Normal file
21
Converter/LitterConverter.cs
Normal file
@@ -0,0 +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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
8
Dtos/BreederDto.cs
Normal file
8
Dtos/BreederDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace GerbilManager.Dtos
|
||||||
|
{
|
||||||
|
public record BreederDto
|
||||||
|
{
|
||||||
|
public Guid Id { get; init; }
|
||||||
|
public string Name { get; init; }
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Dtos/CreateBreederDto.cs
Normal file
7
Dtos/CreateBreederDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace GerbilManager.Dtos
|
||||||
|
{
|
||||||
|
public record CreateBreederDto
|
||||||
|
{
|
||||||
|
public string Name { get; init; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Dtos/CreateGerbilDto.cs
Normal file
11
Dtos/CreateGerbilDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
Dtos/CreateLitterDto.cs
Normal file
11
Dtos/CreateLitterDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Dtos/GenderDto.cs
Normal file
9
Dtos/GenderDto.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace GerbilManager.Dtos
|
||||||
|
{
|
||||||
|
public enum GenderDto
|
||||||
|
{
|
||||||
|
unknown = 0,
|
||||||
|
male = 1,
|
||||||
|
female = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Dtos/GerbilDto.cs
Normal file
11
Dtos/GerbilDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Dtos/LitterDto.cs
Normal file
12
Dtos/LitterDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Dtos/UpdateBreederDto.cs
Normal file
8
Dtos/UpdateBreederDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
namespace GerbilManager.Dtos
|
||||||
|
{
|
||||||
|
public record UpdateBreederDto
|
||||||
|
{
|
||||||
|
public string Name { get; init; }
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Dtos/UpdateGerbilDto.cs
Normal file
10
Dtos/UpdateGerbilDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Dtos/UpdateLitterDto.cs
Normal file
12
Dtos/UpdateLitterDto.cs
Normal file
@@ -0,0 +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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ namespace GerbilManager.Models
|
|||||||
{
|
{
|
||||||
public enum Gender
|
public enum Gender
|
||||||
{
|
{
|
||||||
unknown,
|
unknown = 0,
|
||||||
male,
|
male = 1,
|
||||||
female
|
female = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using GerbilManager.Repositories;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
@@ -7,8 +10,13 @@ builder.Services.AddControllers();
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IGerbilRepository, InMemGerbilRepository>();
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<ApplicationContext>(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection")));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|||||||
17
Repositories/IBreederRepository.cs
Normal file
17
Repositories/IBreederRepository.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using GerbilManager.Models;
|
||||||
|
|
||||||
|
namespace GerbilManager.Repositories
|
||||||
|
{
|
||||||
|
public interface IBreederRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Breeder> GetBreeders();
|
||||||
|
|
||||||
|
Breeder GetBreeder(Guid id);
|
||||||
|
|
||||||
|
void CreateBreeder(Breeder breeder);
|
||||||
|
|
||||||
|
void UpdateBreeder(Breeder breeder);
|
||||||
|
|
||||||
|
void DeleteBreeder(Breeder breeder);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Repositories/IGerbilRepository.cs
Normal file
17
Repositories/IGerbilRepository.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using GerbilManager.Models;
|
||||||
|
|
||||||
|
namespace GerbilManager.Repositories
|
||||||
|
{
|
||||||
|
public interface IGerbilRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Gerbil> GetGerbils();
|
||||||
|
|
||||||
|
Gerbil GetGerbil(Guid id);
|
||||||
|
|
||||||
|
void CreateGerbil(Gerbil gerbil);
|
||||||
|
|
||||||
|
void UpdateGerbil(Gerbil gerbil);
|
||||||
|
|
||||||
|
void DeleteGerbil(Gerbil gerilb);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Repositories/ILitterRepostitory.cs
Normal file
15
Repositories/ILitterRepostitory.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using GerbilManager.Models;
|
||||||
|
|
||||||
|
namespace GerbilManager.Repositories
|
||||||
|
{
|
||||||
|
public interface ILitterRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Litter> GetLitters();
|
||||||
|
|
||||||
|
Litter GetLitter(Guid id);
|
||||||
|
|
||||||
|
void CreateLitter(Litter litter);
|
||||||
|
void UpdateLitter(Litter litter);
|
||||||
|
void DeleteLitter(Litter litter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,7 @@ using GerbilManager.Models;
|
|||||||
|
|
||||||
namespace GerbilManager.Repositories
|
namespace GerbilManager.Repositories
|
||||||
{
|
{
|
||||||
|
public class InMemGerbilRepository : IGerbilRepository
|
||||||
public class InMemGerbilRepository
|
|
||||||
{
|
{
|
||||||
private readonly List<Gerbil> _gerbilList = new()
|
private readonly List<Gerbil> _gerbilList = new()
|
||||||
{
|
{
|
||||||
@@ -18,6 +17,23 @@ namespace GerbilManager.Repositories
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Gerbil GetGerbil(Guid id) => _gerbilList.SingleOrDefault(x => x.Id == id);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,8 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"sqlConnection": "server=.; database=GerbilManager; Integrated Security=true"
|
||||||
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user