Skip to content

Commit d7e3f32

Browse files
committed
Merge remote-tracking branch 'Feyko/tags' into tags
2 parents 5537a1c + b0e6258 commit d7e3f32

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

db/postgres/mod.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,41 @@ func NewModQuery(ctx context.Context, filter *models.ModFilter, unapproved bool,
263263
return query.Debug()
264264
}
265265

266-
func GetModByIDOrReference(ctx context.Context, modIDOrReference string) *Mod {
267-
cacheKey := "GetModByIDOrReference_" + modIDOrReference
268-
if mod, ok := dbCache.Get(cacheKey); ok {
269-
return mod.(*Mod)
270-
}
266+
func ClearModTags(ctx context.Context, modID string) error {
267+
r := DBCtx(ctx).Where("mod_id = ?", modID).Delete(&ModTag{})
268+
return r.Error
269+
}
271270

272-
var mod Mod
273-
DBCtx(ctx).Find(&mod, "mod_reference = ? OR id = ?", modIDOrReference, modIDOrReference)
271+
func SetModTags(ctx context.Context, modID string, tagIDs []string) error {
272+
for _, tag := range tagIDs {
273+
err := AddModTag(ctx, modID, tag)
274+
if err != nil {
275+
return err
276+
}
277+
}
278+
return nil
279+
}
274280

275-
if mod.ID == "" {
276-
return nil
281+
func ResetModTags(ctx context.Context, modID string, tagIDs []string) error {
282+
err := ClearModTags(ctx, modID)
283+
if err != nil {
284+
return err
277285
}
286+
err = SetModTags(ctx, modID, tagIDs)
287+
if err != nil {
288+
return err
289+
}
290+
return nil
291+
}
278292

279-
dbCache.Set(cacheKey, &mod, cache.DefaultExpiration)
293+
func AddModTag(ctx context.Context, modID string, tagID string) error {
294+
r := DBCtx(ctx).Create(&ModTag{ModID: modID, TagID: tagID})
295+
return r.Error
296+
}
280297

281-
return &mod
298+
func RemoveModTag(ctx context.Context, modID string, tagID string) error {
299+
r := DBCtx(ctx).Delete(&ModTag{ModID: modID, TagID: tagID})
300+
return r.Error
282301
}
283302

284303
func ClearModTags(modID string, ctx *context.Context) error {

0 commit comments

Comments
 (0)