Change properties search signature to support multiple TargetIDs (#33873)

* change properties search

* add tests

* Fix calls to to the search methods

* Fix SearchPropertyFields call with wrong signature
This commit is contained in:
Julien Tant
2025-09-11 15:56:01 -07:00
committed by GitHub
parent d15b933888
commit 78050bb0d3
20 changed files with 133 additions and 89 deletions
@@ -67,7 +67,7 @@ func (a *App) ListCPAFields() ([]*model.PropertyField, *model.AppError) {
PerPage: CustomProfileAttributesFieldLimit,
}
fields, err := a.Srv().propertyService.SearchPropertyFields(groupID, "", opts)
fields, err := a.Srv().propertyService.SearchPropertyFields(groupID, opts)
if err != nil {
return nil, model.NewAppError("GetCPAFields", "app.custom_profile_attributes.search_property_fields.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
@@ -205,8 +205,9 @@ func (a *App) ListCPAValues(userID string) ([]*model.PropertyValue, *model.AppEr
return nil, model.NewAppError("GetCPAFields", "app.custom_profile_attributes.cpa_group_id.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
values, err := a.Srv().propertyService.SearchPropertyValues(groupID, userID, model.PropertyValueSearchOpts{
PerPage: CustomProfileAttributesFieldLimit,
values, err := a.Srv().propertyService.SearchPropertyValues(groupID, model.PropertyValueSearchOpts{
TargetIDs: []string{userID},
PerPage: CustomProfileAttributesFieldLimit,
})
if err != nil {
return nil, model.NewAppError("ListCPAValues", "app.custom_profile_attributes.list_property_values.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
@@ -588,7 +588,7 @@ func TestDeleteCPAField(t *testing.T) {
t.Run("should correctly delete the field", func(t *testing.T) {
// check that we have the associated values to the field prior deletion
opts := model.PropertyValueSearchOpts{PerPage: 10, FieldID: createdField.ID}
values, err := th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, "", opts)
values, err := th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, opts)
require.NoError(t, err)
require.Len(t, values, 3)
@@ -601,12 +601,12 @@ func TestDeleteCPAField(t *testing.T) {
require.NotZero(t, fetchedField.DeleteAt)
// ensure that the associated fields have been marked as deleted too
values, err = th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, "", opts)
values, err = th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, opts)
require.NoError(t, err)
require.Len(t, values, 0)
opts.IncludeDeleted = true
values, err = th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, "", opts)
values, err = th.App.Srv().propertyService.SearchPropertyValues(cpaGroupID, opts)
require.NoError(t, err)
require.Len(t, values, 3)
for _, value := range values {
+1 -1
View File
@@ -621,7 +621,7 @@ func (s *Server) doSetupContentFlaggingProperties() error {
// Using page size of 100 and not iterating through all pages because the
// number of fields are static and defined here and not expected to be more than 100 for now.
existingProperties, appErr := s.propertyService.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 100})
existingProperties, appErr := s.propertyService.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 100})
if appErr != nil {
return fmt.Errorf("failed to search for existing content flagging properties: %w", appErr)
}
+2 -2
View File
@@ -24,7 +24,7 @@ func TestDoSetupContentFlaggingProperties(t *testing.T) {
require.NotNil(t, group)
require.Equal(t, model.ContentFlaggingGroupName, group.Name)
propertyFields, err := th.Server.propertyService.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 100})
propertyFields, err := th.Server.propertyService.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 100})
require.NoError(t, err)
require.Len(t, propertyFields, 10)
})
@@ -45,7 +45,7 @@ func TestDoSetupContentFlaggingProperties(t *testing.T) {
require.NoError(t, err)
require.Equal(t, model.ContentFlaggingGroupName, group.Name)
propertyFields, err := th.Server.propertyService.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 100})
propertyFields, err := th.Server.propertyService.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 100})
require.NoError(t, err)
require.Len(t, propertyFields, 10)
})
+4 -4
View File
@@ -1526,8 +1526,8 @@ func (api *PluginAPI) DeletePropertyField(groupID, fieldID string) error {
return api.app.PropertyService().DeletePropertyField(groupID, fieldID)
}
func (api *PluginAPI) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
return api.app.PropertyService().SearchPropertyFields(groupID, targetID, opts)
func (api *PluginAPI) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
return api.app.PropertyService().SearchPropertyFields(groupID, opts)
}
func (api *PluginAPI) CountPropertyFields(groupID string, includeDeleted bool) (int64, error) {
@@ -1568,8 +1568,8 @@ func (api *PluginAPI) DeletePropertyValue(groupID, valueID string) error {
return api.app.PropertyService().DeletePropertyValue(groupID, valueID)
}
func (api *PluginAPI) SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
return api.app.PropertyService().SearchPropertyValues(groupID, targetID, opts)
func (api *PluginAPI) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
return api.app.PropertyService().SearchPropertyValues(groupID, opts)
}
func (api *PluginAPI) RegisterPropertyGroup(name string) (*model.PropertyGroup, error) {
@@ -71,7 +71,7 @@ func TestPluginProperties(t *testing.T) {
}
// Search for fields
fields, err := p.API.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 50})
fields, err := p.API.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 50})
if err != nil {
return fmt.Errorf("failed to search property fields: %w", err)
}
@@ -86,7 +86,7 @@ func TestPluginProperties(t *testing.T) {
}
// Verify deletion
fields, err = p.API.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 50})
fields, err = p.API.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 50})
if err != nil {
return fmt.Errorf("failed to search property fields after deletion: %w", err)
}
@@ -199,7 +199,7 @@ func TestPluginProperties(t *testing.T) {
}
// Search for values
values, err := p.API.SearchPropertyValues(group.ID, targetId, model.PropertyValueSearchOpts{PerPage: 50})
values, err := p.API.SearchPropertyValues(group.ID, model.PropertyValueSearchOpts{TargetIDs: []string{targetId}, PerPage: 50})
if err != nil {
return fmt.Errorf("failed to search property values: %w", err)
}
@@ -214,7 +214,7 @@ func TestPluginProperties(t *testing.T) {
}
// Verify deletion
values, err = p.API.SearchPropertyValues(group.ID, targetId, model.PropertyValueSearchOpts{PerPage: 50})
values, err = p.API.SearchPropertyValues(group.ID, model.PropertyValueSearchOpts{TargetIDs: []string{targetId}, PerPage: 50})
if err != nil {
return fmt.Errorf("failed to search property values after deletion: %w", err)
}
@@ -337,7 +337,7 @@ func TestPluginProperties(t *testing.T) {
}
// Search for fields to get one to delete
fields, err := p.API.SearchPropertyFields(group.ID, "", model.PropertyFieldSearchOpts{PerPage: 1})
fields, err := p.API.SearchPropertyFields(group.ID, model.PropertyFieldSearchOpts{PerPage: 1})
if err != nil {
return fmt.Errorf("failed to search property fields: %w", err)
}
@@ -41,11 +41,10 @@ func (ps *PropertyService) CountAllPropertyFieldsForTarget(groupID, targetType,
return ps.fieldStore.CountForTarget(groupID, targetType, targetID, true)
}
func (ps *PropertyService) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
// groupID and targetID are part of the search method signature to
func (ps *PropertyService) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
// groupID is part of the search method signature to
// incentivize the use of the database indexes in searches
opts.GroupID = groupID
opts.TargetID = targetID
return ps.fieldStore.SearchPropertyFields(opts)
}
@@ -19,11 +19,10 @@ func (ps *PropertyService) GetPropertyValues(groupID string, ids []string) ([]*m
return ps.valueStore.GetMany(groupID, ids)
}
func (ps *PropertyService) SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
// groupID and targetID are part of the search method signature to
func (ps *PropertyService) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
// groupID is part of the search method signature to
// incentivize the use of the database indexes in searches
opts.GroupID = groupID
opts.TargetID = targetID
return ps.valueStore.SearchPropertyValues(opts)
}
@@ -172,8 +172,8 @@ func (s *SqlPropertyFieldStore) SearchPropertyFields(opts model.PropertyFieldSea
builder = builder.Where(sq.Eq{"TargetType": opts.TargetType})
}
if opts.TargetID != "" {
builder = builder.Where(sq.Eq{"TargetID": opts.TargetID})
if len(opts.TargetIDs) > 0 {
builder = builder.Where(sq.Eq{"TargetID": opts.TargetIDs})
}
fields := []*model.PropertyField{}
@@ -125,8 +125,8 @@ func (s *SqlPropertyValueStore) SearchPropertyValues(opts model.PropertyValueSea
builder = builder.Where(sq.Eq{"TargetType": opts.TargetType})
}
if opts.TargetID != "" {
builder = builder.Where(sq.Eq{"TargetID": opts.TargetID})
if len(opts.TargetIDs) > 0 {
builder = builder.Where(sq.Eq{"TargetID": opts.TargetIDs})
}
if opts.FieldID != "" {
@@ -790,10 +790,12 @@ func testSearchPropertyFields(t *testing.T, _ request.CTX, ss store.Store) {
TargetType: "test_type",
}
targetID2 := model.NewId()
field4 := &model.PropertyField{
GroupID: groupID,
Name: "Field 4",
Type: model.PropertyFieldTypeText,
TargetID: targetID2,
TargetType: "test_type",
}
@@ -847,8 +849,8 @@ func testSearchPropertyFields(t *testing.T, _ request.CTX, ss store.Store) {
{
name: "filter by target_id",
opts: model.PropertyFieldSearchOpts{
TargetID: targetID,
PerPage: 10,
TargetIDs: []string{targetID},
PerPage: 10,
},
expectedIDs: []string{field1.ID, field2.ID},
},
@@ -874,6 +876,32 @@ func testSearchPropertyFields(t *testing.T, _ request.CTX, ss store.Store) {
},
expectedIDs: []string{field4.ID},
},
{
name: "filter by multiple target_ids",
opts: model.PropertyFieldSearchOpts{
TargetIDs: []string{targetID, targetID2},
PerPage: 10,
},
expectedIDs: []string{field1.ID, field2.ID},
},
{
name: "filter by multiple target_ids including deleted",
opts: model.PropertyFieldSearchOpts{
TargetIDs: []string{targetID, targetID2},
IncludeDeleted: true,
PerPage: 10,
},
expectedIDs: []string{field1.ID, field2.ID, field4.ID},
},
{
name: "filter by multiple target_ids with group filter",
opts: model.PropertyFieldSearchOpts{
GroupID: groupID,
TargetIDs: []string{targetID, targetID2},
PerPage: 10,
},
expectedIDs: []string{field1.ID, field2.ID},
},
}
for _, tc := range tests {
@@ -622,8 +622,8 @@ func testUpsertPropertyValue(t *testing.T, _ request.CTX, ss store.Store) {
// Verify the invalid value was not inserted
results, err := ss.PropertyValue().SearchPropertyValues(model.PropertyValueSearchOpts{
TargetID: invalidValue.TargetID,
PerPage: 10,
TargetIDs: []string{invalidValue.TargetID},
PerPage: 10,
})
require.NoError(t, err)
require.Empty(t, results)
@@ -811,17 +811,17 @@ func testSearchPropertyValues(t *testing.T, _ request.CTX, ss store.Store) {
{
name: "filter by target_id",
opts: model.PropertyValueSearchOpts{
TargetID: targetID,
PerPage: 10,
TargetIDs: []string{targetID},
PerPage: 10,
},
expectedIDs: []string{value1.ID, value2.ID},
},
{
name: "filter by group_id and target_id",
opts: model.PropertyValueSearchOpts{
GroupID: groupID,
TargetID: targetID,
PerPage: 10,
GroupID: groupID,
TargetIDs: []string{targetID},
PerPage: 10,
},
expectedIDs: []string{value1.ID, value2.ID},
},
@@ -862,6 +862,23 @@ func testSearchPropertyValues(t *testing.T, _ request.CTX, ss store.Store) {
},
expectedIDs: []string{value2.ID},
},
{
name: "filter by multiple target_ids",
opts: model.PropertyValueSearchOpts{
TargetIDs: []string{targetID, value4.TargetID},
PerPage: 10,
},
expectedIDs: []string{value1.ID, value2.ID},
},
{
name: "filter by multiple target_ids with group filter",
opts: model.PropertyValueSearchOpts{
GroupID: groupID,
TargetIDs: []string{targetID, value4.TargetID},
PerPage: 10,
},
expectedIDs: []string{value1.ID, value2.ID},
},
}
for _, tc := range tests {
+1 -1
View File
@@ -178,7 +178,7 @@ func (p PropertyFieldSearchCursor) IsValid() error {
type PropertyFieldSearchOpts struct {
GroupID string
TargetType string
TargetID string
TargetIDs []string
IncludeDeleted bool
Cursor PropertyFieldSearchCursor
PerPage int
+1 -1
View File
@@ -92,7 +92,7 @@ func (p PropertyValueSearchCursor) IsValid() error {
type PropertyValueSearchOpts struct {
GroupID string
TargetType string
TargetID string
TargetIDs []string
FieldID string
IncludeDeleted bool
Cursor PropertyValueSearchCursor
+4 -4
View File
@@ -1448,8 +1448,8 @@ type API interface {
// SearchPropertyFields searches for property fields with filtering options.
//
// @tag PropertyField
// Minimum server version: 10.10
SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)
// Minimum server version: 11.0
SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)
// CountPropertyFields counts property fields for a group.
//
@@ -1502,8 +1502,8 @@ type API interface {
// SearchPropertyValues searches for property values with filtering options.
//
// @tag PropertyValue
// Minimum server version: 10.10
SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)
// Minimum server version: 11.0
SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)
// RegisterPropertyGroup registers a new property group.
//
@@ -1534,9 +1534,9 @@ func (api *apiTimerLayer) DeletePropertyField(groupID, fieldID string) error {
return _returnsA
}
func (api *apiTimerLayer) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
func (api *apiTimerLayer) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.SearchPropertyFields(groupID, targetID, opts)
_returnsA, _returnsB := api.apiImpl.SearchPropertyFields(groupID, opts)
api.recordTime(startTime, "SearchPropertyFields", _returnsB == nil)
return _returnsA, _returnsB
}
@@ -1597,9 +1597,9 @@ func (api *apiTimerLayer) DeletePropertyValue(groupID, valueID string) error {
return _returnsA
}
func (api *apiTimerLayer) SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
func (api *apiTimerLayer) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.SearchPropertyValues(groupID, targetID, opts)
_returnsA, _returnsB := api.apiImpl.SearchPropertyValues(groupID, opts)
api.recordTime(startTime, "SearchPropertyValues", _returnsB == nil)
return _returnsA, _returnsB
}
+10 -12
View File
@@ -7359,8 +7359,7 @@ func (s *apiRPCServer) DeletePropertyField(args *Z_DeletePropertyFieldArgs, retu
type Z_SearchPropertyFieldsArgs struct {
A string
B string
C model.PropertyFieldSearchOpts
B model.PropertyFieldSearchOpts
}
type Z_SearchPropertyFieldsReturns struct {
@@ -7368,8 +7367,8 @@ type Z_SearchPropertyFieldsReturns struct {
B error
}
func (g *apiRPCClient) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
_args := &Z_SearchPropertyFieldsArgs{groupID, targetID, opts}
func (g *apiRPCClient) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
_args := &Z_SearchPropertyFieldsArgs{groupID, opts}
_returns := &Z_SearchPropertyFieldsReturns{}
if err := g.client.Call("Plugin.SearchPropertyFields", _args, _returns); err != nil {
log.Printf("RPC call to SearchPropertyFields API failed: %s", err.Error())
@@ -7379,9 +7378,9 @@ func (g *apiRPCClient) SearchPropertyFields(groupID, targetID string, opts model
func (s *apiRPCServer) SearchPropertyFields(args *Z_SearchPropertyFieldsArgs, returns *Z_SearchPropertyFieldsReturns) error {
if hook, ok := s.impl.(interface {
SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)
SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)
}); ok {
returns.A, returns.B = hook.SearchPropertyFields(args.A, args.B, args.C)
returns.A, returns.B = hook.SearchPropertyFields(args.A, args.B)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API SearchPropertyFields called but not implemented."))
@@ -7638,8 +7637,7 @@ func (s *apiRPCServer) DeletePropertyValue(args *Z_DeletePropertyValueArgs, retu
type Z_SearchPropertyValuesArgs struct {
A string
B string
C model.PropertyValueSearchOpts
B model.PropertyValueSearchOpts
}
type Z_SearchPropertyValuesReturns struct {
@@ -7647,8 +7645,8 @@ type Z_SearchPropertyValuesReturns struct {
B error
}
func (g *apiRPCClient) SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
_args := &Z_SearchPropertyValuesArgs{groupID, targetID, opts}
func (g *apiRPCClient) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
_args := &Z_SearchPropertyValuesArgs{groupID, opts}
_returns := &Z_SearchPropertyValuesReturns{}
if err := g.client.Call("Plugin.SearchPropertyValues", _args, _returns); err != nil {
log.Printf("RPC call to SearchPropertyValues API failed: %s", err.Error())
@@ -7658,9 +7656,9 @@ func (g *apiRPCClient) SearchPropertyValues(groupID, targetID string, opts model
func (s *apiRPCServer) SearchPropertyValues(args *Z_SearchPropertyValuesArgs, returns *Z_SearchPropertyValuesReturns) error {
if hook, ok := s.impl.(interface {
SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)
SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)
}); ok {
returns.A, returns.B = hook.SearchPropertyValues(args.A, args.B, args.C)
returns.A, returns.B = hook.SearchPropertyValues(args.A, args.B)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API SearchPropertyValues called but not implemented."))
+18 -18
View File
@@ -5019,9 +5019,9 @@ func (_m *API) SearchPostsInTeamForUser(teamID string, userID string, searchPara
return r0, r1
}
// SearchPropertyFields provides a mock function with given fields: groupID, targetID, opts
func (_m *API) SearchPropertyFields(groupID string, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
ret := _m.Called(groupID, targetID, opts)
// SearchPropertyFields provides a mock function with given fields: groupID, opts
func (_m *API) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
ret := _m.Called(groupID, opts)
if len(ret) == 0 {
panic("no return value specified for SearchPropertyFields")
@@ -5029,19 +5029,19 @@ func (_m *API) SearchPropertyFields(groupID string, targetID string, opts model.
var r0 []*model.PropertyField
var r1 error
if rf, ok := ret.Get(0).(func(string, string, model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)); ok {
return rf(groupID, targetID, opts)
if rf, ok := ret.Get(0).(func(string, model.PropertyFieldSearchOpts) ([]*model.PropertyField, error)); ok {
return rf(groupID, opts)
}
if rf, ok := ret.Get(0).(func(string, string, model.PropertyFieldSearchOpts) []*model.PropertyField); ok {
r0 = rf(groupID, targetID, opts)
if rf, ok := ret.Get(0).(func(string, model.PropertyFieldSearchOpts) []*model.PropertyField); ok {
r0 = rf(groupID, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.PropertyField)
}
}
if rf, ok := ret.Get(1).(func(string, string, model.PropertyFieldSearchOpts) error); ok {
r1 = rf(groupID, targetID, opts)
if rf, ok := ret.Get(1).(func(string, model.PropertyFieldSearchOpts) error); ok {
r1 = rf(groupID, opts)
} else {
r1 = ret.Error(1)
}
@@ -5049,9 +5049,9 @@ func (_m *API) SearchPropertyFields(groupID string, targetID string, opts model.
return r0, r1
}
// SearchPropertyValues provides a mock function with given fields: groupID, targetID, opts
func (_m *API) SearchPropertyValues(groupID string, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
ret := _m.Called(groupID, targetID, opts)
// SearchPropertyValues provides a mock function with given fields: groupID, opts
func (_m *API) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
ret := _m.Called(groupID, opts)
if len(ret) == 0 {
panic("no return value specified for SearchPropertyValues")
@@ -5059,19 +5059,19 @@ func (_m *API) SearchPropertyValues(groupID string, targetID string, opts model.
var r0 []*model.PropertyValue
var r1 error
if rf, ok := ret.Get(0).(func(string, string, model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)); ok {
return rf(groupID, targetID, opts)
if rf, ok := ret.Get(0).(func(string, model.PropertyValueSearchOpts) ([]*model.PropertyValue, error)); ok {
return rf(groupID, opts)
}
if rf, ok := ret.Get(0).(func(string, string, model.PropertyValueSearchOpts) []*model.PropertyValue); ok {
r0 = rf(groupID, targetID, opts)
if rf, ok := ret.Get(0).(func(string, model.PropertyValueSearchOpts) []*model.PropertyValue); ok {
r0 = rf(groupID, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.PropertyValue)
}
}
if rf, ok := ret.Get(1).(func(string, string, model.PropertyValueSearchOpts) error); ok {
r1 = rf(groupID, targetID, opts)
if rf, ok := ret.Get(1).(func(string, model.PropertyValueSearchOpts) error); ok {
r1 = rf(groupID, opts)
} else {
r1 = ret.Error(1)
}
+6 -6
View File
@@ -47,9 +47,9 @@ func (p *PropertyService) DeletePropertyField(groupID, fieldID string) error {
// SearchPropertyFields searches for property fields with filtering options.
//
// Minimum server version: 10.10
func (p *PropertyService) SearchPropertyFields(groupID, targetID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
return p.api.SearchPropertyFields(groupID, targetID, opts)
// Minimum server version: 11.0
func (p *PropertyService) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
return p.api.SearchPropertyFields(groupID, opts)
}
// CountPropertyFields counts property fields for a group.
@@ -110,9 +110,9 @@ func (p *PropertyService) DeletePropertyValue(groupID, valueID string) error {
// SearchPropertyValues searches for property values with filtering options.
//
// Minimum server version: 10.10
func (p *PropertyService) SearchPropertyValues(groupID, targetID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
return p.api.SearchPropertyValues(groupID, targetID, opts)
// Minimum server version: 11.0
func (p *PropertyService) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
return p.api.SearchPropertyValues(groupID, opts)
}
// RegisterPropertyGroup registers a new property group.
+8 -6
View File
@@ -143,7 +143,8 @@ func TestPropertyFieldAPI(t *testing.T) {
// Mock the API call
opts := model.PropertyFieldSearchOpts{
PerPage: 10,
PerPage: 10,
TargetIDs: []string{"target1"},
}
fields := []*model.PropertyField{
{
@@ -159,13 +160,13 @@ func TestPropertyFieldAPI(t *testing.T) {
Type: model.PropertyFieldTypeSelect,
},
}
api.On("SearchPropertyFields", "group1", "target1", opts).Return(fields, nil)
api.On("SearchPropertyFields", "group1", opts).Return(fields, nil)
// Create the client
client := NewClient(api, nil)
// Call the method
result, err := client.Property.SearchPropertyFields("group1", "target1", opts)
result, err := client.Property.SearchPropertyFields("group1", opts)
// Verify the results
require.NoError(t, err)
@@ -420,7 +421,8 @@ func TestPropertyValueAPI(t *testing.T) {
// Mock the API call
opts := model.PropertyValueSearchOpts{
PerPage: 10,
PerPage: 10,
TargetIDs: []string{"target1"},
}
values := []*model.PropertyValue{
{
@@ -440,13 +442,13 @@ func TestPropertyValueAPI(t *testing.T) {
Value: json.RawMessage(`"Test Value 2"`),
},
}
api.On("SearchPropertyValues", "group1", "target1", opts).Return(values, nil)
api.On("SearchPropertyValues", "group1", opts).Return(values, nil)
// Create the client
client := NewClient(api, nil)
// Call the method
result, err := client.Property.SearchPropertyValues("group1", "target1", opts)
result, err := client.Property.SearchPropertyValues("group1", opts)
// Verify the results
require.NoError(t, err)