From c2e95d131333ee89c26ed282db2c60de824042a1 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Tue, 6 Feb 2024 11:52:38 +0300
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
 =?UTF-8?q?=D0=BD=20SystemID?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 id/bson_test.go |  4 ++++
 id/id.go        |  6 ++++++
 id/id_test.go   | 11 ++++++++++-
 id/json_test.go |  4 ++++
 id/system.go    | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 id/system.go

diff --git a/id/bson_test.go b/id/bson_test.go
index 952ecf59..c8080b5d 100644
--- a/id/bson_test.go
+++ b/id/bson_test.go
@@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalBSON(t *testing.T) {
 			name: "FieldID",
 			id:   &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}},
 		},
+		{
+			name: "SystemID",
+			id:   &ID{Descriptor: &SystemID{}},
+		},
 	}
 	type test struct {
 		Text string
diff --git a/id/id.go b/id/id.go
index d3212dea..ca75c29f 100644
--- a/id/id.go
+++ b/id/id.go
@@ -75,6 +75,10 @@ func Parse(s string) (*ID, error) {
 		return &ID{Descriptor: id}, nil
 	}
 
+	if id, _ := parseSystemID(parts); id != nil {
+		return &ID{Descriptor: id}, nil
+	}
+
 	return nil, ErrInvalidID
 }
 
@@ -125,6 +129,8 @@ func FromMap(m map[string]any) (*ID, error) {
 		v.Descriptor = new(RevisionID)
 	case Field:
 		v.Descriptor = new(FieldID)
+	case System:
+		v.Descriptor = new(SystemID)
 	default:
 		return nil, errors.New("unknown type")
 	}
diff --git a/id/id_test.go b/id/id_test.go
index a5a75cc5..041f1cdc 100644
--- a/id/id_test.go
+++ b/id/id_test.go
@@ -128,6 +128,11 @@ func Test_ParseID(t *testing.T) {
 				FieldName: "<field_name>",
 			}},
 		},
+		{
+			name:   "SystemID",
+			id:     "/system",
+			result: &ID{Descriptor: &SystemID{}},
+		},
 		{
 			name:      "With error #1: no backslash in the beginning of id",
 			id:        "spaces/<space_id>",
@@ -278,8 +283,12 @@ func Test_Map(t *testing.T) {
 					ItemID: "<item_id>",
 				},
 				FieldName: "<field_name>",
-			},
 			}},
+		},
+		{
+			name: "SystemID",
+			id:   &ID{Descriptor: &SystemID{}},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/id/json_test.go b/id/json_test.go
index 1ab3bb87..afe831d4 100644
--- a/id/json_test.go
+++ b/id/json_test.go
@@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalJSON(t *testing.T) {
 			name: "FieldID",
 			id:   &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}},
 		},
+		{
+			name: "SystemID",
+			id:   &ID{Descriptor: &SystemID{}},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/id/system.go b/id/system.go
new file mode 100644
index 00000000..0fe640a2
--- /dev/null
+++ b/id/system.go
@@ -0,0 +1,33 @@
+package id
+
+const (
+	System = "system"
+)
+
+type SystemID struct{}
+
+func (t *SystemID) Type() string { return Space }
+
+func (t *SystemID) String() string {
+	return "/" + System
+}
+
+func (t *SystemID) ToMap() map[string]any {
+	return map[string]any{"type": System}
+}
+
+func (t *SystemID) FromMap(m map[string]any) error {
+	return nil
+}
+
+func (t *SystemID) Validate() error {
+	return nil
+}
+
+func parseSystemID(parts []string) (*SystemID, error) {
+	var id SystemID
+	if len(parts) != 1 || parts[0] != System {
+		return nil, ErrInvalidID
+	}
+	return &id, nil
+}
-- 
GitLab