From 069b8b5632a6b1334ccb547c8cbff761f85e6cf3 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 30 Jan 2021 23:41:23 +0000 Subject: [PATCH] Added the new Config API with the frontend services --- .../src/app/wizard/models/OmbiConfigModel.ts | 5 +++ .../src/app/wizard/services/wizard.service.ts | 18 ++++++++ .../ClientApp/src/app/wizard/wizard.module.ts | 2 + src/Ombi/Controllers/V2/WizardController.cs | 43 +++++++++++++------ src/Ombi/Models/V2/OmbiConfigModel.cs | 14 ++++++ 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/Ombi/ClientApp/src/app/wizard/models/OmbiConfigModel.ts create mode 100644 src/Ombi/ClientApp/src/app/wizard/services/wizard.service.ts create mode 100644 src/Ombi/Models/V2/OmbiConfigModel.cs diff --git a/src/Ombi/ClientApp/src/app/wizard/models/OmbiConfigModel.ts b/src/Ombi/ClientApp/src/app/wizard/models/OmbiConfigModel.ts new file mode 100644 index 000000000..29e6e68a9 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/wizard/models/OmbiConfigModel.ts @@ -0,0 +1,5 @@ +export interface IOmbiConfigModel { + applicationName: string; + applicationUrl: string; + logo: string; +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/wizard/services/wizard.service.ts b/src/Ombi/ClientApp/src/app/wizard/services/wizard.service.ts new file mode 100644 index 000000000..0990ca384 --- /dev/null +++ b/src/Ombi/ClientApp/src/app/wizard/services/wizard.service.ts @@ -0,0 +1,18 @@ +import { PlatformLocation, APP_BASE_HREF } from "@angular/common"; +import { HttpClient } from "@angular/common/http"; +import { Injectable, Inject } from "@angular/core"; +import { ICustomizationSettings } from "../../interfaces"; +import { ServiceHelpers } from "../../services"; +import { IOmbiConfigModel } from "../models/OmbiConfigModel"; + + +@Injectable() +export class WizardService extends ServiceHelpers { + constructor(public http: HttpClient, @Inject(APP_BASE_HREF) href:string) { + super(http, "/api/v2/wizard/", href); + } + + public async downvoteAlbum(config: IOmbiConfigModel): Promise { + return await this.http.post(`${this.url}config`, config, {headers: this.headers}).toPromise(); + } +} diff --git a/src/Ombi/ClientApp/src/app/wizard/wizard.module.ts b/src/Ombi/ClientApp/src/app/wizard/wizard.module.ts index 1e34a1de9..e088fa6b3 100644 --- a/src/Ombi/ClientApp/src/app/wizard/wizard.module.ts +++ b/src/Ombi/ClientApp/src/app/wizard/wizard.module.ts @@ -17,6 +17,7 @@ import { JellyfinService } from "../services"; import { PlexService } from "../services"; import { IdentityService } from "../services"; import { PlexOAuthService } from "../services"; +import { WizardService } from "./services/wizard.service"; import { SharedModule } from "../shared/shared.module"; @@ -54,6 +55,7 @@ const routes: Routes = [ EmbyService, JellyfinService, PlexOAuthService, + WizardService, ], }) diff --git a/src/Ombi/Controllers/V2/WizardController.cs b/src/Ombi/Controllers/V2/WizardController.cs index e7fa82fec..bb3bed5b6 100644 --- a/src/Ombi/Controllers/V2/WizardController.cs +++ b/src/Ombi/Controllers/V2/WizardController.cs @@ -1,13 +1,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Ombi.Attributes; using Ombi.Core.Settings; +using Ombi.Helpers; +using Ombi.Models.V2; using Ombi.Settings.Settings.Models; -using System; -using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; namespace Ombi.Controllers.V2 @@ -16,20 +13,42 @@ namespace Ombi.Controllers.V2 [AllowAnonymous] public class WizardController : V2Controller { + private ISettingsService _customizationSettings { get; } - private ISettingsService _ombiSettings { get; } - - - [HttpGet] - public IActionResult Ok() + public WizardController(ISettingsService customizationSettings) { - return Ok(); + _customizationSettings = customizationSettings; } + [HttpPost("config")] + [ApiExplorerSettings(IgnoreApi =true)] + public async Task OmbiConfig([FromBody] OmbiConfigModel config) + { + if (config == null) + { + return BadRequest(); + } + var settings = await _customizationSettings.GetSettingsAsync(); + if (config.ApplicationName.HasValue()) + { + settings.ApplicationName = config.ApplicationName; + } - } + if(config.ApplicationUrl.HasValue()) + { + settings.ApplicationUrl = config.ApplicationUrl; + } + if(config.Logo.HasValue()) + { + settings.Logo = config.Logo; + } + await _customizationSettings.SaveSettingsAsync(settings); + + return new OkObjectResult(settings); + } + } } diff --git a/src/Ombi/Models/V2/OmbiConfigModel.cs b/src/Ombi/Models/V2/OmbiConfigModel.cs new file mode 100644 index 000000000..caecdfa2b --- /dev/null +++ b/src/Ombi/Models/V2/OmbiConfigModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Ombi.Models.V2 +{ + public class OmbiConfigModel + { + public string ApplicationName { get; set; } + public string ApplicationUrl { get; set; } + public string Logo { get; set; } + } +}