Skip to content

Commit

Permalink
Update Idea domain
Browse files Browse the repository at this point in the history
  • Loading branch information
gruz0 committed Nov 25, 2024
1 parent 80ddda3 commit 68c06e2
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 555 deletions.
567 changes: 250 additions & 317 deletions src/idea/adapters/IdeaRepositorySQLite.ts

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/idea/app/commands/MakeReservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ export class MakeReservationHandler {
)
}

const idea = Idea.New(
command.ideaId,
command.conceptId,
concept.content.problem,
concept.content.marketExistence
)

concept.content.targetAudience.forEach((targetAudience) => {
idea.addTargetAudience(
const targetAudiences = concept.content.targetAudience.map(
(targetAudience) =>
TargetAudience.New(
randomUUID(),
command.ideaId,
targetAudience.segment,
targetAudience.description,
targetAudience.challenges
)
)
})
)

const idea = Idea.New(
command.ideaId,
command.conceptId,
concept.content.problem,
concept.content.marketExistence,
targetAudiences
)

await this.repository.addIdea(idea)

Expand Down
5 changes: 1 addition & 4 deletions src/idea/app/commands/RequestSocialMediaCampaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export class RequestSocialMediaCampaignsHandler {
throw new Error(`Idea ${command.ideaId} does not exist`)
}

const socialMediaCampaigns =
await this.repository.getSocialMediaCampaignsByIdeaId(command.ideaId)

if (socialMediaCampaigns) {
if (idea.getSocialMediaCampaigns()) {
return
}

Expand Down
69 changes: 11 additions & 58 deletions src/idea/app/queries/GetIdea.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import * as Sentry from '@sentry/nextjs'
import { NotFoundError } from '@/common/errors/NotFoundError'
import { Idea } from '@/idea/domain/Aggregate'
import { CompetitorAnalysis } from '@/idea/domain/CompetitorAnalysis'
import { ContentIdeasForMarketing } from '@/idea/domain/ContentIdeasForMarketing'
import { ElevatorPitch } from '@/idea/domain/ElevatorPitch'
import { GoogleTrendsKeyword } from '@/idea/domain/GoogleTrendsKeyword'
import { MarketAnalysis } from '@/idea/domain/MarketAnalysis'
import { ProductName } from '@/idea/domain/ProductName'
import { SWOTAnalysis } from '@/idea/domain/SWOTAnalysis'
import { TargetAudience } from '@/idea/domain/TargetAudience'
import { ValueProposition } from '@/idea/domain/ValueProposition'

type Query = {
id: string
Expand Down Expand Up @@ -92,21 +83,6 @@ interface ContentIdeaDTO {

interface ReadModel {
getById(id: string): Promise<Idea | null>
getTargetAudiencesByIdeaId(ideaId: string): Promise<TargetAudience[]>
getValuePropositionByIdeaId(ideaId: string): Promise<ValueProposition | null>
getMarketAnalysisByIdeaId(ideaId: string): Promise<MarketAnalysis | null>
getCompetitorAnalysisByIdeaId(
ideaId: string
): Promise<CompetitorAnalysis | null>
getProductNamesByIdeaId(ideaId: string): Promise<ProductName[] | null>
getSWOTAnalysisByIdeaId(ideaId: string): Promise<SWOTAnalysis | null>
getElevatorPitchesByIdeaId(ideaId: string): Promise<ElevatorPitch[] | null>
getGoogleTrendsKeywordsByIdeaId(
ideaId: string
): Promise<GoogleTrendsKeyword[] | null>
getContentIdeasForMarketingByIdeaId(
ideaId: string
): Promise<ContentIdeasForMarketing | null>
}

export class GetIdeaHandler {
Expand All @@ -124,38 +100,15 @@ export class GetIdeaHandler {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

const targetAudiences = await this.readModel.getTargetAudiencesByIdeaId(
query.id
)

const valueProposition = await this.readModel.getValuePropositionByIdeaId(
query.id
)

const marketAnalysis = await this.readModel.getMarketAnalysisByIdeaId(
query.id
)

const competitorAnalysis =
await this.readModel.getCompetitorAnalysisByIdeaId(query.id)

const productNames = await this.readModel.getProductNamesByIdeaId(
query.id
)

const swotAnalysis = await this.readModel.getSWOTAnalysisByIdeaId(
query.id
)

const elevatorPitches = await this.readModel.getElevatorPitchesByIdeaId(
query.id
)

const googleTrendsKeywords =
await this.readModel.getGoogleTrendsKeywordsByIdeaId(query.id)

const contentIdeas =
await this.readModel.getContentIdeasForMarketingByIdeaId(query.id)
const valueProposition = idea.getValueProposition()
const targetAudiences = idea.getTargetAudiences()
const marketAnalysis = idea.getMarketAnalysis()
const competitorAnalysis = idea.getCompetitorAnalysis()
const productNames = idea.getProductNames()
const swotAnalysis = idea.getSWOTAnalysis()
const elevatorPitches = idea.getElevatorPitches()
const googleTrendsKeywords = idea.getGoogleTrendsKeywords()
const contentIdeasForMarketing = idea.getContentIdeasForMarketing()

return {
id: idea.getId().getValue(),
Expand Down Expand Up @@ -225,8 +178,8 @@ export class GetIdeaHandler {
googleTrendsKeywords: googleTrendsKeywords
? googleTrendsKeywords.map((keyword) => keyword.getKeyword())
: null,
contentIdeasForMarketing: contentIdeas
? contentIdeas.getContentIdeas().reduce(
contentIdeasForMarketing: contentIdeasForMarketing
? contentIdeasForMarketing.getContentIdeas().reduce(
(acc, contentIdea) => {
const section = contentIdea.getSection().getName()

Expand Down
7 changes: 1 addition & 6 deletions src/idea/app/queries/GetSocialMediaCampaigns.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Sentry from '@sentry/nextjs'
import { NotFoundError } from '@/common/errors/NotFoundError'
import { Idea } from '@/idea/domain/Aggregate'
import { SocialMediaCampaigns } from '@/idea/domain/SocialMediaCampaigns'

type Query = {
id: string
Expand Down Expand Up @@ -44,9 +43,6 @@ interface DTO {

interface ReadModel {
getById(id: string): Promise<Idea | null>
getSocialMediaCampaignsByIdeaId(
ideaId: string
): Promise<SocialMediaCampaigns | null>
}

export class GetSocialMediaCampaignsHandler {
Expand All @@ -64,8 +60,7 @@ export class GetSocialMediaCampaignsHandler {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

const socialMediaCampaigns =
await this.readModel.getSocialMediaCampaignsByIdeaId(query.id)
const socialMediaCampaigns = idea.getSocialMediaCampaigns()

return {
id: idea.getId().getValue(),
Expand Down
Loading

0 comments on commit 68c06e2

Please sign in to comment.