ops_simple_notification_group.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 *SimpleNotificationGroupOp) Find(ctx context.Context, conditions *iaas.FindCondition) (*iaas.SimpleNotificationGroupFindResult, error) {
27 results, _ := find(o.key, iaas.APIDefaultZone, conditions)
28 var values []*iaas.SimpleNotificationGroup
29 for _, res := range results {
30 dest := &iaas.SimpleNotificationGroup{}
31 copySameNameField(res, dest)
32 values = append(values, dest)
33 }
34 return &iaas.SimpleNotificationGroupFindResult{
35 Total: len(results),
36 Count: len(results),
37 From: 0,
38 SimpleNotificationGroups: values,
39 }, nil
40 }
41
42 // Create is fake implementation
43 func (o *SimpleNotificationGroupOp) Create(ctx context.Context, param *iaas.SimpleNotificationGroupCreateRequest) (*iaas.SimpleNotificationGroup, error) {
44 result := &iaas.SimpleNotificationGroup{}
45 copySameNameField(param, result)
46 fill(result, fillID, fillCreatedAt)
47
48 result.Availability = types.Availabilities.Available
49 putSimpleNotificationGroup(iaas.APIDefaultZone, result)
50 return result, nil
51 }
52
53 // Read is fake implementation
54 func (o *SimpleNotificationGroupOp) Read(ctx context.Context, id types.ID) (*iaas.SimpleNotificationGroup, error) {
55 value := getSimpleNotificationGroupByID(iaas.APIDefaultZone, id)
56 if value == nil {
57 return nil, newErrorNotFound(o.key, id)
58 }
59 dest := &iaas.SimpleNotificationGroup{}
60 copySameNameField(value, dest)
61 return dest, nil
62 }
63
64 // Update is fake implementation
65 func (o *SimpleNotificationGroupOp) Update(ctx context.Context, id types.ID, param *iaas.SimpleNotificationGroupUpdateRequest) (*iaas.SimpleNotificationGroup, 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 *SimpleNotificationGroupOp) UpdateSettings(ctx context.Context, id types.ID, param *iaas.SimpleNotificationGroupUpdateSettingsRequest) (*iaas.SimpleNotificationGroup, 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
85 return value, nil
86 }
87
88 // Delete is fake implementation
89 func (o *SimpleNotificationGroupOp) Delete(ctx context.Context, id types.ID) error {
90 _, err := o.Read(ctx, id)
91 if err != nil {
92 return err
93 }
94
95 ds().Delete(o.key, iaas.APIDefaultZone, id)
96 return nil
97 }
98
99 // PostMessage is fake implementation
100 func (o *SimpleNotificationGroupOp) PostMessage(ctx context.Context, id types.ID, message string) error {
101 return nil
102 }
103
104 func (o *SimpleNotificationGroupOp) History(ctx context.Context) (*iaas.SimpleNotificationHistories, error) {
105 return &iaas.SimpleNotificationHistories{
106 NotificationHistories: []*iaas.SimpleNotificationHistory{
107 {
108 RequestID: "11111",
109 SourceID: "1",
110 ReceivedAt: time.Now(),
111 Message: &iaas.SimpleNotificationHistoryMessage{
112 Body: "body",
113 Color: "color",
114 ColorCode: "#000000",
115 IconURL: "",
116 ImageURL: "",
117 Title: "title",
118 },
119 Statuses: []*iaas.SimpleNotificationHistoryStatus{
120 {
121 ID: "1",
122 Status: 1,
123 ErrorInfo: "error",
124 NotificationRequestID: "11111",
125 GroupID: "123456789012",
126 CreatedAt: time.Now(),
127 UpdatedAt: time.Now(),
128 },
129 },
130 },
131 },
132 }, nil
133 }
134