Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy #76

Merged
merged 10 commits into from
May 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.chat.yourway.config.openapi.OpenApiExamples;
import com.chat.yourway.dto.request.AuthRequestDto;
import com.chat.yourway.dto.request.ContactRequestDto;
import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.dto.response.AuthResponseDto;
import com.chat.yourway.security.LogoutService;
import com.chat.yourway.service.interfaces.ActivateAccountService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.chat.yourway.config.openapi.OpenApiExamples;
import com.chat.yourway.dto.request.ChangePasswordDto;
import com.chat.yourway.dto.request.RestorePasswordDto;
import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.service.interfaces.ChangePasswordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.chat.yourway.config.openapi.OpenApiExamples;
import com.chat.yourway.dto.request.EditContactProfileRequestDto;
import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.dto.response.ContactProfileResponseDto;
import com.chat.yourway.service.interfaces.ContactService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static com.chat.yourway.config.openapi.OpenApiMessages.MESSAGE_NOT_FOUND;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_REPORTED_MESSAGE;

import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.service.interfaces.MessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import com.chat.yourway.dto.request.TopicPrivateRequestDto;
import com.chat.yourway.dto.request.TopicRequestDto;
import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.dto.response.ContactResponseDto;
import com.chat.yourway.dto.response.TopicInfoResponseDto;
import com.chat.yourway.dto.response.TopicResponseDto;
import com.chat.yourway.service.interfaces.TopicService;
import com.chat.yourway.service.interfaces.TopicSubscriberService;
Expand Down Expand Up @@ -149,7 +150,7 @@ public TopicResponseDto findById(@PathVariable Integer id) {
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@GetMapping(path = "/all", produces = APPLICATION_JSON_VALUE)
public List<TopicResponseDto> findAllPublic() {
public List<TopicInfoResponseDto> findAllPublic() {
return topicService.findAllPublic();
}

Expand Down Expand Up @@ -322,7 +323,7 @@ public void removeToFavouriteTopic(
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@GetMapping(path = "/favourite", produces = APPLICATION_JSON_VALUE)
public List<TopicResponseDto> findAllFavouriteTopics(
public List<TopicInfoResponseDto> findAllFavouriteTopics(
@AuthenticationPrincipal UserDetails userDetails) {
return topicService.findAllFavouriteTopics(userDetails);
}
Expand All @@ -333,7 +334,7 @@ public List<TopicResponseDto> findAllFavouriteTopics(
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_FOUND_TOPIC)
})
@GetMapping(path = "/popular/public", produces = APPLICATION_JSON_VALUE)
public List<TopicResponseDto> findAllPopularPublicTopics() {
public List<TopicInfoResponseDto> findAllPopularPublicTopics() {
return topicService.findPopularPublicTopics();
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/chat/yourway/controller/TypingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.chat.yourway.controller;

import com.chat.yourway.service.interfaces.ChatTypingEventService;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;

@Controller
@RequiredArgsConstructor
public class TypingController {

private final ChatTypingEventService chatTypingEventService;

@MessageMapping("/typing/{isTyping}")
public void updateTypingEvent(@DestinationVariable boolean isTyping, Principal principal) {
String email = principal.getName();
chatTypingEventService.updateTypingEvent(isTyping, email);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chat.yourway.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@ToString
public class TopicInfoResponseDto {
@Schema(description = "ID", example = "1")
private Integer id;
@Schema(description = "New Topic name", example = "My programming topic")
private String topicName;
@Schema(description = "Email of Topic creator", example = "[email protected]")
private String createdBy;
@Schema(description = "Created time")
private LocalDateTime createdAt;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chat.yourway.dto.response;
package com.chat.yourway.dto.response.error;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chat.yourway.dto.response;
package com.chat.yourway.dto.response.error;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chat.yourway.dto.response;
package com.chat.yourway.dto.response.notification;

import java.time.LocalDateTime;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chat.yourway.dto.response;
package com.chat.yourway.dto.response.notification;

import com.chat.yourway.model.event.EventType;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chat.yourway.dto.response;
package com.chat.yourway.dto.response.notification;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -13,11 +13,12 @@
@ToString
public class TopicNotificationResponseDto {

private TopicResponseDto topic;
private Integer topicId;

private Integer unreadMessages;

private LastMessageResponseDto lastMessage;

private TypingEventResponseDto typingEvent;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.chat.yourway.dto.response.notification;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@ToString
public class TypingEventResponseDto {

private String email;

private boolean isTyping;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;

import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.error.ApiErrorResponseDto;
import com.chat.yourway.exception.ContactAlreadySubscribedToTopicException;
import com.chat.yourway.exception.ContactEmailNotExist;
import com.chat.yourway.exception.ContactNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.chat.yourway.exception.handler;

import com.chat.yourway.dto.response.MessageErrorResponseDto;
import com.chat.yourway.dto.response.error.MessageErrorResponseDto;
import com.chat.yourway.exception.MessagePermissionDeniedException;
import com.chat.yourway.exception.TopicNotFoundException;
import com.chat.yourway.exception.TopicSubscriberNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import static com.chat.yourway.model.event.EventType.SUBSCRIBED;

import com.chat.yourway.config.websocket.WebsocketProperties;
import com.chat.yourway.dto.response.LastMessageResponseDto;
import com.chat.yourway.dto.response.notification.LastMessageResponseDto;
import com.chat.yourway.dto.response.notification.TypingEventResponseDto;
import com.chat.yourway.model.event.ContactEvent;
import com.chat.yourway.service.interfaces.ChatNotificationService;
import com.chat.yourway.service.interfaces.ContactEventService;
Expand All @@ -31,6 +32,7 @@ public class StompSubscriptionListener {
private final ChatNotificationService chatNotificationService;

private static LastMessageResponseDto lastMessageDto;
private static TypingEventResponseDto typingEvent;
private static final String USER_DESTINATION = "/user";
private static final String TOPICS_DESTINATION = "/topics";
private static final String SLASH = "/";
Expand All @@ -44,8 +46,13 @@ public void handleWebSocketSubscribeListener(SessionSubscribeEvent event) {
if (isTopicDestination(destination)) {
lastMessageDto = contactEventService.getByTopicIdAndEmail(getTopicId(event), email)
.getLastMessage();
int unreadMessages = contactEventService.getByTopicIdAndEmail(getTopicId(event), email)
.getUnreadMessages();
typingEvent = contactEventService.getByTopicIdAndEmail(
getTopicId(event), email).getTypingEvent();

var contactEvent = new ContactEvent(email, getTopicId(event), SUBSCRIBED,
getTimestamp(event), lastMessageDto);
getTimestamp(event), unreadMessages, lastMessageDto, typingEvent);
contactEventService.updateEventTypeByEmail(ONLINE, email);
contactEventService.save(contactEvent);
}
Expand All @@ -58,7 +65,7 @@ public void handleWebSocketSubscribeListener(SessionSubscribeEvent event) {
}

if (destination.equals(USER_DESTINATION + properties.getNotifyPrefix() + TOPICS_DESTINATION)) {
chatNotificationService.notifyAllPublicTopics(getEmail(event));
chatNotificationService.notifyAllTopics(getEmail(event));
}

log.info("Contact [{}] subscribe to [{}]", email, destination);
Expand All @@ -72,7 +79,7 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) {
try {
if (isTopicDestination(destination)) {
var contactEvent = new ContactEvent(email, getTopicId(event), ONLINE,
getTimestamp(event), lastMessageDto);
getTimestamp(event), 0, lastMessageDto, typingEvent);
contactEventService.save(contactEvent);
}

Expand Down

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/com/chat/yourway/mapper/NotificationMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.chat.yourway.mapper;

import com.chat.yourway.dto.response.notification.MessageNotificationResponseDto;
import com.chat.yourway.dto.response.notification.TopicNotificationResponseDto;
import com.chat.yourway.model.event.ContactEvent;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface NotificationMapper {

@Mapping(target = "status", source = "eventType")
@Mapping(target = "lastRead", source = "timestamp")
@Mapping(target = "email", source = "email")
MessageNotificationResponseDto toMessageNotificationResponseDto(ContactEvent event);

@Mapping(target = "topicId", source = "topicId")
@Mapping(target = "unreadMessages", source = "unreadMessages")
@Mapping(target = "lastMessage", source = "lastMessage")
@Mapping(target = "typingEvent", source = "typingEvent")
TopicNotificationResponseDto toTopicNotificationResponseDto(ContactEvent event);

}
3 changes: 3 additions & 0 deletions src/main/java/com/chat/yourway/mapper/TopicMapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chat.yourway.mapper;

import com.chat.yourway.dto.response.TopicInfoResponseDto;
import com.chat.yourway.dto.response.TopicResponseDto;
import com.chat.yourway.model.Topic;
import java.util.List;
Expand All @@ -12,6 +13,8 @@ public interface TopicMapper {
TopicResponseDto toResponseDto(Topic topic);
List<TopicResponseDto> toListResponseDto(List<Topic> topics);

List<TopicInfoResponseDto> toListInfoResponseDto(List<Topic> topics);

@Mapping(target = "messages", ignore = true)
Topic toEntity(TopicResponseDto topicResponseDto);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/chat/yourway/model/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public class Topic {
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;

@ManyToMany(fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
schema = "chat",
name = "topic_tag",
joinColumns = @JoinColumn(name = "topic_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id"))
private Set<Tag> tags;

@OneToMany(mappedBy = "topic", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OneToMany(mappedBy = "topic", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<TopicSubscriber> topicSubscribers;

@OneToMany(mappedBy = "topic", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/chat/yourway/model/event/ContactEvent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chat.yourway.model.event;

import com.chat.yourway.dto.response.LastMessageResponseDto;
import com.chat.yourway.dto.response.notification.LastMessageResponseDto;
import com.chat.yourway.dto.response.notification.TypingEventResponseDto;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -26,17 +27,21 @@ public class ContactEvent {
private Integer topicId;
private EventType eventType;
private LocalDateTime timestamp;
private int unreadMessages;
private LastMessageResponseDto lastMessage;
private TypingEventResponseDto typingEvent;


public ContactEvent(String email, Integer topicId, EventType eventType, LocalDateTime timestamp,
LastMessageResponseDto lastMessage) {
int unreadMessages, LastMessageResponseDto lastMessage, TypingEventResponseDto typingEvent) {
this.id = email + "_" + topicId;
this.email = email;
this.topicId = topicId;
this.eventType = eventType;
this.timestamp = timestamp;
this.unreadMessages = unreadMessages;
this.lastMessage = lastMessage;
this.typingEvent = typingEvent;
}

}
Loading
Loading