1
0
forked from PGL/Clyde

idk what do

This commit is contained in:
Debucquoy Anthony 2024-03-26 23:40:16 +01:00
parent 384bd106be
commit d29cf8a51e
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
3 changed files with 32 additions and 56 deletions

View File

@ -49,12 +49,26 @@ public class MessagesController {
@PatchMapping("/discussion/{id}") @PatchMapping("/discussion/{id}")
public ResponseEntity<Discussion> AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Discussion data){ public ResponseEntity<Discussion> AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Discussion data){
return new ResponseEntity<>(discRepo.findById(id).orElse(null), HttpStatus.OK); User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null);
disc.setName(data.getName());
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);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null); Discussion disc = discRepo.findById(id).orElse(null);
msg.setAuthor(user);
if(disc != null) if(disc != null)
discServ.CreateMessage(disc, msg); discServ.CreateMessage(disc, msg);
return new ResponseEntity<>(disc, HttpStatus.OK); return new ResponseEntity<>(disc, HttpStatus.OK);

View File

@ -7,7 +7,7 @@
<script setup> <script setup>
import { ref, reactive } from 'vue' import { ref, reactive } from 'vue'
import { getDiscussions, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage} from '@/rest/msg.js' import { getDiscussions, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName} from '@/rest/msg.js'
const discussionsList = reactive(await getDiscussions()); const discussionsList = reactive(await getDiscussions());
const msgContent = ref(""); const msgContent = ref("");
@ -21,10 +21,10 @@
<button id="createDiscussion" @click="createDiscussion('New Discussion').then( e => discussionsList.push(e) )">+</button> <button id="createDiscussion" @click="createDiscussion('New Discussion').then( e => discussionsList.push(e) )">+</button>
</div> </div>
<div id="discussion"> <div id="discussion">
<h1 id=msgName >{{currentDiscussion.name}}</h1> <h1 id=msgName ><input class="InputTitle" type="text" @blur="updateDiscussionName(currentDiscussion.id, currentDiscussion.name).then(e => { getDiscussions().then(e => { discussionsList = e }) })" v-model="currentDiscussion.name"></h1>
<div id=msgs> <div id=msgs>
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id"> <div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
{{ msg.text }} {{ msg.content }}
</div> </div>
</div> </div>
<div id=messageBox> <div id=messageBox>
@ -57,6 +57,14 @@ div#discList{
} }
.InputTitle{
background: inherit;
border: inherit;
font-size: inherit;
font-family: inherit;
text-align: inherit;
}
.discItem{ .discItem{
color: darkorange; color: darkorange;
display: flex; display: flex;
@ -92,7 +100,7 @@ div#discussion{
#msgName{ #msgName{
text-align: center; text-align: center;
display: block; display: block;
background-color: #0202f755; background-color: #2a1981;
border-radius: 5px; border-radius: 5px;
color: white; color: white;
width: 75%; width: 75%;

View File

@ -5,7 +5,7 @@
* Description: Messages frontend api consumer * Description: Messages frontend api consumer
*******************************************************/ *******************************************************/
import { restGet, restPost } from './restConsumer.js' import { restGet, restPost, restPatch } from './restConsumer.js'
import { ref } from 'vue' import { ref } from 'vue'
export const currentDiscussion = ref({}); export const currentDiscussion = ref({});
@ -21,54 +21,6 @@ export async function getDiscussions(){
} }
export async function fetchDiscussion(id){ export async function fetchDiscussion(id){
// currentDiscussion.value = {
// id: id,
// name: "Discussion#2",
// msgs: [
// {
// id: 1,
// author: 1,
// sender: true,
// attachment: null,
// text: "Hello world!"
// },
// {
// id: 2,
// author: 2,
// sender: false,
// attachment: null,
// text: "Hello What?"
// },
// {
// id: 3,
// author: 2,
// sender: false,
// attachment: null,
// text: "You morron"
// },
// {
// id: 4,
// author: 1,
// sender: true,
// attachment: null,
// text: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
// },
// // {
// // id: 5,
// // author: 1,
// // sender: true,
// // attachment: null,
// // text: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
// // },
// {
// id: 6,
// author: 2,
// sender: false,
// attachment: null,
// text: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
// }
// ]
// }
currentDiscussion.value = await restGet("/discussion/" + id); currentDiscussion.value = await restGet("/discussion/" + id);
} }
@ -86,7 +38,9 @@ export async function sendMessage(id, content, responseId){
content: content, content: content,
response: responseId, response: responseId,
} }
console.log(content)
console.log(data)
restPost("/discussion/" + id, data); restPost("/discussion/" + id, data);
} }
export async function updateDiscussionName(id, name){
return restPatch("/discussion/" + id, {name: name});
}