Git Product home page Git Product logo

dart-ref-repo's Introduction

dart-ref-repo

Servicestack Service implementation to reproduce issue with dart-ref.

generated service reference: foos.dtos.dart

Using JsonServiceClient to get data from backend:

  var client = new JsonServiceClient("http://localhost:5000");
  var response = await client.get(new GetFoos());

Results in this exception (screenshot taken from flutter app on ios simulator): exception

The call to createInstance() is in json_converters.dart where typeInfo is null.

We wrap retrieving lists in a PagedResult which leads to this problem. Using ts-ref/typescripts JsonServiceClient works perfectly fine in our other aurelia SPAs with these dtos and the same backend.

Backend:

    public class FooService : Service
    {
        public PagedResult<FooListDto> Get(GetFoos request)
        {
            var list = new List<FooListDto>
            {
                new FooListDto {Id = "claims/1-A"},
            };

            return new PagedResult<FooListDto>(list, 1, 1, 1);
        }
    }
    
    [Route("/foos", "GET")]
    public class GetFoos : PagedAndOrderedRequest, IReturn<PagedResult<FooListDto>>
    {
    }

    public abstract class PagedAndOrderedRequest : PagedRequest
    {
        public string OrderBy { get; set; }
    }

    public abstract class PagedRequest
    {
        public int Page { get; set; }
        public int PageSize { get; set; }

        protected PagedRequest()
        {
            Page = 1;
            PageSize = 15;
        }
    }

    public class PagedResult<T>
    {
        public int Page { get; set; }
        public int PageSize { get; set; }
        public long TotalResults { get; set; }

        public List<T> Results { get; private set; }

        public PagedResult()
        {
            Results = new List<T>();
        }

        public PagedResult(List<T> results, int page, int pageSize, long totalResults)
        {
            if (results == null)
            {
                Results = new List<T>();
            }
            else
            {
                Results = results;
            }

            Page = page;
            PageSize = pageSize;
            TotalResults = totalResults;
        }

        public PagedResult(List<T> results, PagedRequest request, long totalResults)
            : this(results, request.Page, request.PageSize, totalResults)
        {
        }
    }
    
    public class FooListDto
    {
        public string Id { get; set; }
    }
    

dart-ref-repo's People

Contributors

tobiaszuercher avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.