Skip to content

Commit 60e4af2

Browse files
author
Nitin Sawant
committed
re-written api in .net 8, updated addon to add "add proposal functionality"
1 parent 80dc482 commit 60e4af2

67 files changed

Lines changed: 88 additions & 34746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vs/ProposalAPI/config/applicationhost.config

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
44
IIS configuration sections.
@@ -189,8 +189,7 @@
189189
<virtualDirectory path="/" physicalPath="D:\Projects\Nitin\UpWorkify\ProposalAPI.Core" />
190190
</application>
191191
<bindings>
192-
<binding protocol="http" bindingInformation="*:59808:localhost" />
193-
<binding protocol="https" bindingInformation="*:44312:localhost" />
192+
<binding protocol="http" bindingInformation="*:5000:localhost" />
194193
</bindings>
195194
</site>
196195
<siteDefaults>

.vs/ProposalAPI/v17/.suo

-31.5 KB
Binary file not shown.

.vs/ProposalAPI/v17/DocumentLayout.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
{
1919
"$type": "Bookmark",
2020
"Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
21-
},
22-
{
23-
"$type": "Bookmark",
24-
"Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
2521
}
2622
]
2723
}

.vs/VSWorkspaceState.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"ExpandedNodes": [
3-
""
3+
"",
4+
"\\ProposalAPI"
45
],
6+
"SelectedNode": "\\ProposalAPI.sln",
57
"PreviewInSolutionExplorer": false
68
}

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

ProposalAPI.Core/Content/Proposals/first.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

ProposalAPI.Core/Core/AppJsonSerializerContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace ProposalAPI.Core
55
{
66
[JsonSerializable(typeof(ModifyProposalModel[]))]
7+
[JsonSerializable(typeof(string[]))]
78
internal partial class AppJsonSerializerContext : JsonSerializerContext
89
{
910

ProposalAPI.Core/Program.cs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111
{
1212
options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
1313
});
14+
builder.Services.AddCors();
1415

1516
var app = builder.Build();
17+
app.UseCors(policy =>
18+
{
19+
policy.AllowAnyHeader();
20+
policy.AllowAnyMethod();
21+
policy.AllowAnyOrigin();
22+
});
1623

1724
string ProposalsDirectory = Environment.CurrentDirectory + "\\" + @"Content\Proposals\";
1825

19-
Func<Exception, IResult> ErrorDetails = (ex) => {
26+
Func<Exception, IResult> ErrorDetails = (ex) =>
27+
{
2028
return Results.Problem(new Microsoft.AspNetCore.Mvc.ProblemDetails()
2129
{
2230
Title = "Unexpected error occurred",
@@ -26,14 +34,15 @@
2634
};
2735

2836
var proposalApi = app.MapGroup("/proposals");
29-
proposalApi.MapGet("/", () =>{
37+
proposalApi.MapGet("/", () =>
38+
{
3039
try
3140
{
3241
DirectoryInfo dir = new DirectoryInfo(ProposalsDirectory);
3342
var files = dir.GetFiles("*.txt").Select(x => x.Name).ToList();
3443
var data = files.Select(x => new
3544
{
36-
index = int.Parse(new String(x.Where(Char.IsDigit).ToArray())),
45+
index = int.Parse(new String(x.Where(Char.IsDigit).Count() == 0 ? new char[] { '0' } : x.Where(Char.IsDigit).ToArray())),
3746
value = x
3847
}).OrderByDescending(x => x.index).Select(x => x.value).ToArray();
3948

@@ -45,19 +54,21 @@
4554
}
4655
});
4756

48-
proposalApi.MapGet("/{fileName}", (int fileName) => {
49-
try
50-
{
51-
string content = File.ReadAllText(ProposalsDirectory + fileName);
52-
return Results.Ok(content);
53-
}
54-
catch (Exception ex)
55-
{
56-
return ErrorDetails(ex);
57-
}
58-
});
59-
60-
proposalApi.MapPost("/", (string fileName) => {
57+
//proposalApi.MapGet("/{fileName}", (string fileName) =>
58+
//{
59+
// try
60+
// {
61+
// string content = File.ReadAllText(ProposalsDirectory + fileName);
62+
// return Results.Ok(content);
63+
// }
64+
// catch (Exception ex)
65+
// {
66+
// return ErrorDetails(ex);
67+
// }
68+
//});
69+
70+
proposalApi.MapPost("/", (string fileName) =>
71+
{
6172
try
6273
{
6374
string content = File.ReadAllText(ProposalsDirectory + fileName);
@@ -69,10 +80,11 @@
6980
}
7081
});
7182

72-
proposalApi.MapPut("/", (ModifyProposalModel model) => {
83+
proposalApi.MapPut("/", (ModifyProposalModel model) =>
84+
{
7385
try
7486
{
75-
string filePath = ProposalsDirectory + model.fileName;
87+
string filePath = ProposalsDirectory + (model.fileName.ToLower().EndsWith(".txt")?model.fileName:model.fileName + ".txt");
7688

7789
if (File.Exists(filePath))
7890
{
@@ -93,7 +105,8 @@
93105
}
94106
});
95107

96-
proposalApi.MapDelete("/", (ModifyProposalModel model) => {
108+
proposalApi.MapDelete("/", (ModifyProposalModel model) =>
109+
{
97110
try
98111
{
99112
File.Delete(ProposalsDirectory + model.fileName);

ProposalAPI.Core/ProposalAPI.Core.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
4+
<ActiveDebugProfile>http</ActiveDebugProfile>
55
</PropertyGroup>
66
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
77
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>

ProposalAPI.Core/ProposalAPI.Core.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@ProposalAPI.Core_HostAddress = http://localhost:44312
1+
@ProposalAPI.Core_HostAddress = http://localhost:5000/
22

33
GET {{ProposalAPI.Core_HostAddress}}/proposals/
44
Accept: application/json

0 commit comments

Comments
 (0)