Skip to content

Commit ebb731c

Browse files
committed
refactor(api): implement centralized tag collection
Create a dedicated `tags` collection to centralize tag management across the application. This replaces the previous string-based tag association with a reference-based model using tag IDs. The schema for a tag is as follow: ```json { "_id": ObjectId, "tenant_id": String, "created_at": Time, "updated_at": Time, "name": String } ``` Update all tag-related collections to use tag IDs instead of tag names. A migration handles the conversion of existing tag data to the new format. API response format now includes tag objects: ```json { ... "tags": [ { "name": String }, { "name": String }, { "name": String } ] } ``` Implement generic tag management methods in the store layer to handle tag operations (push/pull) consistently across all taggable collections. Add new query options to filter items by tags. Introduce dual tag representation in taggable entities: - TagsID: Internal array of tag IDs (not exposed via API) - Tags: Array of models.Tag objects for API responses
1 parent f607c23 commit ebb731c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5316
-5336
lines changed

api/routes/device.go

-54
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const (
1919
OfflineDeviceURL = "/devices/:uid/offline"
2020
LookupDeviceURL = "/lookup"
2121
UpdateDeviceStatusURL = "/devices/:uid/:status"
22-
CreateTagURL = "/devices/:uid/tags" // Add a tag to a device.
23-
UpdateTagURL = "/devices/:uid/tags" // Update device's tags with a new set.
24-
RemoveTagURL = "/devices/:uid/tags/:tag" // Delete a tag from a device.
2522
UpdateDevice = "/devices/:uid"
2623
)
2724

@@ -243,57 +240,6 @@ func (h *Handler) UpdateDeviceStatus(c gateway.Context) error {
243240
return c.NoContent(http.StatusOK)
244241
}
245242

246-
func (h *Handler) CreateDeviceTag(c gateway.Context) error {
247-
var req requests.DeviceCreateTag
248-
if err := c.Bind(&req); err != nil {
249-
return err
250-
}
251-
252-
if err := c.Validate(&req); err != nil {
253-
return err
254-
}
255-
256-
if err := h.service.CreateDeviceTag(c.Ctx(), models.UID(req.UID), req.Tag); err != nil {
257-
return err
258-
}
259-
260-
return c.NoContent(http.StatusOK)
261-
}
262-
263-
func (h *Handler) RemoveDeviceTag(c gateway.Context) error {
264-
var req requests.DeviceRemoveTag
265-
if err := c.Bind(&req); err != nil {
266-
return err
267-
}
268-
269-
if err := c.Validate(&req); err != nil {
270-
return err
271-
}
272-
273-
if err := h.service.RemoveDeviceTag(c.Ctx(), models.UID(req.UID), req.Tag); err != nil {
274-
return err
275-
}
276-
277-
return c.NoContent(http.StatusOK)
278-
}
279-
280-
func (h *Handler) UpdateDeviceTag(c gateway.Context) error {
281-
var req requests.DeviceUpdateTag
282-
if err := c.Bind(&req); err != nil {
283-
return err
284-
}
285-
286-
if err := c.Validate(&req); err != nil {
287-
return err
288-
}
289-
290-
if err := h.service.UpdateDeviceTag(c.Ctx(), models.UID(req.UID), req.Tags); err != nil {
291-
return err
292-
}
293-
294-
return c.NoContent(http.StatusOK)
295-
}
296-
297243
func (h *Handler) UpdateDevice(c gateway.Context) error {
298244
var req requests.DeviceUpdate
299245
if err := c.Bind(&req); err != nil {

0 commit comments

Comments
 (0)