diff --git a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java index 8d137d1..58dcd4a 100644 --- a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java +++ b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java @@ -5,8 +5,6 @@ import com.chat.yourway.dto.request.EmailRequestDto; import com.chat.yourway.dto.response.AuthResponseDto; import com.chat.yourway.dto.response.error.ApiErrorResponseDto; -import com.chat.yourway.security.LogoutService; -import com.chat.yourway.service.ActivateAccountService; import com.chat.yourway.service.AuthenticationService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -34,8 +32,6 @@ public class AuthenticationController { private final AuthenticationService authService; - private final ActivateAccountService activateAccountService; - private final LogoutService logoutService; private static final String REGISTER = "/register"; private static final String ACTIVE_SEND_TOKEN = "/resend/email"; private static final String LOGIN = "/login"; @@ -91,7 +87,7 @@ public AuthResponseDto refreshToken(HttpServletRequest request) { }) @PostMapping(path = ACTIVATE, consumes = APPLICATION_JSON_VALUE) public void activateAccount(@RequestParam(name = "Email token") UUID token) { - activateAccountService.activateAccount(token); + authService.activateAccount(token); } @Operation(summary = "Resend email", responses = { @@ -110,6 +106,6 @@ public void activeAccountSend(@RequestBody EmailRequestDto email, }) @PostMapping(value = LOGOUT, consumes = APPLICATION_JSON_VALUE) public void logout(HttpServletRequest request, HttpServletResponse response, Authentication auth) { - logoutService.logout(request, response, auth); + authService.logout(request, response, auth); } } diff --git a/src/main/java/com/chat/yourway/controller/rest/ContactController.java b/src/main/java/com/chat/yourway/controller/rest/ContactController.java index 05dfb49..1ab7bdf 100644 --- a/src/main/java/com/chat/yourway/controller/rest/ContactController.java +++ b/src/main/java/com/chat/yourway/controller/rest/ContactController.java @@ -4,7 +4,6 @@ import com.chat.yourway.dto.response.ContactProfileResponseDto; import com.chat.yourway.dto.response.ContactResponseDto; import com.chat.yourway.dto.response.error.ApiErrorResponseDto; -import com.chat.yourway.service.ContactOnlineService; import com.chat.yourway.service.ContactService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -28,7 +27,6 @@ public class ContactController { private final ContactService contactService; - private final ContactOnlineService contactOnlineService; private static final String PROFILE = "/profile"; private static final String GET_PROFILE = "/profile"; private static final String MESSAGE_SEND_PROHIBIT = "/message/send/prohibit"; @@ -93,7 +91,7 @@ public void permitSendingPrivateMessages() { }) @GetMapping(path = ONLINE_TOPIC_ID, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) public List findAllOnlineContactsByTopicId(@PathVariable("topic-id") UUID topicId) { - return contactOnlineService.getOnlineUsersByTopicId(topicId); + return contactService.findAllOnlineContactsByTopicId(topicId); } @Operation(summary = "Find all online contacts", responses = { @@ -103,6 +101,6 @@ public List findAllOnlineContactsByTopicId(@PathVariable("to }) @GetMapping(path = ONLINE, produces = APPLICATION_JSON_VALUE) public List findAllOnlineContacts() { - return contactOnlineService.getOnlineContactsDto(); + return contactService.findAllOnlineContacts(); } } diff --git a/src/main/java/com/chat/yourway/controller/rest/TopicController.java b/src/main/java/com/chat/yourway/controller/rest/TopicController.java index 4d9bbf5..e7b0341 100644 --- a/src/main/java/com/chat/yourway/controller/rest/TopicController.java +++ b/src/main/java/com/chat/yourway/controller/rest/TopicController.java @@ -7,7 +7,6 @@ import com.chat.yourway.dto.response.TopicResponseDto; import com.chat.yourway.dto.response.error.ApiErrorResponseDto; import com.chat.yourway.service.TopicService; -import com.chat.yourway.service.TopicSubscriberService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -17,7 +16,6 @@ import jakarta.validation.constraints.Pattern; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.net.URLDecoder; @@ -35,7 +33,6 @@ public class TopicController { private final TopicService topicService; - private final TopicSubscriberService topicSubscriberService; private static final String CREATE = "/create"; private static final String UPDATE_ID = "/update/{id}"; @@ -135,7 +132,7 @@ public void delete(@PathVariable UUID id) { }) @PostMapping(path = SUBSCRIBE_TOPIC_ID, consumes = APPLICATION_JSON_VALUE) public void subscribeToTopic(@PathVariable UUID topicId) { - topicSubscriberService.subscribeToTopicById(topicId); + topicService.subscribeToTopic(topicId); } @Operation(summary = "Unsubscribe from the topic", responses = { @@ -149,7 +146,7 @@ public void subscribeToTopic(@PathVariable UUID topicId) { }) @PatchMapping(path = UNSUBSCRIBE_TOPIC_ID, consumes = APPLICATION_JSON_VALUE) public void unsubscribeFromTopic(@PathVariable UUID topicId) { - topicSubscriberService.unsubscribeFromTopicById(topicId); + topicService.unsubscribeFromTopic(topicId); } @Operation(summary = "Find all subscribers to topic by topicId", responses = { @@ -159,7 +156,7 @@ public void unsubscribeFromTopic(@PathVariable UUID topicId) { }) @GetMapping(path = SUBSCRIBERS_TOPIC_ID, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) public List findAllSubscribersByTopicId(@PathVariable UUID topicId) { - return topicSubscriberService.findAllSubscribersByTopicId(topicId); + return topicService.findAllSubscribersByTopicId(topicId); } @Operation(summary = "Find all topics by tag name", responses = { @@ -196,7 +193,7 @@ public List findAllByTopicName( @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping(path = TOPIC_ID_FAVOURITE_ADD, consumes = APPLICATION_JSON_VALUE) public void addToFavouriteTopic(@PathVariable("topic-id") UUID topicId) { - topicSubscriberService.addTopicToFavourite(topicId); + topicService.addTopicToFavourite(topicId); } @Operation(summary = "Remove topic from favourite", responses = { @@ -209,7 +206,7 @@ public void addToFavouriteTopic(@PathVariable("topic-id") UUID topicId) { @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping(path = TOPIC_ID_FAVOURITE_REMOVE, consumes = APPLICATION_JSON_VALUE) public void removeToFavouriteTopic(@PathVariable("topic-id") UUID topicId) { - topicSubscriberService.removeTopicFromFavourite(topicId); + topicService.removeTopicFromFavourite(topicId); } @Operation(summary = "Find all favourite topics of contact", responses = { @@ -242,6 +239,6 @@ public List findAllPopularPublicTopics() { @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping(value = TOPIC_ID_COMPLAIN, consumes = APPLICATION_JSON_VALUE) public void complainTopic(@PathVariable("topic-id") UUID topicId) { - topicSubscriberService.complainTopic(topicId); + topicService.complainTopic(topicId); } } diff --git a/src/main/java/com/chat/yourway/service/AuthenticationService.java b/src/main/java/com/chat/yourway/service/AuthenticationService.java index c189f90..908486b 100644 --- a/src/main/java/com/chat/yourway/service/AuthenticationService.java +++ b/src/main/java/com/chat/yourway/service/AuthenticationService.java @@ -10,26 +10,32 @@ import com.chat.yourway.exception.InvalidTokenException; import com.chat.yourway.model.token.Token; import com.chat.yourway.security.JwtService; +import com.chat.yourway.security.LogoutService; import com.chat.yourway.security.TokenService; import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + @Service @RequiredArgsConstructor @Slf4j public class AuthenticationService { - private final ContactService contactService; - private final JwtService jwtService; - private final TokenService tokenService; private final ActivateAccountService activateAccountService; private final AuthenticationManager authManager; + private final ContactService contactService; + private final LogoutService logoutService; + private final TokenService tokenService; + private final JwtService jwtService; @Transactional public void register(ContactRequestDto contactRequestDto, String clientHost) { @@ -86,6 +92,14 @@ public AuthResponseDto refreshToken(HttpServletRequest request) { return AuthResponseDto.builder().accessToken(accessToken).refreshToken(refreshToken).build(); } + public void activateAccount(UUID token) { + activateAccountService.activateAccount(token); + } + + public void logout(HttpServletRequest request, HttpServletResponse response, Authentication auth) { + logoutService.logout(request, response, auth); + } + private void saveContactToken(String email, String jwtToken) { var token = Token.builder() .email(email) diff --git a/src/main/java/com/chat/yourway/service/ContactService.java b/src/main/java/com/chat/yourway/service/ContactService.java index db4d509..a499942 100644 --- a/src/main/java/com/chat/yourway/service/ContactService.java +++ b/src/main/java/com/chat/yourway/service/ContactService.java @@ -4,6 +4,7 @@ import com.chat.yourway.dto.request.ContactRequestDto; import com.chat.yourway.dto.request.EditContactProfileRequestDto; import com.chat.yourway.dto.response.ContactProfileResponseDto; +import com.chat.yourway.dto.response.ContactResponseDto; import com.chat.yourway.exception.ContactNotFoundException; import com.chat.yourway.exception.PasswordsAreNotEqualException; import com.chat.yourway.exception.ValueNotUniqException; @@ -15,8 +16,10 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.PathVariable; import java.util.List; +import java.util.UUID; import static com.chat.yourway.model.Role.USER; @@ -25,6 +28,7 @@ @Slf4j public class ContactService { + private final ContactOnlineService contactOnlineService; private final ContactRepository contactRepository; private final MyPasswordEncoder myPasswordEncoder; @@ -33,6 +37,14 @@ public void save(Contact contact) { contactRepository.save(contact); } + public List findAllOnlineContacts() { + return contactOnlineService.getOnlineContactsDto(); + } + + public List findAllOnlineContactsByTopicId(UUID topicId) { + return contactOnlineService.getOnlineUsersByTopicId(topicId); + } + @Transactional public Contact create(ContactRequestDto contactRequestDto) { log.trace("Started create contact, contact email: [{}]", contactRequestDto.getEmail()); diff --git a/src/main/java/com/chat/yourway/service/TopicService.java b/src/main/java/com/chat/yourway/service/TopicService.java index a38bd45..ffb38df 100644 --- a/src/main/java/com/chat/yourway/service/TopicService.java +++ b/src/main/java/com/chat/yourway/service/TopicService.java @@ -2,6 +2,7 @@ import com.chat.yourway.dto.request.TagRequestDto; import com.chat.yourway.dto.request.TopicRequestDto; +import com.chat.yourway.dto.response.ContactResponseDto; import com.chat.yourway.dto.response.PrivateTopicInfoResponseDto; import com.chat.yourway.dto.response.PublicTopicInfoResponseDto; import com.chat.yourway.dto.response.TopicResponseDto; @@ -34,12 +35,13 @@ @Slf4j public class TopicService { + private final TopicSubscriberService topicSubscriberService; + private final ContactOnlineService contactOnlineService; + private final NotificationService notificationService; private final TopicRepository topicRepository; + private final ContactService contactService; private final TagRepository tagRepository; private final TopicMapper topicMapper; - private final ContactService contactService; - private final ContactOnlineService contactOnlineService; - private final NotificationService notificationService; @Transactional public TopicResponseDto create(TopicRequestDto topicRequestDto) { @@ -210,6 +212,30 @@ public Topic getTopic(UUID topicId) { }); } + public void subscribeToTopic(UUID topicId) { + topicSubscriberService.subscribeToTopicById(topicId); + } + + public void unsubscribeFromTopic(UUID topicId) { + topicSubscriberService.unsubscribeFromTopicById(topicId); + } + + public List findAllSubscribersByTopicId(UUID topicId) { + return topicSubscriberService.findAllSubscribersByTopicId(topicId); + } + + public void addTopicToFavourite( UUID topicId) { + topicSubscriberService.addTopicToFavourite(topicId); + } + + public void removeTopicFromFavourite(UUID topicId) { + topicSubscriberService.removeTopicFromFavourite(topicId); + } + + public void complainTopic(UUID topicId) { + topicSubscriberService.complainTopic(topicId); + } + private Topic getTopicByName(String name) { return topicRepository .findByName(name)