Adding update endpoint for location, player, spawnable, and user
This commit is contained in:
@@ -45,6 +45,30 @@ public class LocationController : ControllerBase
|
||||
return Ok(newLoc);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> Update(string id, [FromBody] UpdateLocationRequest req)
|
||||
{
|
||||
var location = await _locationService.GetByIdAsync(id);
|
||||
if (location == null)
|
||||
return NotFound("Location not found.");
|
||||
|
||||
location.X = req.X;
|
||||
location.Y = req.Y;
|
||||
location.Z = req.Z;
|
||||
location.N = req.N;
|
||||
location.NE = req.NE;
|
||||
location.E = req.E;
|
||||
location.SE = req.SE;
|
||||
location.S = req.S;
|
||||
location.SW = req.SW;
|
||||
location.W = req.W;
|
||||
location.NW = req.NW;
|
||||
|
||||
await _locationService.UpdateAsync(location);
|
||||
return Ok(location);
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
|
||||
@@ -93,6 +93,21 @@ public class PlayerController : ControllerBase
|
||||
return Ok(player);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Update([FromBody] UpdatePlayerRequest req)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var player = await _playerService.GetByUserIdAsync(userId);
|
||||
if (player == null)
|
||||
return NotFound("Player not found.");
|
||||
|
||||
player.Name = req.Name;
|
||||
player.Climbing = req.Climbing;
|
||||
await _playerService.UpdateAsync(player);
|
||||
return Ok(player);
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> Delete()
|
||||
|
||||
@@ -33,6 +33,23 @@ public class SpawnableController : ControllerBase
|
||||
return Ok(spawnable);
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> Update(string id, [FromBody] UpdateSpawnableRequest req)
|
||||
{
|
||||
var spawnable = await _spawnableService.GetByIdAsync(id);
|
||||
if (spawnable == null)
|
||||
return NotFound("Spawnable not found.");
|
||||
|
||||
spawnable.Name = req.Name.ToLower();
|
||||
spawnable.SpawnRate = req.SpawnRate;
|
||||
spawnable.CollectAction = req.CollectAction;
|
||||
spawnable.CollectResults = req.CollectResults;
|
||||
|
||||
await _spawnableService.UpdateAsync(spawnable);
|
||||
return Ok(spawnable);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> GetAll()
|
||||
|
||||
@@ -26,6 +26,20 @@ public class UserController : ControllerBase
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> UpdateUser([FromQuery] string username, [FromBody] UpdateUserRequest req)
|
||||
{
|
||||
var user = await _userService.GetByUsernameAsync(username);
|
||||
if (user == null)
|
||||
return NotFound($"User '{username}' not found.");
|
||||
|
||||
user.Role = req.Role;
|
||||
user.Email = req.Email;
|
||||
await _userService.UpdateAsync(user);
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
// DELETE: /api/User?username=foo
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
|
||||
Reference in New Issue
Block a user