Is requested to provide the possibility of the tweets that is going to be published, they can have as additional content one or more images.
Is needed to provide the url where the image is available
In order to complete this feature, is needed to modify the domain of the application, adding two new entities to Pending Tweet and Tweet agreggate roots:
This also changes the database adding two new tables: PENDING_IMAGE and TWEET_IMAGE, both with a foreign key related to PENDING_TWEET and TWEET respectively:
Control of the feature toggle is done in following parts:
- PublisherService.buildPublishTweetRequest(PendingTweet pendingTweet): when a tweet is going to be published. Called when a tweet is going to be published using Scheduled task and also when it is published on demand.
- CreatePendingTweetRequestMapper.mapRequest(final PendingTweetRequest request): when a request to create a pending tweet is received
- PendingTweetResponseMapper.mapResponse(PendingTweet pendingTweet): when a pending tweet response is built. Called in the response when a pending tweet is created, when it is searched by ID and when all pending tweets are requested.
- TweetResponseMapper.mapResponse(Tweet tweet): when a tweet response is built. Called from getTweets and getTweetById
Example of pending tweet creation request with images:
{
"message": "This is a test tweet with attached images",
"publicationDate": "2022-04-01T10:00:00Z",
"images": [
{
"url": "https://davidrojo.eu/images/tfm/1.jpg"
},
{
"url": "https://davidrojo.eu/images/tfm/2.jpg"
}
]
}
Following steps has been achieved to implement current feature:
- Add new feature toggle disabled
- Add new database tables and refactor mappers
- Add images as not required to tweet domain
- Add images as not required to pending tweet domain
- Add infrastructure adapters with images
- Add images to twitter publisher service
- Add images as optional to pending tweet service
- Add images to controllers
- Set feature toggle as enabled
- Delete feature toggle
On Features.java
add new feature toggle:
@Label("Tweets with images")
TWEETS_WITH_IMAGES
It is disabled by default
Include script V3__add_images.sql
with new tables and the OneToMany relation expressed with the foreign key:
CREATE TABLE IF NOT EXISTS PENDING_IMAGE (
ID bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
URL TEXT NOT NULL,
PENDING_TWEET_ID bigint NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_PENDING_TWEET_ID FOREIGN KEY (PENDING_TWEET_ID) REFERENCES PENDING_TWEET (ID)
);
CREATE TABLE IF NOT EXISTS TWEET_IMAGE (
ID bigint NOT NULL,
SIZE bigint NOT NULL,
TYPE TEXT NOT NULL,
WIDTH int NOT NULL,
HEIGHT int NOT NULL,
TWEET_ID bigint NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_TWEET_ID FOREIGN KEY (TWEET_ID) REFERENCES TWEET (ID)
);
On Features.java
enable TWEETS_WITH_IMAGE feature toggle:
@EnabledByDefault
@Label("Tweets with images")
TWEETS_WITH_IMAGES
As it can be seen below, two commits failed when GitHub actions workflow was executed, so the application was not deployed in Heroku. Specifically, I forgot to add flywway script and I named flyway script wrong: