Skip to content

Commit

Permalink
chore():multiples fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaut-Mouton committed May 3, 2024
1 parent bbfa516 commit a97bebc
Show file tree
Hide file tree
Showing 27 changed files with 275 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: build
run: mvn compile -f backend/pom.xml
run: mvn -Dmaven.test.skip=true compile -f backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.mercure.controller;

import com.mercure.dto.WrapperMessageDTO;
import com.mercure.service.GroupUserJoinService;
import com.mercure.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping(value = "/messages")
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:3000")
Expand All @@ -17,9 +20,18 @@ public class MessageController {
@Autowired
private MessageService messageService;

@Autowired
private GroupUserJoinService groupUserJoinService;

@GetMapping(value = "{offset}/group/{groupUrl}")
public WrapperMessageDTO fetchGroupMessages(@PathVariable String groupUrl, @PathVariable int offset) {
this.log.debug("Fetching messages from conversation");
return this.messageService.getConversationMessage(groupUrl, offset);
}

@GetMapping(value = "seen/group/{groupUrl}/user/{userId}")
public void markMessageAsSeen(@PathVariable String groupUrl, @PathVariable int userId) {
this.log.debug("Mark message as seen");
this.groupUserJoinService.saveLastMessageDate(userId, groupUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:3000")
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:3000", methods = {RequestMethod.GET, RequestMethod.POST})
public class WsFileController {

private static final Logger log = LoggerFactory.getLogger(WsFileController.class);
Expand Down Expand Up @@ -68,4 +69,9 @@ public ResponseEntity<?> uploadFile(@RequestParam(name = "file") MultipartFile f
}
return ResponseEntity.ok().build();
}

@GetMapping("files/groupUrl/{groupUrl}")
public List<String> getMultimediaContent(@PathVariable String groupUrl) {
return messageService.getMultimediaContentByGroup(groupUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FileRepository extends JpaRepository<FileEntity,Integer> {
public interface FileRepository extends JpaRepository<FileEntity, Integer> {

FileEntity findByMessageId(int id);

@Query(value = "SELECT storage.url FROM file_storage storage WHERE storage.fk_message_id = :id", nativeQuery = true)
String findFileUrlByMessageId(@Param(value = "id") int id);

@Query(value = "SELECT url FROM file_storage file INNER JOIN message m ON m.id = file.fk_message_id WHERE m.msg_group_id = :groupId", nativeQuery = true)
List<String> findFilesUrlsByGroupId(@Param(value = "groupId") int groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public interface MessageRepository extends JpaRepository<MessageEntity, Integer>
@Query(value = "SELECT m1.id FROM message m1 INNER JOIN (SELECT MAX(m.id) as id FROM message m GROUP BY m.msg_group_id) temp ON temp.id = m1.id WHERE msg_group_id = :idOfGroup", nativeQuery = true)
int findLastMessageIdByGroupId(@Param(value = "idOfGroup") int groupId);

@Query(value = "SELECT m. FROM message m WHERE m.id = :idOfGroup AND m.type = 'FILE'", nativeQuery = true)
List<MessageEntity> findAllFilesByGroupId(@Param(value = "idOfGroup") int groupId);

@Modifying
@Query(value = "DELETE m, mu FROM message m JOIN message_user mu ON m.id = mu.message_id WHERE m.msg_group_id = :groupId", nativeQuery = true)
void deleteMessagesDataByGroupId(@Param(value = "groupId") int groupId);
Expand Down
8 changes: 7 additions & 1 deletion backend/src/main/java/com/mercure/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileService {

Expand All @@ -19,7 +21,11 @@ public FileEntity findByFkMessageId(int id) {
return fileRepository.findByMessageId(id);
}

public List<String> getFilesUrlByGroupId(int groupId) {
return fileRepository.findFilesUrlsByGroupId(groupId);
}

public String findFileUrlByMessageId(int id) {
return fileRepository.findFileUrlByMessageId(id);
return fileRepository.findFileUrlByMessageId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.mercure.entity.GroupRoleKey;
import com.mercure.entity.GroupUser;
import com.mercure.repository.GroupUserJoinRepository;
import org.aspectj.weaver.ast.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Optional;

Expand All @@ -23,6 +26,9 @@ public class GroupUserJoinService {
@Autowired
private MessageService messageService;

@Autowired
private GroupService groupService;

public GroupUser save(GroupUser groupUser) {
return groupUserJoinRepository.save(groupUser);
}
Expand Down Expand Up @@ -51,6 +57,14 @@ public GroupUser findGroupUser(int userId, int groupId) {
return groupUserJoinRepository.getGroupUser(userId, groupId);
}

public void saveLastMessageDate(int userId, String groupUrl) {
int groupId = groupService.findGroupByUrl(groupUrl);
GroupUser groupUser = groupUserJoinRepository.getGroupUser(userId, groupId);
Date date = new Date();
Timestamp ts = new Timestamp(date.getTime());
groupUser.setLastMessageSeenDate(ts);
}

public boolean checkIfUserIsAuthorizedInGroup(int userId, int groupId) {
List<Integer> ids = groupUserJoinRepository.getUsersIdInGroup(groupId);
return ids.stream().noneMatch(id -> id == userId);
Expand Down
21 changes: 14 additions & 7 deletions backend/src/main/java/com/mercure/service/MessageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.mercure.dto.MessageDTO;
import com.mercure.dto.NotificationDTO;
import com.mercure.dto.WrapperMessageDTO;
import com.mercure.entity.FileEntity;
import com.mercure.entity.GroupEntity;
import com.mercure.entity.MessageEntity;
import com.mercure.entity.UserEntity;
import com.mercure.entity.*;
import com.mercure.repository.MessageRepository;
import com.mercure.utils.MessageTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -22,6 +19,9 @@ public class MessageService {
@Autowired
private MessageRepository messageRepository;

@Autowired
private FileService fileService;

@Autowired
private MessageService messageService;

Expand All @@ -31,9 +31,6 @@ public class MessageService {
@Autowired
private UserService userService;

@Autowired
private FileService fileService;

public MessageEntity createAndSaveMessage(int userId, int groupId, String type, String data) {
MessageEntity msg = new MessageEntity(userId, groupId, type, data);
return messageRepository.save(msg);
Expand Down Expand Up @@ -116,6 +113,10 @@ public NotificationDTO createNotificationDTO(MessageEntity msg) {
notificationDTO.setType(MessageTypeEnum.TEXT);
notificationDTO.setMessage(msg.getMessage());
}
if (msg.getType().equals(MessageTypeEnum.CALL.toString())) {
notificationDTO.setType(MessageTypeEnum.CALL);
notificationDTO.setMessage(msg.getMessage());
}
if (msg.getType().equals(MessageTypeEnum.FILE.toString())) {
FileEntity fileEntity = fileService.findByFkMessageId(msg.getId());
notificationDTO.setType(MessageTypeEnum.FILE);
Expand Down Expand Up @@ -154,6 +155,12 @@ public MessageDTO createNotificationMessageDTO(MessageEntity msg, int userId) {
return messageDTO;
}

// TODO check that the request is authorized by user making the call
public List<String> getMultimediaContentByGroup(String groupUrl) {
int groupId = groupService.findGroupByUrl(groupUrl);
return fileService.getFilesUrlByGroupId(groupId);
}

public WrapperMessageDTO getConversationMessage(String url, int messageId) {
WrapperMessageDTO wrapper = new WrapperMessageDTO();
if (url != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.mercure.utils;

public enum MessageTypeEnum {
TEXT, FILE
TEXT, FILE, CALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NoteAddOutlinedIcon from "@mui/icons-material/NoteAddOutlined"
import {Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField} from "@mui/material"
import {HttpGroupService} from "../../service/http-group-service"
import {AlertAction, AlertContext} from "../../context/AlertContext"
import {redirect} from "react-router-dom"
import {useNavigate} from "react-router-dom"
import {GroupContext, GroupContextAction} from "../../context/GroupContext"

export function CreateConversationComponent(): React.JSX.Element {
Expand All @@ -14,6 +14,7 @@ export function CreateConversationComponent(): React.JSX.Element {
const httpService = new HttpGroupService()
const {changeGroupState} = useContext(GroupContext)!
const {dispatch} = useContext(AlertContext)!
const navigate = useNavigate()

function handleClickOpen() {
setOpen(true)
Expand All @@ -39,7 +40,7 @@ export function CreateConversationComponent(): React.JSX.Element {
})
changeGroupState({type: GroupContextAction.ADD_GROUP, payload: data})
setOpen(false)
redirect(`/t/messages/${data.url}`)
navigate(`/t/messages/${data.url}`)
} catch (error) {
dispatch({
type: AlertAction.ADD_ALERT,
Expand Down
59 changes: 25 additions & 34 deletions frontend-web/src/components/home.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
import {Box, Card, CardContent, Grid, Typography} from "@mui/material"
import React, {useContext, useEffect} from "react"
import {Card, CardContent, Grid, Typography} from "@mui/material"
import React, {useEffect} from "react"
import {generateColorMode} from "./utils/enable-dark-mode"
import {useThemeContext} from "../context/theme-context"
import {FooterComponent} from "./partials/footer-component"
import {LoginComponent} from "./login/LoginComponent"
import {UserContext} from "../context/UserContext"

export const HomeComponent = (): React.JSX.Element => {
const {theme} = useThemeContext()
const {user} = useContext(UserContext)!

useEffect(() => {
document.title = "Home | FLM"
}, [])

return (
<div className={generateColorMode(theme)}
style={{
width: "100%",
height: "calc(100% - 64px)",
textAlign: "center"
}}>
<Box p={2}>
<Grid container>
<Grid item xs={6}>
<Card variant="outlined">
<CardContent>
<Typography variant="h5" gutterBottom>
Welcome to FastLiteMessage {user?.firstName}
</Typography>
<div className={generateColorMode(theme)} style={{height: "100%"}}>
<Grid container style={{height: "100%", verticalAlign: "middle"}}>
<Grid item xs={6}>
<Card variant="outlined">
<CardContent>
<Typography variant="h5" gutterBottom>
Welcome to FastLiteMessage
</Typography>

<img src={"/assets/icons/landing_logo.svg"} height={"300"} alt={"test svg"}/>
<img src={"/assets/icons/landing_logo.svg"} height={"300"} alt={"test svg"}/>

<Typography variant="h5" gutterBottom>
Simple, fast and secure
</Typography>
<div>FastLiteMessage allow to communicate with other people, create groups, make
serverless video calls in an easy way. Log into your account or register to start
using FastLiteMessage.
</div>
<FooterComponent/>
</CardContent>
</Card>
</Grid>
<Grid item xs={6}>
<LoginComponent/>
</Grid>
<Typography variant="h5" gutterBottom>
Simple, fast and secure
</Typography>
<div>FastLiteMessage allow to communicate with other people, create groups, make
serverless video calls in an easy way. Log into your account or register to start
using FastLiteMessage.
</div>
<FooterComponent/>
</CardContent>
</Card>
</Grid>
</Box>
<Grid xs={6}>
<LoginComponent/>
</Grid>
</Grid>
</div>
)
}
Loading

0 comments on commit a97bebc

Please sign in to comment.