github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/base_entity.go (about) 1 /* 2 * Copyright 2020 The Compass Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package model 18 19 import ( 20 "time" 21 22 "github.com/kyma-incubator/compass/components/director/pkg/resource" 23 ) 24 25 // Entity denotes a model-layer entity which can be timestamped with created_at, updated_at, deleted_at and ready values 26 type Entity interface { 27 GetID() string 28 GetType() resource.Type 29 30 GetReady() bool 31 SetReady(ready bool) 32 33 GetCreatedAt() time.Time 34 SetCreatedAt(t time.Time) 35 36 GetUpdatedAt() time.Time 37 SetUpdatedAt(t time.Time) 38 39 GetDeletedAt() time.Time 40 SetDeletedAt(t time.Time) 41 42 GetError() *string 43 SetError(err string) 44 } 45 46 // BaseEntity missing godoc 47 type BaseEntity struct { 48 ID string 49 Ready bool 50 CreatedAt *time.Time 51 UpdatedAt *time.Time 52 DeletedAt *time.Time 53 Error *string 54 } 55 56 // GetID missing godoc 57 func (e *BaseEntity) GetID() string { 58 return e.ID 59 } 60 61 // GetType missing godoc 62 func (e *BaseEntity) GetType() resource.Type { 63 return "" 64 } 65 66 // GetReady missing godoc 67 func (e *BaseEntity) GetReady() bool { 68 return e.Ready 69 } 70 71 // SetReady missing godoc 72 func (e *BaseEntity) SetReady(ready bool) { 73 e.Ready = ready 74 } 75 76 // GetCreatedAt missing godoc 77 func (e *BaseEntity) GetCreatedAt() time.Time { 78 if e.CreatedAt == nil { 79 return time.Time{} 80 } 81 return *e.CreatedAt 82 } 83 84 // SetCreatedAt missing godoc 85 func (e *BaseEntity) SetCreatedAt(t time.Time) { 86 e.CreatedAt = &t 87 } 88 89 // GetUpdatedAt missing godoc 90 func (e *BaseEntity) GetUpdatedAt() time.Time { 91 if e.UpdatedAt == nil { 92 return time.Time{} 93 } 94 return *e.UpdatedAt 95 } 96 97 // SetUpdatedAt missing godoc 98 func (e *BaseEntity) SetUpdatedAt(t time.Time) { 99 e.UpdatedAt = &t 100 } 101 102 // GetDeletedAt missing godoc 103 func (e *BaseEntity) GetDeletedAt() time.Time { 104 if e.DeletedAt == nil { 105 return time.Time{} 106 } 107 return *e.DeletedAt 108 } 109 110 // SetDeletedAt missing godoc 111 func (e *BaseEntity) SetDeletedAt(t time.Time) { 112 e.DeletedAt = &t 113 } 114 115 // GetError missing godoc 116 func (e *BaseEntity) GetError() *string { 117 return e.Error 118 } 119 120 // SetError missing godoc 121 func (e *BaseEntity) SetError(err string) { 122 if err == "" { 123 e.Error = nil 124 } else { 125 e.Error = &err 126 } 127 }