dev #9

Merged
mfnefd merged 77 commits from dev into main 2024-12-25 23:49:45 +04:00
4 changed files with 129 additions and 130 deletions
Showing only changes of commit 03302065ab - Show all commits

View File

@ -62,10 +62,11 @@ namespace Cloud.Controllers
{
try
{
var farm = new Farm {
var farm = new Farm
{
Name = farmRequest.Name,
UserId = userId,
RaspberryMacAddr = farmRequest.RaspberryMacAddr,
RaspberryIP = farmRequest.RaspberryIP,
};
Farm? farmCreated = _context.Farms.Add(farm).Entity;
@ -90,7 +91,7 @@ namespace Cloud.Controllers
return NotFound("Farm is not found");
farm.Name = farmRequest.Name;
farm.RaspberryMacAddr = farmRequest.RaspberryMacAddr;
farm.RaspberryIP = farmRequest.RaspberryIP;
_context.Farms.Update(farm);
await _context.SaveChangesAsync();
@ -123,6 +124,5 @@ namespace Cloud.Controllers
return BadRequest(ex.Message);
}
}
}
}

View File

@ -6,7 +6,6 @@
public string Name { get; set; }
public int UserId { get; set; }
public User? User { get; set; }
public string RaspberryMacAddr { get; set; }
public string RaspberryIP { get; set; }
}
}

View File

@ -3,6 +3,6 @@
public class FarmRequest
{
public string Name { get; set; }
public string RaspberryMacAddr { get; set; }
public string RaspberryIP { get; set; }
}
}

View File

@ -7,9 +7,9 @@ namespace Cloud.Validation
{
public FarmValidator()
{
RuleFor(request => request.RaspberryMacAddr)
.NotEmpty().WithMessage("MAC address can't be empty")
.Matches("^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$").WithMessage("MAC address is not valid");
RuleFor(request => request.RaspberryIP)
.NotEmpty().WithMessage("IP address can't be empty")
.Matches(@"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$").WithMessage("IP address is not valid");
RuleFor(request => request.Name)
.NotEmpty().WithMessage("Name can't be empty");