diff options
author | crupest <crupest@outlook.com> | 2019-02-18 19:56:13 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-02-18 19:56:13 +0800 |
commit | 1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b (patch) | |
tree | 8e1e2ac2dd6df278f59a97a37e5d374bc2644843 | |
parent | 9756acc50f5f228968cf45d9e73c8dd3b4eacc6a (diff) | |
download | timeline-1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b.tar.gz timeline-1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b.tar.bz2 timeline-1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b.zip |
Add get pat api.
-rw-r--r-- | Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css | 4 | ||||
-rw-r--r-- | Timeline/ClientApp/src/app/todo-list.service.ts | 39 | ||||
-rw-r--r-- | Timeline/Configs/TodoListConfig.cs | 12 | ||||
-rw-r--r-- | Timeline/Controllers/TodoListController.cs | 30 | ||||
-rw-r--r-- | Timeline/Controllers/UserController.cs | 2 | ||||
-rw-r--r-- | Timeline/Startup.cs | 2 |
6 files changed, 74 insertions, 15 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css index 43bd26d8..c17267c5 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.css @@ -6,3 +6,7 @@ width: 1.2rem; height: 1.2rem; } + +mat-list-item { + margin: 10px; +} diff --git a/Timeline/ClientApp/src/app/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list.service.ts index b1bc5ff3..238919d3 100644 --- a/Timeline/ClientApp/src/app/todo-list.service.ts +++ b/Timeline/ClientApp/src/app/todo-list.service.ts @@ -28,28 +28,41 @@ export interface WorkItem { export class TodoListService { private username = 'crupest'; - private pat = 'ehnmegogmk6r7qlkpy6zdl2hnfl6ntqbvggzxvvgp4a5vhr7lmnq'; private organization = 'crupest-web'; private project = 'Timeline'; private fieldId = 'System.Title'; - private headers: HttpHeaders; - constructor(private client: HttpClient) { - this.headers = new HttpHeaders({ - 'Accept': 'application/json', - 'Authorization': `Basic ${btoa(this.username + ':' + this.pat)}` + constructor(private client: HttpClient) { } + + private getAzureDevOpsPat(): Observable<string> { + return this.client.get('/api/TodoList/AzureDevOpsPat', { + headers: { + 'Accept': 'text/plain' + }, + responseType: 'text' }); } getWorkItemList(): Observable<WorkItem[]> { - return this.client.post<WiqlResult>(`https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { - query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' - }, { headers: this.headers }).pipe( - switchMap(result => result.workItems), - concatMap(result => this.client.get<WorkItemResult>(result.url, {headers: this.headers})), - map(result => <WorkItem>{ id: result.id, title: result.fields[this.fieldId] }), - toArray() + return this.getAzureDevOpsPat().pipe( + switchMap( + pat => { + const headers = new HttpHeaders({ + 'Accept': 'application/json', + 'Authorization': `Basic ${btoa(this.username + ':' + pat)}` + }); + return this.client.post<WiqlResult>( + `https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { + query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' + }, { headers: headers }).pipe( + switchMap(result => result.workItems), + concatMap(result => this.client.get<WorkItemResult>(result.url, { headers: headers })), + map(result => <WorkItem>{ id: result.id, title: result.fields[this.fieldId] }), + toArray() + ); + } + ) ); } } diff --git a/Timeline/Configs/TodoListConfig.cs b/Timeline/Configs/TodoListConfig.cs new file mode 100644 index 00000000..a69e8d03 --- /dev/null +++ b/Timeline/Configs/TodoListConfig.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Timeline.Configs +{ + public class TodoListConfig + { + public string AzureDevOpsPat { get; set; } + } +} diff --git a/Timeline/Controllers/TodoListController.cs b/Timeline/Controllers/TodoListController.cs new file mode 100644 index 00000000..b773ed2e --- /dev/null +++ b/Timeline/Controllers/TodoListController.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using Timeline.Configs; + +namespace Timeline.Controllers +{ + [Route("api/[controller]")] + public class TodoListController : Controller + { + private readonly IOptionsMonitor<TodoListConfig> _config; + + public TodoListController(IOptionsMonitor<TodoListConfig> config) + { + _config = config; + } + + [HttpGet("[action]")] + [AllowAnonymous] + [Produces("text/plain")] + public ActionResult<string> AzureDevOpsPat() + { + return Ok(_config.CurrentValue.AzureDevOpsPat); + } + } +} diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 1ffed22b..45242ce3 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System.IO; using Timeline.Entities; using Timeline.Services; diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 6381a58a..a6bde7fd 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -41,6 +41,8 @@ namespace Timeline }); + services.Configure<TodoListConfig>(Configuration.GetSection("TodoListConfig")); + services.Configure<JwtConfig>(Configuration.GetSection("JwtConfig")); var jwtConfig = Configuration.GetSection("JwtConfig").Get<JwtConfig>(); |