Publish a New Article
Pre-releaseThe current user (as identified by an injected authorisation class) can create and persist a new Prolog::Core::Article
.
To use this, instantiate a new Prolog::UseCases::PublishNewArticle
class, passing a :repository
and an :authoriser
as parameters to the initialiser, and then call the instance's #call
method, passing in a Hash
or equivalent containing the necessary/desired attributes.
The :authoriser
passed to #initialize
must respond to
- the
:guest?
message, returningtrue
orfalse
; and - the
:current_user
message, returning a string with the current logged-in user name (or a null equivalent such as "Guest User" when no user is logged in).
The :repository
passed to #initialize
must respond to the :save
message, accepting a Prolog::Core::Article
instance as a parameter and returning the passed-in parameter on success. (The failure semantics for #save
have not yet been defined).
The Hash of parameters passed into #call
are as follows:
Key | Required? | Description of value |
---|---|---|
:title |
Yes | A trimmed string (see Note 1) containing the title of the new Article |
:author_name |
Yes | A trimmed string containing the user name of the Member creating the new Article |
:current_user |
Yes | A string containing the user name of the Member presently logged in, or a null equivalent such as "Guest User" when no user is logged in. |
:body |
See Note 2 | If specified, a string containing the body text of the new Article |
:image_url |
See Note 2 | If specified, a string containing a valid URL for an image to be associated with the Article |
:keywords |
No | An array of strings to be used as keywords for the new Article |
Notes
Note 1: A "trimmed string" is a string which
- is not empty;
- is not completely blank (containing only spaces or other similar whitespace);
- has no leading or trailing whitespace;
- has no more than one space between words in its text.
Note 2: A valid Article must have valid :body
text, a valid :image_url
, or both. For a :body
to be valid, it must be a non-zero-length, non-blank string. A valid :image_url
attribute is an http
- or https
-protocol URL that is valid in form (whether the image is actually retrievable is not checked).