Compare commits
2 Commits
66e7fa24a1
...
4848a2c269
Author | SHA1 | Date | |
---|---|---|---|
4848a2c269 | |||
914f6bdf36 |
@ -4,6 +4,7 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@ -11,11 +12,13 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository;
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||||
import ovh.herisson.Clyde.Services.Msg.DiscussionService;
|
import ovh.herisson.Clyde.Services.Msg.DiscussionService;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
import ovh.herisson.Clyde.Tables.Msg.Discussion;
|
import ovh.herisson.Clyde.Tables.Msg.Discussion;
|
||||||
|
import ovh.herisson.Clyde.Tables.Msg.Message;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||||
@ -24,6 +27,7 @@ public class MessagesController {
|
|||||||
|
|
||||||
private AuthenticatorService authServ;
|
private AuthenticatorService authServ;
|
||||||
private DiscussionService discServ;
|
private DiscussionService discServ;
|
||||||
|
private DiscussionRepository discRepo;
|
||||||
|
|
||||||
@GetMapping("/discussions")
|
@GetMapping("/discussions")
|
||||||
public ResponseEntity<Iterable<Discussion>> getDiscussions(@RequestHeader("Authorization") String token ){
|
public ResponseEntity<Iterable<Discussion>> getDiscussions(@RequestHeader("Authorization") String token ){
|
||||||
@ -39,9 +43,23 @@ public class MessagesController {
|
|||||||
|
|
||||||
@GetMapping("/discussion/{id}")
|
@GetMapping("/discussion/{id}")
|
||||||
public ResponseEntity<Discussion> getDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id){
|
public ResponseEntity<Discussion> getDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||||
return null; // TODO
|
return new ResponseEntity<>(discRepo.findById(id).orElse(null), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/discussion/{id}")
|
||||||
|
public ResponseEntity<Discussion> AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Discussion data){
|
||||||
|
return new ResponseEntity<>(discRepo.findById(id).orElse(null), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/discussion/{id}")
|
||||||
|
public ResponseEntity<Discussion> sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){
|
||||||
|
Discussion disc = discRepo.findById(id).orElse(null);
|
||||||
|
if(disc != null)
|
||||||
|
discServ.CreateMessage(disc, msg);
|
||||||
|
return new ResponseEntity<>(disc, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/discussion")
|
@PostMapping("/discussion")
|
||||||
public ResponseEntity<Discussion> createDiscussion(@RequestHeader("Authorization") String token, @RequestBody Discussion data){
|
public ResponseEntity<Discussion> createDiscussion(@RequestHeader("Authorization") String token, @RequestBody Discussion data){
|
||||||
return new ResponseEntity<>(discServ.create(data.getName(), authServ.getUserFromToken(token)), HttpStatus.OK);
|
return new ResponseEntity<>(discServ.create(data.getName(), authServ.getUserFromToken(token)), HttpStatus.OK);
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package ovh.herisson.Clyde.Repositories.Msg;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import ovh.herisson.Clyde.Tables.Msg.Message;
|
||||||
|
|
||||||
|
public interface MessageRepository extends CrudRepository<Message, Long> {
|
||||||
|
}
|
@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository;
|
import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
import ovh.herisson.Clyde.Tables.Msg.Discussion;
|
import ovh.herisson.Clyde.Tables.Msg.Discussion;
|
||||||
|
import ovh.herisson.Clyde.Tables.Msg.Message;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -21,4 +22,9 @@ public class DiscussionService {
|
|||||||
return discRepo.findByMembership(author.getRegNo());
|
return discRepo.findByMembership(author.getRegNo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Discussion CreateMessage(Discussion disc, Message msg){
|
||||||
|
disc.addMessage(msg);
|
||||||
|
return discRepo.save(disc);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Tables.Msg;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
@ -9,6 +10,7 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.JoinTable;
|
import jakarta.persistence.JoinTable;
|
||||||
import jakarta.persistence.ManyToMany;
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -33,6 +35,9 @@ public class Discussion{
|
|||||||
)
|
)
|
||||||
private List<User> members;
|
private List<User> members;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy="discussion", orphanRemoval = true, cascade = CascadeType.ALL)
|
||||||
|
private List<Message> msgs;
|
||||||
|
|
||||||
public Discussion(String name){
|
public Discussion(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@ -41,4 +46,9 @@ public class Discussion{
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.members = List.of(user);
|
this.members = List.of(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMessage(Message msg){
|
||||||
|
msg.setDiscussion(this);
|
||||||
|
msgs.add(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package ovh.herisson.Clyde.Tables.Msg;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
public class Message {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long id;
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
private User author;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
private Message response;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
private Discussion discussion;
|
||||||
|
|
||||||
|
}
|
@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { getDiscussions, currentDiscussion, fetchDiscussion, createDiscussion } from '@/rest/msg.js'
|
import { getDiscussions, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage} from '@/rest/msg.js'
|
||||||
|
|
||||||
const discussionsList = ref(await getDiscussions());
|
const discussionsList = reactive(await getDiscussions());
|
||||||
|
const msgContent = ref("");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -17,7 +18,7 @@
|
|||||||
<div id="msg">
|
<div id="msg">
|
||||||
<div id="discList">
|
<div id="discList">
|
||||||
<div @click="fetchDiscussion(discussion.id)" class="discItem" v-for="discussion in discussionsList" :key="discussion.id">{{ discussion.name }}</div>
|
<div @click="fetchDiscussion(discussion.id)" class="discItem" v-for="discussion in discussionsList" :key="discussion.id">{{ discussion.name }}</div>
|
||||||
<button id="createDiscussion" @click="createDiscussion('New Discussion'); getDiscussions().then(e => { discussionsList = 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 >{{currentDiscussion.name}}</h1>
|
||||||
@ -27,8 +28,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id=messageBox>
|
<div id=messageBox>
|
||||||
<input type="text" name="messageBox" value="">
|
<input type="text" v-model="msgContent">
|
||||||
<input type="submit" name="" id="" value="send">
|
<input type="submit" @click="sendMessage(currentDiscussion.id, msgContent, null)" value="send">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,62 +21,72 @@ export async function getDiscussions(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchDiscussion(id){
|
export async function fetchDiscussion(id){
|
||||||
currentDiscussion.value = {
|
// currentDiscussion.value = {
|
||||||
id: id,
|
// id: id,
|
||||||
name: "Discussion#2",
|
// name: "Discussion#2",
|
||||||
msgs: [
|
// 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,
|
// 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,
|
// author: 1,
|
||||||
// sender: true,
|
// sender: true,
|
||||||
// attachment: null,
|
// 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."
|
// 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,
|
// // id: 5,
|
||||||
author: 2,
|
// // author: 1,
|
||||||
sender: false,
|
// // sender: true,
|
||||||
attachment: null,
|
// // 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."
|
// // 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,
|
||||||
// currentDiscussion.value = restGet("/discussion/" + id);
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createDiscussion(name){
|
export async function createDiscussion(name){
|
||||||
restPost("/discussion", {name: name});
|
return restPost("/discussion", {name: name});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function invite(id, regNo){
|
export async function invite(id, regNo){
|
||||||
restPost("/discussion/"+ id+ "/invite", {user: regNo});
|
restPost("/discussion/"+ id+ "/invite", {user: regNo});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function sendMessage(id, content, responseId){
|
||||||
|
let data = {
|
||||||
|
content: content,
|
||||||
|
response: responseId,
|
||||||
|
}
|
||||||
|
console.log(content)
|
||||||
|
console.log(data)
|
||||||
|
restPost("/discussion/" + id, data);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user