Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relations/types mangement api cleanup #15910

Merged
merged 13 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
using Umbraco.Cms.Api.Management.ViewModels.RelationType;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.RelationType;

[ApiVersion("1.0")]
public class RootRelationTypeTreeController : RelationTypeControllerBase
kjac marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly IRelationService _relationService;
private readonly IUmbracoMapper _umbracoMapper;

public RootRelationTypeTreeController(
IRelationService relationService,
IUmbracoMapper umbracoMapper)
{
_relationService = relationService;
_umbracoMapper = umbracoMapper;
}

[HttpGet]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<RelationTypeResponseModel>), StatusCodes.Status200OK)]
public async Task<ActionResult<PagedViewModel<RelationTypeResponseModel>>> Get(int skip = 0, int take = 100)
{
PagedModel<IRelationType> allRelationTypes = await _relationService.GetPagedRelationTypesAsync(skip, take);

var pagedResult = new PagedViewModel<RelationTypeResponseModel>
{
Total = allRelationTypes.Total,
Items = _umbracoMapper.MapEnumerable<IRelationType, RelationTypeResponseModel>(allRelationTypes.Items.Skip(skip).Take(take)),
};

return Ok(pagedResult);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal static IUmbracoBuilder AddRelationTypes(this IUmbracoBuilder builder)
.Add<RelationTypeViewModelsMapDefinition>();

builder.Services.AddTransient<IObjectTypePresentationFactory, ObjectTypePresentationFactory>();
builder.Services.AddTransient<IRelationTypePresentationFactory, RelationTypePresentationFactory>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing this will clash with #15933

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will do a forward merge when #15933 has been merged in dev and fix it

return builder;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Api.Management.ViewModels;
using Umbraco.Cms.Api.Management.ViewModels.Relation;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Api.Management.ViewModels.Relation;

namespace Umbraco.Cms.Api.Management.Factories;

Expand All @@ -19,22 +19,24 @@ public RelationPresentationFactory(IRelationService relationService, IEntityServ

public RelationResponseModel Create(IRelation relation)
{
var child = _entityService.Get(relation.ChildId)!;
var parent = _entityService.Get(relation.ParentId)!;
IEntitySlim child = _entityService.Get(relation.ChildId)!;
IEntitySlim parent = _entityService.Get(relation.ParentId)!;

RelationResponseModel relationResponseModel = new RelationResponseModel()
var relationResponseModel = new RelationResponseModel(
new ReferenceByIdModel(relation.RelationType.Key),
new RelationReferenceModel(parent.Key),
new RelationReferenceModel(child.Key))
{
ChildId = child.Key,
Id = relation.Key,
Comment = relation.Comment,
CreateDate = relation.CreateDate,
ParentId = parent.Key,
};
Tuple<IUmbracoEntity, IUmbracoEntity>? entities = _relationService.GetEntitiesFromRelation(relation);

if (entities is not null)
{
relationResponseModel.ParentName = entities.Item1.Name;
relationResponseModel.ChildName = entities.Item2.Name;
relationResponseModel.Parent.Name = entities.Item1.Name;
relationResponseModel.Child.Name = entities.Item2.Name;
}

return relationResponseModel;
Expand Down
Loading
Loading