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

@ -21,7 +21,7 @@ namespace Cloud.Controllers
} }
[HttpGet("{userId}/farm")] [HttpGet("{userId}/farm")]
public async Task<ActionResult<List<Farm>>> Index (int userId) public async Task<ActionResult<List<Farm>>> Index(int userId)
{ {
try try
{ {
@ -62,10 +62,11 @@ namespace Cloud.Controllers
{ {
try try
{ {
var farm = new Farm { var farm = new Farm
{
Name = farmRequest.Name, Name = farmRequest.Name,
UserId = userId, UserId = userId,
RaspberryMacAddr = farmRequest.RaspberryMacAddr, RaspberryIP = farmRequest.RaspberryIP,
}; };
Farm? farmCreated = _context.Farms.Add(farm).Entity; Farm? farmCreated = _context.Farms.Add(farm).Entity;
@ -90,7 +91,7 @@ namespace Cloud.Controllers
return NotFound("Farm is not found"); return NotFound("Farm is not found");
farm.Name = farmRequest.Name; farm.Name = farmRequest.Name;
farm.RaspberryMacAddr = farmRequest.RaspberryMacAddr; farm.RaspberryIP = farmRequest.RaspberryIP;
_context.Farms.Update(farm); _context.Farms.Update(farm);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
@ -123,6 +124,5 @@ namespace Cloud.Controllers
return BadRequest(ex.Message); return BadRequest(ex.Message);
} }
} }
} }
} }

View File

@ -6,7 +6,6 @@
public string Name { get; set; } public string Name { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public User? User { 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 class FarmRequest
{ {
public string Name { get; set; } 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() public FarmValidator()
{ {
RuleFor(request => request.RaspberryMacAddr) RuleFor(request => request.RaspberryIP)
.NotEmpty().WithMessage("MAC address can't be empty") .NotEmpty().WithMessage("IP address can't be empty")
.Matches("^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$").WithMessage("MAC address is not valid"); .Matches(@"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$").WithMessage("IP address is not valid");
RuleFor(request => request.Name) RuleFor(request => request.Name)
.NotEmpty().WithMessage("Name can't be empty"); .NotEmpty().WithMessage("Name can't be empty");