Skip to content

Parameters Support for List And Map - #196

Closed
anandsubbu007 wants to merge 5 commits into
serverpod:mainfrom
anandsubbu007:Parameters-Updates
Closed

anandsubbu007 wants to merge 5 commits into
serverpod:mainfrom
anandsubbu007:Parameters-Updates

Conversation

@anandsubbu007

Copy link
Copy Markdown

Now we can able to pass List of String, double, int, DateTime, model (that generated), bool as parameter in endpoint

Map<String, dynamic> parameter can also be passed as an argument.

with return of list

@anandsubbu007

Copy link
Copy Markdown
Author

Client Side

      final strTst = await client.userFunc.testListOfString(['Hi', 'There']);
      print(strTst);
      final bolTst = await client.userFunc.testListOfbool([true, false]);
      print(bolTst);
      final dobTst = await client.userFunc.testListOfdouble([1, 2, 3.3]);
      print(dobTst);
      final dynamTst =
          await client.userFunc.testListOfdynamic(['String txt', 123]);
      print(dynamTst);
      final mapTst = await client.userFunc
          .testListOfmapDynamic({'Name': 'Anand', "Age": 24});
      print(mapTst);
      final modelTst = await client.userFunc.testListOfSimpleData([Example(name:'Anand',data: 007 )]);
      print(modelTst);
      final dtTst = await client.userFunc
          .testListOfDateTime([DateTime(2020), DateTime(2020)]);
      print(dtTst);

Server Side Code

  Future<List<String>> testListOfString(
      Session session, List<String> value) async {
    print('Received: $value');
    return value;
  }

  Future<List> testListOfdynamic(Session session, List value) async {
    print('Received: $value');
    return value;
  }

  Future<List<double>> testListOfdouble(
      Session session, List<double> value) async {
    print('Received: $value');
    return value;
  }

  Future<List<DateTime>> testListOfDateTime(
      Session session, List<DateTime> value) async {
    print('Received: $value');
    return value;
  }

  Future<List<bool>> testListOfbool(Session session, List<bool> value) async {
    print('Received: $value');
    return value;
  }

  Future<Map<String, dynamic>> testListOfmapDynamic(
      Session session, Map<String, dynamic> value) async {
    print('Received: $value');
    return value;
  }

  Future<List<BannersClass>> testListOfSimpleData(
      Session session, List<Example> object) async {
    int i = 0;
    for (var e in object) {
      i++;
      e.data = i.toString();
    }
    return object;
  }

@vlidholt

Copy link
Copy Markdown
Collaborator

Before I review this pull request I just wanted to check some general things.

Does it support Maps with any of the Serverpod primitive types (int, bool, double, DateTime, ByteData) both as keys and values? Does it support Serializable as key and value? Are there tests for all of the types?

Currently the tests are failing for the PR. It's possible to run the tests locally before doing a PR by doing util/run_tests (unfortunately may only work on Mac yet).

@ordru ordru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If I am not mistaken, the destination branch should be dev instead of main?

@anandsubbu007

anandsubbu007 commented May 31, 2022 •

Copy link
Copy Markdown
Author

It Supports
List of String, int, DateTime, bool, double, SerializableEntity & dynamic(if within this mentioned types)
For Map
Keys -> String
Values -> String, double, int, bool, DateTime, SerializableEntity (with null support)

I didn't test it with byteData & other key types value in Map

@anandsubbu007

Copy link
Copy Markdown
Author

util/run_tests

Can't able to run Test in my mac

The terminal process "/bin/zsh '--login'" terminated with exit code: 1.

@anandsubbu007

anandsubbu007 commented May 31, 2022 •

Copy link
Copy Markdown
Author

All test passed in my device.
with dart 17 sdk.
Let me know if something wrong

  • Not tested with ByteData

@anandsubbu007
anandsubbu007 requested a review from vlidholt June 3, 2022 05:11
@vlidholt

Copy link
Copy Markdown
Collaborator

I'm closing this as it doesn't support e.g. Map<DateTime, String?> or Map<int, dynamic>. I'm planning a bit of another approach to support these and also any of the supported types as parameters.

In future, make sure to also send requests to the dev branch.

@vlidholt vlidholt closed this Jun 23, 2022
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants