generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #633 from it-at-m/564-exemplarische-backend-kommun…
…ikation 564 exemplarische backend kommunikation
- Loading branch information
Showing
10 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default class WLSException { | ||
constructor( | ||
public readonly category: string, | ||
public readonly code: string, | ||
public readonly message: string, | ||
public readonly service: string | ||
) {} | ||
|
||
static isWLSException(obj: any): obj is WLSException { | ||
return ( | ||
obj && | ||
typeof obj.category === "string" && | ||
typeof obj.code === "string" && | ||
typeof obj.message === "string" && | ||
typeof obj.service === "string" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
wls-gui-wahllokalsystem/src/api/wls-clients/broadcast-service/BroadcastMessageToRead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface BroadcastMessageToRead { | ||
readonly oid: string; | ||
readonly wahlbezirkIDs: string[]; | ||
readonly nachricht: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
wls-gui-wahllokalsystem/src/api/wls-clients/broadcast-service/BroadcastMessageToSend.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default class BroadcastMessageToSend { | ||
constructor( | ||
public wahlbezirkIDs: string[], | ||
public nachricht: string | ||
) {} | ||
} |
39 changes: 39 additions & 0 deletions
39
wls-gui-wahllokalsystem/src/api/wls-clients/broadcast-service/broadcast-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
getConfig, | ||
postConfig, | ||
wlsCatchHandler, | ||
wlsResponseHandler, | ||
} from "@/api/fetch-utils"; | ||
import BroadcastMessageToSend from "@/api/wls-clients/broadcast-service/BroadcastMessageToSend"; | ||
|
||
export const BROADCAST_API_URL = new URL( | ||
"/api/broadcast-service/businessActions/", | ||
window.location.origin | ||
).toString(); | ||
|
||
export function getBroadcastMessage(wahlbezirkID: string): Promise<Response> { | ||
return fetch(`${BROADCAST_API_URL}getMessage/` + wahlbezirkID, getConfig()) | ||
.then(wlsResponseHandler) | ||
.catch(wlsCatchHandler); | ||
} | ||
|
||
export function postBroadcastMessage( | ||
wahlbezirkIDs: string[], | ||
message: string | ||
): Promise<Response> { | ||
return fetch( | ||
`${BROADCAST_API_URL}broadcast`, | ||
postConfig(new BroadcastMessageToSend(wahlbezirkIDs, message)) | ||
) | ||
.then(wlsResponseHandler) | ||
.catch(wlsCatchHandler); | ||
} | ||
|
||
export function broadcastMessageRead(nachrichtID: string): Promise<Response> { | ||
return fetch( | ||
`${BROADCAST_API_URL}messageRead/` + nachrichtID, | ||
postConfig(nachrichtID) | ||
) | ||
.then(wlsResponseHandler) | ||
.catch(wlsCatchHandler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
wls-gui-wahllokalsystem/src/views/ExampleBackendCommunicationView.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<template> | ||
<v-container> | ||
<v-col class="text-center"> | ||
<h2>This view shows how communication with backend-services will work</h2> | ||
</v-col> | ||
<v-responsive class="mx-auto"> | ||
<v-col class="text-center"> | ||
<h4>Get or Post a Broadcast message:</h4> | ||
<br /> | ||
<v-text-field | ||
v-model="messageInput" | ||
class="ml-auto mr-auto" | ||
width="350" | ||
clearable | ||
label="ID" | ||
></v-text-field> | ||
<v-btn @click="postMessage(['wbz-1', 'wbz-2'])" | ||
>post message with fetch utils | ||
</v-btn> | ||
<p v-if="errors.post">{{ errors.post }}</p> | ||
<br /> | ||
<br /> | ||
<v-btn @click="getMessage('wbz-1')" | ||
>get message with fetch utils | ||
</v-btn> | ||
<pre v-if="message"> {{ message }} </pre> | ||
<p v-if="errors.get">{{ errors.get }}</p> | ||
<p v-if="errors.read">{{ errors.read }}</p> | ||
</v-col> | ||
</v-responsive> | ||
</v-container> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { BroadcastMessageToRead } from "@/api/wls-clients/broadcast-service/BroadcastMessageToRead"; | ||
import { ref } from "vue"; | ||
import { | ||
VBtn, | ||
VCol, | ||
VContainer, | ||
VResponsive, | ||
VTextField, | ||
} from "vuetify/components"; | ||
import { | ||
broadcastMessageRead, | ||
getBroadcastMessage, | ||
postBroadcastMessage, | ||
} from "@/api/wls-clients/broadcast-service/broadcast-client"; | ||
const messageInput = ref("Broadcast Message"); | ||
const message = ref(""); | ||
const errors = ref({ get: "", post: "", read: "" }); | ||
let messageId = ""; | ||
async function getMessage(wahlbezirkID: string) { | ||
errors.value.get = ""; | ||
message.value = ""; | ||
try { | ||
const response = await getBroadcastMessage(wahlbezirkID); | ||
const content: BroadcastMessageToRead = await response.json(); | ||
message.value = content.nachricht; | ||
messageId = content.oid; | ||
await broadcastMessageRead(messageId).catch((e) => { | ||
errors.value.read = | ||
"Es ist ein Fehler beim Lesen der Nachricht aufgetreten"; | ||
}); | ||
} catch (e) { | ||
errors.value.get = (e as Error).message; | ||
} | ||
} | ||
function postMessage(wahlbezirkIDs: string[]) { | ||
errors.value.post = ""; | ||
postBroadcastMessage(wahlbezirkIDs, messageInput.value).catch((e) => { | ||
errors.value.post = e.message; | ||
}); | ||
messageInput.value = ""; | ||
} | ||
</script> |