new endpoint sendAvisoErstelltNotification

This commit is contained in:
2025-10-07 15:45:09 +02:00
parent 52b9003785
commit c9486aa05d

View File

@@ -16,6 +16,61 @@ Namespace ApiController.Controllers
Public Class AVISOController
Inherits System.Web.Http.ApiController
<ApiVersion("1")>
<System.Web.Http.Route("api/v{version:apiVersion}/sendAvisoErstelltNotification")>
<BasicAuthentication>
Public Function sendAvisoErstelltNotification(avisoId As Integer, username As String) As HttpResponseMessage
VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = False
VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.LOG
Dim response As HttpResponseMessage
Try
' Eingabevalidierung
If avisoId <= 0 Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'avisoId' muss eine gültige positive Zahl sein.")
End If
If String.IsNullOrWhiteSpace(username) Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'username' darf nicht leer sein.")
End If
' Aviso laden und prüfen ob es existiert
Dim avisoObjekt As cAviso = cAviso.getAvisoById(avisoId)
If avisoObjekt Is Nothing Then
Return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Das angegebene Aviso wurde nicht gefunden. ID: " & avisoId)
End If
' Benachrichtigung senden
Dim code As Integer = cAvisoBenachrichtigungenCodes.AVISO_ERSTELLT
Dim TXT_Titel As String = "Neues Aviso erstellt"
Dim TXT_Mitteilung As String = "Ein neues Aviso mit der ID " & avisoId & " wurde von " & username & " erstellt und ist bereit zur Bearbeitung."
Dim benachrichtigungErfolg As Boolean = cAvisoBenachrichtigungen.send_BENACHRICHTIGUNG_AKTIV_AVISOUSER(
avisoId,
Nothing,
TXT_Titel,
TXT_Mitteilung,
code,
avisoObjekt.FIRMA
)
If benachrichtigungErfolg Then
response = Request.CreateResponse(HttpStatusCode.OK, "Die AVISO_ERSTELLT")
Else
response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Die Benachrichtigung konnte nicht gesendet werden.")
End If
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Ein unerwarteter Fehler ist aufgetreten: " & ex.Message)
End Try
Return response
End Function
''' <summary>
''' Upload Files in Base64-Format and attach it to an existring LKW (with avisoId) or an specific consignment (with sendungsId)
''' </summary>
@@ -24,7 +79,6 @@ Namespace ApiController.Controllers
''' <response code="200">Returns 200 file is uploaded sucessfully</response>
''' <response code="400">Returns 400 upload failed</response>
<ApiVersion("1")>
<System.Web.Http.Route("api/v{version:apiVersion}/uploadAvisoAttachment")>
<BasicAuthentication>
@@ -742,59 +796,6 @@ Namespace ApiController.Controllers
End Function
<ApiVersion("1")>
<System.Web.Http.Route("api/v{version:apiVersion}/sendAvisoErstelltNotification")>
<BasicAuthentication>
Public Function sendAvisoErstelltNotification(avisoId As Integer, username As String) As HttpResponseMessage
' Globale Fehlerbehandlung einstellen
VERAG_PROG_ALLGEMEIN.cAllgemein.TESTSYSTEM = True
VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.LOG
Dim response As HttpResponseMessage
Try
' Eingabevalidierung
If avisoId <= 0 Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'avisoId' muss eine gültige positive Zahl sein.")
End If
If String.IsNullOrWhiteSpace(username) Then
Return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Der Parameter 'username' darf nicht leer sein.")
End If
' Aviso laden und prüfen ob es existiert
Dim avisoObjekt As cAviso = cAviso.getAvisoById(avisoId)
If avisoObjekt Is Nothing Then
Return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Das angegebene Aviso wurde nicht gefunden. ID: " & avisoId)
End If
' Benachrichtigung senden
Dim code As Integer = cAvisoBenachrichtigungenCodes.AVISO_ERSTELLT
Dim TXT_Titel As String = "Neues Aviso erstellt"
Dim TXT_Mitteilung As String = "Ein neues Aviso mit der ID " & avisoId & " wurde von " & username & " erstellt und ist bereit zur Bearbeitung."
Dim benachrichtigungErfolg As Boolean = cAvisoBenachrichtigungen.send_BENACHRICHTIGUNG_AKTIV_AVISOUSER(
avisoId,
-1, ' sendungsId nicht relevant für AVISO_ERSTELLT
TXT_Titel,
TXT_Mitteilung,
code,
avisoObjekt.FIRMA
)
If benachrichtigungErfolg Then
response = Request.CreateResponse(HttpStatusCode.OK, "Die AVISO_ERSTELLT")
Else
response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Die Benachrichtigung konnte nicht gesendet werden.")
End If
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine, System.Reflection.MethodInfo.GetCurrentMethod.Name)
response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Ein unerwarteter Fehler ist aufgetreten: " & ex.Message)
End Try
Return response
End Function
End Class