diff --git a/ApiGatewayService/Controllers/AuthService/AccessDataCacheController.cs b/ApiGatewayService/Controllers/AuthService/AccessDataCacheController.cs deleted file mode 100644 index bf5506a..0000000 --- a/ApiGatewayService/Controllers/AuthService/AccessDataCacheController.cs +++ /dev/null @@ -1,14 +0,0 @@ -using ApiGatewayService.Models.AuthService.AccessDataCache.Requests; -using Microsoft.AspNetCore.Mvc; - -namespace ApiGatewayService.Controllers.AuthService; - -[ApiController] -[Route("api/[controller]")] -public class AccessDataCacheController : Controller -{ - public Task RecacheUser([FromBody] RecacheUserRequest recacheUserRequest) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/ApiGatewayService/Controllers/EntertainmentService/TagController.cs b/ApiGatewayService/Controllers/EntertainmentService/TagController.cs deleted file mode 100644 index fdad6ed..0000000 --- a/ApiGatewayService/Controllers/EntertainmentService/TagController.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiGatewayService.Controllers.EntertainmentService; - -[ApiController] -[Route("api/[controller]")] -public class TagController : ControllerBase -{ - public Task GetTag() - { - throw new NotImplementedException(); - } - public Task GetTags() - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/ApiGatewayService/KafkaServices/AccountKafkaService.cs b/ApiGatewayService/KafkaServices/AccountKafkaService.cs deleted file mode 100644 index 09e1b98..0000000 --- a/ApiGatewayService/KafkaServices/AccountKafkaService.cs +++ /dev/null @@ -1,467 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Confluent.Kafka; -using Newtonsoft.Json; -using TourService.Kafka; -using TourService.KafkaException; -using TourService.KafkaException.ConsumerException; -using UserService.Models; -using UserService.Models.Account.Requests; -using UserService.Services.Account; - -namespace UserService.KafkaServices -{ - public class AccountKafkaService : KafkaService - { - private readonly string _accountResponseTopic = Environment.GetEnvironmentVariable("ACCOUNT_RESPONSE_TOPIC") ?? "userServiceAccountsResponses"; - private readonly string _accountRequestTopic = Environment.GetEnvironmentVariable("ACCOUNT_REQUEST_TOPIC") ?? "userServiceAccountsRequests"; - private readonly IAccountService _accountService; - public AccountKafkaService( - ILogger logger, - IAccountService accountService, - IProducer producer, - KafkaTopicManager kafkaTopicManager) : base(logger, producer, kafkaTopicManager) - { - _accountService = accountService; - base.ConfigureConsumer(_accountRequestTopic); - } - - public override async Task Consume() - { - try - { - - while (true) - { - if(_consumer == null) - { - _logger.LogError("Consumer is null"); - throw new ConsumerException("Consumer is null"); - } - ConsumeResult consumeResult = _consumer.Consume(); - if (consumeResult != null) - { - var headerBytes = consumeResult.Message.Headers - .FirstOrDefault(x => x.Key.Equals("method")) ?? throw new NullReferenceException("headerBytes is null"); - - - var methodString = Encoding.UTF8.GetString(headerBytes.GetValueBytes()); - switch (methodString) - { - case "AccountAccessData": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.AccountAccessData(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("AccountAccessData")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("AccountAccessData")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - - break; - case "BeginPasswordReset": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.BeginPasswordReset(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("BeginPasswordReset")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("BeginPasswordReset")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "BeginRegistration": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.BeginRegistration(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("BeginRegistration")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("BeginRegistration")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "ChangePassword": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.ChangePassword(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("ChangePassword")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("ChangePassword")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "CompletePasswordReset": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(await _accountService.CompletePasswordReset(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("CompletePasswordReset")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("CompletePasswordReset")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "CompleteRegistration": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.CompleteRegistration(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("CompleteRegistration")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("CompleteRegistration")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "ResendPasswordResetCode": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(await _accountService.ResendPasswordResetCode(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("ResendPasswordResetCode")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("ResendPasswordResetCode")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "ResendRegistrationCode": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.ResendRegistrationCode(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("ResendRegistrationCode")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("ResendRegistrationCode")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "VerifyPasswordResetCode": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.VerifyPasswordResetCode(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("VerifyPasswordResetCode")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("VerifyPasswordResetCode")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - case "VerifyRegistrationCode": - try - { - if(await base.Produce(_accountResponseTopic,new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject( await _accountService.VerifyRegistrationCode(JsonConvert.DeserializeObject(consumeResult.Message.Value))), - Headers = [ - new Header("method",Encoding.UTF8.GetBytes("VerifyRegistrationCode")), - new Header("sender",Encoding.UTF8.GetBytes("userService")), - ] - })) - { - _logger.LogDebug("Successfully sent message {Key}",consumeResult.Message.Key); - _consumer.Commit(consumeResult); - } - } - catch (Exception e) - { - if(e is MyKafkaException) - { - _logger.LogError(e,"Error sending message"); - throw; - } - _ = await base.Produce(_accountResponseTopic, new Message() - { - Key = consumeResult.Message.Key, - Value = JsonConvert.SerializeObject(new MessageResponse(){ Message = e.Message}), - Headers = [ - new Header("method", Encoding.UTF8.GetBytes("VerifyRegistrationCode")), - new Header("sender", Encoding.UTF8.GetBytes("userService")), - new Header("error", Encoding.UTF8.GetBytes(e.Message)) - ] - }); - _consumer.Commit(consumeResult); - _logger.LogError(e, "Error sending message"); - } - break; - default: - _consumer.Commit(consumeResult); - - throw new ConsumerRecievedMessageInvalidException("Invalid message received"); - } - - } - } - } - catch(Exception ex) - { - if(_consumer != null) - { - _consumer.Dispose(); - } - if (ex is MyKafkaException) - { - _logger.LogError(ex,"Consumer error"); - throw new ConsumerException("Consumer error ",ex); - } - else - { - _logger.LogError(ex,"Unhandled error"); - throw; - } - } - } - - } -} \ No newline at end of file diff --git a/ApiGatewayService/Services/AuthService/AccessDataCache/AccessDataCacheService.cs b/ApiGatewayService/Services/AuthService/AccessDataCache/AccessDataCacheService.cs deleted file mode 100644 index 4ec9046..0000000 --- a/ApiGatewayService/Services/AuthService/AccessDataCache/AccessDataCacheService.cs +++ /dev/null @@ -1,43 +0,0 @@ -using ApiGatewayService.Models.AuthService.AccessDataCache.Requests; -using ApiGatewayService.Models.AuthService.AccessDataCache.Responses; -using ApiGatewayService.Models.AuthService.Models; -using AuthService.Services.AccessDataCache; -using TourService.Kafka; - -namespace ApiGatewayService.sServices.AuthService.AccessDataCache; - -public class AccessDataCacheService(ILogger logger, KafkaRequestService kafkaRequestService) : IAccessDataCacheService -{ - private readonly ILogger _logger = logger; - private readonly KafkaRequestService _kafkaRequestService = kafkaRequestService; - - public Task Get(string username) - { - throw new NotImplementedException(); - } - - public Task RecacheUser(RecacheUserRequest user) - { - throw new NotImplementedException(); - } - - public Task RecacheUser() - { - throw new NotImplementedException(); - } - - public Task RequestAndCacheUser(string username) - { - throw new NotImplementedException(); - } - - Task IAccessDataCacheService.Get(string username) - { - throw new NotImplementedException(); - } - - Task IAccessDataCacheService.RequestAndCacheUser(string username) - { - throw new NotImplementedException(); - } -} diff --git a/ApiGatewayService/Services/Profile/IProfileService.cs b/ApiGatewayService/Services/Profile/IProfileService.cs deleted file mode 100644 index 65d6f09..0000000 --- a/ApiGatewayService/Services/Profile/IProfileService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UserService.Models.Profile.Requests; -using UserService.Models.Profile.Responses; - -namespace UserService.Services.Profile; - -public interface IProfileService -{ - Task GetMyProfile(long userId); - Task UpdateProfile(long userId, UpdateProfileRequest request); - Task UploadAvatar(long userId, UploadAvatarRequest request); - Task GetUsernameAndAvatar(long userId); -} \ No newline at end of file diff --git a/ApiGatewayService/Services/Profile/ProfileService.cs b/ApiGatewayService/Services/Profile/ProfileService.cs deleted file mode 100644 index 5e2973b..0000000 --- a/ApiGatewayService/Services/Profile/ProfileService.cs +++ /dev/null @@ -1,115 +0,0 @@ -using UserService.Database.Models; -using UserService.Exceptions.Account; -using UserService.Models.Profile.Requests; -using UserService.Models.Profile.Responses; -using UserService.Repositories; - -namespace UserService.Services.Profile; - -public class ProfileService(UnitOfWork unitOfWork, ILogger logger) : IProfileService -{ - private readonly UnitOfWork _uow = unitOfWork; - private readonly ILogger _logger = logger; - - public async Task GetMyProfile(long userId) - { - Meta profile; - try - { - profile = await _uow.Metas.FindOneAsync(p => p.UserId == userId); - _logger.LogDebug("Found profile for user {userId}", userId); - } - catch (Exception e) - { - _logger.LogDebug("Failed to acquire profile for user {userId}", userId); - - try - { - User user = await _uow.Users.FindOneAsync(u => u.Id == userId); - } - catch (NullReferenceException) - { - _logger.LogDebug("No user with id {userId} found", userId); - throw new UserNotFoundException($"No profile for user {userId} found"); - } - throw; - } - return (GetProfileResponse)profile; - } - - public async Task GetUsernameAndAvatar(long userId) - { - User user; - Meta profile; - try - { - user = await _uow.Users.FindOneAsync(u => u.Id == userId); - profile = await _uow.Metas.FindOneAsync(p => p.UserId == userId); - _logger.LogDebug("Found profile for user {userId}", userId); - - return new GetUsernameAndAvatarResponse - { - Username = user.Username, - Avatar = profile.Avatar - }; - } - catch (Exception e) - { - _logger.LogDebug("Failed to acquire profile for user {userId}", userId); - try - { - user = await _uow.Users.FindOneAsync(u => u.Id == userId); - } - catch (NullReferenceException) - { - _logger.LogDebug("No user with id {userId} found", userId); - throw new UserNotFoundException($"No profile for user {userId} found"); - } - throw; - } - } - - public async Task UpdateProfile(long userId, UpdateProfileRequest request) - { - Meta profile; - using var transaction = _uow.BeginTransaction(); - try - { - profile = await _uow.Metas.FindOneAsync(p => p.UserId == userId); - _logger.LogDebug("Found profile for user {userId}", userId); - - profile.Name = request.Name ?? profile.Name; - profile.Surname = request.Surname ?? profile.Surname; - profile.Patronymic = request.Patronymic ?? profile.Patronymic; - profile.Birthday = request.Birthday ?? profile.Birthday; - profile.Avatar = request.Avatar ?? profile.Avatar; - - transaction.SaveAndCommit(); - - _logger.LogDebug("Updated profile for user {userId}", userId); - } - catch (Exception e) - { - _logger.LogDebug("Failed to acquire profile for user {userId}", userId); - transaction.Rollback(); - - try - { - User user = await _uow.Users.FindOneAsync(u => u.Id == userId); - } - catch (NullReferenceException) - { - _logger.LogDebug("No user with id {userId} found", userId); - throw new UserNotFoundException($"No profile for user {userId} found"); - } - throw; - } - return (UpdateProfileResponse)profile; - } - - // TODO: Ereshkigal wants to implement this - public async Task UploadAvatar(long userId, UploadAvatarRequest request) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfo.cs b/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfo.cs index 6757ec7..dc5f516 100644 --- a/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfo.cs +++ b/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfo.cs @@ -13,7 +13,7 @@ [assembly: System.Reflection.AssemblyCompanyAttribute("AuthService")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+da29b83128157cd57c09466789111b8e4510e95b")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e49ba90d63e92f74c12404caf0d112fc6d49181a")] [assembly: System.Reflection.AssemblyProductAttribute("AuthService")] [assembly: System.Reflection.AssemblyTitleAttribute("AuthService")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfoInputs.cache b/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfoInputs.cache index 7b3f92d..047e438 100644 --- a/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfoInputs.cache +++ b/AuthService/obj/Debug/net8.0/AuthService.AssemblyInfoInputs.cache @@ -1 +1 @@ -515f0974aa4c11696610743246c1a515c728008fd313777f1c4149933e83b6cd +84cec0948a65870bd6487cf9c7cd55da8448db247581f00f6ec10f38b0418468