Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PodeRouteGroup with a file path #1329

Open
eltyBelgium opened this issue Jun 7, 2024 · 0 comments · May be fixed by #1331
Open

PodeRouteGroup with a file path #1329

eltyBelgium opened this issue Jun 7, 2024 · 0 comments · May be fixed by #1331
Assignees

Comments

@eltyBelgium
Copy link

Question

Is the following possible on any way?

Server.ps1

 Add-PodeRouteGroup -Path '/network' -FilePath './Routes/File.ps1'

File.ps1

{
    Add-PodeRoute -Method Get -Path '/domains' -ScriptBlock {
        $result = vsz-getdomains | ConvertTo-Json

        Write-PodeJsonResponse -Value $result
    }

    Add-PodeRoute -Method Get -Path '/zones' -ScriptBlock {
        $result = vsz-getzones | ConvertTo-Json

        Write-PodeJsonResponse -Value $result
    }

    Add-PodeRoute -Method Get -Path '/zones/:zoneId/wlans' -ScriptBlock {
        $result = vsz-getwlans $WebEvent.Parameters['zoneId']| ConvertTo-Json

        $specificWlan = $result | Where-Object { $_.ZoneID -eq $WebEvent.Query['wlandId'] }

        if($null -eq $specificWlan) {
            Write-PodeJsonResponse -Value $result
            
        }else{
            Write-PodeJsonResponse -Value $specificWlan
        }
    }

    Add-PodeRoute -Method Get -Path '/zones/:zoneId/dpsks' -ScriptBlock {
        $result = vsz-getdpsks $WebEvent.Parameters['zoneId']| ConvertTo-Json

        $specificWlan = $result | Where-Object { $_.ZoneID -eq $WebEvent.Query['dpsk'] }

        if($null -eq $specificWlan) {
            Write-PodeJsonResponse -Value $result
            
        }else{
            Write-PodeJsonResponse -Value $specificWlan
        }
    }

    Add-PodeRoute -Method Post -Path '/zones/:zoneId/dpsks' -ScriptBlock {

        try{
            $result = vsz-createdpsks -zoneID $WebEvent.Parameters['zoneId'] -wlanID $WebEvent.Data.wlandID -username $WebEvent.Data.username -userrole $WebEvent.Data.userrole
            Write-PodeTextResponse -Value $result -ContentType "application/json"
        }
        catch{
            Write-PodeErrorLog -Exception $_.Exception
            Write-PodeJsonResponse -Value @{"message" = $_.Exception.Message} -StatusCode 500
        }

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants