From f62ef8290a4deabb3df936b02a8762197768adde Mon Sep 17 00:00:00 2001 From: katjam Date: Mon, 28 Oct 2024 12:41:12 +0000 Subject: [PATCH 1/5] WIP - allow multiple partnershiop tags --- src/Data/PlaceCal/Events.elm | 4 ++++ src/Data/PlaceCal/Partners.elm | 28 +++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Data/PlaceCal/Events.elm b/src/Data/PlaceCal/Events.elm index 3119c7b..f026c13 100644 --- a/src/Data/PlaceCal/Events.elm +++ b/src/Data/PlaceCal/Events.elm @@ -2,6 +2,7 @@ module Data.PlaceCal.Events exposing (Event, EventPartner, afterDate, allEventsQ import BackendTask import BackendTask.Custom +import Constants import Data.PlaceCal.Api import Data.PlaceCal.Partners import FatalError @@ -14,6 +15,7 @@ import Time type alias Event = { id : String + , partnershipTagList : List String , name : String , summary : String , description : String @@ -58,6 +60,7 @@ type alias Geo = emptyEvent : Event emptyEvent = { id = "" + , partnershipTagList = [] , name = "" , summary = "" , description = "" @@ -187,6 +190,7 @@ decode = Json.Decode.succeed Event |> Json.Decode.Pipeline.required "id" Json.Decode.string + |> Json.Decode.Pipeline.optional "partnershipTagList" (Json.Decode.succeed [ "3" ]) [ "3" ] |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" diff --git a/src/Data/PlaceCal/Partners.elm b/src/Data/PlaceCal/Partners.elm index e0e58f2..f15d702 100644 --- a/src/Data/PlaceCal/Partners.elm +++ b/src/Data/PlaceCal/Partners.elm @@ -11,6 +11,7 @@ import Json.Encode type alias Partner = { id : String + , partnershipTagList : List String , name : String , summary : String , description : String @@ -54,6 +55,7 @@ type alias ServiceArea = emptyPartner : Partner emptyPartner = { id = "" + , partnershipTagList = [] , name = "" , summary = "" , description = "" @@ -76,19 +78,33 @@ type alias AllPartnersResponse = { allPartners : List Partner } +partnerTagId = + "3" + + partnersData : BackendTask.BackendTask { fatal : FatalError.FatalError, recoverable : BackendTask.Custom.Error } AllPartnersResponse partnersData = - Data.PlaceCal.Api.fetchAndCachePlaceCalData "partners" - allPartnersQuery - partnersDecoder + BackendTask.combine + [ Data.PlaceCal.Api.fetchAndCachePlaceCalData + ("partners-" ++ partnerTagId) + allPartnersQuery + partnersDecoder + , Data.PlaceCal.Api.fetchAndCachePlaceCalData + ("partners-" ++ partnerTagId) + allPartnersQuery + partnersDecoder + ] allPartnersQuery : Json.Encode.Value allPartnersQuery = Json.Encode.object [ ( "query" - , Json.Encode.string """ - query { partnersByTag(tagId: 3) { + , Json.Encode.string + ("query { partnersByTag(tagId: " + ++ partnerTagId + ++ """ + ) { id name description @@ -100,6 +116,7 @@ allPartnersQuery = logo } } """ + ) ) ] @@ -114,6 +131,7 @@ decodePartner : Json.Decode.Decoder Partner decodePartner = Json.Decode.succeed Partner |> Json.Decode.Pipeline.required "id" Json.Decode.string + |> Json.Decode.Pipeline.optional "partnershipTagList" (Json.Decode.succeed [ "3" ]) [ "3" ] |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" Json.Decode.string "" |> Json.Decode.Pipeline.optional "description" Json.Decode.string "" From 24a23253c67652af8e5c99817bf6f5cc130e5840 Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 2 Nov 2024 10:20:53 +0000 Subject: [PATCH 2/5] feat: Allow for multiple partnerships --- .env.example | 2 + app/Route/Partners/Partner_.elm | 6 +-- elm-constants.json | 3 +- src/Data/PlaceCal/Partners.elm | 86 ++++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 30 deletions(-) diff --git a/.env.example b/.env.example index 911f4c3..82bea08 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,6 @@ CANONICAL_URL=http://localhost:3030/ PLACECAL_API=https://placecal.org/api/v1/graphql +# comma seperated list of id|name for partnerships to include +PARTNERSHIP_TAG_LIST=3|London,30|Manchester JOIN_US_FUNCTION_URL=https://formspree.io/f/xeqdljwl diff --git a/app/Route/Partners/Partner_.elm b/app/Route/Partners/Partner_.elm index 75f2988..32f1eeb 100644 --- a/app/Route/Partners/Partner_.elm +++ b/app/Route/Partners/Partner_.elm @@ -240,11 +240,7 @@ pages = partnerData.allPartners |> List.map (\partner -> { partner = partner.id }) ) - (Data.PlaceCal.Api.fetchAndCachePlaceCalData - "partners" - Data.PlaceCal.Partners.allPartnersQuery - Data.PlaceCal.Partners.partnersDecoder - ) + Data.PlaceCal.Partners.partnersData |> BackendTask.allowFatal diff --git a/elm-constants.json b/elm-constants.json index 683fb9a..355d190 100644 --- a/elm-constants.json +++ b/elm-constants.json @@ -4,6 +4,7 @@ "values": [ "CANONICAL_URL", "PLACECAL_API", - "JOIN_US_FUNCTION_URL" + "JOIN_US_FUNCTION_URL", + "PARTNERSHIP_TAG_LIST" ] } diff --git a/src/Data/PlaceCal/Partners.elm b/src/Data/PlaceCal/Partners.elm index f15d702..966d261 100644 --- a/src/Data/PlaceCal/Partners.elm +++ b/src/Data/PlaceCal/Partners.elm @@ -2,6 +2,7 @@ module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, import BackendTask import BackendTask.Custom +import Constants import Data.PlaceCal.Api import FatalError import Json.Decode @@ -11,7 +12,7 @@ import Json.Encode type alias Partner = { id : String - , partnershipTagList : List String + , partnershipTag : String , name : String , summary : String , description : String @@ -55,7 +56,7 @@ type alias ServiceArea = emptyPartner : Partner emptyPartner = { id = "" - , partnershipTagList = [] + , partnershipTag = "" , name = "" , summary = "" , description = "" @@ -78,31 +79,68 @@ type alias AllPartnersResponse = { allPartners : List Partner } -partnerTagId = - "3" +type alias PartnershipTag = + { id : Int + , name : String + } + + +partnershipTagList : List PartnershipTag +partnershipTagList = + String.split "," Constants.partnershipTagList + |> List.map + (\tagInfo -> + { id = partnershipTagId tagInfo + , name = partnershipTagName tagInfo + } + ) + + +partnershipTagIdList : List Int +partnershipTagIdList = + partnershipTagList + |> List.map .id + + +partnershipTagId : String -> Int +partnershipTagId tagInfo = + List.head (String.split "|" tagInfo) + |> Maybe.withDefault "" + |> String.toInt + |> Maybe.withDefault 0 + + +partnershipTagName : String -> String +partnershipTagName tagInfo = + List.head + (List.reverse (String.split "|" tagInfo)) + |> Maybe.withDefault "" partnersData : BackendTask.BackendTask { fatal : FatalError.FatalError, recoverable : BackendTask.Custom.Error } AllPartnersResponse partnersData = BackendTask.combine - [ Data.PlaceCal.Api.fetchAndCachePlaceCalData - ("partners-" ++ partnerTagId) - allPartnersQuery - partnersDecoder - , Data.PlaceCal.Api.fetchAndCachePlaceCalData - ("partners-" ++ partnerTagId) - allPartnersQuery - partnersDecoder - ] - - -allPartnersQuery : Json.Encode.Value -allPartnersQuery = + (List.map + (\partnershipTag -> + Data.PlaceCal.Api.fetchAndCachePlaceCalData + ("partners-" ++ partnershipTag) + (allPartnersQuery partnershipTag) + (partnersDecoder partnershipTag) + ) + (List.map (\id -> String.fromInt id) partnershipTagIdList) + ) + |> BackendTask.map (List.map .allPartners) + |> BackendTask.map List.concat + |> BackendTask.map (\partnerList -> { allPartners = partnerList }) + + +allPartnersQuery : String -> Json.Encode.Value +allPartnersQuery partnershipTag = Json.Encode.object [ ( "query" , Json.Encode.string ("query { partnersByTag(tagId: " - ++ partnerTagId + ++ partnershipTag ++ """ ) { id @@ -121,17 +159,17 @@ allPartnersQuery = ] -partnersDecoder : Json.Decode.Decoder AllPartnersResponse -partnersDecoder = +partnersDecoder : String -> Json.Decode.Decoder AllPartnersResponse +partnersDecoder partnershipTag = Json.Decode.succeed AllPartnersResponse - |> Json.Decode.Pipeline.requiredAt [ "data", "partnersByTag" ] (Json.Decode.list decodePartner) + |> Json.Decode.Pipeline.requiredAt [ "data", "partnersByTag" ] (Json.Decode.list (decodePartner partnershipTag)) -decodePartner : Json.Decode.Decoder Partner -decodePartner = +decodePartner : String -> Json.Decode.Decoder Partner +decodePartner partnershipTag = Json.Decode.succeed Partner |> Json.Decode.Pipeline.required "id" Json.Decode.string - |> Json.Decode.Pipeline.optional "partnershipTagList" (Json.Decode.succeed [ "3" ]) [ "3" ] + |> Json.Decode.Pipeline.optional "partnershipTag" (Json.Decode.succeed partnershipTag) "" |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" Json.Decode.string "" |> Json.Decode.Pipeline.optional "description" Json.Decode.string "" From 87d2904cc9558a7a074d9085157d4e172ed5b6cf Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 2 Nov 2024 10:54:08 +0000 Subject: [PATCH 3/5] Use Int for partnership tag id --- src/Data/PlaceCal/Events.elm | 6 +++--- src/Data/PlaceCal/Partners.elm | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Data/PlaceCal/Events.elm b/src/Data/PlaceCal/Events.elm index f026c13..3c675ba 100644 --- a/src/Data/PlaceCal/Events.elm +++ b/src/Data/PlaceCal/Events.elm @@ -15,7 +15,7 @@ import Time type alias Event = { id : String - , partnershipTagList : List String + , partnershipTagId : Int , name : String , summary : String , description : String @@ -60,7 +60,7 @@ type alias Geo = emptyEvent : Event emptyEvent = { id = "" - , partnershipTagList = [] + , partnershipTagId = 0 , name = "" , summary = "" , description = "" @@ -190,7 +190,7 @@ decode = Json.Decode.succeed Event |> Json.Decode.Pipeline.required "id" Json.Decode.string - |> Json.Decode.Pipeline.optional "partnershipTagList" (Json.Decode.succeed [ "3" ]) [ "3" ] + |> Json.Decode.Pipeline.optional "partnershipTagId" (Json.Decode.succeed 3) 3 |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" diff --git a/src/Data/PlaceCal/Partners.elm b/src/Data/PlaceCal/Partners.elm index 966d261..231086e 100644 --- a/src/Data/PlaceCal/Partners.elm +++ b/src/Data/PlaceCal/Partners.elm @@ -12,7 +12,7 @@ import Json.Encode type alias Partner = { id : String - , partnershipTag : String + , partnershipTagId : Int , name : String , summary : String , description : String @@ -56,7 +56,7 @@ type alias ServiceArea = emptyPartner : Partner emptyPartner = { id = "" - , partnershipTag = "" + , partnershipTagId = 0 , name = "" , summary = "" , description = "" @@ -121,13 +121,13 @@ partnersData : BackendTask.BackendTask { fatal : FatalError.FatalError, recovera partnersData = BackendTask.combine (List.map - (\partnershipTag -> + (\partnershipTagInt -> Data.PlaceCal.Api.fetchAndCachePlaceCalData - ("partners-" ++ partnershipTag) - (allPartnersQuery partnershipTag) - (partnersDecoder partnershipTag) + ("partners-" ++ String.fromInt partnershipTagInt) + (allPartnersQuery (String.fromInt partnershipTagInt)) + (partnersDecoder partnershipTagInt) ) - (List.map (\id -> String.fromInt id) partnershipTagIdList) + partnershipTagIdList ) |> BackendTask.map (List.map .allPartners) |> BackendTask.map List.concat @@ -159,17 +159,17 @@ allPartnersQuery partnershipTag = ] -partnersDecoder : String -> Json.Decode.Decoder AllPartnersResponse -partnersDecoder partnershipTag = +partnersDecoder : Int -> Json.Decode.Decoder AllPartnersResponse +partnersDecoder partnershipTagInt = Json.Decode.succeed AllPartnersResponse - |> Json.Decode.Pipeline.requiredAt [ "data", "partnersByTag" ] (Json.Decode.list (decodePartner partnershipTag)) + |> Json.Decode.Pipeline.requiredAt [ "data", "partnersByTag" ] (Json.Decode.list (decodePartner partnershipTagInt)) -decodePartner : String -> Json.Decode.Decoder Partner -decodePartner partnershipTag = +decodePartner : Int -> Json.Decode.Decoder Partner +decodePartner partnershipTagInt = Json.Decode.succeed Partner |> Json.Decode.Pipeline.required "id" Json.Decode.string - |> Json.Decode.Pipeline.optional "partnershipTag" (Json.Decode.succeed partnershipTag) "" + |> Json.Decode.Pipeline.optional "partnershipTagId" (Json.Decode.succeed partnershipTagInt) 0 |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" Json.Decode.string "" |> Json.Decode.Pipeline.optional "description" Json.Decode.string "" From c78d1496a09e091d8133b40728bed5da954491ce Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 2 Nov 2024 11:26:18 +0000 Subject: [PATCH 4/5] Load events from multiple partners --- app/Route/Events/Event_.elm | 6 +---- src/Data/PlaceCal/Events.elm | 40 +++++++++++++++++++++++----------- src/Data/PlaceCal/Partners.elm | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/Route/Events/Event_.elm b/app/Route/Events/Event_.elm index d747c9e..dcfb331 100644 --- a/app/Route/Events/Event_.elm +++ b/app/Route/Events/Event_.elm @@ -61,11 +61,7 @@ pages = eventData.allEvents |> List.map (\event -> { event = event.id }) ) - (Data.PlaceCal.Api.fetchAndCachePlaceCalData - "events" - Data.PlaceCal.Events.allEventsQuery - Data.PlaceCal.Events.eventsDecoder - ) + Data.PlaceCal.Events.eventsData |> BackendTask.allowFatal diff --git a/src/Data/PlaceCal/Events.elm b/src/Data/PlaceCal/Events.elm index 3c675ba..9cee84d 100644 --- a/src/Data/PlaceCal/Events.elm +++ b/src/Data/PlaceCal/Events.elm @@ -152,18 +152,31 @@ eventsWithPartners eventList partnerList = eventsData : BackendTask.BackendTask { fatal : FatalError.FatalError, recoverable : BackendTask.Custom.Error } AllEventsResponse eventsData = - Data.PlaceCal.Api.fetchAndCachePlaceCalData "events" - allEventsQuery - eventsDecoder + BackendTask.combine + (List.map + (\partnershipTagInt -> + Data.PlaceCal.Api.fetchAndCachePlaceCalData + ("events-" ++ String.fromInt partnershipTagInt) + (allEventsQuery (String.fromInt partnershipTagInt)) + (eventsDecoder partnershipTagInt) + ) + Data.PlaceCal.Partners.partnershipTagIdList + ) + |> BackendTask.map (List.map .allEvents) + |> BackendTask.map List.concat + |> BackendTask.map (\eventList -> { allEvents = eventList }) -allEventsQuery : Json.Encode.Value -allEventsQuery = +allEventsQuery : String -> Json.Encode.Value +allEventsQuery partnershipTag = Json.Encode.object [ ( "query" -- Note hardcoded to load events from 2022-09-01 - , Json.Encode.string """ - query { eventsByFilter(tagId: 3, fromDate: "2024-01-01 00:00", toDate: "2025-06-15 00:00") { + , Json.Encode.string + ("query { eventsByFilter(tagId: " + ++ partnershipTag + ++ """ + , fromDate: "2024-01-01 00:00", toDate: "2025-06-15 00:00") { id name summary @@ -175,22 +188,23 @@ allEventsQuery = organizer { id } } } """ + ) ) ] -eventsDecoder : Json.Decode.Decoder AllEventsResponse -eventsDecoder = +eventsDecoder : Int -> Json.Decode.Decoder AllEventsResponse +eventsDecoder partnershipTagInt = Json.Decode.succeed AllEventsResponse - |> Json.Decode.Pipeline.requiredAt [ "data", "eventsByFilter" ] (Json.Decode.list decode) + |> Json.Decode.Pipeline.requiredAt [ "data", "eventsByFilter" ] (Json.Decode.list (decodeEvent partnershipTagInt)) -decode : Json.Decode.Decoder Event -decode = +decodeEvent : Int -> Json.Decode.Decoder Event +decodeEvent partnershipTagInt = Json.Decode.succeed Event |> Json.Decode.Pipeline.required "id" Json.Decode.string - |> Json.Decode.Pipeline.optional "partnershipTagId" (Json.Decode.succeed 3) 3 + |> Json.Decode.Pipeline.optional "partnershipTagId" (Json.Decode.succeed partnershipTagInt) 0 |> Json.Decode.Pipeline.required "name" Json.Decode.string |> Json.Decode.Pipeline.optional "summary" diff --git a/src/Data/PlaceCal/Partners.elm b/src/Data/PlaceCal/Partners.elm index 231086e..ee43f0a 100644 --- a/src/Data/PlaceCal/Partners.elm +++ b/src/Data/PlaceCal/Partners.elm @@ -1,4 +1,4 @@ -module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, allPartnersQuery, partnerFromSlug, partnerNamesFromIds, partnersData, partnersDecoder) +module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, allPartnersQuery, partnerFromSlug, partnerNamesFromIds, partnersData, partnersDecoder, partnershipTagIdList) import BackendTask import BackendTask.Custom From 79fee7ce2df4ba31348a6689abc7d238b7a07265 Mon Sep 17 00:00:00 2001 From: katjam Date: Sat, 2 Nov 2024 11:40:51 +0000 Subject: [PATCH 5/5] Clear up unused imports --- app/Route/Events/Event_.elm | 1 - app/Route/Partners/Partner_.elm | 1 - src/Data/PlaceCal/Events.elm | 3 +-- src/Data/PlaceCal/Partners.elm | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Route/Events/Event_.elm b/app/Route/Events/Event_.elm index dcfb331..69b5c35 100644 --- a/app/Route/Events/Event_.elm +++ b/app/Route/Events/Event_.elm @@ -9,7 +9,6 @@ module Route.Events.Event_ exposing (Model, Msg, RouteParams, route, Data, Actio import BackendTask import Copy.Keys exposing (Key(..)) import Copy.Text exposing (t) -import Data.PlaceCal.Api import Data.PlaceCal.Events import FatalError import Head diff --git a/app/Route/Partners/Partner_.elm b/app/Route/Partners/Partner_.elm index 32f1eeb..09e2bfa 100644 --- a/app/Route/Partners/Partner_.elm +++ b/app/Route/Partners/Partner_.elm @@ -10,7 +10,6 @@ import BackendTask import Browser.Dom import Copy.Keys exposing (Key(..)) import Copy.Text exposing (t) -import Data.PlaceCal.Api import Data.PlaceCal.Events import Data.PlaceCal.Partners import Effect diff --git a/src/Data/PlaceCal/Events.elm b/src/Data/PlaceCal/Events.elm index 9cee84d..51f8a8b 100644 --- a/src/Data/PlaceCal/Events.elm +++ b/src/Data/PlaceCal/Events.elm @@ -1,8 +1,7 @@ -module Data.PlaceCal.Events exposing (Event, EventPartner, afterDate, allEventsQuery, eventFromSlug, eventPartnerFromId, eventsData, eventsDecoder, eventsFromDate, eventsWithPartners, next4Events, onOrBeforeDate) +module Data.PlaceCal.Events exposing (Event, EventPartner, afterDate, eventFromSlug, eventPartnerFromId, eventsData, eventsFromDate, eventsWithPartners, next4Events, onOrBeforeDate) import BackendTask import BackendTask.Custom -import Constants import Data.PlaceCal.Api import Data.PlaceCal.Partners import FatalError diff --git a/src/Data/PlaceCal/Partners.elm b/src/Data/PlaceCal/Partners.elm index ee43f0a..a21370e 100644 --- a/src/Data/PlaceCal/Partners.elm +++ b/src/Data/PlaceCal/Partners.elm @@ -1,4 +1,4 @@ -module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, allPartnersQuery, partnerFromSlug, partnerNamesFromIds, partnersData, partnersDecoder, partnershipTagIdList) +module Data.PlaceCal.Partners exposing (Address, Contact, Partner, ServiceArea, partnerFromSlug, partnerNamesFromIds, partnersData, partnershipTagIdList) import BackendTask import BackendTask.Custom