Ignore:
Timestamp:
03/22/26 17:58:40 (4 months ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
73b69b2
Parents:
b62cefc
Message:

Added fixes for the login,stories management and reading lists

Location:
ChapterX.Application
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ChapterX.Application/Auth/LoginHandler.cs

    rb62cefc racf690c  
    2525            var token = _jwtTokenService.GenerateToken(user);
    2626
    27             return new LoginResponse(token, user.Id, user.Username, user.Email);
     27            var role = user.Admin != null ? "admin"
     28                : user.Writer != null ? "writer"
     29                : "regular";
     30
     31            return new LoginResponse(token, user.Id, user.Username, user.Email, user.Name, user.Surname, role);
    2832        }
    2933    }
  • ChapterX.Application/Auth/LoginResponse.cs

    rb62cefc racf690c  
    11namespace ChapterX.Application.Auth
    22{
    3     public record LoginResponse(string Token, int UserId, string Username, string Email);
     3    public record LoginResponse(string Token, int UserId, string Username, string Email, string Name, string Surname, string Role);
    44}
  • ChapterX.Application/Auth/RegisterHandler.cs

    rb62cefc racf690c  
    77    {
    88        private readonly IUserRepository _userRepository;
     9        private readonly IWriterRepository _writerRepository;
    910
    10         public RegisterHandler(IUserRepository userRepository)
     11        public RegisterHandler(IUserRepository userRepository, IWriterRepository writerRepository)
    1112        {
    1213            _userRepository = userRepository;
     14            _writerRepository = writerRepository;
    1315        }
    1416
     
    3234            await _userRepository.AddAsync(user, cancellationToken);
    3335
     36            var writer = new Domain.Entities.Writer { Id = user.Id };
     37            await _writerRepository.AddAsync(writer, cancellationToken);
     38
    3439            return new RegisterResponse(user.Id, user.Username, user.Email);
    3540        }
  • ChapterX.Application/ReadingListItems/Commands/AddHandler.cs

    rb62cefc racf690c  
    1818        public async Task<AddResponse> Handle(AddRequest request, CancellationToken cancellationToken)
    1919        {
     20            var exists = await _readingListItemsRepository.ExistsAsync(request.ReadingListId, request.StoryId, cancellationToken);
     21            if (exists)
     22                throw new InvalidOperationException("Story is already in this reading list.");
     23
    2024            var readingListItems = new Domain.Entities.ReadingListItems
    2125            {
Note: See TracChangeset for help on using the changeset viewer.