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

feat: added topic slug to topic dto #15

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions api/topicservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ components:
type: string
example: "Topic name"
maxLength: 100
slug:
type: string
example: "topic_slug"
maxLength: 100
description:
type: string
example: "Description"
Expand Down Expand Up @@ -318,6 +322,10 @@ components:
type: object
additionalProperties:
type: string
slug:
type: string
example: "topic_slug"
maxLength: 100
description:
type: object
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public TopicDTO toDTO(final TopicEntity topic, final String lang) {
new TopicDTO()
.id(topic.getId())
.name(getTranslatedStringFromMap(topic.getName(), lang))
.slug(topic.getSlug())
.description(getTranslatedStringFromMap(topic.getDescription(), lang))
.status(topic.getStatus().name())
.fallbackAgencyId(topic.getFallbackAgencyId())
Expand Down Expand Up @@ -64,6 +65,7 @@ public TopicMultilingualDTO toMultilingualDTO(final TopicEntity topic) {
new TopicMultilingualDTO()
.id(topic.getId())
.name(convertMapFromJson(topic.getName()))
.slug(topic.getSlug())
.description(convertMapFromJson(topic.getDescription()))
.status(topic.getStatus().name())
.fallbackAgencyId(topic.getFallbackAgencyId())
Expand Down Expand Up @@ -93,6 +95,7 @@ public List<TopicDTO> toDTOList(final Collection<TopicEntity> topicEntities) {
public TopicEntity toEntity(final TopicMultilingualDTO topicDTO) {
final TopicEntity topicEntity = new TopicEntity();
topicEntity.setName(convertToJson(topicDTO.getName()));
topicEntity.setSlug(topicDTO.getSlug());
topicEntity.setStatus(TopicStatus.valueOf(topicDTO.getStatus().toUpperCase()));
topicEntity.setDescription(convertToJson(topicDTO.getDescription()));
topicEntity.setUpdateDate(LocalDateTime.now(ZoneOffset.UTC));
Expand All @@ -109,6 +112,7 @@ public TopicEntity toEntity(final TopicMultilingualDTO topicDTO) {

public TopicEntity toEntity(final TopicEntity targetEntity, final TopicMultilingualDTO topicDTO) {
targetEntity.setName(convertToJson(topicDTO.getName()));
targetEntity.setSlug(topicDTO.getSlug());
targetEntity.setStatus(TopicStatus.valueOf(topicDTO.getStatus()));
targetEntity.setDescription(convertToJson(topicDTO.getDescription()));
targetEntity.setInternalIdentifier(topicDTO.getInternalIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@ public class TopicEntity implements TenantAware {

@Column(name = "titles_dropdown")
private String titlesDropdown;

@Column(name = "slug")
private String slug;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private TopicMultilingualDTO copyNotSanitizedAttributes(final TopicMultilingualD
output.setCreateDate(input.getCreateDate());
output.setUpdateDate(input.getUpdateDate());
output.setTitles(input.getTitles());
output.setSlug(input.getSlug());
return output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void updateTopic_Should_returnStatusOk_When_calledWithValidCreateParamsAndValidA
new MultilingualTopicTestDataBuilder()
.topicDTO()
.withName("new name")
.withSlug("new_slug")
.withDescription("new desc")
.withInternalIdentifier("new ident")
.withStatus(TopicStatus.INACTIVE.toString())
Expand All @@ -120,6 +121,7 @@ void updateTopic_Should_returnStatusOk_When_calledWithValidCreateParamsAndValidA
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.name['de']").value("new name"))
.andExpect(jsonPath("$.slug").value("new_slug"))
.andExpect(jsonPath("$.description['de']").value("new desc"))
.andExpect(jsonPath("$.internalIdentifier").value("new ident"))
.andExpect(jsonPath("$.status").value(TopicStatus.INACTIVE.toString()))
Expand All @@ -134,6 +136,7 @@ void updateTopic_Should_returnStatusOk_When_featureToggleIsDisabled() throws Exc
new MultilingualTopicTestDataBuilder()
.topicDTO()
.withName("new name")
.withName("new_slug")
.withDescription("new desc")
.withInternalIdentifier("new ident")
.withStatus(TopicStatus.INACTIVE.toString())
Expand Down Expand Up @@ -204,6 +207,7 @@ void createTopic_Should_returnStatusOk_When_calledWithValidCreateParamsAndValidA
final EasyRandom easyRandom = new EasyRandom();
final TopicMultilingualDTO topicDTO = easyRandom.nextObject(TopicMultilingualDTO.class);
topicDTO.setStatus(TopicStatus.INACTIVE.toString());
topicDTO.setSlug("slug");
topicDTO.setTitles(
new TitlesDTO()
._short("short")
Expand All @@ -222,6 +226,7 @@ void createTopic_Should_returnStatusOk_When_calledWithValidCreateParamsAndValidA
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.slug").exists())
.andExpect(jsonPath("$.description").exists())
.andExpect(jsonPath("$.status").value("INACTIVE"))
.andExpect(jsonPath("$.internalIdentifier").exists())
Expand Down Expand Up @@ -266,6 +271,7 @@ void getAllTopics_Should_ReturnTopicsList_When_UserIsAuthenticated() throws Exce
.andExpect(jsonPath("$", hasSize(greaterThan(1))))
.andExpect(jsonPath("$[0].id").value(1))
.andExpect(jsonPath("$[0].name").exists())
.andExpect(jsonPath("$[0].slug").exists())
.andExpect(jsonPath("$[0].description").exists())
.andExpect(jsonPath("$[0].status").exists())
.andExpect(jsonPath("$[0].createDate").exists());
Expand Down Expand Up @@ -294,6 +300,7 @@ void getTopicWithTranslationById_Should_ReturnTopic_When_UserIsAuthenticated() t
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(1))
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.slug").exists())
.andExpect(jsonPath("$.description").exists())
.andExpect(jsonPath("$.status").exists())
.andExpect(jsonPath("$.createDate").exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void getTopicList_Should_ReturnTopicsList_When_UserIsAuthenticated() throws Exce
.andExpect(jsonPath("$", hasSize(greaterThan(1))))
.andExpect(jsonPath("$[0].id").value(1))
.andExpect(jsonPath("$[0].name").exists())
.andExpect(jsonPath("$[0].slug").exists())
.andExpect(jsonPath("$[0].description").exists())
.andExpect(jsonPath("$[0].status").exists())
.andExpect(jsonPath("$[0].createDate").exists());
Expand All @@ -90,6 +91,7 @@ void getAllActiveTopics_Should_returnActiveTopicsList() throws Exception {
.andExpect(jsonPath("$", hasSize(2)))
.andExpect(jsonPath("$[0].id").exists())
.andExpect(jsonPath("$[0].name").exists())
.andExpect(jsonPath("$[0].slug").exists())
.andExpect(jsonPath("$[0].description").exists())
.andExpect(jsonPath("$[0].status").exists())
.andExpect(jsonPath("$[0].createDate").exists());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void toEntity_should_convertToEntityAndBackToMultilingualDTO() {
.status(TopicStatus.ACTIVE.toString())
.internalIdentifier("identifier")
.name(name)
.slug("slug")
.titles(
new TitlesDTO()._short("ts")._long("tl").registrationDropdown("td").welcome("tw"))
.description(description);
Expand All @@ -44,6 +45,7 @@ void toEntity_should_convertToEntityAndBackToMultilingualDTO() {
// then
final TopicDTO actual = topicConverter.toDTO(entity);
assertThat(actual.getName()).isEqualTo(topicDTO.getName().get("de"));
assertThat(actual.getSlug()).isEqualTo(topicDTO.getSlug());
assertThat(actual.getDescription()).isEqualTo(topicDTO.getDescription().get("de"));
}

Expand All @@ -58,6 +60,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier")
.name("{\"de\":\"name de\", \"en\":\"name en\"}")
.description("{\"de\":\"desc de\", \"en\":\"desc en\"}")
.slug("slug")
.titlesShort("ts")
.titlesLong("tl")
.titlesDropdown("td")
Expand All @@ -70,6 +73,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier 2")
.name("{\"de\":\"name 2 de\", \"en\":\"name 2 en\"}")
.description("{\"de\":\"desc 2 de\", \"en\":\"desc 2 en\"}")
.slug("slug")
.titlesShort("ts")
.titlesLong("tl")
.titlesDropdown("td")
Expand All @@ -83,6 +87,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.status(TopicStatus.ACTIVE.toString())
.internalIdentifier("identifier")
.name("name en")
.slug("slug")
.titles(titles)
.description("desc en");
final var topicDTO2 =
Expand All @@ -91,6 +96,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.status(TopicStatus.ACTIVE.toString())
.internalIdentifier("identifier 2")
.name("name 2 en")
.slug("slug")
.titles(titles)
.description("desc 2 en");

Expand All @@ -113,6 +119,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier")
.name("{\"de\":\"name de\", \"en\":\"name en\"}")
.description("{\"de\":\"desc de\", \"en\":\"desc en\"}")
.slug("slug")
.titlesShort("ts")
.titlesLong("tl")
.titlesDropdown("td")
Expand All @@ -125,6 +132,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier 2")
.name("{\"de\":\"name 2 de\", \"en\":\"name 2 en\"}")
.description("{\"de\":\"desc 2 de\", \"en\":\"desc 2 en\"}")
.slug("slug")
.titlesShort("ts")
.titlesLong("tl")
.titlesDropdown("td")
Expand All @@ -138,6 +146,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.status(TopicStatus.ACTIVE.toString())
.internalIdentifier("identifier")
.name("name de")
.slug("slug")
.titles(titles)
.description("desc de");
final var topicDTO2 =
Expand All @@ -146,6 +155,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.status(TopicStatus.ACTIVE.toString())
.internalIdentifier("identifier 2")
.name("name 2 de")
.slug("slug")
.titles(titles)
.description("desc 2 de");

Expand All @@ -168,6 +178,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier")
.name("{\"de\":\"name de\", \"en\":\"name en\"}")
.description("{\"de\":\"desc de\", \"en\":\"desc en\"}")
.slug("slug")
.titlesLong(titles.getLong())
.titlesShort(titles.getShort())
.titlesDropdown(titles.getRegistrationDropdown())
Expand All @@ -180,6 +191,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier 2")
.name("{\"de\":\"name 2 de\", \"en\":\"name 2 en\"}")
.description("{\"de\":\"desc 2 de\", \"en\":\"desc 2 en\"}")
.slug("slug")
.titlesLong(titles.getLong())
.titlesShort(titles.getShort())
.titlesWelcome(titles.getWelcome())
Expand All @@ -205,6 +217,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier")
.name(name1)
.description(description1)
.slug("slug")
.titles(titles);
final var topicDTO2 =
new TopicMultilingualDTO()
Expand All @@ -213,6 +226,7 @@ void toDTOList_Should_convertCollectionOfTopicEntitiesToListOfTopicDTOsWithCorre
.internalIdentifier("identifier 2")
.name(name2)
.description(description2)
.slug("slug")
.titles(titles);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void topicGroupRepositoryReturnsSomeMeaningfulData() {
val te1 =
TopicEntity.builder()
.name("te1")
.slug("s1")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand All @@ -56,6 +57,7 @@ void topicGroupRepositoryReturnsSomeMeaningfulData() {
val te2 =
TopicEntity.builder()
.name("te2")
.slug("s2")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand Down Expand Up @@ -97,6 +99,7 @@ void deletingTopicGroupKeepsTopicsUntouched() {
val te1 =
TopicEntity.builder()
.name("te1")
.slug("s1")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand All @@ -107,6 +110,7 @@ void deletingTopicGroupKeepsTopicsUntouched() {
val te2 =
TopicEntity.builder()
.name("te2")
.slug("s2")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand All @@ -117,6 +121,7 @@ void deletingTopicGroupKeepsTopicsUntouched() {
val te3 =
TopicEntity.builder()
.name("te3")
.slug("s3")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand All @@ -127,6 +132,7 @@ void deletingTopicGroupKeepsTopicsUntouched() {
val te4 =
TopicEntity.builder()
.name("te4")
.slug("s4")
.createDate(now)
.updateDate(now)
.titlesDropdown("td")
Expand Down Expand Up @@ -180,6 +186,7 @@ void deletingTopicGetsItRemovedFromGroup() {
val te1 =
TopicEntity.builder()
.name("te1")
.slug("s1")
.createDate(now)
.updateDate(now)
.titlesLong("long")
Expand All @@ -190,6 +197,7 @@ void deletingTopicGetsItRemovedFromGroup() {
val te2 =
TopicEntity.builder()
.name("te2")
.slug("s2")
.createDate(now)
.updateDate(now)
.titlesLong("long")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void save_Should_saveNewTopic() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.titlesLong("long")
.titlesShort("short")
Expand All @@ -78,6 +79,7 @@ void save_Should_saveNewTopic_withFallbackAgencyId() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.fallbackAgencyId(123)
.titlesLong("long")
Expand All @@ -100,6 +102,7 @@ void save_Should_saveNewTopic_withoutFallbackAgencyId() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.titlesLong("long")
.titlesShort("short")
Expand All @@ -125,6 +128,7 @@ void save_Should_saveNewTopic_withFallbackUrl() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.fallbackUrl(fallbackUrl)
.titlesLong("long")
Expand All @@ -147,6 +151,7 @@ void save_Should_saveNewTopic_withoutFallbackUrl() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.titlesLong("long")
.titlesShort("short")
Expand All @@ -172,6 +177,7 @@ void save_Should_saveNewTopic_withWelcomeMessage() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.welcomeMessage(welcomeMessage)
.titlesShort("short")
Expand All @@ -194,6 +200,7 @@ void save_Should_saveNewTopic_withoutWelcomeMessage() {
TopicEntity.builder()
.name(NEW_TOPIC_NAME)
.description("desc")
.slug("slug")
.createDate(LocalDateTime.now())
.titlesWelcome("welcome")
.titlesLong("long")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private static TopicEntity newTopicEntity(String te1, LocalDateTime now) {
.name(te1)
.createDate(now)
.updateDate(now)
.slug("slug")
.titlesDropdown("td")
.titlesWelcome("tw")
.titlesLong("tl")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public MultilingualTopicTestDataBuilder withDescription(final String desc, final
return this;
}

public MultilingualTopicTestDataBuilder withSlug(final String slug) {
topicMultilingualDTO.setSlug(slug);
return this;
}

public TopicMultilingualDTO build() {
return topicMultilingualDTO;
}
Expand Down
Loading
Loading