Skip to content

Commit

Permalink
fix(aait.backend.1a.tofik-abdu): refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tans1 committed Sep 2, 2023
1 parent 84b6644 commit 9b50503
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Features\PostFeatureTest\Queries\" />
</ItemGroup>

</Project>

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Application.DTO.UserDTO.DTO
{
public class UserUpdateDTO : IBaseUserDTO
{
public int Id { get; set; }
public required string Username { get; set; }
public required string Email { get; set; }
public required string Password { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ public async Task<BaseResponse<CommentResponseDTO>> Handle(UpdateCommentCommand
{
throw new ValidationException(validationResult);
}
var exists = await _commentRepository.Exists(request.Id);
var comment = await _commentRepository.Get(request.Id);

if (!exists)
if (comment == null)
{
throw new NotFoundException("Comment is not found");
}


var newComment = _mapper.Map<Comment>(request.CommentData);
newComment.Id = request.Id;
newComment.UserId = request.userId;
var updationResult = await _commentRepository.Update(newComment);
_mapper.Map(request.CommentData, comment);

var updationResult = await _commentRepository.Update(comment);
var result = _mapper.Map<CommentResponseDTO>(updationResult);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ public async Task<BaseResponse<PostResponseDTO>> Handle(UpdatePostCommand reques
{
throw new ValidationException(validationResult);
}
var exists = await _postRepository.Exists(request.Id);
var post = await _postRepository.Get(request.Id);


if (!exists)
if (post == null)
{
throw new NotFoundException("Post is not found");
}

var newPost = _mapper.Map<Post>(request.PostUpdateData);
newPost.Id = request.Id;
newPost.UserId = request.userId;
var updationResult = await _postRepository.Update(newPost);
_mapper.Map(request.PostUpdateData, post);

//var newPost = _mapper.Map<Post>(request.PostUpdateData);
//newPost.Id = request.Id;
//newPost.UserId = request.userId;
var updationResult = await _postRepository.Update(post);
var result = _mapper.Map<PostResponseDTO>(updationResult);

return new BaseResponse<PostResponseDTO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Application.DTO.Common;
using Application.DTO.UserDTO.DTO;
using Application.DTO.UserDTO.validations;
using Application.Exceptions;
using Application.Features.UserFeature.Requests.Commands;
using AutoMapper;
using Domain.Entities;
Expand Down Expand Up @@ -33,15 +34,21 @@ public async Task<UserResponseDTO> Handle(UpdateUserCommand request, Cancellatio

if (!validationResult.IsValid)
{
throw new Exception();
throw new ValidationException(validationResult);
}
if (request.userId <= 0)
{
throw new Exception();
throw new BadRequestException("USER with this Id doesnt exist");
}
var newUser = _mapper.Map<User>(request.UserUpdateData);
newUser.Id = request.userId;
var updationResult = await _UserRepository.Update(newUser);
var user = await _UserRepository.Get(request.userId);
if (user == null)
{
throw new NotFoundException("User is not found");
}

var newUser = _mapper.Map(request.UserUpdateData,user);
//newUser.Id = request.userId;
var updationResult = await _UserRepository.Update(user);

return _mapper.Map<UserResponseDTO>(updationResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public MappingProfile()
CreateMap<ReactionResponseDTO, PostReaction>().ReverseMap();
CreateMap<ReactionDTO, CommentReaction>().ReverseMap();
CreateMap<ReactionResponseDTO, CommentReaction>().ReverseMap();
CreateMap<PostUpdateDTO, Post>().ReverseMap();


CreateMap<NotificationCreateDTO, Notification>().ReverseMap();
Expand Down
2 changes: 1 addition & 1 deletion aait/backend/group-1A/Application/Response/BaseResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class BaseResponse<T>

public string Message { get; set; } = "";

public T Value { get; set; }
public T? Value { get; set; }
}
}
2 changes: 1 addition & 1 deletion aait/backend/group-1A/WebApi/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<ActionResult<UserResponseDTO>> Get(int id)



[HttpPut("{id}")]
[HttpPut("")]
[Authorize]
public async Task<ActionResult<UserResponseDTO>> Put(int id, [FromBody] UserUpdateDTO UpdateUserData)
{
Expand Down
2 changes: 1 addition & 1 deletion aait/backend/group-1A/WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
ValidateIssuerSigningKey = true,
ValidIssuer = builder.Configuration["Jwt:Issuer"],
ValidAudience = builder.Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(builder.Configuration["Jwt : Key"]))
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("4A7F9D8C3E6B025F1A4D763CACB2E832A6E9D6F591B6322A54CE33D25773E45B"))
};
});

Expand Down
2 changes: 1 addition & 1 deletion aait/backend/group-1A/WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"SocialMediaApp": "Host=localhost; Database=SocialMediaApp2; Username=postgres; Password=12345678;"
"SocialMediaApp": "Host=localhost; Database=SocialMediaApp4; Username=postgres; Password=12345678;"
},
"Logging": {
"LogLevel": {
Expand Down

0 comments on commit 9b50503

Please sign in to comment.