ops_simple_notification_destination.go raw
1 // Copyright 2022-2025 The sacloud/iaas-api-go Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package fake
16
17 import (
18 "context"
19 "time"
20
21 "github.com/sacloud/iaas-api-go"
22 "github.com/sacloud/iaas-api-go/types"
23 )
24
25 // Find is fake implementation
26 func (o *SimpleNotificationDestinationOp) Find(ctx context.Context, conditions *iaas.FindCondition) (*iaas.SimpleNotificationDestinationFindResult, error) {
27 results, _ := find(o.key, iaas.APIDefaultZone, conditions)
28 var values []*iaas.SimpleNotificationDestination
29 for _, res := range results {
30 dest := &iaas.SimpleNotificationDestination{}
31 copySameNameField(res, dest)
32 values = append(values, dest)
33 }
34 return &iaas.SimpleNotificationDestinationFindResult{
35 Total: len(results),
36 Count: len(results),
37 From: 0,
38 SimpleNotificationDestinations: values,
39 }, nil
40 }
41
42 // Create is fake implementation
43 func (o *SimpleNotificationDestinationOp) Create(ctx context.Context, param *iaas.SimpleNotificationDestinationCreateRequest) (*iaas.SimpleNotificationDestination, error) {
44 result := &iaas.SimpleNotificationDestination{}
45 copySameNameField(param, result)
46 fill(result, fillID, fillCreatedAt)
47
48 result.Availability = types.Availabilities.Available
49 putSimpleNotificationDestination(iaas.APIDefaultZone, result)
50 return result, nil
51 }
52
53 // Read is fake implementation
54 func (o *SimpleNotificationDestinationOp) Read(ctx context.Context, id types.ID) (*iaas.SimpleNotificationDestination, error) {
55 value := getSimpleNotificationDestinationByID(iaas.APIDefaultZone, id)
56 if value == nil {
57 return nil, newErrorNotFound(o.key, id)
58 }
59 dest := &iaas.SimpleNotificationDestination{}
60 copySameNameField(value, dest)
61 return dest, nil
62 }
63
64 // Update is fake implementation
65 func (o *SimpleNotificationDestinationOp) Update(ctx context.Context, id types.ID, param *iaas.SimpleNotificationDestinationUpdateRequest) (*iaas.SimpleNotificationDestination, error) {
66 value, err := o.Read(ctx, id)
67 if err != nil {
68 return nil, err
69 }
70 copySameNameField(param, value)
71 fill(value, fillModifiedAt)
72
73 return value, nil
74 }
75
76 // UpdateSettings is fake implementation
77 func (o *SimpleNotificationDestinationOp) UpdateSettings(ctx context.Context, id types.ID, param *iaas.SimpleNotificationDestinationUpdateSettingsRequest) (*iaas.SimpleNotificationDestination, error) {
78 value, err := o.Read(ctx, id)
79 if err != nil {
80 return nil, err
81 }
82 copySameNameField(param, value)
83 fill(value, fillModifiedAt)
84 return value, err
85 }
86
87 // Delete is fake implementation
88 func (o *SimpleNotificationDestinationOp) Delete(ctx context.Context, id types.ID) error {
89 _, err := o.Read(ctx, id)
90 if err != nil {
91 return err
92 }
93
94 ds().Delete(o.key, iaas.APIDefaultZone, id)
95 return nil
96 }
97
98 // Status is fake implementation
99 func (o *SimpleNotificationDestinationOp) Status(ctx context.Context, id types.ID) (*iaas.SimpleNotificationDestinationStatus, error) {
100 _, err := o.Read(ctx, id)
101 if err != nil {
102 return nil, err
103 }
104
105 return &iaas.SimpleNotificationDestinationStatus{
106 Disabled: false,
107 ModifiedAt: time.Now(),
108 }, nil
109 }
110