|
| 1 | +package article |
| 2 | + |
| 3 | +import ( |
| 4 | + "time" |
| 5 | + |
| 6 | + "golang.org/x/net/context" |
| 7 | + "google.golang.org/appengine/datastore" |
| 8 | + |
| 9 | + miniprop "github.com/firefirestyle/engine-v01/prop" |
| 10 | + "google.golang.org/appengine/memcache" |
| 11 | +) |
| 12 | + |
| 13 | +type GaeObjectArticle struct { |
| 14 | + UserName string |
| 15 | + Title string `datastore:",noindex"` |
| 16 | + Tags []string `datastore:"Tags.Tag"` |
| 17 | + Point float64 |
| 18 | + Lat float64 |
| 19 | + Lng float64 |
| 20 | + PropNames []string `datastore:"Props.Name"` |
| 21 | + PropValues []string `datastore:"Props.Value"` |
| 22 | + Cont string `datastore:",noindex"` |
| 23 | + Info string `datastore:",noindex"` |
| 24 | + Sign string `datastore:",noindex"` |
| 25 | + ArticleId string |
| 26 | + Created time.Time |
| 27 | + Updated time.Time |
| 28 | + SecretKey string `datastore:",noindex"` |
| 29 | + IconUrl string `datastore:",noindex"` |
| 30 | +} |
| 31 | + |
| 32 | +type Article struct { |
| 33 | + gaeObjectKey *datastore.Key |
| 34 | + gaeObject *GaeObjectArticle |
| 35 | + kind string |
| 36 | +} |
| 37 | + |
| 38 | +const ( |
| 39 | + TypeUserName = "UserName" |
| 40 | + TypeTitle = "Title" |
| 41 | + TypeTag = "Tag" |
| 42 | + TypePoint = "Point" |
| 43 | + TypePropNames = "PropNames" |
| 44 | + TypePropValues = "PropValues" |
| 45 | + TypeCont = "Cont" |
| 46 | + TypeInfo = "Info" |
| 47 | + TypeType = "Type" |
| 48 | + TypeSign = "Sign" |
| 49 | + TypeArticleId = "ArticleId" |
| 50 | + TypeCreated = "Created" |
| 51 | + TypeUpdated = "Updated" |
| 52 | + TypeSecretKey = "SecretKey" |
| 53 | + TypeTarget = "Target" |
| 54 | + TypeLat = "Lat" |
| 55 | + TypeLng = "Lng" |
| 56 | + TypeIconUrl = "IconUrl" |
| 57 | +) |
| 58 | + |
| 59 | +func (obj *Article) updateMemcache(ctx context.Context) error { |
| 60 | + userObjMemSource := obj.ToJson() |
| 61 | + userObjMem := &memcache.Item{ |
| 62 | + Key: obj.gaeObjectKey.StringID(), |
| 63 | + Value: []byte(userObjMemSource), // |
| 64 | + } |
| 65 | + memcache.Set(ctx, userObjMem) |
| 66 | + return nil |
| 67 | +} |
| 68 | + |
| 69 | +// |
| 70 | +// |
| 71 | +// |
| 72 | +func (obj *Article) GetGaeObjectKind() string { |
| 73 | + return obj.kind |
| 74 | +} |
| 75 | + |
| 76 | +func (obj *Article) GetGaeObjectKey() *datastore.Key { |
| 77 | + return obj.gaeObjectKey |
| 78 | +} |
| 79 | + |
| 80 | +func (obj *Article) GetUserName() string { |
| 81 | + return obj.gaeObject.UserName |
| 82 | +} |
| 83 | + |
| 84 | +func (obj *Article) GetSign() string { |
| 85 | + return obj.gaeObject.Sign |
| 86 | +} |
| 87 | + |
| 88 | +func (obj *Article) GetIconUrl() string { |
| 89 | + return obj.gaeObject.IconUrl |
| 90 | +} |
| 91 | + |
| 92 | +func (obj *Article) SetIconUrl(v string) { |
| 93 | + obj.gaeObject.IconUrl = v |
| 94 | +} |
| 95 | + |
| 96 | +func (obj *Article) GetInfo() string { |
| 97 | + return obj.gaeObject.Info |
| 98 | +} |
| 99 | + |
| 100 | +func (obj *Article) SetInfo(v string) { |
| 101 | + obj.gaeObject.Info = v |
| 102 | +} |
| 103 | + |
| 104 | +func (obj *Article) SetUserName(v string) { |
| 105 | + obj.gaeObject.UserName = v |
| 106 | +} |
| 107 | + |
| 108 | +func (obj *Article) GetTitle() string { |
| 109 | + return obj.gaeObject.Title |
| 110 | +} |
| 111 | + |
| 112 | +func (obj *Article) SetTitle(v string) { |
| 113 | + obj.gaeObject.Title = v |
| 114 | +} |
| 115 | + |
| 116 | +func (obj *Article) GetTags() []string { |
| 117 | + ret := make([]string, 0) |
| 118 | + for _, v := range obj.gaeObject.Tags { |
| 119 | + ret = append(ret, v) |
| 120 | + } |
| 121 | + return ret |
| 122 | +} |
| 123 | + |
| 124 | +func (obj *Article) SetTags(vs []string) { |
| 125 | + obj.gaeObject.Tags = make([]string, 0) |
| 126 | + for _, v := range vs { |
| 127 | + obj.gaeObject.Tags = append(obj.gaeObject.Tags, v) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +func (obj *Article) GetCont() string { |
| 132 | + return obj.gaeObject.Cont |
| 133 | +} |
| 134 | + |
| 135 | +func (obj *Article) SetCont(v string) { |
| 136 | + obj.gaeObject.Cont = v |
| 137 | +} |
| 138 | + |
| 139 | +func (obj *Article) GetParentId() string { |
| 140 | + return obj.gaeObject.Sign |
| 141 | +} |
| 142 | + |
| 143 | +func (obj *Article) SetParentId(v string) { |
| 144 | + obj.gaeObject.Sign = v |
| 145 | +} |
| 146 | + |
| 147 | +func (obj *Article) GetArticleId() string { |
| 148 | + return obj.gaeObject.ArticleId |
| 149 | +} |
| 150 | + |
| 151 | +func (obj *Article) GetCreated() time.Time { |
| 152 | + return obj.gaeObject.Created |
| 153 | +} |
| 154 | + |
| 155 | +func (obj *Article) GetUpdated() time.Time { |
| 156 | + return obj.gaeObject.Updated |
| 157 | +} |
| 158 | + |
| 159 | +func (obj *Article) SetUpdated(v time.Time) { |
| 160 | + obj.gaeObject.Updated = v |
| 161 | +} |
| 162 | + |
| 163 | +func (obj *Article) GetPoint() float64 { |
| 164 | + return obj.gaeObject.Point |
| 165 | +} |
| 166 | + |
| 167 | +func (obj *Article) SetPoint(v float64) { |
| 168 | + obj.gaeObject.Point = v |
| 169 | +} |
| 170 | + |
| 171 | +func (obj *Article) GetLat() float64 { |
| 172 | + return obj.gaeObject.Lat |
| 173 | +} |
| 174 | + |
| 175 | +func (obj *Article) SetLat(v float64) { |
| 176 | + obj.gaeObject.Lat = v |
| 177 | +} |
| 178 | + |
| 179 | +func (obj *Article) GetLng() float64 { |
| 180 | + return obj.gaeObject.Lng |
| 181 | +} |
| 182 | + |
| 183 | +func (obj *Article) SetLng(v float64) { |
| 184 | + obj.gaeObject.Lng = v |
| 185 | +} |
| 186 | + |
| 187 | +func (obj *Article) ClearProp() { |
| 188 | + obj.gaeObject.PropNames = nil |
| 189 | + obj.gaeObject.PropValues = nil |
| 190 | +} |
| 191 | + |
| 192 | +func (obj *Article) GetProp(name string) string { |
| 193 | + index := -1 |
| 194 | + for i, v := range obj.gaeObject.PropNames { |
| 195 | + if v == name { |
| 196 | + index = i |
| 197 | + break |
| 198 | + } |
| 199 | + } |
| 200 | + if index < 0 { |
| 201 | + return "" |
| 202 | + } |
| 203 | + p := miniprop.NewMiniPropFromJson([]byte(obj.gaeObject.PropValues[index])) |
| 204 | + return p.GetString(name, "") |
| 205 | +} |
| 206 | + |
| 207 | +func (obj *Article) SetProp(name, v string) { |
| 208 | + index := -1 |
| 209 | + p := miniprop.NewMiniProp() |
| 210 | + p.SetString(name, v) |
| 211 | + v = string(p.ToJson()) |
| 212 | + for i, iv := range obj.gaeObject.PropNames { |
| 213 | + if iv == name { |
| 214 | + index = i |
| 215 | + break |
| 216 | + } |
| 217 | + } |
| 218 | + if index == -1 { |
| 219 | + obj.gaeObject.PropValues = append(obj.gaeObject.PropValues, v) |
| 220 | + obj.gaeObject.PropNames = append(obj.gaeObject.PropNames, name) |
| 221 | + } else { |
| 222 | + obj.gaeObject.PropValues[index] = v |
| 223 | + } |
| 224 | +} |
0 commit comments