| throw new EntityNotFoundException("Applicant not found"); | throw new EntityNotFoundException("Applicant not found"); | ||||
| } | } | ||||
| _logger.LogError($"Removing Applicant with id = {id}"); | |||||
| _logger.LogInformation($"Removing Applicant with id = {id}"); | |||||
| _context.Applicants.Remove(applicant); | _context.Applicants.Remove(applicant); | ||||
| var result = _context.SaveChangesAsync(); | var result = _context.SaveChangesAsync(); | ||||
| _logger.LogError($"Applicant with id = {id} is removed successfully"); | |||||
| _logger.LogInformation($"Applicant with id = {id} is removed successfully"); | |||||
| await result; | await result; | ||||
| } | } | ||||
| public async Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(AuthenticateRequestDto model) | public async Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(AuthenticateRequestDto model) | ||||
| { | { | ||||
| _logger.LogError($"Checking credentials for user: {model.Username}"); | |||||
| _logger.LogInformation($"Checking credentials for user: {model.Username}"); | |||||
| var user = await _userManager.FindByNameAsync(model.Username); | var user = await _userManager.FindByNameAsync(model.Username); | ||||
| // return null if user not found | // return null if user not found | ||||
| // return null if user is disabled | // return null if user is disabled | ||||
| if (user.IsEnabled == false) | if (user.IsEnabled == false) | ||||
| { | { | ||||
| _logger.LogError($"User: {model.Username} is not enabled"); | |||||
| _logger.LogInformation($"User: {model.Username} is not enabled"); | |||||
| return new ServiceResponseDTO<AuthenticateResponseDto> | return new ServiceResponseDTO<AuthenticateResponseDto> | ||||
| { | { | ||||
| IsError = true, | IsError = true, | ||||
| // password is not correct | // password is not correct | ||||
| if (!result) | if (!result) | ||||
| { | { | ||||
| _logger.LogError($"Password for user: {model.Username} is not correct"); | |||||
| _logger.LogInformation($"Password for user: {model.Username} is not correct"); | |||||
| await _userManager.AccessFailedAsync(user); | await _userManager.AccessFailedAsync(user); | ||||
| return new ServiceResponseDTO<AuthenticateResponseDto> | return new ServiceResponseDTO<AuthenticateResponseDto> | ||||
| }; | }; | ||||
| } | } | ||||
| var token = await GenerateToken(user); | var token = await GenerateToken(user); | ||||
| _logger.LogError($"Successfull login token: {token}"); | |||||
| _logger.LogInformation($"Successfull login token: {token}"); | |||||
| return token; | return token; | ||||
| } | } | ||||
| public async Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(GoogleApiModel model) | public async Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(GoogleApiModel model) | ||||
| { | { | ||||
| _logger.LogError($"Checking token for google login {model.Token}"); | |||||
| _logger.LogInformation($"Checking token for google login {model.Token}"); | |||||
| if (!(await _httpClient.IsTokenValid(model.Token))) | if (!(await _httpClient.IsTokenValid(model.Token))) | ||||
| { | { | ||||
| _logger.LogError($"Token is not valid"); | _logger.LogError($"Token is not valid"); | ||||
| ErrorMessage = "Invalid Google Api Token" | ErrorMessage = "Invalid Google Api Token" | ||||
| }; | }; | ||||
| } | } | ||||
| _logger.LogError($"Checking if user exists in Db with email : {model.User.email}"); | |||||
| _logger.LogInformation($"Checking if user exists in Db with email : {model.User.email}"); | |||||
| var user = await _userManager.FindByEmailAsync(model.User.email); | var user = await _userManager.FindByEmailAsync(model.User.email); | ||||
| // return null if user not found | // return null if user not found |
| throw new EntityNotFoundException("Pattern already exists in database"); | throw new EntityNotFoundException("Pattern already exists in database"); | ||||
| } | } | ||||
| _logger.LogError($"Pattern are not in database"); | |||||
| _logger.LogInformation($"Pattern is not in database"); | |||||
| _logger.LogInformation($"Mapping PatternCreateDto to model"); | _logger.LogInformation($"Mapping PatternCreateDto to model"); | ||||
| var pattern = _mapper.Map<Pattern>(patternCreateDto); | var pattern = _mapper.Map<Pattern>(patternCreateDto); | ||||
| _logger.LogInformation($"Pattern mapped successfully"); | _logger.LogInformation($"Pattern mapped successfully"); |
| throw new EntityNotFoundException("Selection level not found"); | throw new EntityNotFoundException("Selection level not found"); | ||||
| } | } | ||||
| _logger.LogError($"Level with id = {id} found and returned to client"); | |||||
| _logger.LogInformation($"Level with id = {id} found and returned to client"); | |||||
| return sl; | return sl; | ||||
| } | } | ||||
| throw new EntityNotFoundException("Selection process not found"); | throw new EntityNotFoundException("Selection process not found"); | ||||
| } | } | ||||
| _logger.LogError($"Changing status for {model.Id}"); | |||||
| _logger.LogInformation($"Changing status for {model.Id}"); | |||||
| sp.Status = "Odrađen"; | sp.Status = "Odrađen"; | ||||
| _logger.LogError($"Skipping throught levels to come to next level"); | |||||
| _logger.LogInformation($"Skipping throught levels to come to next level"); | |||||
| var nextLevel = _context.SelectionLevels.AsEnumerable() | var nextLevel = _context.SelectionLevels.AsEnumerable() | ||||
| .SkipWhile(obj => obj.Id != sp.SelectionLevelId) | .SkipWhile(obj => obj.Id != sp.SelectionLevelId) | ||||
| .Skip(1).First(); | .Skip(1).First(); | ||||
| SchedulerId = model.SchedulerId | SchedulerId = model.SchedulerId | ||||
| }; | }; | ||||
| _context.SelectionProcesses.Add(newProcess); | _context.SelectionProcesses.Add(newProcess); | ||||
| _logger.LogError($"Create and add new selection process"); | |||||
| _logger.LogInformation($"Create and add new selection process"); | |||||
| var result = await _context.SaveChangesAsync() > 0; | var result = await _context.SaveChangesAsync() > 0; | ||||
| _logger.LogError($"Saved changes to db"); | |||||
| _logger.LogInformation($"Saved changes to db"); | |||||
| return result; | return result; | ||||
| } | } | ||||