diff --git a/SyncUp.Data/Models/Tenancy/Tenant.cs b/SyncUp.Data/Models/Tenancy/Tenant.cs index 10f8525..e6162bd 100644 --- a/SyncUp.Data/Models/Tenancy/Tenant.cs +++ b/SyncUp.Data/Models/Tenancy/Tenant.cs @@ -1,6 +1,7 @@ using IntelliTect.SyncUp.Data.Services; using SyncUp.Data.Models; using System.ComponentModel; +using File = IntelliTect.Coalesce.Models.File; namespace IntelliTect.SyncUp.Data.Models; @@ -24,7 +25,41 @@ public class Tenant [ForeignKey(nameof(BannerImageId))] public Image? BannerImage { get; set; } + [Coalesce] + public async Task> UploadImageFile(AppDbContext db, [Inject] ImageService imageService, File file) + { + try + { + Image image = await imageService.AddImage(file); + + BannerImageId = image.ImageId; + await db.SaveChangesAsync(); + + return image; + } + catch(Exception ex) + { + return ex.Message; + } + } + [Coalesce] + public async Task> UploadImageUrl(AppDbContext db, [Inject] ImageService imageService, string url) + { + try + { + Image image = await imageService.AddImage(url); + + BannerImageId = image.ImageId; + await db.SaveChangesAsync(); + + return image; + } + catch (Exception ex) + { + return ex.Message; + } + } [DefaultDataSource] public class DefaultSource(CrudContext context) : AppDataSource(context) diff --git a/SyncUp.Data/Services/ImageService.cs b/SyncUp.Data/Services/ImageService.cs index cd54233..8c4ed14 100644 --- a/SyncUp.Data/Services/ImageService.cs +++ b/SyncUp.Data/Services/ImageService.cs @@ -6,28 +6,25 @@ using IntelliTect.SyncUp.Data; using SyncUp.Data.Models; using System.Net; +using File = IntelliTect.Coalesce.Models.File; namespace IntelliTect.SyncUp.Data.Services; -[Coalesce, Service] public class ImageService(AppDbContext db, IOptions options) { - [Coalesce] - [Execute(SecurityPermissionLevels.AllowAuthenticated, HttpMethod = IntelliTect.Coalesce.DataAnnotations.HttpMethod.Post)] - public async Task> Upload(byte[] content) + public async Task AddImage(string url) { - try - { - return await AddImage(content); - } - catch (Exception ex) + byte[] bytes = []; + using (var client = new HttpClient()) { - return ex.Message; + bytes = await client.GetByteArrayAsync(url); } + + return await AddImage(new File(bytes)); } - public async Task AddImage(byte[] content) + public async Task AddImage(File file) { - if (content.Length == 0) throw new Exception("No image provided"); + if (file.Length == 0 || file.Content is null) throw new Exception("No image provided"); try { var imageId = Guid.NewGuid().ToString().Replace("-", ""); @@ -36,7 +33,7 @@ public async Task AddImage(byte[] content) try { - await cloudBlob.UploadAsync(new MemoryStream(content), new BlobUploadOptions + await cloudBlob.UploadAsync(file.Content, new BlobUploadOptions { Conditions = new() { IfNoneMatch = Azure.ETag.All } }); @@ -46,7 +43,11 @@ public async Task AddImage(byte[] content) throw new Exception("An Error occurred while trying to save the specified image to blob storage", ex); } - var imageScan = new MagickImage(content); + + // Reset stream position to 0 before reusing + file.Content.Position = 0; + + var imageScan = new MagickImage(file.Content); var colors = imageScan.Histogram(); string dominantColor = colors.MaxBy(kvp => kvp.Value).Key.ToHexString(); @@ -69,31 +70,6 @@ public async Task AddImage(byte[] content) } } - [Coalesce] - [Execute(SecurityPermissionLevels.AllowAuthenticated, HttpMethod = IntelliTect.Coalesce.DataAnnotations.HttpMethod.Post)] - public async Task> UploadFromUrl(string url) - { - // Download the file get a byte array - try - { - return await AddImage(url); - } - catch - { - // TODO: Log this - return $"An Error occurred while trying to download the specified image."; - } - } - - public async Task AddImage(string url) - { - using (var client = new HttpClient()) - { - var bytes = await client.GetByteArrayAsync(url); - return await AddImage(bytes); - } - } - private BlobClient GetBlobClient(string relativeLocation) { var connectionString = options.Value.ConnectionString; diff --git a/SyncUp.Web/Api/Generated/ImageServiceController.g.cs b/SyncUp.Web/Api/Generated/ImageServiceController.g.cs deleted file mode 100644 index 62c0abc..0000000 --- a/SyncUp.Web/Api/Generated/ImageServiceController.g.cs +++ /dev/null @@ -1,162 +0,0 @@ - -using IntelliTect.Coalesce; -using IntelliTect.Coalesce.Api; -using IntelliTect.Coalesce.Api.Behaviors; -using IntelliTect.Coalesce.Api.Controllers; -using IntelliTect.Coalesce.Api.DataSources; -using IntelliTect.Coalesce.Mapping; -using IntelliTect.Coalesce.Mapping.IncludeTrees; -using IntelliTect.Coalesce.Models; -using IntelliTect.Coalesce.TypeDefinition; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using SyncUp.Web.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Net; -using System.Threading.Tasks; - -namespace SyncUp.Web.Api -{ - [Route("api/ImageService")] - [ServiceFilter(typeof(IApiActionFilter))] - public partial class ImageServiceController : BaseApiController - { - protected IntelliTect.SyncUp.Data.Services.ImageService Service { get; } - - public ImageServiceController(CrudContext context, IntelliTect.SyncUp.Data.Services.ImageService service) : base(context) - { - GeneratedForClassViewModel = context.ReflectionRepository.GetClassViewModel(); - Service = service; - } - - /// - /// Method: Upload - /// - [HttpPost("Upload")] - [Authorize] - [Consumes("application/x-www-form-urlencoded", "multipart/form-data")] - public virtual async Task> Upload( - [FromForm(Name = "content")] byte[] content) - { - var _params = new - { - Content = content ?? await ((await Request.ReadFormAsync()).Files[nameof(content)]?.OpenReadStream().ReadAllBytesAsync(true) ?? Task.FromResult(null)) - }; - - if (Context.Options.ValidateAttributesForMethods) - { - var _validationResult = ItemResult.FromParameterValidation( - GeneratedForClassViewModel!.MethodByName("Upload"), _params, HttpContext.RequestServices); - if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); - } - - IncludeTree includeTree = null; - var _mappingContext = new MappingContext(Context); - var _methodResult = await Service.Upload( - _params.Content - ); - var _result = new ItemResult(_methodResult); - _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); - return _result; - } - - public class UploadParameters - { - public byte[] Content { get; set; } - } - - /// - /// Method: Upload - /// - [HttpPost("Upload")] - [Authorize] - [Consumes("application/json")] - public virtual async Task> Upload( - [FromBody] UploadParameters _params - ) - { - if (Context.Options.ValidateAttributesForMethods) - { - var _validationResult = ItemResult.FromParameterValidation( - GeneratedForClassViewModel!.MethodByName("Upload"), _params, HttpContext.RequestServices); - if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); - } - - IncludeTree includeTree = null; - var _mappingContext = new MappingContext(Context); - var _methodResult = await Service.Upload( - _params.Content - ); - var _result = new ItemResult(_methodResult); - _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); - return _result; - } - - /// - /// Method: UploadFromUrl - /// - [HttpPost("UploadFromUrl")] - [Authorize] - [Consumes("application/x-www-form-urlencoded", "multipart/form-data")] - public virtual async Task> UploadFromUrl( - [FromForm(Name = "url")] string url) - { - var _params = new - { - Url = url - }; - - if (Context.Options.ValidateAttributesForMethods) - { - var _validationResult = ItemResult.FromParameterValidation( - GeneratedForClassViewModel!.MethodByName("UploadFromUrl"), _params, HttpContext.RequestServices); - if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); - } - - IncludeTree includeTree = null; - var _mappingContext = new MappingContext(Context); - var _methodResult = await Service.UploadFromUrl( - _params.Url - ); - var _result = new ItemResult(_methodResult); - _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); - return _result; - } - - public class UploadFromUrlParameters - { - public string Url { get; set; } - } - - /// - /// Method: UploadFromUrl - /// - [HttpPost("UploadFromUrl")] - [Authorize] - [Consumes("application/json")] - public virtual async Task> UploadFromUrl( - [FromBody] UploadFromUrlParameters _params - ) - { - if (Context.Options.ValidateAttributesForMethods) - { - var _validationResult = ItemResult.FromParameterValidation( - GeneratedForClassViewModel!.MethodByName("UploadFromUrl"), _params, HttpContext.RequestServices); - if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); - } - - IncludeTree includeTree = null; - var _mappingContext = new MappingContext(Context); - var _methodResult = await Service.UploadFromUrl( - _params.Url - ); - var _result = new ItemResult(_methodResult); - _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); - return _result; - } - } -} diff --git a/SyncUp.Web/Api/Generated/TenantController.g.cs b/SyncUp.Web/Api/Generated/TenantController.g.cs index a16bbf4..46194a1 100644 --- a/SyncUp.Web/Api/Generated/TenantController.g.cs +++ b/SyncUp.Web/Api/Generated/TenantController.g.cs @@ -86,6 +86,182 @@ public virtual Task> BulkSave( // Methods from data class exposed through API Controller. + /// + /// Method: UploadImageFile + /// + [HttpPost("UploadImageFile")] + [Authorize] + [Consumes("application/x-www-form-urlencoded", "multipart/form-data")] + public virtual async Task> UploadImageFile( + [FromServices] IDataSourceFactory dataSourceFactory, + [FromServices] IntelliTect.SyncUp.Data.Services.ImageService imageService, + [FromForm(Name = "id")] string id, + Microsoft.AspNetCore.Http.IFormFile file) + { + var _params = new + { + Id = id, + File = file == null ? null : new IntelliTect.Coalesce.Models.File { Name = file.FileName, ContentType = file.ContentType, Length = file.Length, Content = file.OpenReadStream() } + }; + + var dataSource = dataSourceFactory.GetDataSource("Default"); + var itemResult = await dataSource.GetItemAsync(_params.Id, new DataSourceParameters()); + if (!itemResult.WasSuccessful) + { + return new ItemResult(itemResult); + } + var item = itemResult.Object; + if (Context.Options.ValidateAttributesForMethods) + { + var _validationResult = ItemResult.FromParameterValidation( + GeneratedForClassViewModel!.MethodByName("UploadImageFile"), _params, HttpContext.RequestServices); + if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); + } + + IncludeTree includeTree = null; + var _mappingContext = new MappingContext(Context); + var _methodResult = await item.UploadImageFile( + Db, + imageService, + _params.File + ); + var _result = new ItemResult(_methodResult); + _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); + return _result; + } + + public class UploadImageFileParameters + { + public string Id { get; set; } + public IntelliTect.Coalesce.Models.FileParameter File { get; set; } + } + + /// + /// Method: UploadImageFile + /// + [HttpPost("UploadImageFile")] + [Authorize] + [Consumes("application/json")] + public virtual async Task> UploadImageFile( + [FromServices] IDataSourceFactory dataSourceFactory, + [FromServices] IntelliTect.SyncUp.Data.Services.ImageService imageService, + [FromBody] UploadImageFileParameters _params + ) + { + var dataSource = dataSourceFactory.GetDataSource("Default"); + var itemResult = await dataSource.GetItemAsync(_params.Id, new DataSourceParameters()); + if (!itemResult.WasSuccessful) + { + return new ItemResult(itemResult); + } + var item = itemResult.Object; + if (Context.Options.ValidateAttributesForMethods) + { + var _validationResult = ItemResult.FromParameterValidation( + GeneratedForClassViewModel!.MethodByName("UploadImageFile"), _params, HttpContext.RequestServices); + if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); + } + + IncludeTree includeTree = null; + var _mappingContext = new MappingContext(Context); + var _methodResult = await item.UploadImageFile( + Db, + imageService, + _params.File + ); + var _result = new ItemResult(_methodResult); + _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); + return _result; + } + + /// + /// Method: UploadImageUrl + /// + [HttpPost("UploadImageUrl")] + [Authorize] + [Consumes("application/x-www-form-urlencoded", "multipart/form-data")] + public virtual async Task> UploadImageUrl( + [FromServices] IDataSourceFactory dataSourceFactory, + [FromServices] IntelliTect.SyncUp.Data.Services.ImageService imageService, + [FromForm(Name = "id")] string id, + [FromForm(Name = "url")] string url) + { + var _params = new + { + Id = id, + Url = url + }; + + var dataSource = dataSourceFactory.GetDataSource("Default"); + var itemResult = await dataSource.GetItemAsync(_params.Id, new DataSourceParameters()); + if (!itemResult.WasSuccessful) + { + return new ItemResult(itemResult); + } + var item = itemResult.Object; + if (Context.Options.ValidateAttributesForMethods) + { + var _validationResult = ItemResult.FromParameterValidation( + GeneratedForClassViewModel!.MethodByName("UploadImageUrl"), _params, HttpContext.RequestServices); + if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); + } + + IncludeTree includeTree = null; + var _mappingContext = new MappingContext(Context); + var _methodResult = await item.UploadImageUrl( + Db, + imageService, + _params.Url + ); + var _result = new ItemResult(_methodResult); + _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); + return _result; + } + + public class UploadImageUrlParameters + { + public string Id { get; set; } + public string Url { get; set; } + } + + /// + /// Method: UploadImageUrl + /// + [HttpPost("UploadImageUrl")] + [Authorize] + [Consumes("application/json")] + public virtual async Task> UploadImageUrl( + [FromServices] IDataSourceFactory dataSourceFactory, + [FromServices] IntelliTect.SyncUp.Data.Services.ImageService imageService, + [FromBody] UploadImageUrlParameters _params + ) + { + var dataSource = dataSourceFactory.GetDataSource("Default"); + var itemResult = await dataSource.GetItemAsync(_params.Id, new DataSourceParameters()); + if (!itemResult.WasSuccessful) + { + return new ItemResult(itemResult); + } + var item = itemResult.Object; + if (Context.Options.ValidateAttributesForMethods) + { + var _validationResult = ItemResult.FromParameterValidation( + GeneratedForClassViewModel!.MethodByName("UploadImageUrl"), _params, HttpContext.RequestServices); + if (!_validationResult.WasSuccessful) return new ItemResult(_validationResult); + } + + IncludeTree includeTree = null; + var _mappingContext = new MappingContext(Context); + var _methodResult = await item.UploadImageUrl( + Db, + imageService, + _params.Url + ); + var _result = new ItemResult(_methodResult); + _result.Object = Mapper.MapToDto(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree); + return _result; + } + /// /// Method: Create /// diff --git a/SyncUp.Web/src/api-clients.g.ts b/SyncUp.Web/src/api-clients.g.ts index 2c3c240..719313e 100644 --- a/SyncUp.Web/src/api-clients.g.ts +++ b/SyncUp.Web/src/api-clients.g.ts @@ -66,6 +66,24 @@ export class RoleApiClient extends ModelApiClient<$models.Role> { export class TenantApiClient extends ModelApiClient<$models.Tenant> { constructor() { super($metadata.Tenant) } + public uploadImageFile(id: string | null, file: File | null, $config?: AxiosRequestConfig): AxiosPromise> { + const $method = this.$metadata.methods.uploadImageFile + const $params = { + id, + file, + } + return this.$invoke($method, $params, $config) + } + + public uploadImageUrl(id: string | null, url: string | null, $config?: AxiosRequestConfig): AxiosPromise> { + const $method = this.$metadata.methods.uploadImageUrl + const $params = { + id, + url, + } + return this.$invoke($method, $params, $config) + } + public create(name: string | null, adminEmail: string | null, $config?: AxiosRequestConfig): AxiosPromise> { const $method = this.$metadata.methods.create const $params = { @@ -157,27 +175,6 @@ export class UserRoleApiClient extends ModelApiClient<$models.UserRole> { } -export class ImageServiceApiClient extends ServiceApiClient { - constructor() { super($metadata.ImageService) } - public upload(content: string | Uint8Array | null, $config?: AxiosRequestConfig): AxiosPromise> { - const $method = this.$metadata.methods.upload - const $params = { - content, - } - return this.$invoke($method, $params, $config) - } - - public uploadFromUrl(url: string | null, $config?: AxiosRequestConfig): AxiosPromise> { - const $method = this.$metadata.methods.uploadFromUrl - const $params = { - url, - } - return this.$invoke($method, $params, $config) - } - -} - - export class SecurityServiceApiClient extends ServiceApiClient { constructor() { super($metadata.SecurityService) } public whoAmI($config?: AxiosRequestConfig): AxiosPromise> { diff --git a/SyncUp.Web/src/components/UploadImage.vue b/SyncUp.Web/src/components/UploadImage.vue index a67609e..949c183 100644 --- a/SyncUp.Web/src/components/UploadImage.vue +++ b/SyncUp.Web/src/components/UploadImage.vue @@ -6,7 +6,8 @@ accept="image/*" style="display: none" /> - + +
import { Image } from "@/models.g"; -import { ImageServiceViewModel } from "@/viewmodels.g"; +import { TenantViewModel } from "@/viewmodels.g"; const image = defineModel({ default: null }); @@ -43,24 +44,21 @@ const props = defineProps<{ cover?: boolean; height?: number; width?: number; + viewModel: TenantViewModel; //| GroupViewModel; // Uncomment when implemented on the Group Model as well. }>(); -//console.log(props.height); - const emits = defineEmits(["changed"]); const file = ref(null); -const imageService = new ImageServiceViewModel(); const busy = ref(false); const errorMessage = ref(null); watch(file, async (value) => { if (value) { busy.value = true; - const bytes = await fileToByteArray(value); - imageService - .upload(bytes) + props.viewModel + .uploadImageFile(value) .then((result) => { if (result) { busy.value = false; @@ -97,29 +95,12 @@ function imageClick() { }; } -async function fileToByteArray(file: File): Promise { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = (event) => { - const arrayBuffer = event.target?.result as ArrayBuffer; - const byteArray = new Uint8Array(arrayBuffer); - resolve(byteArray); - }; - - reader.onerror = (error) => { - reject(error); - }; - - reader.readAsArrayBuffer(file); - }); -} - async function imageLink() { const url = prompt("Enter the URL of the image"); if (url) { busy.value = true; - imageService - .uploadFromUrl(url) + props.viewModel + .uploadImageUrl(url) .then((result) => { busy.value = false; if (result) { diff --git a/SyncUp.Web/src/metadata.g.ts b/SyncUp.Web/src/metadata.g.ts index ad29432..653695c 100644 --- a/SyncUp.Web/src/metadata.g.ts +++ b/SyncUp.Web/src/metadata.g.ts @@ -1250,6 +1250,74 @@ export const Tenant = domain.types.Tenant = { }, }, methods: { + uploadImageFile: { + name: "uploadImageFile", + displayName: "Upload Image File", + transportType: "item", + httpMethod: "POST", + params: { + id: { + name: "id", + displayName: "Primary Key", + type: "string", + role: "value", + get source() { return (domain.types.Tenant as ModelType & { name: "Tenant" }).props.tenantId }, + rules: { + required: val => (val != null && val !== '') || "Primary Key is required.", + } + }, + file: { + name: "file", + displayName: "File", + type: "file", + role: "value", + rules: { + required: val => val != null || "File is required.", + } + }, + }, + return: { + name: "$return", + displayName: "Result", + type: "model", + get typeDef() { return (domain.types.Image as ModelType & { name: "Image" }) }, + role: "value", + }, + }, + uploadImageUrl: { + name: "uploadImageUrl", + displayName: "Upload Image Url", + transportType: "item", + httpMethod: "POST", + params: { + id: { + name: "id", + displayName: "Primary Key", + type: "string", + role: "value", + get source() { return (domain.types.Tenant as ModelType & { name: "Tenant" }).props.tenantId }, + rules: { + required: val => (val != null && val !== '') || "Primary Key is required.", + } + }, + url: { + name: "url", + displayName: "Url", + type: "string", + role: "value", + rules: { + required: val => (val != null && val !== '') || "Url is required.", + } + }, + }, + return: { + name: "$return", + displayName: "Result", + type: "model", + get typeDef() { return (domain.types.Image as ModelType & { name: "Image" }) }, + role: "value", + }, + }, create: { name: "create", displayName: "Create", @@ -1800,62 +1868,6 @@ export const UserInfo = domain.types.UserInfo = { }, }, } -export const ImageService = domain.services.ImageService = { - name: "ImageService", - displayName: "Image Service", - type: "service", - controllerRoute: "ImageService", - methods: { - upload: { - name: "upload", - displayName: "Upload", - transportType: "item", - httpMethod: "POST", - params: { - content: { - name: "content", - displayName: "Content", - type: "binary", - role: "value", - rules: { - required: val => val != null || "Content is required.", - } - }, - }, - return: { - name: "$return", - displayName: "Result", - type: "model", - get typeDef() { return (domain.types.Image as ModelType & { name: "Image" }) }, - role: "value", - }, - }, - uploadFromUrl: { - name: "uploadFromUrl", - displayName: "Upload From Url", - transportType: "item", - httpMethod: "POST", - params: { - url: { - name: "url", - displayName: "Url", - type: "string", - role: "value", - rules: { - required: val => (val != null && val !== '') || "Url is required.", - } - }, - }, - return: { - name: "$return", - displayName: "Result", - type: "model", - get typeDef() { return (domain.types.Image as ModelType & { name: "Image" }) }, - role: "value", - }, - }, - }, -} export const SecurityService = domain.services.SecurityService = { name: "SecurityService", displayName: "Security Service", @@ -1953,7 +1965,6 @@ interface AppDomain extends Domain { UserRole: typeof UserRole } services: { - ImageService: typeof ImageService SecurityService: typeof SecurityService TenantsService: typeof TenantsService } diff --git a/SyncUp.Web/src/viewmodels.g.ts b/SyncUp.Web/src/viewmodels.g.ts index 4f5be3b..bbccf32 100644 --- a/SyncUp.Web/src/viewmodels.g.ts +++ b/SyncUp.Web/src/viewmodels.g.ts @@ -348,6 +348,28 @@ export interface TenantViewModel extends $models.Tenant { export class TenantViewModel extends ViewModel<$models.Tenant, $apiClients.TenantApiClient, string> implements $models.Tenant { static DataSources = $models.Tenant.DataSources; + public get uploadImageFile() { + const uploadImageFile = this.$apiClient.$makeCaller( + this.$metadata.methods.uploadImageFile, + (c, file: File | null) => c.uploadImageFile(this.$primaryKey, file), + () => ({file: null as File | null, }), + (c, args) => c.uploadImageFile(this.$primaryKey, args.file)) + + Object.defineProperty(this, 'uploadImageFile', {value: uploadImageFile}); + return uploadImageFile + } + + public get uploadImageUrl() { + const uploadImageUrl = this.$apiClient.$makeCaller( + this.$metadata.methods.uploadImageUrl, + (c, url: string | null) => c.uploadImageUrl(this.$primaryKey, url), + () => ({url: null as string | null, }), + (c, args) => c.uploadImageUrl(this.$primaryKey, args.url)) + + Object.defineProperty(this, 'uploadImageUrl', {value: uploadImageUrl}); + return uploadImageUrl + } + constructor(initialData?: DeepPartial<$models.Tenant> | null) { super($metadata.Tenant, new $apiClients.TenantApiClient(), initialData) } @@ -530,36 +552,6 @@ export class UserRoleListViewModel extends ListViewModel<$models.UserRole, $apiC } -export class ImageServiceViewModel extends ServiceViewModel { - - public get upload() { - const upload = this.$apiClient.$makeCaller( - this.$metadata.methods.upload, - (c, content: string | Uint8Array | null) => c.upload(content), - () => ({content: null as string | Uint8Array | null, }), - (c, args) => c.upload(args.content)) - - Object.defineProperty(this, 'upload', {value: upload}); - return upload - } - - public get uploadFromUrl() { - const uploadFromUrl = this.$apiClient.$makeCaller( - this.$metadata.methods.uploadFromUrl, - (c, url: string | null) => c.uploadFromUrl(url), - () => ({url: null as string | null, }), - (c, args) => c.uploadFromUrl(args.url)) - - Object.defineProperty(this, 'uploadFromUrl', {value: uploadFromUrl}); - return uploadFromUrl - } - - constructor() { - super($metadata.ImageService, new $apiClients.ImageServiceApiClient()) - } -} - - export class SecurityServiceViewModel extends ServiceViewModel { public get whoAmI() { @@ -638,7 +630,6 @@ const listViewModelTypeLookup = ListViewModel.typeLookup = { UserRole: UserRoleListViewModel, } const serviceViewModelTypeLookup = ServiceViewModel.typeLookup = { - ImageService: ImageServiceViewModel, SecurityService: SecurityServiceViewModel, TenantsService: TenantsServiceViewModel, } diff --git a/SyncUp.Web/src/views/Tenant.vue b/SyncUp.Web/src/views/Tenant.vue index acdb8bb..b7bb3bb 100644 --- a/SyncUp.Web/src/views/Tenant.vue +++ b/SyncUp.Web/src/views/Tenant.vue @@ -48,6 +48,7 @@ :height="100" :width="350" cover + :view-model="tenant" @changed="tenant.$save()" />