Skip to content

Latest commit

 

History

History
147 lines (100 loc) · 5.65 KB

feature-tweets-with-images.md

File metadata and controls

147 lines (100 loc) · 5.65 KB

Feature: tweets with images


Feature requisites

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

How feature is implemented

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:

domain-tweet-images

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:

db-tweet-images

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"
    }
  ]
}

Implementation steps

Following steps has been achieved to implement current feature:

Add new feature toggle disabled

On Features.java add new feature toggle:

	@Label("Tweets with images")
	TWEETS_WITH_IMAGES

It is disabled by default

tweet-images-disabled

Add new database tables and refactor mappers

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)
);

Add images as not required to tweet domain

Commit

Add images as not required to pending tweet domain

Commit

Add infrastructure adapters with images

Commit

Add images to twitter publisher service

Commit

Add images as optional to pending tweet service

Commit

Add images to controllers

Commit

Set feature toggle as enabled

On Features.java enable TWEETS_WITH_IMAGE feature toggle:

  @EnabledByDefault
	@Label("Tweets with images")
	TWEETS_WITH_IMAGES

tweet-images-enabled

Delete feature toggle

Commit

Commits

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:

tweet-images-commits