Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Backend/Post-Service/uploads/1734619819376.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734619819385.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734619819388.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734619819391.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264676.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264686.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264689.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264693.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264695.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264791.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backend/Post-Service/uploads/1734643264794.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 33 additions & 2 deletions Backend/service-notification/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -11,7 +11,7 @@
<groupId>com.message</groupId>
<artifactId>service-notification</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>service-notification</name>
<name>service_chat</name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
Expand All @@ -28,8 +28,17 @@
</scm>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -38,7 +47,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
Expand All @@ -50,6 +69,17 @@
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
Expand All @@ -61,3 +91,4 @@
</build>

</project>

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.setAllowedOrigins("http://localhost:4200", "http://localhost:8880");
.setAllowedOrigins("http://localhost:4200", "http://localhost:8880").withSockJS();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.springframework.web.bind.annotation.*;

import com.message.entities.ChatMessage;
import com.message.entities.Notification;
import com.message.services.ChatMessageService;
import com.message.services.NotificationService;

import java.util.List;

Expand All @@ -22,15 +24,42 @@ public class MessageController {
private ChatMessageService chatMessageService;
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
@Autowired
private NotificationService notificationService;

@MessageMapping("/chat.sendMessage")
@SendTo("/topic/public")
public ChatMessage sendMessage(
@Payload ChatMessage chatMessage
) {
return chatMessageService.saveMessage(chatMessage);
// Save the chat message
ChatMessage savedMessage = chatMessageService.saveMessage(chatMessage);

// Create and send a notification
Notification notification = new Notification();
notification.setSender(chatMessage.getSender());
notification.setReceiver(chatMessage.getReceiver());
notification.setContent(chatMessage.getContent());
notification.setTimestamp(String.valueOf(System.currentTimeMillis()));

// Save notification to database
notificationService.saveNotification(notification);

// Send notification in real time
simpMessagingTemplate.convertAndSend("/topic/notifications", notification);

return savedMessage;

}
// Add Delete Notification Endpoint
@DeleteMapping("/notifications/delete/{id}")
@ResponseBody
public String deleteNotification(@PathVariable Long id) {
notificationService.deleteNotification(id);
return "Notification deleted successfully!";
}


@MessageMapping("/chat.addUser")
@SendTo("/topic/public")
public ChatMessage addUser(
Expand All @@ -57,6 +86,11 @@ public List<ChatMessage> getAllMessages() {
return chatMessageService.getAllMessages();

}
@GetMapping("/notifications")
@ResponseBody
public List<Notification> getAllNotifications() {
return notificationService.getAllNotifications();
}

@PutMapping("/update/{id}")
@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.message.entities;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "notification")
public class Notification {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String sender;
private String receiver;
private String content;
private String timestamp;
public Notification() {
super();
}
public Notification(Long id, String sender, String receiver, String content, String timestamp) {
super();
this.id = id;
this.sender = sender;
this.receiver = receiver;
this.content = content;
this.timestamp = timestamp;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.message.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.message.entities.Notification;

@Repository
public interface NotificationRepository extends JpaRepository<Notification, Long> {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.message.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.message.entities.ChatMessage;
import com.message.entities.Notification;
import com.message.repositories.NotificationRepository;

@Service
public class NotificationService {

@Autowired
private NotificationRepository notificationRepository;

public Notification saveNotification(Notification notification) {
return notificationRepository.save(notification);
}

public List<Notification> getAllNotifications() {
return notificationRepository.findAll();
}
public void deleteNotification(Long id) {
notificationRepository.deleteById(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import com.example.demo.entities.Event;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface EventRepository extends JpaRepository<Event,Long> {
import java.util.List;

}
public interface EventRepository extends JpaRepository<Event,Long> {
@Query("SELECT e FROM Event e WHERE e.title LIKE %?1% OR e.description LIKE %?1%")
List<Event> findByTitleOrDescriptionContaining(String pattern);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public class EventService {
private EventRepository eventRepository;
@Autowired
private ParticipationRepository participationRepository;
@GetMapping("/search")
public ResponseEntity<List<Event>> searchEvents(@RequestParam("search") String keyword) {
// Fetch events where title or description contains the given keyword
List<Event> events = eventRepository.findByTitleOrDescriptionContaining(keyword);
if (events.isEmpty()) {
return ResponseEntity.noContent().build(); // Return 204 if no events found
}
return ResponseEntity.ok(events); // Return 200 with the list of events
}

@GetMapping("/GetAll")
public List<Event> GetAllevents()
Expand Down
Binary file not shown.
Binary file not shown.
Loading