Skip to content

Support shadowed properties #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
packages/
/src/packages
.vs/
bin/
obj/
/src/WebApiTestApplication/Scripts/CompiledTypeScript/
*.csproj.user
src/WebApiTestApplication/Scripts/typings/
src/WebApiTestApplication/Scripts/CompiledTypeScript/
*.DotSettings.user
*.nupkg
35 changes: 27 additions & 8 deletions src/WebApiTestApplication/Controllers/TestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public class AnotherClass
public string[] List { get; set; }
}

public class DerivedClassWithShadowedProperty : AnotherClass
{
public new string Number { get; set; }
}

public class DerivedClassWithAnotherShadowedProperty : DerivedClassWithShadowedProperty
{
public new int Number { get; set; }
}

[RoutePrefix("api/Test/{hole}/actions")]
public class TestController : ApiController
{
Expand All @@ -83,14 +93,7 @@ public string Get([EncryptedInt] int id, string hole)
{
return $"value {hole} / {id}";
}

//[HttpGet]
//[Route("getty/{id:encryptedInt}")]
//public string Getty(int id, string hole)
//{
// return $"{nameof(Getty)}: value {hole} / {id}";
//}


[HttpGet]
[Route("getSomething/{id}/ha")]
public string GetSomething(string hole, int id, DummyEnum y = DummyEnum.Bye)
Expand All @@ -113,6 +116,22 @@ public string Post(string hole, DummyClass value)
return $"thanks for the {valueJson} in the {hole}";
}

[HttpPost]
[Route("derived")]
public string Post(string hole, DerivedClassWithShadowedProperty value)
{
var valueJson = JsonConvert.SerializeObject(value);
return $"thanks for the {valueJson} in the {hole}";
}

[HttpPost]
[Route("derivedAgain")]
public string Post(string hole, DerivedClassWithAnotherShadowedProperty value)
{
var valueJson = JsonConvert.SerializeObject(value);
return $"thanks for the {valueJson} in the {hole}";
}

[HttpPut]
[Route("{id}")]
public string Put(int id, [FromBody]string value, string hole)
Expand Down
58 changes: 30 additions & 28 deletions src/WebApiTestApplication/Scripts/Angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,72 +25,74 @@ class TestController {
megaClass.something = 7;

endpointsService.Test.Get({
hole: "cap"
})
hole: "cap"
})
.call()
.then(responsePrinter);

endpointsService.Test.Get1({
hole: "cap",
id: "777"
})
hole: "cap",
id: "777"
})
.call()
.then(responsePrinter);

endpointsService.Test.GetSomething({
hole: "cap",
id: 7,
y: Enums.DummyEnum.Bye
})
hole: "cap",
id: 7,
y: Enums.DummyEnum.Bye
})
.call()
.then(responsePrinter);

endpointsService.Test.GetSomethingElse({
hole: "cap",
id: 3,
y: dummyClass
})
hole: "cap",
id: 3,
y: dummyClass
})
.call()
.then(responsePrinter);

endpointsService.Test.Post({
hole: "cap"
})
hole: "cap"
})
.call(null)
.then(responsePrinter);

endpointsService.Test.Post({
hole: "cap"
})
hole: "cap"
})
.call(dummyClass)
.then(responsePrinter);

endpointsService.Test.Put({
hole: "cap",
id: 5
})
hole: "cap",
id: 5
})
.call("b")
.then(responsePrinter);

endpointsService.Test.Delete({
hole: "cap",
id: 2
})
hole: "cap",
id: 2
})
.call()
.then(responsePrinter);

endpointsService.Thingy.Get({
id: 1,
x: "blah",
c: megaClass
})
id: 1,
x: "blah",
c: megaClass
})
.call()
.then(responsePrinter);

endpointsService.Thingy.Post()
.call({
something: 7,
number: 1
number: 1,
name: null,
list: null
})
.then(responsePrinter);
}
Expand Down
46 changes: 44 additions & 2 deletions src/WebApiTestApplication/Scripts/Endpoints/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Endpoints {
}

if (_.isArray(value)) {
var encodedItems = _.map(value, (item) => encodeURIComponent(item.toString()));
parameters.push(`${key}=${encodedItems.join(',')}`);
var encodedItems = _.map(value, (item: any) => encodeURIComponent(item.toString()));
_(encodedItems).each(item => parameters.push(`${key}=${item}`));
}
else {
parameters.push(`${key}=${encodeURIComponent(value.toString())}`);
Expand Down Expand Up @@ -188,6 +188,48 @@ namespace Endpoints {
}
}

export interface IPost1 {
hole: string;
}

export interface IPost1WithCall extends IPost1, IEndpoint {
call<TView>(value: Interfaces.IDerivedClassWithShadowedProperty): ng.IPromise<TView>;
}

export class Post1 implements IPost1, IEndpoint {
_verb = 'POST';
hole: string;

constructor(args: IPost1) {
this.hole = args != null ? args.hole : null;
}

toString = (): string => {
return `/api/Test/${this.hole}/actions/derived`;
}
}

export interface IPost2 {
hole: string;
}

export interface IPost2WithCall extends IPost2, IEndpoint {
call<TView>(value: Interfaces.IDerivedClassWithAnotherShadowedProperty): ng.IPromise<TView>;
}

export class Post2 implements IPost2, IEndpoint {
_verb = 'POST';
hole: string;

constructor(args: IPost2) {
this.hole = args != null ? args.hole : null;
}

toString = (): string => {
return `/api/Test/${this.hole}/actions/derivedAgain`;
}
}

export interface IPut {
id: number;
hole: string;
Expand Down
18 changes: 18 additions & 0 deletions src/WebApiTestApplication/Scripts/Endpoints/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ namespace Endpoints {
});
},

Post1: (args: Endpoints.Test.IPost1): Endpoints.Test.IPost1WithCall => {
var endpoint = new Endpoints.Test.Post1(args);
return _.extendOwn(endpoint, {
call<TView>(value: Interfaces.IDerivedClassWithShadowedProperty) {
return AngularEndpointsService.call<TView>(this, value != null ? value : null);
}
});
},

Post2: (args: Endpoints.Test.IPost2): Endpoints.Test.IPost2WithCall => {
var endpoint = new Endpoints.Test.Post2(args);
return _.extendOwn(endpoint, {
call<TView>(value: Interfaces.IDerivedClassWithAnotherShadowedProperty) {
return AngularEndpointsService.call<TView>(this, value != null ? value : null);
}
});
},

Put: (args: Endpoints.Test.IPut): Endpoints.Test.IPutWithCall => {
var endpoint = new Endpoints.Test.Put(args);
return _.extendOwn(endpoint, {
Expand Down
Loading