Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(Transfers): update transfers with put #154

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: format code with dotnet format
  • Loading branch information
Sharif-C committed Dec 18, 2024
commit 6857eaad028ea1ea5346e0623274834a2014085b
34 changes: 17 additions & 17 deletions api/Controllers/AddressesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IActionResult Create([FromBody] AddressRequest req)

if (newAddress == null) throw new ApiFlowException("Saving new Address failed.");

return Ok(new
return Ok(new
{
message = "Address created",
new_address = new AddressResponse
Expand All @@ -42,11 +42,11 @@ public IActionResult Create([FromBody] AddressRequest req)
[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] AddressRequest req)
{
Address? updateAddress = _addressProvider.Update(id,req);
Address? updateAddress = _addressProvider.Update(id, req);

if (updateAddress == null) throw new ApiFlowException($"Address not found for id '{id}'");

return Ok(new
return Ok(new
{
message = "Address updated",
new_address = new AddressResponse
Expand All @@ -66,26 +66,26 @@ public IActionResult Update(Guid id, [FromBody] AddressRequest req)

[HttpGet()]
public IActionResult ShowAll() => Ok(_addressProvider.GetAll().Select(a => new AddressResponse
{
Id = a.Id,
Street = a.Street,
HouseNumber = a.HouseNumber,
HouseNumberExtension = a.HouseNumberExtension,
HouseNumberExtensionExtra = a.HouseNumberExtensionExtra,
ZipCode = a.ZipCode,
City = a.City,
Province = a.Province,
CountryCode = a.CountryCode
}));
{
Id = a.Id,
Street = a.Street,
HouseNumber = a.HouseNumber,
HouseNumberExtension = a.HouseNumberExtension,
HouseNumberExtensionExtra = a.HouseNumberExtensionExtra,
ZipCode = a.ZipCode,
City = a.City,
Province = a.Province,
CountryCode = a.CountryCode
}));

[HttpGet("{id}")]
public IActionResult ShowSingle(Guid id)
{
Address? foundAddress = _addressProvider.GetById(id);

if (foundAddress == null) throw new ApiFlowException($"Address not found for id '{id}'");

return Ok(new
return Ok(new
{
message = "Address found",
new_address = new AddressResponse
Expand All @@ -109,7 +109,7 @@ public IActionResult Delete(Guid id)

if (deletedAddress == null) throw new ApiFlowException($"Address not found for id '{id}'");

return Ok(new
return Ok(new
{
message = "Address Deleted",
new_address = new AddressResponse
Expand Down
4 changes: 2 additions & 2 deletions api/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public async Task<IActionResult> GenerateToken([FromQuery] string role)
var token = await _tokenService.GenerateToken(role.ToLower());
return Ok(new { Token = token });
}

[HttpGet("admin-only")]
[Authorize(Roles = "admin,operative")]
public IActionResult AdminOnly()
{
return Ok(new{message = "Admin Only Authorized."});
return Ok(new { message = "Admin Only Authorized." });
}
}
2 changes: 1 addition & 1 deletion api/Controllers/ClientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
message = "Client created!",
new_client = new ClientResponse
{
Id = newClient.Id,

Check warning on line 31 in api/Controllers/ClientsController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Dereference of a possibly null reference.
Name = newClient.Name,
Contact = new ContactResponse
{
Expand Down Expand Up @@ -62,10 +62,10 @@

if (updatedClient == null) BadRequest(new { message = "Client update failed." });

Client? foundClient = _clientProvider.GetById(updatedClient.Id);

Check warning on line 65 in api/Controllers/ClientsController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Dereference of a possibly null reference.
return Ok(new ClientResponse
{
Id = foundClient.Id,

Check warning on line 68 in api/Controllers/ClientsController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Dereference of a possibly null reference.
Name = foundClient.Name,
Contact = new ContactResponse
{
Expand All @@ -92,7 +92,7 @@

}


[HttpGet("{id}")]
public IActionResult ShowSingle(Guid id)
{
Expand Down
24 changes: 12 additions & 12 deletions api/Controllers/ContactsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public IActionResult Create([FromBody] ContactRequest req)
{
Contact? newContact = _contactProvider.Create(req);

if (newContact == null) NotFound(new{message = "Contact creation failed"});
if (newContact == null) NotFound(new { message = "Contact creation failed" });

return Ok(new
{
{
message = "Contact created!",
Contact = new ContactResponse
{
Expand All @@ -31,7 +31,7 @@ public IActionResult Create([FromBody] ContactRequest req)
}
});
}

[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] ContactRequest req)
{
Expand All @@ -52,15 +52,15 @@ public IActionResult Update(Guid id, [FromBody] ContactRequest req)
}
});
}

[HttpGet("{id}")]
public IActionResult ShowSingle(Guid id)
{
Contact? foundContact = _contactProvider.GetById(id);

if (foundContact == null)
return NotFound(new { message = $"Contact not found for id {id}" });

return Ok(new
{
message = "Contact found!",
Expand All @@ -76,11 +76,11 @@ public IActionResult ShowSingle(Guid id)

[HttpGet()]
public IActionResult ShowAll() => Ok(_contactProvider.GetAll()?.Select(c => new ContactResponse
{
Id = c.Id,
Name = c.Name,
Phone = c.Phone,
Email = c.Email
}).ToList());
{
Id = c.Id,
Name = c.Name,
Phone = c.Phone,
Email = c.Email
}).ToList());

}
6 changes: 3 additions & 3 deletions api/Controllers/InventoriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public IActionResult Create([FromBody] InventoryRequest req)

[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] InventoryRequest req)
{
{
Inventory? updatedInventory = _inventoriesProvider.Update(id, req);
if(updatedInventory == null) return NotFound(new {message = $"Inventory not found for id '{id}'"});
if (updatedInventory == null) return NotFound(new { message = $"Inventory not found for id '{id}'" });

List<Location> locations = _locationsProvider.GetLocationsByInventoryId(updatedInventory.Id);
Dictionary<string, int> calculatedValues = _inventoriesProvider.GetCalculatedValues(updatedInventory.Id);
Expand Down Expand Up @@ -96,7 +96,7 @@ public IActionResult Delete(Guid id)
Dictionary<string, int> calculatedValues = _inventoriesProvider.GetCalculatedValues(foundInventory.Id);

Inventory? deletedInventory = _inventoriesProvider.Delete(id);
if(deletedInventory == null) throw new ApiFlowException("Failed to delete inventory");
if (deletedInventory == null) throw new ApiFlowException("Failed to delete inventory");

return Ok(new
{
Expand Down
39 changes: 23 additions & 16 deletions api/Controllers/ItemGroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,39 @@
}

[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] ItemGroupRequest req){
ItemGroup? updatedItemGroup = _itemGroupProvider.Update(id,req);
if(updatedItemGroup == null) return NotFound(new {message = $"Item group not found for id '{id}'"});

return Ok(new {
message = "Item group updated.",
updated_item_group = new ItemGroupResponse {
Id = updatedItemGroup.Id,
Name = updatedItemGroup.Name,
public IActionResult Update(Guid id, [FromBody] ItemGroupRequest req)
{
ItemGroup? updatedItemGroup = _itemGroupProvider.Update(id, req);
if (updatedItemGroup == null) return NotFound(new { message = $"Item group not found for id '{id}'" });

return Ok(new
{
message = "Item group updated.",
updated_item_group = new ItemGroupResponse
{
Id = updatedItemGroup.Id,
Name = updatedItemGroup.Name,
Description = updatedItemGroup.Description
}
}
}
);
}

[HttpDelete("{id}")]
public IActionResult Delete(Guid id)
{
ItemGroup? deletedItemGroup = _itemGroupProvider.Delete(id);
if (deletedItemGroup == null) throw new ApiFlowException($"Item group not found for id '{id}'");

return Ok(new {deleted_item_group = new ItemGroupResponse{
Id = deletedItemGroup.Id,
Name = deletedItemGroup.Name,
Description = deletedItemGroup.Description
}});
return Ok(new
{
deleted_item_group = new ItemGroupResponse
{
Id = deletedItemGroup.Id,
Name = deletedItemGroup.Name,
Description = deletedItemGroup.Description
}
});
}

[HttpGet("{id}")]
Expand All @@ -73,7 +80,7 @@
}

[HttpGet()]
public IActionResult ShowAll() => Ok(_itemGroupProvider.GetAll().Select(ig => new ItemGroupResponse

Check warning on line 83 in api/Controllers/ItemGroupsController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Possible null reference argument for parameter 'source' in 'IEnumerable<ItemGroupResponse> Enumerable.Select<ItemGroup, ItemGroupResponse>(IEnumerable<ItemGroup> source, Func<ItemGroup, ItemGroupResponse> selector)'.
{
Id = ig.Id,
Name = ig.Name,
Expand Down
39 changes: 22 additions & 17 deletions api/Controllers/ItemLinesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@
}

[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] ItemLineRequest req){
ItemLine? updatedItemLine = _itemLinesProvider.Update(id,req);
if(updatedItemLine == null) return NotFound(new {message = $"Item line not found for id '{id}'"});

return Ok(new {
message = "Item Line updated!",
updated_item_line = new ItemLineResponse {
Id = updatedItemLine.Id,
Name = updatedItemLine.Name,
public IActionResult Update(Guid id, [FromBody] ItemLineRequest req)
{
ItemLine? updatedItemLine = _itemLinesProvider.Update(id, req);
if (updatedItemLine == null) return NotFound(new { message = $"Item line not found for id '{id}'" });

return Ok(new
{
message = "Item Line updated!",
updated_item_line = new ItemLineResponse
{
Id = updatedItemLine.Id,
Name = updatedItemLine.Name,
Description = updatedItemLine.Description,
CreatedAt = updatedItemLine.CreatedAt,
UpdatedAt = updatedItemLine.UpdatedAt
}
}
}
);
}

Expand All @@ -57,20 +60,22 @@
ItemLine? deletedItemLine = _itemLinesProvider.Delete(id);
if (deletedItemLine == null) throw new ApiFlowException($"Item line not found for id '{id}'");

return Ok(new {
return Ok(new
{
message = "Item Line deleted!",
deleted_item_line = new ItemLineResponse{
Id = deletedItemLine.Id,
Name = deletedItemLine.Name,
Description = deletedItemLine.Description,
CreatedAt = deletedItemLine.CreatedAt,
UpdatedAt = deletedItemLine.UpdatedAt
deleted_item_line = new ItemLineResponse
{
Id = deletedItemLine.Id,
Name = deletedItemLine.Name,
Description = deletedItemLine.Description,
CreatedAt = deletedItemLine.CreatedAt,
UpdatedAt = deletedItemLine.UpdatedAt
}
});
}

[HttpGet()]
public IActionResult ShowAll() => Ok(_itemLinesProvider.GetAll().Select(il => new ItemLineResponse

Check warning on line 78 in api/Controllers/ItemLinesController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Possible null reference argument for parameter 'source' in 'IEnumerable<ItemLineResponse> Enumerable.Select<ItemLine, ItemLineResponse>(IEnumerable<ItemLine> source, Func<ItemLine, ItemLineResponse> selector)'.
{
Id = il.Id,
Name = il.Name,
Expand Down
41 changes: 23 additions & 18 deletions api/Controllers/ItemTypesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@
}

[HttpPut("{id}")]
public IActionResult Update(Guid id, [FromBody] ItemTypeRequest req){
ItemType? updatedItemType = _itemTypesProvider.Update(id,req);
if(updatedItemType == null) return NotFound(new {message = $"Item Type not found for id '{id}'"});

return Ok(new {
message = "Item Type updated!",
updated_item_type = new ItemTypeResponse {
Id = updatedItemType.Id,
Name = updatedItemType.Name,
public IActionResult Update(Guid id, [FromBody] ItemTypeRequest req)
{
ItemType? updatedItemType = _itemTypesProvider.Update(id, req);
if (updatedItemType == null) return NotFound(new { message = $"Item Type not found for id '{id}'" });

return Ok(new
{
message = "Item Type updated!",
updated_item_type = new ItemTypeResponse
{
Id = updatedItemType.Id,
Name = updatedItemType.Name,
Description = updatedItemType.Description,
CreatedAt = updatedItemType.CreatedAt,
UpdatedAt = updatedItemType.UpdatedAt
}
}
}
);
}

Expand All @@ -57,14 +60,16 @@
ItemType? deletedItemType = _itemTypesProvider.Delete(id);
if (deletedItemType == null) throw new ApiFlowException($"Item Type not found for id '{id}'");

return Ok(new {
return Ok(new
{
message = "Item Type deleted!",
deleted_item_type = new ItemTypeResponse{
Id = deletedItemType.Id,
Name = deletedItemType.Name,
Description = deletedItemType.Description,
CreatedAt = deletedItemType.CreatedAt,
UpdatedAt = deletedItemType.UpdatedAt
deleted_item_type = new ItemTypeResponse
{
Id = deletedItemType.Id,
Name = deletedItemType.Name,
Description = deletedItemType.Description,
CreatedAt = deletedItemType.CreatedAt,
UpdatedAt = deletedItemType.UpdatedAt
}
});
}
Expand All @@ -85,9 +90,9 @@
UpdatedAt = foundItemType.UpdatedAt
});
}

[HttpGet()]
public IActionResult ShowAll() => Ok(_itemTypesProvider.GetAll().Select(it => new ItemTypeResponse

Check warning on line 95 in api/Controllers/ItemTypesController.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Generate Code Coverage Report

Possible null reference argument for parameter 'source' in 'IEnumerable<ItemTypeResponse> Enumerable.Select<ItemType, ItemTypeResponse>(IEnumerable<ItemType> source, Func<ItemType, ItemTypeResponse> selector)'.
{
Id = it.Id,
Name = it.Name,
Expand Down
Loading
Loading