Update client for api changes and nickname attr

This commit is contained in:
programmingPug
2025-01-17 17:27:59 -05:00
parent a428aacd99
commit b30eed98d2
13 changed files with 42 additions and 34 deletions

View File

@@ -56,9 +56,9 @@ namespace SoilMoistureAPI.Controllers
// PUT: api/Device/{id}/nickname
[HttpPut("{id}/nickname")]
public async Task<IActionResult> UpdateNickname(string id, [FromBody] string newNickname)
public async Task<IActionResult> UpdateNickname(int id, [FromBody] DeviceDto deviceUpdate)
{
if (string.IsNullOrEmpty(newNickname))
if (string.IsNullOrEmpty(deviceUpdate.Nickname))
{
return BadRequest("Nickname cannot be empty.");
}
@@ -69,7 +69,7 @@ namespace SoilMoistureAPI.Controllers
return NotFound("Device not found.");
}
device.Nickname = newNickname;
device.Nickname = deviceUpdate.Nickname;
_context.Entry(device).State = EntityState.Modified;
try
@@ -106,9 +106,9 @@ namespace SoilMoistureAPI.Controllers
return NoContent(); // 204 No Content
}
private bool DeviceExists(string id)
private bool DeviceExists(int id)
{
return _context.SoilMoisturesFlat.Any(e => e.DeviceId == id);
return _context.SoilMoisturesFlat.Any(e => e.Id == id);
}
}
}

Binary file not shown.

View File

@@ -25,7 +25,7 @@ builder.Services.AddCors(options =>
options.AddPolicy("AllowClient",
builder =>
{
//builder.WithOrigins("http://localhost:3000", "http://soilmoisture_client:80")
//builder.WithOrigins("http://localhost:3000", "http://localhost:4200", "http://soilmoisture_client:80")
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();

Binary file not shown.

Binary file not shown.

Binary file not shown.