Skip to content

Commit 13e7eb1

Browse files
authored
Merge pull request #2120 from afumagalli98/location-scenario
Added location to scenario
2 parents 22d9599 + 2c95e48 commit 13e7eb1

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

api-service/controller/scenarios.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,21 @@ import (
1818
"errors"
1919
"net/http"
2020
"path"
21-
"strings"
2221

2322
"github.com/ercole-io/ercole/v2/api-service/dto"
2423
"github.com/ercole-io/ercole/v2/utils"
2524
"github.com/gorilla/mux"
2625
)
2726

2827
func (ctrl *APIController) CreateScenario(w http.ResponseWriter, r *http.Request) {
29-
f, err := dto.GetGlobalFilter(r)
30-
if err != nil {
31-
utils.WriteAndLogError(ctrl.Log, w, http.StatusBadRequest, err)
32-
return
33-
}
34-
35-
locations := strings.Split(f.Location, ",")
36-
3728
req := &dto.CreateScenarioRequest{}
3829

3930
if err := utils.Decode(r.Body, &req); err != nil {
4031
utils.WriteAndLogError(ctrl.Log, w, http.StatusBadRequest, err)
4132
return
4233
}
4334

44-
scenario, err := ctrl.Service.CreateScenario(*req, locations, *f)
35+
scenario, err := ctrl.Service.CreateScenario(*req)
4536
if err != nil {
4637
utils.WriteAndLogError(ctrl.Log, w, http.StatusUnprocessableEntity, err)
4738
return

api-service/dto/scenario.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
)
2222

2323
type CreateScenarioRequest struct {
24-
Name string `json:"name"`
25-
Hosts []CreateHostScenarioRequest `json:"hosts"`
24+
Name string `json:"name"`
25+
Location string `json:"location"`
26+
Hosts []CreateHostScenarioRequest `json:"hosts"`
2627
}
2728

2829
type CreateHostScenarioRequest struct {
@@ -34,6 +35,7 @@ type ScenarioResponse struct {
3435
ID string `json:"id"`
3536
Name string `json:"name"`
3637
CreatedAt time.Time `json:"createdAt"`
38+
Location string `json:"location"`
3739
Hosts []SimulatedHost `json:"hosts"`
3840
}
3941

@@ -63,6 +65,7 @@ func ToScenarioResponse(m model.Scenario) ScenarioResponse {
6365
ID: m.ID.Hex(),
6466
Name: m.Name,
6567
CreatedAt: m.CreatedAt,
68+
Location: m.Location,
6669
Hosts: simulatedHosts,
6770
}
6871
}
@@ -80,6 +83,7 @@ type ScenarioLicenseComplianceResponse struct {
8083
ID string `json:"id"`
8184
Name string `json:"name"`
8285
CreatedAt time.Time `json:"createdAt"`
86+
Location string `json:"location"`
8387
Licenses []LicenseComplianceSimulation `json:"licenses"`
8488
}
8589

@@ -110,6 +114,7 @@ func ToScenarioLicenseComplianceResponse(m model.Scenario) ScenarioLicenseCompli
110114
ID: m.ID.Hex(),
111115
Name: m.Name,
112116
CreatedAt: m.CreatedAt,
117+
Location: m.Location,
113118
Licenses: licenses,
114119
}
115120
}
@@ -118,6 +123,7 @@ type ScenarioLicenseUsedDatabaseResponse struct {
118123
ID string `json:"id"`
119124
Name string `json:"name"`
120125
CreatedAt time.Time `json:"createdAt"`
126+
Location string `json:"location"`
121127
Licenses []LicenseUsedDatabaseSimulation `json:"licenses"`
122128
}
123129

@@ -148,6 +154,7 @@ func ToScenarioLicenseUsedDatabaseResponse(m model.Scenario) ScenarioLicenseUsed
148154
ID: m.ID.Hex(),
149155
Name: m.Name,
150156
CreatedAt: m.CreatedAt,
157+
Location: m.Location,
151158
Licenses: licenses,
152159
}
153160
}
@@ -156,6 +163,7 @@ type ScenarioLicenseUsedHostResponse struct {
156163
ID string `json:"id"`
157164
Name string `json:"name"`
158165
CreatedAt time.Time `json:"createdAt"`
166+
Location string `json:"location"`
159167
Licenses []LicenseUsedHostSimulation `json:"licenses"`
160168
}
161169

@@ -186,6 +194,7 @@ func ToScenarioLicenseUsedHostResponse(m model.Scenario) ScenarioLicenseUsedHost
186194
ID: m.ID.Hex(),
187195
Name: m.Name,
188196
CreatedAt: m.CreatedAt,
197+
Location: m.Location,
189198
Licenses: licenses,
190199
}
191200
}
@@ -194,6 +203,7 @@ type ScenarioLicenseUsedClusterResponse struct {
194203
ID string `json:"id"`
195204
Name string `json:"name"`
196205
CreatedAt time.Time `json:"createdAt"`
206+
Location string `json:"location"`
197207
Licenses []LicenseUsedClusterSimulation `json:"licenses"`
198208
}
199209

@@ -224,6 +234,7 @@ func ToScenarioLicenseUsedClusterResponse(m model.Scenario) ScenarioLicenseUsedC
224234
ID: m.ID.Hex(),
225235
Name: m.Name,
226236
CreatedAt: m.CreatedAt,
237+
Location: m.Location,
227238
Licenses: licenses,
228239
}
229240
}
@@ -232,6 +243,7 @@ type ScenarioLicenseUsedClusterVeritasResponse struct {
232243
ID string `json:"id"`
233244
Name string `json:"name"`
234245
CreatedAt time.Time `json:"createdAt"`
246+
Location string `json:"location"`
235247
Licenses []LicenseUsedClsuterVeritasSimulation `json:"licenses"`
236248
}
237249

@@ -262,6 +274,7 @@ func ToScenarioLicenseUsedClusterVeritasResponse(m model.Scenario) ScenarioLicen
262274
ID: m.ID.Hex(),
263275
Name: m.Name,
264276
CreatedAt: m.CreatedAt,
277+
Location: m.Location,
265278
Licenses: licenses,
266279
}
267280
}

api-service/service/scenario.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@
1515
package service
1616

1717
import (
18+
"strings"
1819
"time"
1920

2021
"github.com/ercole-io/ercole/v2/api-service/dto"
2122
"github.com/ercole-io/ercole/v2/model"
2223
"go.mongodb.org/mongo-driver/bson/primitive"
2324
)
2425

25-
func (as *APIService) CreateScenario(req dto.CreateScenarioRequest, locations []string, filter dto.GlobalFilter) (*model.Scenario, error) {
26+
func (as *APIService) CreateScenario(req dto.CreateScenarioRequest) (*model.Scenario, error) {
2627
scenario := &model.Scenario{
2728
ID: primitive.NewObjectID(),
2829
Name: req.Name,
2930
CreatedAt: time.Now(),
31+
Location: req.Location,
32+
}
33+
34+
filter := dto.GlobalFilter{
35+
Location: req.Location,
3036
}
3137

3238
for _, h := range req.Hosts {
@@ -43,7 +49,7 @@ func (as *APIService) CreateScenario(req dto.CreateScenarioRequest, locations []
4349
})
4450
}
4551

46-
actualCompliance, err := as.getLicenseCompliance(locations)
52+
actualCompliance, err := as.getLicenseCompliance(req.Location)
4753
if err != nil {
4854
return nil, err
4955
}
@@ -89,7 +95,7 @@ func (as *APIService) CreateScenario(req dto.CreateScenarioRequest, locations []
8995
}
9096
}
9197

92-
gotCompliance, err := as.getLicenseCompliance(locations)
98+
gotCompliance, err := as.getLicenseCompliance(req.Location)
9399
if err != nil {
94100
return nil, err
95101
}
@@ -143,7 +149,9 @@ func (as *APIService) CreateScenario(req dto.CreateScenarioRequest, locations []
143149
return res, nil
144150
}
145151

146-
func (as *APIService) getLicenseCompliance(locations []string) ([]model.LicenseCompliance, error) {
152+
func (as *APIService) getLicenseCompliance(location string) ([]model.LicenseCompliance, error) {
153+
locations := strings.Split(location, ",")
154+
147155
licensesCompliance, err := as.GetDatabaseLicensesCompliance(locations)
148156
if err != nil {
149157
return nil, err

api-service/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ type APIServiceInterface interface {
352352
GetExadataPatchAdvisors() ([]dto.OracleExadataPatchAdvisor, error)
353353
GetAllExadataPatchAdvisorsAsXlsx() (*excelize.File, error)
354354

355-
CreateScenario(req dto.CreateScenarioRequest, locations []string, filter dto.GlobalFilter) (*model.Scenario, error)
355+
CreateScenario(req dto.CreateScenarioRequest) (*model.Scenario, error)
356356
GetScenarios() ([]model.Scenario, error)
357357
GetScenario(id primitive.ObjectID) (*model.Scenario, error)
358358
RemoveScenario(id primitive.ObjectID) error

model/scenario.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import (
2121
)
2222

2323
type Scenario struct {
24-
ID primitive.ObjectID `bson:"_id"`
25-
Name string `bson:"name"`
26-
CreatedAt time.Time `bson:"createdAt"`
27-
Hosts []SimulatedHost `bson:"hosts"`
24+
ID primitive.ObjectID `bson:"_id"`
25+
Name string `bson:"name"`
26+
CreatedAt time.Time `bson:"createdAt"`
27+
28+
Location string `bson:"location"`
29+
Hosts []SimulatedHost `bson:"hosts"`
30+
2831
LicenseCompliance LicensesComplianceScenario `bson:"licenseCompliance"`
2932
LicenseUsed LicenseUsedScenario `bson:"licenseUsed"`
3033
}

swagger.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,8 @@ components:
27162716
properties:
27172717
name:
27182718
type: string
2719+
location:
2720+
type: string
27192721
hosts:
27202722
type: array
27212723
items:
@@ -2737,6 +2739,8 @@ components:
27372739
type: string
27382740
format: date-time
27392741
example: "2025-10-06T08:23:40.000Z"
2742+
location:
2743+
type: string
27402744
hosts:
27412745
type: array
27422746
items:
@@ -2762,6 +2766,8 @@ components:
27622766
type: string
27632767
format: date-time
27642768
example: "2025-10-06T08:23:40.000Z"
2769+
location:
2770+
type: string
27652771
licenses:
27662772
type: array
27672773
items:
@@ -2783,6 +2789,8 @@ components:
27832789
type: string
27842790
format: date-time
27852791
example: "2025-10-06T08:23:40.000Z"
2792+
location:
2793+
type: string
27862794
licenses:
27872795
type: array
27882796
items:
@@ -2804,6 +2812,8 @@ components:
28042812
type: string
28052813
format: date-time
28062814
example: "2025-10-06T08:23:40.000Z"
2815+
location:
2816+
type: string
28072817
licenses:
28082818
type: array
28092819
items:
@@ -2825,6 +2835,8 @@ components:
28252835
type: string
28262836
format: date-time
28272837
example: "2025-10-06T08:23:40.000Z"
2838+
location:
2839+
type: string
28282840
licenses:
28292841
type: array
28302842
items:
@@ -2846,6 +2858,8 @@ components:
28462858
type: string
28472859
format: date-time
28482860
example: "2025-10-06T08:23:40.000Z"
2861+
location:
2862+
type: string
28492863
licenses:
28502864
type: array
28512865
items:

0 commit comments

Comments
 (0)