Skip to content

Commit

Permalink
Added migrations, services & repositories for generic content. See #1335
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Sep 30, 2020
1 parent e39be04 commit e6ef9f7
Show file tree
Hide file tree
Showing 46 changed files with 3,311 additions and 94 deletions.
2 changes: 1 addition & 1 deletion core/Piranha.AttributeBuilder/ContentTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ContentTypeBuilder AddType(Type type)
else
{
// Type is a non abstract class, check if it is a content type
if (typeof(IContent).IsAssignableFrom(type))
if (typeof(GenericContent).IsAssignableFrom(type))
{
if (type.GetCustomAttribute<ContentTypeAttribute>() != null)
{
Expand Down
7 changes: 7 additions & 0 deletions core/Piranha/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public sealed class Api : IApi, IDisposable
/// </summary>
public IArchiveService Archives { get; }

/// <summary>
/// Gets the content service.
/// </summary>
public IContentService Content { get; }

/// <summary>
/// Gets the content group service.
/// </summary>
Expand Down Expand Up @@ -103,6 +108,7 @@ public Api(
IContentFactory contentFactory,
IAliasRepository aliasRepository,
IArchiveRepository archiveRepository,
IContentRepository contentRepository,
IContentGroupRepository contentGroupRepository,
IContentTypeRepository contentTypeRepository,
ILanguageRepository languageRepository,
Expand Down Expand Up @@ -132,6 +138,7 @@ public Api(
SiteTypes = new SiteTypeService(siteTypeRepository, cache);

// Create services with dependencies
Content = new ContentService(contentRepository, contentFactory, Languages, cache, search);
Sites = new SiteService(siteRepository, contentFactory, Languages,cache);
Aliases = new AliasService(aliasRepository, Sites, cache);
Media = new MediaService(mediaRepository, Params, storage, processor, cache);
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Blocks/HtmlBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Piranha.Extend.Blocks
/// Single column HTML block.
/// </summary>
[BlockType(Name = "Content", Category = "Content", Icon = "fas fa-paragraph", Component = "html-block")]
public class HtmlBlock : Block, ISearchable
public class HtmlBlock : Block, ISearchable, ITranslatable
{
/// <summary>
/// Gets/sets the HTML body.
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Blocks/QuoteBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Piranha.Extend.Blocks
/// Single column quote block.
/// </summary>
[BlockType(Name = "Quote", Category = "Content", Icon = "fas fa-quote-right", Component = "quote-block")]
public class QuoteBlock : Block, ISearchable
public class QuoteBlock : Block, ISearchable, ITranslatable
{
/// <summary>
/// Gets/sets the author
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Blocks/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Piranha.Extend.Blocks
/// Single column text block.
/// </summary>
[BlockType(Name = "Text", Category = "Content", Icon = "fas fa-font", Component = "text-block")]
public class TextBlock : Block, ISearchable
public class TextBlock : Block, ISearchable, ITranslatable
{
/// <summary>
/// Gets/sets the text body.
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Fields/HtmlField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Piranha.Extend.Fields
{
[FieldType(Name = "Html", Shorthand = "Html", Component = "html-field")]
public class HtmlField : SimpleField<string>, ISearchable
public class HtmlField : SimpleField<string>, ISearchable, ITranslatable
{
/// <summary>
/// Implicit operator for converting a string to a field.
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Fields/MarkdownField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Piranha.Extend.Fields
{
[FieldType(Name = "Markdown", Shorthand = "Markdown", Component = "markdown-field")]
public class MarkdownField : SimpleField<string>, ISearchable
public class MarkdownField : SimpleField<string>, ISearchable, ITranslatable
{
/// <summary>
/// Implicit operator for converting a string to a field.
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Fields/StringField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Piranha.Extend.Fields
{
[FieldType(Name = "String", Shorthand = "String", Component = "string-field")]
public class StringField : SimpleField<string>, ISearchable
public class StringField : SimpleField<string>, ISearchable, ITranslatable
{
/// <summary>
/// Implicit operator for converting a string to a field.
Expand Down
2 changes: 1 addition & 1 deletion core/Piranha/Extend/Fields/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Piranha.Extend.Fields
{
[FieldType(Name = "Text", Shorthand = "Text", Component = "text-field")]
public class TextField : SimpleField<string>, ISearchable
public class TextField : SimpleField<string>, ISearchable, ITranslatable
{
/// <summary>
/// Implicit operator for converting a string to a field.
Expand Down
17 changes: 17 additions & 0 deletions core/Piranha/Extend/ITranslatable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) .NET Foundation and Contributors
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
* https://github.com/piranhacms/piranha.core
*
*/

namespace Piranha.Extend
{
/// <summary>
/// Interface for marking a block or field as translatable.
/// </summary>
public interface ITranslatable { }
}
5 changes: 5 additions & 0 deletions core/Piranha/IApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public interface IApi : IDisposable
/// </summary>
IArchiveService Archives { get; }

/// <summary>
/// Gets the content service.
/// </summary>
IContentService Content { get; }

/// <summary>
/// Gets the content group service.
/// </summary>
Expand Down
24 changes: 12 additions & 12 deletions core/Piranha/Models/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
*
*/

using System.Collections.Generic;
using Piranha.Extend.Fields;
using System.Threading.Tasks;

namespace Piranha.Models
{
/// <summary>
/// Base class for project defined content.
/// Base class for generic content.
/// </summary>
/// <typeparam name="T">The type</typeparam>
public abstract class Content<T> : ContentBase, IContent where T : Content<T>
/// <typeparam name="T">The content type</typeparam>
public abstract class Content<T> : GenericContent where T : Content<T>
{
/// <summary>
/// Gets/sets the optional primary image.
/// Creates a new page model using the given page type id.
/// </summary>
public ImageField PrimaryImage { get; set; } = new ImageField();

/// <summary>
/// Gets/sets the optional excerpt.
/// </summary>
public string Excerpt { get; set; }
/// <param name="api">The current api</param>
/// <param name="typeId">The unique page type id</param>
/// <returns>The new model</returns>
public static Task<T> CreateAsync(IApi api, string typeId = null)
{
return api.Content.CreateAsync<T>(typeId);
}
}
}
30 changes: 30 additions & 0 deletions core/Piranha/Models/GenericContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) .NET Foundation and Contributors
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
* https://github.com/piranhacms/piranha.core
*
*/

using Piranha.Extend.Fields;

namespace Piranha.Models
{
/// <summary>
/// Base class for generic content.
/// </summary>
public abstract class GenericContent : ContentBase
{
/// <summary>
/// Gets/sets the optional primary image.
/// </summary>
public ImageField PrimaryImage { get; set; } = new ImageField();

/// <summary>
/// Gets/sets the optional excerpt.
/// </summary>
public string Excerpt { get; set; }
}
}
41 changes: 41 additions & 0 deletions core/Piranha/Repositories/IContentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) .NET Foundation and Contributors
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
* http://github.com/piranhacms/piranha
*
*/

using System;
using System.Threading.Tasks;
using Piranha.Models;

namespace Piranha.Repositories
{
public interface IContentRepository
{
/// <summary>
/// Gets the content model with the specified id.
/// </summary>
/// <typeparam name="T">The model type</typeparam>
/// <param name="id">The unique id</param>
/// <param name="languageId">The selected language id</param>
/// <returns>The content model</returns>
Task<T> GetById<T>(Guid id, Guid languageId) where T : GenericContent;

/// <summary>
/// Saves the given content model
/// </summary>
/// <param name="model">The content model</param>
/// <param name="languageId">The selected language id</param>
Task Save<T>(T model, Guid languageId) where T : GenericContent;

/// <summary>
/// Deletes the content model with the specified id.
/// </summary>
/// <param name="id">The unique id</param>
Task Delete(Guid id);
}
}
Loading

0 comments on commit e6ef9f7

Please sign in to comment.