@@ -321,41 +321,47 @@ func (q *fakeQuerier) GetWorkspacesWithFilter(_ context.Context, arg database.Ge
321
321
322
322
workspaces := make ([]database.Workspace , 0 )
323
323
for _ , workspace := range q .workspaces {
324
- if arg .OrganizationID != uuid .Nil && workspace .OrganizationID != arg .OrganizationID {
325
- continue
326
- }
327
324
if arg .OwnerID != uuid .Nil && workspace .OwnerID != arg .OwnerID {
328
325
continue
329
326
}
327
+ if arg .OwnerUsername != "" {
328
+ owner , err := q .GetUserByID (context .Background (), workspace .OwnerID )
329
+ if err == nil && arg .OwnerUsername != owner .Username {
330
+ continue
331
+ }
332
+ }
333
+ if arg .TemplateName != "" {
334
+ templates , err := q .GetTemplatesWithFilter (context .Background (), database.GetTemplatesWithFilterParams {
335
+ ExactName : arg .TemplateName ,
336
+ })
337
+ // Add to later param
338
+ if err == nil {
339
+ for _ , t := range templates {
340
+ arg .TemplateIds = append (arg .TemplateIds , t .ID )
341
+ }
342
+ }
343
+ }
330
344
if ! arg .Deleted && workspace .Deleted {
331
345
continue
332
346
}
333
347
if arg .Name != "" && ! strings .Contains (workspace .Name , arg .Name ) {
334
348
continue
335
349
}
336
- workspaces = append (workspaces , workspace )
337
- }
338
-
339
- return workspaces , nil
340
- }
341
-
342
- func (q * fakeQuerier ) GetWorkspacesByTemplateID (_ context.Context , arg database.GetWorkspacesByTemplateIDParams ) ([]database.Workspace , error ) {
343
- q .mutex .RLock ()
344
- defer q .mutex .RUnlock ()
345
-
346
- workspaces := make ([]database.Workspace , 0 )
347
- for _ , workspace := range q .workspaces {
348
- if workspace .TemplateID .String () != arg .TemplateID .String () {
349
- continue
350
- }
351
- if workspace .Deleted != arg .Deleted {
352
- continue
350
+ if len (arg .TemplateIds ) > 0 {
351
+ match := false
352
+ for _ , id := range arg .TemplateIds {
353
+ if workspace .TemplateID == id {
354
+ match = true
355
+ break
356
+ }
357
+ }
358
+ if ! match {
359
+ continue
360
+ }
353
361
}
354
362
workspaces = append (workspaces , workspace )
355
363
}
356
- if len (workspaces ) == 0 {
357
- return nil , sql .ErrNoRows
358
- }
364
+
359
365
return workspaces , nil
360
366
}
361
367
@@ -641,25 +647,6 @@ func (q *fakeQuerier) GetWorkspaceBuildByWorkspaceIDAndBuildNumber(_ context.Con
641
647
return database.WorkspaceBuild {}, sql .ErrNoRows
642
648
}
643
649
644
- func (q * fakeQuerier ) GetWorkspacesByOrganizationIDs (_ context.Context , req database.GetWorkspacesByOrganizationIDsParams ) ([]database.Workspace , error ) {
645
- q .mutex .RLock ()
646
- defer q .mutex .RUnlock ()
647
-
648
- workspaces := make ([]database.Workspace , 0 )
649
- for _ , workspace := range q .workspaces {
650
- for _ , id := range req .Ids {
651
- if workspace .OrganizationID != id {
652
- continue
653
- }
654
- if workspace .Deleted != req .Deleted {
655
- continue
656
- }
657
- workspaces = append (workspaces , workspace )
658
- }
659
- }
660
- return workspaces , nil
661
- }
662
-
663
650
func (q * fakeQuerier ) GetOrganizations (_ context.Context ) ([]database.Organization , error ) {
664
651
q .mutex .RLock ()
665
652
defer q .mutex .RUnlock ()
@@ -786,6 +773,44 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
786
773
return sql .ErrNoRows
787
774
}
788
775
776
+ func (q * fakeQuerier ) GetTemplatesWithFilter (_ context.Context , arg database.GetTemplatesWithFilterParams ) ([]database.Template , error ) {
777
+ q .mutex .RLock ()
778
+ defer q .mutex .RUnlock ()
779
+
780
+ var templates []database.Template
781
+ for _ , template := range q .templates {
782
+ if template .Deleted != arg .Deleted {
783
+ continue
784
+ }
785
+ if arg .OrganizationID != uuid .Nil && template .OrganizationID != arg .OrganizationID {
786
+ continue
787
+ }
788
+
789
+ if arg .ExactName != "" && ! strings .EqualFold (template .Name , arg .ExactName ) {
790
+ continue
791
+ }
792
+
793
+ if len (arg .Ids ) > 0 {
794
+ match := false
795
+ for _ , id := range arg .Ids {
796
+ if template .ID == id {
797
+ match = true
798
+ break
799
+ }
800
+ }
801
+ if ! match {
802
+ continue
803
+ }
804
+ }
805
+ templates = append (templates , template )
806
+ }
807
+ if len (templates ) > 0 {
808
+ return templates , nil
809
+ }
810
+
811
+ return nil , sql .ErrNoRows
812
+ }
813
+
789
814
func (q * fakeQuerier ) GetTemplateVersionsByTemplateID (_ context.Context , arg database.GetTemplateVersionsByTemplateIDParams ) (version []database.TemplateVersion , err error ) {
790
815
q .mutex .RLock ()
791
816
defer q .mutex .RUnlock ()
@@ -923,45 +948,6 @@ func (q *fakeQuerier) GetParameterValueByScopeAndName(_ context.Context, arg dat
923
948
return database.ParameterValue {}, sql .ErrNoRows
924
949
}
925
950
926
- func (q * fakeQuerier ) GetTemplatesByOrganization (_ context.Context , arg database.GetTemplatesByOrganizationParams ) ([]database.Template , error ) {
927
- q .mutex .RLock ()
928
- defer q .mutex .RUnlock ()
929
-
930
- templates := make ([]database.Template , 0 )
931
- for _ , template := range q .templates {
932
- if template .Deleted != arg .Deleted {
933
- continue
934
- }
935
- if template .OrganizationID != arg .OrganizationID {
936
- continue
937
- }
938
- templates = append (templates , template )
939
- }
940
- if len (templates ) == 0 {
941
- return nil , sql .ErrNoRows
942
- }
943
- return templates , nil
944
- }
945
-
946
- func (q * fakeQuerier ) GetTemplatesByIDs (_ context.Context , ids []uuid.UUID ) ([]database.Template , error ) {
947
- q .mutex .RLock ()
948
- defer q .mutex .RUnlock ()
949
-
950
- templates := make ([]database.Template , 0 )
951
- for _ , template := range q .templates {
952
- for _ , id := range ids {
953
- if template .ID .String () != id .String () {
954
- continue
955
- }
956
- templates = append (templates , template )
957
- }
958
- }
959
- if len (templates ) == 0 {
960
- return nil , sql .ErrNoRows
961
- }
962
- return templates , nil
963
- }
964
-
965
951
func (q * fakeQuerier ) GetOrganizationMemberByUserID (_ context.Context , arg database.GetOrganizationMemberByUserIDParams ) (database.OrganizationMember , error ) {
966
952
q .mutex .RLock ()
967
953
defer q .mutex .RUnlock ()
0 commit comments