Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/deploy.yml
  • Loading branch information
Troha7 committed Feb 26, 2024
2 parents d01fdc7 + da40df1 commit d4be6f4
Show file tree
Hide file tree
Showing 44 changed files with 559 additions and 340 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

env:
AWS_REGION: eu-central-1
Expand Down Expand Up @@ -41,6 +46,7 @@ jobs:

deploy:
needs: build
if: github.event_name != 'pull_request'
name: Deploy
runs-on: ubuntu-latest
steps:
Expand All @@ -62,4 +68,4 @@ jobs:
deployment_package: ${{ env.JAR_FILE }}

- name: Print finished deployment
run: echo "Deployment completed successfully!"
run: echo "Deployment completed successfully!"
4 changes: 4 additions & 0 deletions src/main/java/com/chat/yourway/ChatYourWayApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableCaching
@EnableAsync
@SpringBootApplication
public class ChatYourWayApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class OpenApiMessages {
"Topic added to favourite successfully";
public static final String SUCCESSFULLY_REMOVE_TOPIC_FROM_FAVOURITE =
"Topic removed from favourite successfully";

public static final String SUCCESSFULLY_COMPLAIN_TOPIC =
"Topic was complained successfully";
public static final String USER_DID_NOT_SUBSCRIBED_TO_TOPIC =
"User did not subscribe to topic";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.chat.yourway.config.security;

import com.chat.yourway.exception.ContactNotFoundException;
import com.chat.yourway.repository.ContactRepository;
import lombok.RequiredArgsConstructor;
import com.chat.yourway.service.interfaces.ContactService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
Expand All @@ -14,16 +13,17 @@
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@RequiredArgsConstructor
public class SecurityConfig {

private final ContactRepository contactRepository;
private final ContactService contactService;

public SecurityConfig(@Lazy ContactService contactService) {
this.contactService = contactService;
}

@Bean
public UserDetailsService userDetailsService() {
return username -> contactRepository.findByEmailIgnoreCase(username)
.orElseThrow(() -> new ContactNotFoundException(
String.format("Contact with email: %s wasn't found", username)));
return contactService::findByEmail;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public void configureMessageBroker(MessageBrokerRegistry registry) {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(properties.getEndpoint());
registry.addEndpoint(properties.getEndpoint()).withSockJS();
registry.addEndpoint(properties.getEndpoint()).setAllowedOriginPatterns("*").withSockJS();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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.service.interfaces.ChangePasswordService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -10,6 +11,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -43,9 +45,8 @@ public class ChangePasswordController {
content = @Content(schema = @Schema(implementation = ChangePasswordDto.class),
examples = @ExampleObject(value = OpenApiExamples.CHANGE_PASSWORD,
description = "Old and new passwords"))))
@PatchMapping(path = "/password",
consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public void changePassword(@RequestBody ChangePasswordDto request,
@PatchMapping(path = "/password", consumes = APPLICATION_JSON_VALUE)
public void changePassword(@Valid @RequestBody ChangePasswordDto request,
@AuthenticationPrincipal UserDetails userDetails) {
changePasswordService.changePassword(request, userDetails);
}
Expand All @@ -70,8 +71,8 @@ public void sendRequestToRestorePassword(@RequestParam String email,
@ApiResponse(responseCode = "404", description = EMAIL_TOKEN_NOT_FOUND,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@PatchMapping(path = "/password/restore", produces = APPLICATION_JSON_VALUE)
public void restorePassword(@RequestParam String newPassword, @RequestParam String token) {
changePasswordService.restorePassword(newPassword, token);
@PatchMapping(path = "/password/restore", consumes = APPLICATION_JSON_VALUE)
public void restorePassword(@Valid @RequestBody RestorePasswordDto restorePasswordDto) {
changePasswordService.restorePassword(restorePasswordDto);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/chat/yourway/controller/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.chat.yourway.dto.request.MessagePrivateRequestDto;
import com.chat.yourway.dto.request.MessagePublicRequestDto;
import com.chat.yourway.dto.request.PageRequestDto;
import com.chat.yourway.dto.response.MessageResponseDto;
import com.chat.yourway.service.interfaces.ChatMessageService;
import jakarta.validation.Valid;
import java.security.Principal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
Expand All @@ -32,4 +34,11 @@ public MessageResponseDto sendToPrivateTopic(@DestinationVariable Integer topicI
return chatMessageService.sendToPrivateTopic(topicId, message, email);
}

@MessageMapping("/history/topic/{topicId}")
public List<MessageResponseDto> getTopicHistory(@DestinationVariable Integer topicId,
@Valid @Payload PageRequestDto pageRequestDto, Principal principal) {
String email = principal.getName();
return chatMessageService.sendMessageHistoryByTopicId(topicId, pageRequestDto, email);
}

}
34 changes: 9 additions & 25 deletions src/main/java/com/chat/yourway/controller/MessageController.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package com.chat.yourway.controller;

import static com.chat.yourway.config.openapi.OpenApiMessages.CONTACT_UNAUTHORIZED;
import static com.chat.yourway.config.openapi.OpenApiMessages.MESSAGE_HAS_ALREADY_REPORTED;
import static com.chat.yourway.config.openapi.OpenApiMessages.MESSAGE_NOT_FOUND;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_FOUND_MESSAGE;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_REPORTED_MESSAGE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import com.chat.yourway.dto.response.ApiErrorResponseDto;
import com.chat.yourway.dto.response.MessageResponseDto;
import com.chat.yourway.service.interfaces.MessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.security.Principal;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -29,32 +23,22 @@
@RequestMapping("/messages")
@RequiredArgsConstructor
public class MessageController {

private final MessageService messageService;

@Operation(summary = "Make report to message",
responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_REPORTED_MESSAGE,
content = @Content),
@ApiResponse(responseCode = "400", description = MESSAGE_HAS_ALREADY_REPORTED,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))),
@ApiResponse(responseCode = "404", description = MESSAGE_NOT_FOUND,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_REPORTED_MESSAGE,
content = @Content),
@ApiResponse(responseCode = "400", description = MESSAGE_HAS_ALREADY_REPORTED,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))),
@ApiResponse(responseCode = "404", description = MESSAGE_NOT_FOUND,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@PostMapping("/{id}/report")
public void reportMessage(
@PathVariable int id, Principal principal) {
String email = principal.getName();
messageService.reportMessageById(id, email);
}

@Operation(summary = "Find all messages by topic id",
responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_FOUND_MESSAGE),
@ApiResponse(responseCode = "403", description = CONTACT_UNAUTHORIZED,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@GetMapping(path = "/all/{topicId}", produces = APPLICATION_JSON_VALUE)
public List<MessageResponseDto> findAllByTopicId(@PathVariable Integer topicId){
return messageService.findAllByTopicId(topicId);
}
}
48 changes: 26 additions & 22 deletions src/main/java/com/chat/yourway/controller/TopicController.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
package com.chat.yourway.controller;

import static com.chat.yourway.config.openapi.OpenApiMessages.ALREADY_SUBSCRIBED;
import static com.chat.yourway.config.openapi.OpenApiMessages.CONTACT_UNAUTHORIZED;
import static com.chat.yourway.config.openapi.OpenApiMessages.CONTACT_WASNT_SUBSCRIBED;
import static com.chat.yourway.config.openapi.OpenApiMessages.INVALID_VALUE;
import static com.chat.yourway.config.openapi.OpenApiMessages.OWNER_CANT_UNSUBSCRIBED;
import static com.chat.yourway.config.openapi.OpenApiMessages.RECIPIENT_EMAIL_NOT_EXIST;
import static com.chat.yourway.config.openapi.OpenApiMessages.SEARCH_TOPIC_VALIDATION;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_ADD_TOPIC_TO_FAVOURITE;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_CREATED_TOPIC;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_DELETE_TOPIC;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_FOUND_TOPIC;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_REMOVE_TOPIC_FROM_FAVOURITE;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_SUBSCRIBED;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_UNSUBSCRIBED;
import static com.chat.yourway.config.openapi.OpenApiMessages.SUCCESSFULLY_UPDATED_TOPIC;
import static com.chat.yourway.config.openapi.OpenApiMessages.TOPIC_NOT_ACCESS;
import static com.chat.yourway.config.openapi.OpenApiMessages.TOPIC_NOT_FOUND;
import static com.chat.yourway.config.openapi.OpenApiMessages.USER_DID_NOT_SUBSCRIBED_TO_TOPIC;
import static com.chat.yourway.config.openapi.OpenApiMessages.VALUE_NOT_UNIQUE;
import static com.chat.yourway.config.openapi.OpenApiMessages.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

Expand Down Expand Up @@ -300,7 +282,7 @@ public List<TopicResponseDto> findAllByTopicName(
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping(path = "{topic-id}/favourite/add", consumes = APPLICATION_JSON_VALUE)
@PatchMapping(path = "{topic-id}/favourite/add")
public void addToFavouriteTopic(
@PathVariable("topic-id") Integer topicId, @AuthenticationPrincipal UserDetails userDetails) {
topicSubscriberService.addTopicToFavourite(topicId, userDetails);
Expand All @@ -324,7 +306,7 @@ public void addToFavouriteTopic(
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping(path = "{topic-id}/favourite/remove", consumes = APPLICATION_JSON_VALUE)
@PatchMapping(path = "{topic-id}/favourite/remove")
public void removeToFavouriteTopic(
@PathVariable("topic-id") Integer topicId, @AuthenticationPrincipal UserDetails userDetails) {
topicSubscriberService.removeTopicFromFavourite(topicId, userDetails);
Expand All @@ -350,10 +332,32 @@ public List<TopicResponseDto> findAllFavouriteTopics(
responses = {
@ApiResponse(responseCode = "200", description = SUCCESSFULLY_FOUND_TOPIC)
})
@GetMapping(path = "/popular/public")
@GetMapping(path = "/popular/public", produces = APPLICATION_JSON_VALUE)
public List<TopicResponseDto> findAllPopularPublicTopics() {
return topicService.findPopularPublicTopics();
}

@Operation(
summary = "Complain topic",
responses = {
@ApiResponse(responseCode = "204", description = SUCCESSFULLY_COMPLAIN_TOPIC),
@ApiResponse(
responseCode = "403",
description = CONTACT_UNAUTHORIZED,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))),
@ApiResponse(
responseCode = "404",
description = TOPIC_NOT_FOUND,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))),
@ApiResponse(
responseCode = "409",
description = USER_DID_NOT_SUBSCRIBED_TO_TOPIC,
content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class)))
})
@PatchMapping("/{topic-id}/complain")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void complainTopic(@AuthenticationPrincipal UserDetails userDetails, @PathVariable("topic-id") Integer topicId) {
topicSubscriberService.complainTopic(topicId, userDetails);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.chat.yourway.dto.request;

import com.chat.yourway.annotation.PasswordValidation;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ChangePasswordDto {
@PasswordValidation
private String oldPassword;

@PasswordValidation
private String newPassword;
}
26 changes: 26 additions & 0 deletions src/main/java/com/chat/yourway/dto/request/PageRequestDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chat.yourway.dto.request;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

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

@NotNull(message = "Page should not be null")
@Min(value = 0, message = "Page should be greater or equals 0")
private Integer page;

@NotNull(message = "Page size should not be null")
@Min(value = 1, message = "Page size should be greater or equals 1")
private Integer pageSize;

}
26 changes: 26 additions & 0 deletions src/main/java/com/chat/yourway/dto/request/RestorePasswordDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chat.yourway.dto.request;

import com.chat.yourway.annotation.PasswordValidation;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

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

@Schema(description = "New password", example = "Password-321")
@PasswordValidation
private String newPassword;

@Schema(description = "Email token", example = "245034-cc65-4dce-b374-7419fbfc18e5")
@NotEmpty(message = "Email token cannot be empty")
private String emailToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public class TopicSubscriberResponseDto {

private boolean isPermittedSendingMessage;

private boolean hasComplaint;

}
Loading

0 comments on commit d4be6f4

Please sign in to comment.