now able to create chats with oneself and print them

This commit is contained in:
Jona Kläß
2024-05-04 13:59:15 +02:00
parent 74d9c2a62e
commit 288f7e0522
4 changed files with 130 additions and 30 deletions

27
src/stores/chat-store.ts Normal file
View File

@@ -0,0 +1,27 @@
import { defineStore } from 'pinia';
import { chat } from 'src/models';
import { api } from 'src/boot/axios';
import { useUserStore } from 'stores/user-store';
const userStore = useUserStore();
export const useChatStore = defineStore('chatStore',{
state:() => ({
chats: [] as chat[],
}),
actions: {
async getChatsByUser(): Promise<chat[]> {
if(!this.chats){
await this.loadChatsByUser();
}
return this.chats;
},
async loadChatsByUser() : Promise<chat[]>{
this.chats = (await api.get("/users/chat/" + userStore.keycloakId)).data.response;
return this.chats;
},
async createChat(chatName: string, members: string[]){
return (await api.post("/chats/create/" + chatName, members)).data;
}
}
});

View File

@@ -3,6 +3,29 @@ import { api } from 'src/boot/axios';
import { ptpUser, responseModel } from 'src/models';
import Keycloak, { KeycloakInitOptions, KeycloakLoginOptions } from 'keycloak-js';
/**
* Variablen für Keycloak Funktionen; sind in quasar.config.js definiert.
* @param keycloakPort Port, auf dem Keycloak läuft, hinterlegt in docker-compose.yml
* @param frontendPort Port, auf dem das Frontend läuft, hinterlegt in quasar.config.js und realm-export.json von Keycloak für die Redirect-URL
* @param realm Name des Realms, hinterlegt in realm-export.json von Keycloak
* @param clientId Name des Clients, hinterlegt in realm-export.json von Keycloak
*/
const keycloakPort: string = "" + process.env.PORT_KEYCLOAK;
const frontendPort: string = "" + process.env.PORT_FRONTEND;
const realm : string= "" + process.env.KEYCLOAK_REALM;
const clientId: string = "" + process.env.KEYCLOAK_CLIENT_ID;
const keycloak: Keycloak = new Keycloak({
url: 'http://localhost:' + keycloakPort + '/',
realm: realm,
clientId: clientId
});
const initOptions: KeycloakInitOptions = {
onLoad: 'login-required', //erzwingt Login
redirectUri: 'http://localhost:' + frontendPort + '/',
checkLoginIframe: false,
locale: 'login-required',
}
export const useUserStore = defineStore('userStore', {
state: () => ({
user: null as ptpUser | null,
@@ -11,7 +34,6 @@ export const useUserStore = defineStore('userStore', {
keycloakId: "",
users: [] as ptpUser[],
}),
getters: {},
actions: {
async getPtpUserByKeycloakID(keycloakID : string) {
await this.loadPtpUsersByKeycloakID(keycloakID).then((response : responseModel) => {
@@ -22,32 +44,12 @@ export const useUserStore = defineStore('userStore', {
async loadPtpUsersByKeycloakID(keycloakID : string) : Promise<responseModel> {
return (await api.get("/users/login/"+keycloakID)).data;
},
async loadAllUsers(){
async loadAllUsers(): Promise<ptpUser[]> {
this.users = (await api.get("/users/user")).data;
return this.users;
},
async initKeycloak() {
/**
* Variablen sind in quasar.config.js definiert und werden hier verwendet.
* @param keycloakPort Port, auf dem Keycloak läuft, hinterlegt in docker-compose.yml
* @param frontendPort Port, auf dem das Frontend läuft, hinterlegt in quasar.config.js und realm-export.json von Keycloak für die Redirect-URL
* @param realm Name des Realms, hinterlegt in realm-export.json von Keycloak
* @param clientId Name des Clients, hinterlegt in realm-export.json von Keycloak
*/
const keycloakPort: string = "" + process.env.PORT_KEYCLOAK;
const frontendPort: string = "" + process.env.PORT_FRONTEND;
const realm : string= "" + process.env.KEYCLOAK_REALM;
const clientId: string = "" + process.env.KEYCLOAK_CLIENT_ID;
const keycloak: Keycloak = new Keycloak({
url: 'http://localhost:' + keycloakPort + '/',
realm: realm,
clientId: clientId
});
const initOptions: KeycloakInitOptions = {
onLoad: 'login-required', //erzwingt Login
redirectUri: 'http://localhost:' + frontendPort + '/',
checkLoginIframe: false,
locale: 'login-required',
}
async initKeycloak() : Promise<Keycloak>{
try {
await keycloak.init(initOptions).then( (auth: boolean): void => {
console.log("Authenticated: " + auth);
@@ -64,7 +66,7 @@ export const useUserStore = defineStore('userStore', {
}else await this.keycloak?.login( {prompt: 'login'} as KeycloakLoginOptions);
},
async logout() {
window.location.href= 'http://localhost:' + process.env.PORT_KEYCLOAK + '/realms/' + process.env.KEYCLOAK_REALM + '/protocol/openid-connect/logout?post_logout_redirect_uri=http%3A%2F%2Flocalhost:' + process.env.PORT_FRONTEND + '&client_id=' + process.env.KEYCLOAK_CLIENT_ID;
}
window.location.href= 'http://localhost:' + keycloakPort + '/realms/' + realm + '/protocol/openid-connect/logout?post_logout_redirect_uri=http%3A%2F%2Flocalhost:' + frontendPort + '&client_id=' + clientId;
},
},
});