-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add GET operations for DeviceGroups and Network Slices #81
Changes from all commits
200219e
e8f599b
e9a3a8d
04f5f0c
13afae2
bc532c2
16c9c9e
17a5457
6d2509f
1fd9f74
786990a
98536a3
a3093f5
6dd1539
1e339c9
f37c9d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-FileCopyrightText: 2023 Open Networking Foundation <info@opennetworking.org> | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Unit tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
unit-test-webconsole: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
|
||
- name: Run unit tests for webconsole | ||
run: | | ||
make test |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ cscope.* | |
bin/ | ||
public/ | ||
!/frontend/public/*.license | ||
.coverage/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,57 @@ | |
package configapi | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/MongoDBLibrary" | ||
"github.com/omec-project/webconsole/backend/logger" | ||
"github.com/omec-project/webconsole/configmodels" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
const ( | ||
devGroupDataColl = "webconsoleData.snapshots.devGroupData" | ||
sliceDataColl = "webconsoleData.snapshots.sliceData" | ||
) | ||
|
||
var ( | ||
RestfulAPIGetMany = MongoDBLibrary.RestfulAPIGetMany | ||
RestfulAPIGetOne = MongoDBLibrary.RestfulAPIGetOne | ||
) | ||
|
||
// GetDeviceGroups - | ||
func GetDeviceGroups(c *gin.Context) { | ||
setCorsHeader(c) | ||
logger.WebUILog.Infoln("Get all Device Groups") | ||
|
||
var deviceGroups []string = make([]string, 0) | ||
rawDeviceGroups := RestfulAPIGetMany(devGroupDataColl, bson.M{}) | ||
for _, rawDeviceGroup := range rawDeviceGroups { | ||
deviceGroups = append(deviceGroups, rawDeviceGroup["group-name"].(string)) | ||
} | ||
|
||
c.JSON(http.StatusOK, deviceGroups) | ||
} | ||
|
||
// GetDeviceGroupsByName - | ||
func GetDeviceGroupByName(c *gin.Context) { | ||
setCorsHeader(c) | ||
logger.WebUILog.Infoln("Get Device Group by name") | ||
|
||
var deviceGroup configmodels.DeviceGroups | ||
filter := bson.M{"group-name": c.Param("group-name")} | ||
rawDeviceGroup := RestfulAPIGetOne(devGroupDataColl, filter) | ||
json.Unmarshal(mapToByte(rawDeviceGroup), &deviceGroup) | ||
|
||
if deviceGroup.DeviceGroupName == "" { | ||
c.JSON(http.StatusNotFound, nil) | ||
} else { | ||
c.JSON(http.StatusOK, deviceGroup) | ||
} | ||
} | ||
|
||
// DeviceGroupGroupNameDelete - | ||
func DeviceGroupGroupNameDelete(c *gin.Context) { | ||
logger.ConfigLog.Debugf("DeviceGroupGroupNameDelete") | ||
|
@@ -58,6 +102,37 @@ func DeviceGroupGroupNamePost(c *gin.Context) { | |
} | ||
} | ||
|
||
// GetNetworkSlices - | ||
func GetNetworkSlices(c *gin.Context) { | ||
setCorsHeader(c) | ||
logger.WebUILog.Infoln("Get all Network Slices") | ||
|
||
var networkSlices []string = make([]string, 0) | ||
rawNetworkSlices := RestfulAPIGetMany(sliceDataColl, bson.M{}) | ||
for _, rawNetworkSlice := range rawNetworkSlices { | ||
networkSlices = append(networkSlices, rawNetworkSlice["SliceName"].(string)) | ||
} | ||
|
||
c.JSON(http.StatusOK, networkSlices) | ||
} | ||
|
||
// GetNetworkSliceByName - | ||
func GetNetworkSliceByName(c *gin.Context) { | ||
setCorsHeader(c) | ||
logger.WebUILog.Infoln("Get Network Slice by name") | ||
|
||
var networkSlice configmodels.Slice | ||
filter := bson.M{"SliceName": c.Param("slice-name")} | ||
rawNetworkSlice := RestfulAPIGetOne(sliceDataColl, filter) | ||
json.Unmarshal(mapToByte(rawNetworkSlice), &networkSlice) | ||
|
||
if networkSlice.SliceName == "" { | ||
c.JSON(http.StatusNotFound, nil) | ||
} else { | ||
c.JSON(http.StatusOK, networkSlice) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you share curl command output how it looks like both success & failure case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, in the case that the slice does not exist, we get:
In the case where it exists, we get this:
|
||
} | ||
} | ||
|
||
// NetworkSliceSliceNameDelete - | ||
func NetworkSliceSliceNameDelete(c *gin.Context) { | ||
logger.ConfigLog.Debugf("Received NetworkSliceSliceNameDelete ") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add check for query param presence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also a path parameter defined in the router.