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

fix(Category):update Category fixed #104

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
172 changes: 26 additions & 146 deletions AnalysisData/AnalysisData.sln.DotSettings.user

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public async Task<IActionResult> DeleteCategory(int id)

[Authorize(Policy = "silver")]
[HttpPut]
public async Task<IActionResult> UpdateCategory(int id, [FromBody] NewCategoryDto newCategory)
public async Task<IActionResult> UpdateCategory([FromBody] NewCategoryDto newCategory)
{
await _categoryService.UpdateAsync(newCategory, id);
await _categoryService.UpdateAsync(newCategory);
return Ok(new { massage = "updated successfully" });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace AnalysisData.Dtos.GraphDto.CategoryDto;

public class NewCategoryDto
{
[Required] public int Id { get; set; }
[Required] public string Name { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface ICategoryService
{
Task<PaginationCategoryDto> GetAllCategoriesAsync(int pageNumber, int pageSize);
Task AddAsync(NewCategoryDto categoryDto);
Task UpdateAsync(NewCategoryDto newCategoryDto, int preCategoryId);
Task UpdateAsync(NewCategoryDto newCategoryDto);
Task DeleteAsync(int id);
Task<Category> GetByIdAsync(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public async Task AddAsync(NewCategoryDto categoryDto)
await _categoryRepository.AddAsync(category);
}

public async Task UpdateAsync(NewCategoryDto newCategoryDto, int preCategoryId)
public async Task UpdateAsync(NewCategoryDto newCategoryDto)
{
var currentCategory = await _categoryRepository.GetByIdAsync(preCategoryId);
var currentCategory = await _categoryRepository.GetByIdAsync(newCategoryDto.Id);
var existingCategory = await _categoryRepository.GetByNameAsync(newCategoryDto.Name);
if (existingCategory != null && newCategoryDto.Name != currentCategory.Name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ public async Task UpdateCategory_ShouldReturnOk_WhenCategoryIsUpdatedSuccessfull
{
// Arrange
int categoryId = 1;
var newCategoryDto = new NewCategoryDto { Name = "UpdatedCategory" };
var newCategoryDto = new NewCategoryDto { Id = 1, Name = "UpdatedCategory" };

// Act
var result = await _controller.UpdateCategory(categoryId, newCategoryDto);
var result = await _controller.UpdateCategory(newCategoryDto);

// Assert
var okResult = Assert.IsType<OkObjectResult>(result);
var responseContent = JsonConvert.SerializeObject(okResult.Value);
var expectedResponseContent = JsonConvert.SerializeObject(new { massage = "updated successfully" });
Assert.Equal(expectedResponseContent, responseContent);

_categoryServiceMock.Verify(service => service.UpdateAsync(newCategoryDto, categoryId), Times.Once);
_categoryServiceMock.Verify(service => service.UpdateAsync(newCategoryDto), Times.Once);
}


Expand Down
Loading