remove member of a discussion
This commit is contained in:
parent
729d1ad504
commit
2bdffe6ab4
@ -65,7 +65,7 @@ public class MessagesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/discussion/{id}/add")
|
@PatchMapping("/discussion/{id}/add")
|
||||||
public ResponseEntity<Discussion> AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){
|
public ResponseEntity<Discussion> invite(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){
|
||||||
User user = authServ.getUserFromToken(token);
|
User user = authServ.getUserFromToken(token);
|
||||||
if(user == null){
|
if(user == null){
|
||||||
return new UnauthorizedResponse<>(null);
|
return new UnauthorizedResponse<>(null);
|
||||||
@ -78,6 +78,20 @@ public class MessagesController {
|
|||||||
return new ResponseEntity<>(disc, HttpStatus.OK);
|
return new ResponseEntity<>(disc, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/discussion/{id}/remove")
|
||||||
|
public ResponseEntity<Discussion> removeMember(@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 member = userServ.getUserById(data.getRegNo());
|
||||||
|
disc.delMember(member);
|
||||||
|
discRepo.save(disc);
|
||||||
|
return new ResponseEntity<>(disc, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/discussion/{id}")
|
@PostMapping("/discussion/{id}")
|
||||||
public ResponseEntity<Discussion> sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){
|
public ResponseEntity<Discussion> sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){
|
||||||
User user = authServ.getUserFromToken(token);
|
User user = authServ.getUserFromToken(token);
|
||||||
|
@ -55,4 +55,8 @@ public class Discussion{
|
|||||||
public void addMember(User user) {
|
public void addMember(User user) {
|
||||||
members.add(user);
|
members.add(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delMember(User user) {
|
||||||
|
members.remove(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { discussionsList, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName, invite} from '@/rest/msg.js'
|
import { discussionsList, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName, invite, removeMember} from '@/rest/msg.js'
|
||||||
|
|
||||||
const msgContent = ref("");
|
const msgContent = ref("");
|
||||||
const addMember = ref(false);
|
const addMember = ref(false);
|
||||||
@ -33,7 +33,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="members" v-if="currentDiscussion.length != 0">
|
<div id="members" v-if="currentDiscussion.length != 0">
|
||||||
<div class="memberItem" v-for="member in currentDiscussion.members" :key="member.id">{{ member.firstName }} {{ member.lastName.toUpperCase() }}</div>
|
<div class="memberItem" v-for="member in currentDiscussion.members" @click="removeMember(currentDiscussion.id, member.regNo)" :key="member.id"><span>{{ member.firstName }} {{ member.lastName.toUpperCase() }}</span></div>
|
||||||
<input type=text id="addMembers" @focus="addMember = true" @blur="addMember = false;$event.target.value = ''" @change="invite(currentDiscussion.id, $event.target.value)" :placeholder="addMember ? 'Regno' : '+'"/>
|
<input type=text id="addMembers" @focus="addMember = true" @blur="addMember = false;$event.target.value = ''" @change="invite(currentDiscussion.id, $event.target.value)" :placeholder="addMember ? 'Regno' : '+'"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -102,6 +102,19 @@ div#members{
|
|||||||
border: 1px solid darkorange;
|
border: 1px solid darkorange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.memberItem:hover span{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memberItem:hover{
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.memberItem:hover:before{
|
||||||
|
color: white;
|
||||||
|
content: "X"
|
||||||
|
}
|
||||||
|
|
||||||
#createDiscussion{
|
#createDiscussion{
|
||||||
height: 4vh;
|
height: 4vh;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
|
@ -27,6 +27,10 @@ export async function invite(id, regNo){
|
|||||||
restPatch("/discussion/"+ id+ "/add", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
|
restPatch("/discussion/"+ id+ "/add", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function removeMember(id, regNo){
|
||||||
|
restPatch("/discussion/"+ id+ "/remove", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
|
||||||
|
}
|
||||||
|
|
||||||
export async function sendMessage(id, content, responseId){
|
export async function sendMessage(id, content, responseId){
|
||||||
let data = {
|
let data = {
|
||||||
content: content,
|
content: content,
|
||||||
|
Loading…
Reference in New Issue
Block a user