Skip to content

Commit

Permalink
Merge pull request #87 from Chat-Your-Way/v3
Browse files Browse the repository at this point in the history
Updated v4_ws
  • Loading branch information
Vladik-gif authored Sep 25, 2024
2 parents ab870c8 + a2a2a77 commit c8f8905
Show file tree
Hide file tree
Showing 35 changed files with 128 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers(WHITELIST_URLS).permitAll()
.requestMatchers("/demo-controller").hasAuthority("USER")
.anyRequest().authenticated()
)
.sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class ChangePasswordController {
private static final String PASSWORD_EMAIL = "/password/email";
private static final String PASSWORD_RESTORE = "/password/restore";

@Operation(summary = "Change to new password",
responses = {
@Operation(summary = "Change to new password", responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_CHANGING_PASSWORD,
content = @Content),
@ApiResponse(responseCode = "400", description = INVALID_OLD_PASSWORD,
Expand All @@ -40,8 +39,7 @@ public void changePassword(@Valid @RequestBody ChangePasswordDto request) {
changePasswordService.changePassword(request);
}

@Operation(summary = "Send email to restore password",
responses = {
@Operation(summary = "Send email to restore password", responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_SEND_REQUEST_RESTORE_PASSWORD,
content = @Content),
@ApiResponse(responseCode = "400", description = ERR_SENDING_EMAIL,
Expand All @@ -53,8 +51,7 @@ public void sendRequestToRestorePassword(@RequestParam String email,
changePasswordService.sendEmailToRestorePassword(email, clientHost);
}

@Operation(summary = "Restore password",
responses = {
@Operation(summary = "Restore password", responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_RESTORED_PASSWORD,
content = @Content),
@ApiResponse(responseCode = "404", description = EMAIL_TOKEN_NOT_FOUND,
Expand All @@ -64,4 +61,4 @@ public void sendRequestToRestorePassword(@RequestParam String email,
public void restorePassword(@Valid @RequestBody RestorePasswordDto restorePasswordDto) {
changePasswordService.restorePassword(restorePasswordDto);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public MessageResponseDto sendToPrivateContact(@PathVariable String sendToEmail,
return messageService.sendToContact(sendToEmail, message);
}

@Operation(summary = "Get messages by topic",
responses = {
@Operation(summary = "Get messages by topic", responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_REPORTED_MESSAGE),
@ApiResponse(responseCode = "400", description = INVALID_VALUE),
@ApiResponse(responseCode = "403", description = TOPIC_NOT_ACCESS,
Expand Down Expand Up @@ -108,8 +107,7 @@ public void reportMessage(@PathVariable UUID id) {
messageService.reportMessageById(id);
}

@Operation(summary = "Mark a message as read",
responses = {
@Operation(summary = "Mark a message as read", responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY,
content = @Content),
@ApiResponse(responseCode = "400", description = MESSAGE_HAS_ALREADY_REPORTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ public List<ContactResponseDto> findAllSubscribersByTopicId(@PathVariable UUID t
})
@GetMapping(path = ALL_TAG, produces = APPLICATION_JSON_VALUE)
public List<TopicResponseDto> findAllByTegName(@PathVariable String tag) {
String decodedTag = URLDecoder.decode(tag, UTF_8);
return topicService.findTopicsByTagName(decodedTag);
return topicService.findTopicsByTagName(URLDecoder.decode(tag, UTF_8));
}

@Operation(summary = "Find all topics by topic name", responses = {
Expand All @@ -185,8 +184,7 @@ public List<TopicResponseDto> findAllByTegName(@PathVariable String tag) {
public List<TopicResponseDto> findAllByTopicName(
@Pattern(regexp = "^[a-zA-Z0-9а-яА-ЯІіЇї]*$", message = SEARCH_TOPIC_VALIDATION)
@RequestParam String topicName) {
String decodeTopicName = URLDecoder.decode(topicName, UTF_8);
return topicService.findTopicsByTopicName(decodeTopicName);
return topicService.findTopicsByTopicName(URLDecoder.decode(topicName, UTF_8));
}

@Operation(summary = "Add topic to favourite", responses = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

public record EmailMessageDto(String to,
String subject,
String text
) {
}

String text) { }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ public record EmailMessageInfoDto(String username,
String email,
UUID uuidToken,
String path,
EmailMessageType emailMessageType) {

}
EmailMessageType emailMessageType) { }
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
@ToString
public class LastMessageResponseDto {

private static final int MAX_LENGTH = 20;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime timestamp;
private String sentFrom;
Expand All @@ -26,20 +24,10 @@ public class LastMessageResponseDto {
public LastMessageResponseDto(LocalDateTime timestamp,
String sentFrom,
String lastMessage,
UUID topicId
) {
UUID topicId) {
this.timestamp = timestamp;
this.sentFrom = sentFrom;
this.lastMessage = lastMessage;
this.topicId = topicId;
}

public void setLastMessage(String lastMessage) {
if (lastMessage.length() <= MAX_LENGTH) {
this.lastMessage = lastMessage;
} else {
this.lastMessage = lastMessage.substring(0, MAX_LENGTH) + "...";
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.chat.yourway.exception;

public class ContactAlreadySubscribedToTopicException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class ContactAlreadySubscribedToTopicException extends BaseRuntimeException {
public ContactAlreadySubscribedToTopicException(String message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class ContactEmailNotExist extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class ContactEmailNotExist extends BaseRuntimeException {
public ContactEmailNotExist(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class ContactNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class ContactNotFoundException extends BaseRuntimeException {
public ContactNotFoundException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class EmailSendingException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class EmailSendingException extends BaseRuntimeException {
public EmailSendingException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class EmailTokenNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class EmailTokenNotFoundException extends BaseRuntimeException {
public EmailTokenNotFoundException() {
super("Current token does not exist");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class InvalidCredentialsException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class InvalidCredentialsException extends BaseRuntimeException {
public InvalidCredentialsException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class InvalidTokenException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class InvalidTokenException extends BaseRuntimeException {

public InvalidTokenException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class MessageHasAlreadyReportedException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class MessageHasAlreadyReportedException extends BaseRuntimeException {
public MessageHasAlreadyReportedException() {
super("Message has already reported.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class MessageNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class MessageNotFoundException extends BaseRuntimeException {
public MessageNotFoundException() {
super("Message is not found.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class MessagePermissionDeniedException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class MessagePermissionDeniedException extends BaseRuntimeException {
public MessagePermissionDeniedException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class NotSubscribedTopicException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class NotSubscribedTopicException extends BaseRuntimeException {
public NotSubscribedTopicException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class OwnerCantUnsubscribedException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class OwnerCantUnsubscribedException extends BaseRuntimeException {

public OwnerCantUnsubscribedException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class PasswordsAreNotEqualException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class PasswordsAreNotEqualException extends BaseRuntimeException {
public PasswordsAreNotEqualException() {
super("Passwords are not equal.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class TokenNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class TokenNotFoundException extends BaseRuntimeException {
public TokenNotFoundException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class TopicAccessException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class TopicAccessException extends BaseRuntimeException {
public TopicAccessException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class TopicNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class TopicNotFoundException extends BaseRuntimeException {
public TopicNotFoundException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.chat.yourway.exception;

public class TopicSubscriberNotFoundException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class TopicSubscriberNotFoundException extends BaseRuntimeException {

public TopicSubscriberNotFoundException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.chat.yourway.exception;

public class ValueNotUniqException extends RuntimeException {
import com.chat.yourway.exception.handler.BaseRuntimeException;

public class ValueNotUniqException extends BaseRuntimeException {
public ValueNotUniqException(String message) {
super(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.chat.yourway.exception.handler;

public class BaseRuntimeException extends RuntimeException {
public BaseRuntimeException() {
super();
}

public BaseRuntimeException(Throwable cause) {
super(cause);
}

public BaseRuntimeException(String message) {
super(message);
}

public BaseRuntimeException(String message, Throwable cause) {
super(message, cause);
}

protected BaseRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.ControllerAdvice;

@ControllerAdvice
public class WebsocketExceptionHandler {
public class WebSocketExceptionHandler {

@MessageExceptionHandler({
TopicNotFoundException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) {
String email = getEmail(event);

if (isTopicDestination(destination)) {
UUID topicId = getTopicId(event);
contactOnlineService.setUserOnline(email);
log.info("Contact [{}] unsubscribe from [{}]", email, destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.UUID;

import com.chat.yourway.model.TopicScope;
import jakarta.validation.constraints.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down Expand Up @@ -35,8 +34,7 @@ public interface TopicRepository extends JpaRepository<Topic, UUID> {
Optional<Topic> findByName(@Param("name") String name);

@Query(value = "SELECT t FROM Topic t Where t.id = :id and t.scope != 'DELETED'")
@Override
Optional<Topic> findById(UUID id);
Optional<Topic> findById(@Param("id") UUID id);

@Query(value = """
SELECT t FROM Topic t JOIN FETCH t.topicSubscribers s
Expand Down
Loading

0 comments on commit c8f8905

Please sign in to comment.