Fix nullable
This commit is contained in:
@@ -49,8 +49,8 @@ namespace GerbilManagerWebAPI.Controllers
|
|||||||
Litter litter = new Litter{
|
Litter litter = new Litter{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Date = dto.Date,
|
Date = dto.Date,
|
||||||
Father = gerbilrepository.GetGerbil(dto.Father),
|
Father = gerbilrepository.GetGerbil(dto.Father ?? Guid.Empty),
|
||||||
Mother = gerbilrepository.GetGerbil(dto.Mother),
|
Mother = gerbilrepository.GetGerbil(dto.Mother ?? Guid.Empty),
|
||||||
Name = dto.Name,
|
Name = dto.Name,
|
||||||
Strength = dto.Strength
|
Strength = dto.Strength
|
||||||
};
|
};
|
||||||
@@ -70,10 +70,10 @@ namespace GerbilManagerWebAPI.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
Litter updatedLitter = existingItem with{
|
Litter updatedLitter = existingItem with{
|
||||||
Date = litterDto.Date,
|
Date = litterDto.Date ?? DateTime.Now,
|
||||||
Strength = litterDto.Strength,
|
Strength = litterDto.Strength,
|
||||||
Father = gerbilrepository.GetGerbil(litterDto.Father),
|
Father = gerbilrepository.GetGerbil(litterDto.Father ?? Guid.Empty),
|
||||||
Mother = gerbilrepository.GetGerbil(litterDto.Mother),
|
Mother = gerbilrepository.GetGerbil(litterDto.Mother ?? Guid.Empty),
|
||||||
Name = litterDto.Name
|
Name = litterDto.Name
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace GerbilManagerWebAPI.Converter
|
|||||||
return new LitterDto{
|
return new LitterDto{
|
||||||
Id = litter.Id,
|
Id = litter.Id,
|
||||||
Date = litter.Date,
|
Date = litter.Date,
|
||||||
Father = litter.Father.AsDto(),
|
Father = litter.Father?.AsDto(),
|
||||||
Mother = litter.Mother.AsDto(),
|
Mother = litter.Mother?.AsDto(),
|
||||||
Name = litter.Name,
|
Name = litter.Name,
|
||||||
Strength = litter.Strength
|
Strength = litter.Strength
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace GerbilManagerWebAPI.Dtos
|
|||||||
public required string Name { get; init; }
|
public required string Name { get; init; }
|
||||||
public required DateTime Date { get; init; }
|
public required DateTime Date { get; init; }
|
||||||
public int? Strength { get; init; }
|
public int? Strength { get; init; }
|
||||||
public Guid Father { get; init; }
|
public Guid? Father { get; init; }
|
||||||
public Guid Mother { get; init; }
|
public Guid? Mother { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,6 @@ namespace GerbilManagerWebAPI.Dtos
|
|||||||
{
|
{
|
||||||
public record UpdateBreederDto
|
public record UpdateBreederDto
|
||||||
{
|
{
|
||||||
public string Name { get; init; }
|
public string? Name { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,9 @@ namespace GerbilManagerWebAPI.Dtos
|
|||||||
{
|
{
|
||||||
public record UpdateGerbilDto
|
public record UpdateGerbilDto
|
||||||
{
|
{
|
||||||
public string Name { get; init; }
|
public string? Name { get; init; }
|
||||||
public GenderDto Gender { get; init; }
|
public GenderDto? Gender { get; init; }
|
||||||
public LitterDto Litter { get; init; }
|
public LitterDto? Litter { get; init; }
|
||||||
public BreederDto Breeder { get; init; }
|
public BreederDto? Breeder { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,10 @@ namespace GerbilManagerWebAPI.Dtos
|
|||||||
{
|
{
|
||||||
public record UpdateLitterDto
|
public record UpdateLitterDto
|
||||||
{
|
{
|
||||||
public string Name { get; init; }
|
public string? Name { get; init; }
|
||||||
public DateTime Date { get; init; }
|
public DateTime? Date { get; init; }
|
||||||
public int Strength { get; init; }
|
public int? Strength { get; init; }
|
||||||
public Guid Father { get; init; }
|
public Guid? Father { get; init; }
|
||||||
public Guid Mother { get; init; }
|
public Guid? Mother { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@ namespace GerbilManagerWebAPI.Models
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; init; }
|
||||||
public required string Name { get; init; }
|
public required string Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ namespace GerbilManagerWebAPI.Models
|
|||||||
public record Gerbil
|
public record Gerbil
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; init; } // init => properties are immutable by default, they are only mutable in the constructor and initializer.
|
||||||
public required string Name { get; init; }
|
public required string Name { get; set; } //required => parameter is necessary in constructor and object iniilization list. So it cannot be intantiated without it
|
||||||
public Gender Gender { get; init; }
|
public required Gender Gender { get; set; }
|
||||||
public Litter? Litter { get; set; }
|
public Litter? Litter { get; set; } // Any variable where the ? isn't appended to the type name is a non-nullable reference type.
|
||||||
public Breeder? Breeder { get; set; }
|
public Breeder? Breeder { get; set; } // You use the null-forgiving operator ! following a variable name to force the null-state to be not-null. For example, if you know the name variable isn't null but the compiler issues a warning, you can write the following code to override the compiler's analysis:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,11 @@ namespace GerbilManagerWebAPI.Models
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; init; }
|
||||||
public required string Name { get; init; }
|
public required string Name { get; set; }
|
||||||
public required DateTime Date { get; init; }
|
public required DateTime Date { get; set; }
|
||||||
public int? Strength { get; init; }
|
public int? Strength { get; set; }
|
||||||
public Gerbil? Father { get; init; }
|
public Gerbil? Father { get; set; }
|
||||||
public Gerbil? Mother { get; init; }
|
public Gerbil? Mother { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ dotnet ef migrations add <name>
|
|||||||
|
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
Backup docker volume database
|
- Backup docker volume database
|
||||||
|
- run "dotnet ef database update" if no database exist.
|
||||||
@@ -12,7 +12,7 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: GerbilManagerWebAPI/Dockerfile
|
dockerfile: GerbilManagerWebAPI/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- ConnectionStrings:sqlConnection=server=database; database=GerbilManager; Integrated Security=true
|
- ConnectionStrings:sqlConnection=server=database; database=GerbilManager; User Id=sa;Password=StrongerThenYYou1;Encrypt=False;TrustServerCertificate=True
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
Reference in New Issue
Block a user