Move webapi to sub folder
This commit is contained in:
12
GerbilManagerWebAPI/ApplicationContext.cs
Normal file
12
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Controllers/BreedersController.cs
Normal file
91
GerbilManagerWebAPI/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();
|
||||
}
|
||||
}
|
||||
}
|
||||
95
GerbilManagerWebAPI/Controllers/GerbilsController.cs
Normal file
95
GerbilManagerWebAPI/Controllers/GerbilsController.cs
Normal file
@@ -0,0 +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<GerbilDto> GetGerbils()
|
||||
{
|
||||
var items = repository.GetGerbils().Select( gerbil => gerbil.AsDto());
|
||||
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
GerbilManagerWebAPI/Controllers/LittersController.cs
Normal file
99
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Converter/BreederConveter.cs
Normal file
18
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Converter/GerbilConverter.cs
Normal file
19
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Converter/LitterConverter.cs
Normal file
21
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/BreederDto.cs
Normal file
8
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/CreateBreederDto.cs
Normal file
7
GerbilManagerWebAPI/Dtos/CreateBreederDto.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace GerbilManager.Dtos
|
||||
{
|
||||
public record CreateBreederDto
|
||||
{
|
||||
public string Name { get; init; }
|
||||
}
|
||||
}
|
||||
11
GerbilManagerWebAPI/Dtos/CreateGerbilDto.cs
Normal file
11
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/CreateLitterDto.cs
Normal file
11
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/GenderDto.cs
Normal file
9
GerbilManagerWebAPI/Dtos/GenderDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace GerbilManager.Dtos
|
||||
{
|
||||
public enum GenderDto
|
||||
{
|
||||
unknown = 0,
|
||||
male = 1,
|
||||
female = 2
|
||||
}
|
||||
}
|
||||
11
GerbilManagerWebAPI/Dtos/GerbilDto.cs
Normal file
11
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/LitterDto.cs
Normal file
12
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/UpdateBreederDto.cs
Normal file
8
GerbilManagerWebAPI/Dtos/UpdateBreederDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace GerbilManager.Dtos
|
||||
{
|
||||
public record UpdateBreederDto
|
||||
{
|
||||
public string Name { get; init; }
|
||||
}
|
||||
}
|
||||
10
GerbilManagerWebAPI/Dtos/UpdateGerbilDto.cs
Normal file
10
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Dtos/UpdateLitterDto.cs
Normal file
12
GerbilManagerWebAPI/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; }
|
||||
}
|
||||
}
|
||||
16
GerbilManagerWebAPI/GerbilManager.csproj
Normal file
16
GerbilManagerWebAPI/GerbilManager.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
8
GerbilManagerWebAPI/Models/Breeder.cs
Normal file
8
GerbilManagerWebAPI/Models/Breeder.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace GerbilManager.Models
|
||||
{
|
||||
public record Breeder
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public string Name { get; init; }
|
||||
}
|
||||
}
|
||||
9
GerbilManagerWebAPI/Models/Gender.cs
Normal file
9
GerbilManagerWebAPI/Models/Gender.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace GerbilManager.Models
|
||||
{
|
||||
public enum Gender
|
||||
{
|
||||
unknown = 0,
|
||||
male = 1,
|
||||
female = 2
|
||||
}
|
||||
}
|
||||
11
GerbilManagerWebAPI/Models/Gerbil.cs
Normal file
11
GerbilManagerWebAPI/Models/Gerbil.cs
Normal file
@@ -0,0 +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; }
|
||||
}
|
||||
}
|
||||
13
GerbilManagerWebAPI/Models/Litter.cs
Normal file
13
GerbilManagerWebAPI/Models/Litter.cs
Normal file
@@ -0,0 +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; }
|
||||
}
|
||||
}
|
||||
|
||||
33
GerbilManagerWebAPI/Program.cs
Normal file
33
GerbilManagerWebAPI/Program.cs
Normal file
@@ -0,0 +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<IGerbilRepository, InMemGerbilRepository>();
|
||||
|
||||
builder.Services.AddDbContext<ApplicationContext>(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();
|
||||
41
GerbilManagerWebAPI/Properties/launchSettings.json
Normal file
41
GerbilManagerWebAPI/Properties/launchSettings.json
Normal file
@@ -0,0 +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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
GerbilManagerWebAPI/Repositories/IBreederRepository.cs
Normal file
17
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Repositories/IGerbilRepository.cs
Normal file
17
GerbilManagerWebAPI/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
GerbilManagerWebAPI/Repositories/ILitterRepostitory.cs
Normal file
15
GerbilManagerWebAPI/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);
|
||||
}
|
||||
}
|
||||
39
GerbilManagerWebAPI/Repositories/InMemGerbilRepository.cs
Normal file
39
GerbilManagerWebAPI/Repositories/InMemGerbilRepository.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using GerbilManager.Models;
|
||||
|
||||
namespace GerbilManager.Repositories
|
||||
{
|
||||
public class InMemGerbilRepository : IGerbilRepository
|
||||
{
|
||||
private readonly List<Gerbil> _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<Gerbil> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
GerbilManagerWebAPI/appsettings.Development.json
Normal file
11
GerbilManagerWebAPI/appsettings.Development.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"sqlConnection": "server=.; database=GerbilManagerDebug; Integrated Security=true"
|
||||
}
|
||||
}
|
||||
12
GerbilManagerWebAPI/appsettings.json
Normal file
12
GerbilManagerWebAPI/appsettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"sqlConnection": "server=.; database=GerbilManager; Integrated Security=true"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user