diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java index a40545f..8cee27c 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/MessagesController.java @@ -1,5 +1,6 @@ package ovh.herisson.Clyde.EndPoints.Msg; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; @@ -13,9 +14,11 @@ import org.springframework.web.bind.annotation.RestController; import lombok.AllArgsConstructor; import ovh.herisson.Clyde.DTO.Msg.DiscussionDTO; +import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.UserService; import ovh.herisson.Clyde.Services.Msg.DiscussionService; import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.Msg.Discussion; @@ -29,6 +32,7 @@ public class MessagesController { private AuthenticatorService authServ; private DiscussionService discServ; private DiscussionRepository discRepo; + private UserService userServ; @GetMapping("/discussions") public ResponseEntity> getDiscussions(@RequestHeader("Authorization") String token ){ @@ -60,6 +64,20 @@ public class MessagesController { return new ResponseEntity<>(disc, HttpStatus.OK); } + @PatchMapping("/discussion/{id}/add") + public ResponseEntity AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){ + User user = authServ.getUserFromToken(token); + if(user == null){ + return new UnauthorizedResponse<>(null); + } + + Discussion disc = discRepo.findById(id).orElse(null); + User invited = userServ.getUserById(data.getRegNo()); + disc.addMember(invited); + discRepo.save(disc); + return new ResponseEntity<>(disc, HttpStatus.OK); + } + @PostMapping("/discussion/{id}") public ResponseEntity sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){ User user = authServ.getUserFromToken(token); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java index 028bb4f..e98bd1e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Discussion.java @@ -51,4 +51,8 @@ public class Discussion{ msg.setDiscussion(this); msgs.add(msg); } + + public void addMember(User user) { + members.add(user); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java index a06e2b3..ea1f473 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Message.java @@ -2,11 +2,13 @@ package ovh.herisson.Clyde.Tables.Msg; import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import lombok.AllArgsConstructor; import lombok.Getter; @@ -26,7 +28,7 @@ public class Message { private long id; private String content; - @OneToOne + @ManyToOne private User author; public User getAuthor() { diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index 300a58c..2badd32 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; import ovh.herisson.Clyde.Tables.Msg.Discussion; +import ovh.herisson.Clyde.Tables.Msg.Message; import java.util.Date; import java.util.List; @@ -24,6 +25,11 @@ public class User { private ovh.herisson.Clyde.Tables.Role role; private String password; + ////// Extension Messagerie ///// + @OneToMany(mappedBy = "author", cascade = CascadeType.ALL) + private List msgs; + ///////////////////////////////// + @ManyToMany( mappedBy = "members" ) private List discussions; diff --git a/frontend/src/Apps/Msg.vue b/frontend/src/Apps/Msg.vue index 92c9c49..b74f980 100644 --- a/frontend/src/Apps/Msg.vue +++ b/frontend/src/Apps/Msg.vue @@ -7,9 +7,10 @@ @@ -19,8 +20,8 @@
{{ discussion.name }}
-
-

+
+

{{ msg.content }} @@ -31,6 +32,10 @@
+
+
{{ member.firstName }} {{ member.lastName.toUpperCase() }}
+ +
@@ -42,7 +47,7 @@ div#msg{ height: 100%; display: grid; - grid-template-columns: 20% auto; + grid-template-columns: 20% auto 10%; } div#discList{ @@ -53,7 +58,17 @@ div#discList{ padding: 10px; display: flex; flex-direction: column; +} +div#members{ + margin: 30px 0; + border-radius: 10px 0 0 10px; + background-color: red; + background-color: rgba(255, 255, 255, 0.05); + overflow: hidden; + display: flex; + padding: 10px 0 0 10px; + flex-direction: column; } .InputTitle{ @@ -74,6 +89,19 @@ div#discList{ border: 1px solid darkorange; } +.memberItem{ + color: darkorange; + display: flex; + font-family: sans-serif; + font-weight: bold; + height: 4vh; + margin: 5px; + border-radius: 30px 0 0 30px; + align-items: center; + justify-content: center; + border: 1px solid darkorange; +} + #createDiscussion{ height: 4vh; margin: 5px; @@ -84,6 +112,17 @@ div#discList{ font-weight: 900; font-size: 2em; } +#addMembers{ + height: 4vh; + margin: 5px; + text-align: center; + color: white; + background-color: green; + border-radius: 30px 0 0 30px; + border: none; + font-weight: 900; + font-size: 2em; +} div#discussion{ display: flex; diff --git a/frontend/src/rest/msg.js b/frontend/src/rest/msg.js index d1a9521..a27161b 100644 --- a/frontend/src/rest/msg.js +++ b/frontend/src/rest/msg.js @@ -13,8 +13,8 @@ import { ref } from 'vue' * - name * - members */ -export const discussionsList = ref({}); -export const currentDiscussion = ref({}); +export const discussionsList = ref(); +export const currentDiscussion = ref([]); export async function createDiscussion(name){ @@ -24,7 +24,7 @@ export async function createDiscussion(name){ export async function invite(id, regNo){ - restPost("/discussion/"+ id+ "/invite", {user: regNo}); + restPatch("/discussion/"+ id+ "/add", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id)) } export async function sendMessage(id, content, responseId){