Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
47e7c05
Update README.md
mustaqiimuhar Feb 14, 2018
3e08f94
Initial commit
qhng Feb 23, 2018
fc14739
Add ignores
qhng Feb 23, 2018
be7e4a1
Update ignores
qhng Feb 23, 2018
76dceb0
Remove unwanted tracking
qhng Feb 23, 2018
cd31488
Added run script on mac since no md5sum
Feb 23, 2018
8680fdd
Changed to docker-compose
qhng Feb 23, 2018
f5daf79
Updated connection strings
qhng Feb 23, 2018
6819207
Add docker options
qhng Feb 23, 2018
80b7ff7
Remove unused sql express database
qhng Feb 23, 2018
ec30694
Add VS Code debug configs
qhng Feb 23, 2018
7e93653
Merge pull request #1 from CS5331-G2/ops-docker-dotnetcore
zzzikai Feb 23, 2018
a660387
Add API controller
qhng Feb 23, 2018
3fff2d7
Merge pull request #2 from CS5331-G2/ops-docker-dotnetcore
qhng Feb 23, 2018
fc1f1da
Remove unused controller
qhng Feb 24, 2018
632ecb5
Update run.sh
qhng Feb 24, 2018
75df421
Logging configuration
qhng Feb 24, 2018
f67f6b2
More logging configuration
qhng Feb 24, 2018
bafa927
Set up internal proxy.
qhng Feb 24, 2018
08c2f80
Added Web API endpoints
qhng Feb 24, 2018
c7dcf19
Fix incorrect formatting
qhng Feb 24, 2018
915aa5a
Add API skeleton for Diary
qhng Feb 24, 2018
2a7affa
sed to remove \r for windows platforms.
qhng Feb 24, 2018
c0124b1
Merge pull request #3 from CS5331-G2/qh-api-skeleton
yeejfe Feb 24, 2018
b29ceb6
Refactor diary model
qhng Feb 27, 2018
87f3853
Add diary entity [needs image recreation]
qhng Feb 27, 2018
a23eda6
Add required fields for model validation
qhng Feb 27, 2018
7baa3b1
Add uuidv4 token [needs image recreation]
qhng Feb 27, 2018
fda5177
Expose 1433 for db image
qhng Feb 27, 2018
b4a815c
Add missing property
qhng Feb 27, 2018
823bcbb
Add CRUD for diary
qhng Feb 27, 2018
b061416
Add stub for getting uuidv4Tokens
qhng Feb 27, 2018
82bc9bb
Fix Diary mapped to non-existent table in EF
qhng Feb 27, 2018
1a2847a
Fix proxy handler not copying body
qhng Feb 27, 2018
2207059
Merge pull request #4 from CS5331-G2/qh-api-skeleton
qhng Feb 27, 2018
016521d
Fix duplicate deserialization properties
qhng Feb 27, 2018
fd861e3
Merge pull request #5 from CS5331-G2/qh-api-skeleton
qhng Feb 27, 2018
d3eb1eb
API doc update
qhng Feb 28, 2018
0a3af5c
Update API with new specs
qhng Feb 28, 2018
3e510c2
Fix missing tags needed for JSON deserialization via the request body
qhng Feb 28, 2018
00fe8db
Add connection strings for debug environment
qhng Feb 28, 2018
a0c272b
Enable CORS for localhost
qhng Feb 28, 2018
4695aac
Merge pull request #6 from CS5331-G2/qh-api-skeleton
qhng Feb 28, 2018
dfdd6c4
Added Authentication and Register to UserController
zzzikai Mar 1, 2018
922775a
Added Retrieve User Information
zzzikai Mar 1, 2018
340cb87
Codes
zzzikai Mar 3, 2018
429cb47
Tokens
zzzikai Mar 3, 2018
e5bcb72
More changes
zzzikai Mar 3, 2018
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
out/
bin/
obj/

46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/diary.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/diary.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
175 changes: 175 additions & 0 deletions ApiControllers/DiaryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using diary.ApiModels;
using diary.ApiModels.DiaryController;
using diary.Data;
using diary.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace diary.Controllers
{
[Route("api/[controller]")]
public class DiaryController : Controller
{
private readonly ApplicationDbContext _dbContext;

public DiaryController(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
}

// GET /api/diary OR :8080/diary
[HttpGet]
public RetrieveDiaryResponse Get()
{
return new RetrieveDiaryResponse()
{
Status = true,
Result = _dbContext.Diaries.Where(p => p.IsPublic == true).ToList()
};
}

// POST /api/diary OR :8080/diary
[HttpPost]
public RetrieveDiaryResponse Post([FromBody]RetrieveDiaryRequest retrieveRequest)
{
if (ModelState.IsValid)
{
ApplicationUser user = _dbContext.GetUserWithToken(retrieveRequest.Token);
if (user != null)
{
return new RetrieveDiaryResponse()
{
Status = true,
Result = _dbContext.Diaries.Where(p => p.Author == user.UserName).ToList()
};
}
}

return new RetrieveDiaryResponse()
{
Status = false,
Error = "Invalid authentication token."
};
}

// POST /api/diary/create OR :8080/diary/create
[HttpPost]
[Route("create")]
public ApiResponseModel Create([FromBody]CreateDiaryRequest createRequest)
{
if (ModelState.IsValid)
{
ApplicationUser user = _dbContext.GetUserWithToken(createRequest.Token);
if (user != null)
{

Diary newDiary = new Diary()
{
Title = createRequest.Title,
Author = user.UserName,
PublishDate = DateTime.Now,
IsPublic = createRequest.IsPublic,
Text = createRequest.Text
};
_dbContext.Add(newDiary);
if (_dbContext.SaveChanges() > 0)
{
Response.StatusCode = 201;
return new ApiResponseModel()
{
Status = true,
Result = new CreateDiaryResultModel()
{
Id = newDiary.Id.ToString()
}
};
}
}
}

return new ApiResponseModel()
{
Status = false,
Error = "Invalid authentication token."
};
}

// POST /api/diary/delete OR :8080/diary/delete
[HttpPost]
[Route("delete")]
public DeleteDiaryResponse Delete([FromBody]DeleteDiaryRequest deleteRequest)
{
int deleteId = 0;
if (ModelState.IsValid && int.TryParse(deleteRequest.Id, out deleteId))
{
ApplicationUser user = _dbContext.GetUserWithToken(deleteRequest.Token);
if (user != null)
{
IQueryable<Diary> result = _dbContext.Diaries.Where(
p => p.Author == user.UserName &&
p.Id == deleteId);
if (result.Count() == 1)
{
Diary toDelete = result.First();
_dbContext.Diaries.Remove(toDelete);
if (_dbContext.SaveChanges() > 0)
{
return new DeleteDiaryResponse()
{
Status = true
};
}
}
}
}

return new DeleteDiaryResponse()
{
Status = false,
Error = "Invalid authentication token."
};
}

// POST /api/diary/permission OR :8080/diary/permission
[HttpPost]
[Route("permission")]
public AdjustDiaryPermissionResponse Permission([FromBody]AdjustDiaryPermissionRequest adjustRequest)
{
int adjustId = 0;
if (ModelState.IsValid && int.TryParse(adjustRequest.Id, out adjustId))
{
ApplicationUser user = _dbContext.GetUserWithToken(adjustRequest.Token);
if (user != null)
{
IQueryable<Diary> result = _dbContext.Diaries.Where(
p => p.Author == user.UserName &&
p.Id == adjustId);

if (result.Count() == 1)
{
Diary toAdjust = result.First();
toAdjust.IsPublic = adjustRequest.IsPublic;
_dbContext.Diaries.Update(toAdjust);
if (_dbContext.SaveChanges() > 0)
{
return new AdjustDiaryPermissionResponse()
{
Status = true
};
}
}
}
}

return new AdjustDiaryPermissionResponse()
{
Status = false,
Error = "Invalid authentication token."
};
}
}
}
47 changes: 47 additions & 0 deletions ApiControllers/MetaController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using diary.ApiModels;
using diary.ApiModels.MetaController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace diary.Controllers
{
[Route("api/[controller]")]
public class MetaController : Controller
{
private static readonly string[] MEMBERS =
{
"Muhammad Mustaqiim Bin Muhar",
"Ng Qing Hua",
"Ng Zi Kai",
"Yee Jian Feng, Eric"
};


// GET /api/meta/heartbeat OR :8080/meta/heartbeat
[HttpGet]
[Route("heartbeat")]
public ApiResponseModel Heartbeat()
{
return new ApiResponseModel()
{
Status = true
};
}

// GET /api/meta/members OR :8080/meta/members
[HttpGet]
[Route("members")]
public MembersResponse Members()
{
return new MembersResponse()
{
Status = true,
Result = MEMBERS.ToList()
};
}
}
}
40 changes: 40 additions & 0 deletions ApiControllers/RootController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using diary.ApiModels.RootController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace diary.Controllers
{
[Route("api/[controller]")]
public class RootController : Controller
{
private static readonly string[] IMPLEMENTED_ENDPOINTS =
{
"/",
"/meta/heartbeat",
"/meta/members",
"/users/register",
"/users/authenticate",
"/users/expire",
"/users",
"/diary",
"/diary/create",
"/diary/delete",
"/diary/permission"
};

// GET /api/root OR GET :8080/
[HttpGet]
public ImplementedEndpointsResponse Get()
{
return new ImplementedEndpointsResponse()
{
Status = true,
Result = IMPLEMENTED_ENDPOINTS.ToList()
};
}
}
}
Loading