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

common-service documentation #213

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
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
19 changes: 16 additions & 3 deletions DSL/Ruuter.public/GET/calendar/national-holidays/eoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@ declaration:
call: declare
version: 0.1
name: "Find Holidays Until End of Year"
description: |
This service returns all holidays from today's date until the end of the year, based on a mock API response of 2024 public holidays.
description: "Returns all holidays from today till the end of the year"
method: get
params: []
accepts: json
returns: json
allowlist:
body:
- field: chatId
type: string
description: "The chat ID for the message"
- field: authorId
type: string
description: "The author ID for the message"
- field: today
type: string
description: "The current date in ISO format - ex. 'yyyy-mm-dd'"
- field: yearEnd
type: string
description: "The end of the year in ISO format - ex. 'yyyy-mm-dd'"

prepare:
assign:
Expand Down
26 changes: 21 additions & 5 deletions DSL/Ruuter.public/GET/calendar/national-holidays/find/by-month.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
declaration:
name: "Holiday Filter by Month"
description: "Fetches and filters Estonian national holidays for a specified month in 2024."
parameters:
- month: "The month for which to retrieve holidays."
name: "Filter by Month"
description: "Fetches and filters Estonian national holidays for a specified month in 2024"
params:
- chatId: "The chat ID for the message - string"
- authorId: "The author ID for the message- string"
- month: "The month for which to retrieve holidays - string - ex. 'mai' or 'veebruar'"

method: get
return: json
accepts: json
returns: json
namespace: common-services
allowlist:
body:
- field: chatId
type: string
description: "The chat ID for the message"
- field: authorId
type: string
description: "The author ID for the message"
- field: month
type: string
description: "The incoming month for which to retrieve holidays - ex. 'mai' or 'veebruar'"

prepare:
assign:
Expand Down
13 changes: 13 additions & 0 deletions DSL/Ruuter.public/GET/calendar/national-holidays/find/by-name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ declaration:
name: "Holiday Search Service"
description: "Searches for a national holiday by name in the 2024 calendar"
method: get
accepts: json
returns: json
namespace: common-services
allowlist:
body:
- field: chatId
type: string
description: "The chat ID for the message"
- field: authorId
type: string
description: "The author ID for the message"
- field: holidayName
type: string
description: "Holiday name for which to retrieve holidays - string - ex. 'jaanipäev'"

prepare:
assign:
Expand Down
86 changes: 71 additions & 15 deletions DSL/Ruuter.public/GET/calendar/national-holidays/mock/eoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ declaration:
call: declare
version: 0.1
name: "MOCK - Find Holidays Until End of Year"
description: |
This mock service returns all holidays from today's date until the end of the year, based on a mock API response of 2024 public holidays.
description: "MOCK - Returns all holidays from today's date until the end of the year"
method: get
params: []
accepts: json
returns: json
allowlist:
body:
- field: chatId
type: string
description: "The chat ID for the message"
- field: authorId
type: string
description: "The author ID for the message"
- field: today
type: string
description: "The current date in ISO format - ex. 'yyyy-mm-dd'"
- field: yearEnd
type: string
description: "The end of the year in ISO format - ex. 'yyyy-mm-dd'"

prepare:
assign:
today: "2024-10-10" #${new Date().toISOString().split("T")[0]}
yearEnd: ${today.split("-")[0] + "-12-31"}
chatId: "1010" # ${incoming.params.chatId}
authorId: "abc123" # ${incoming.params.authorId}
today: "2024-09-24" # ${new Date().toISOString().split("T")[0]}
yearEnd: "2024-12-31" # ${today.split("-")[0] + "-12-31"}
next: makeApiCall

makeApiCall:
Expand Down Expand Up @@ -45,25 +60,66 @@ makeApiCall:
name: "esimene jõulupüha"
- date: "2024-12-26"
name: "teine jõulupüha"
result: holiday_data
result: holidayData
next: validateHolidaysEOY

validateHolidaysEOY:
assign:
holidaysEOY: ${holiday_data.response.body.holidays
holidaysEOY: ${holidayData.response.body.holidays
.filter(holiday => holiday.date >= today && holiday.date <= yearEnd)
.sort((a, b) => new Date(a.date) - new Date(b.date))}
next: formatResult

formatResult:
call: reflect.mock
call: reflect.mock # http.post
args:
url: "[#DMAPPER]/hbs/calendar/national-holidays/get_national_holiday_eoy"
response:
result: "Kõik riigipühad alates tänsest kuni aasta lõpuni on: \n*2024-12-24\n jõululaupäev\n\n *2024-12-25\n esimene jõulupüha\n\n *2024-12-26\n teine jõulupüha\n\n"
url: "[#DMAPPER]/common-services/hbs/calendar/national-holidays/get_national_holiday_eoy"
headers:
type: json
body:
data: ${holidaysEOY}
response: {
"result": "Kõik riigipühad alates tänsest kuni aasta lõpuni on: \n*2024-12-24\n jõululaupäev\n\n *2024-12-25\n esimene jõulupüha\n\n *2024-12-26\n teine jõulupüha\n\n"
}
result: formattedHolidays
next: returnValue
next: assignResponse

assignResponse:
assign:
res: ${formattedHolidays.response.body}
next: formatMessages

# format throgh DM bot response to messages
formatMessages:
call: reflect.mock # http.post
args:
url: "[#DMAPPER]/common-services/hbs/bot_responses_to_messages"
headers:
type: json
body:
data:
{
"botMessages": "${[res]}",
"chatId": "${chatId}",
"authorId": "${authorId}",
"authorFirstName": "",
"authorLastName": "",
"authorTimestamp": "${new Date().toISOString()}",
"created": "${new Date().toISOString()}",
}
response:
body:
- chatId: "1010"
content: "Kõik riigipühad alates tänsest kuni aasta lõpuni on: \n*2024-12-24\n jõululaupäev\n\n *2024-12-25\n esimene jõulupüha\n\n *2024-12-26\n teine jõulupüha\n\n"
buttons: []
authorTimestamp: "2024-11-05T12:00:00Z"
authorId: "abc123"
authorFirstName: ""
authorLastName: ""
created: "2024-11-05T12:00:00Z"
result: formatMessage
next: returnResult

returnValue:
return: ${formattedHolidays.response.body}
next: end
returnResult:
return: ${formatMessage.response.body}
next: end
154 changes: 111 additions & 43 deletions DSL/Ruuter.public/GET/calendar/national-holidays/mock/find/by-month.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
declaration:
name: "MOCK - Holiday Filter by Month"
description: "Fetches and filters Estonian national holidays for a specified month in 2024."
method: "get"
return: "json"
name: "MOCK - Filter by Month"
description: "MOCK - Fetches and filters Estonian national holidays for a specified month in 2024"
method: get
accepts: json
returns: json
namespace: common-services
allowlist:
body:
- field: chatId
type: string
description: "The chat ID for the message"
- field: authorId
type: string
description: "The author ID for the message"
- field: month
type: string
description: "The incoming month for which to retrieve holidays - ex. 'mai' or 'veebruar'"

prepare:
assign: # MM - month
searchTerm: "06" #"${incoming.params.month || (new Date().getMonth() + 1).toString()}" # default to current month - ex."10"/MM for october
next: makeApiCall
assign:
chatId: "1010"
authorId: "abc123"
month: "juuni"
monthMap:
map:
"jaanuar": "01"
"veebruar": "02"
"märts": "03"
"aprill": "04"
"mai": "05"
"juuni": "06"
"juuli": "07"
"august": "08"
"september": "09"
"oktoober": "10"
"november": "11"
"detsember": "12"
next: prepareMonth

prepareMonth:
assign:
month: ${monthMap.map[month]}
next: makeApiCall

#--------------------------------------------------------------------------------------------------
makeApiCall:
call: reflect.mock
args:
Expand Down Expand Up @@ -41,55 +76,88 @@ makeApiCall:
- date: "2024-12-26"
name: "teine jõulupüha"
result: holidayData
next: filterHolidaysByMonth
next: filterHolidays

filterHolidaysByMonth:
filterHolidays:
assign:
filteredHolidays: ${holidayData.response.body.holidays.filter(holiday => !isNaN(searchTerm) && parseInt(searchTerm) >= 1 && parseInt(searchTerm) <= 12 && (new Date(holiday.date).getMonth() + 1 === parseInt(searchTerm)))}
holidays: ${holidayData.response.body.holidays.filter(holiday => holiday.date.slice(5, 7) === month.padStart(2, '0'))}
next: checkHolidays

checkHolidays:
switch:
- condition: ${filteredHolidays.length < 1}
- condition: ${holidays.length < 1}
next: holidayNotFound
- condition: ${filteredHolidays.length > 1}
next: formatResult
- condition: ${filteredHolidays.length === 1}
next: assignValue
next: assignValue
- condition: ${holidays.length === 1}
next: assignSingleValue
- condition: ${holidays.length > 1}
next: formatValue

#--------------------------------------------------------------------------------------------------
holidayNotFound:
assign:
res: {
"result": "Antud kuus ei ole riigpühi"
}
next: formatMessages

assignValue:
assignSingleValue:
assign:
holiday:
result: "Antud kuus on ${filteredHolidays[0].name} - ${filteredHolidays[0].date}"
next: returnValue
res: {
"result": "Antud kuus on ${holidays[0].name} - ${holidays[0].date}"
}
next: formatMessages

formatResult:
call: reflect.mock
formatValue:
call: reflect.mock # http.post
args:
url: "[#DMAPPER]/hbs/calendar/national-holidays/get_national_holiday_by_month"
response:
result: "Kõik riigipühad antud kuus on: \n*2024-06-23\n võidupüha\n\n*2024-06-24\n jaanipäev\n\n"
url: "[#DMAPPER]/common-services/hbs/calendar/national-holidays/get_national_holiday_by_month"
headers:
type: json
body:
data: ${holidays}
response: {
"result": "Kõik riigipühad antud kuus on: \n*2024-06-23\n võidupüha\n\n*2024-06-24\n jaanipäev\n\n"
}
result: holiday
next: returnValue
next: assignResponse

returnValue:
return: ${holiday.response.body}
next: end

returnDMValue:
return: ${holiday.result}
next: end

#--------------------------------
holidayNotFound:
#--------------------------------------------------------------------------------------------------
assignResponse:
assign:
noHoliday:
result: "Ei leia riigipühi antud kuus"
next: returnNoHolidays

returnNoHolidays:
return: ${noHoliday}
next: end
res: ${holiday.response.body}
next: formatMessages

# format throgh DM bot response to messages
formatMessages:
call: reflect.mock # http.post
args:
url: "[#DMAPPER]/common-services/hbs/bot_responses_to_messages"
headers:
type: json
body:
data:
{
"botMessages": "${[res]}",
"chatId": "${chatId}",
"authorId": "${authorId}",
"authorFirstName": "",
"authorLastName": "",
"authorTimestamp": "${new Date().toISOString()}",
"created": "${new Date().toISOString()}",
}
response:
body:
- chatId: "1010"
content: "Kõik riigipühad antud kuus on: \n*2024-06-23\n võidupüha\n\n*2024-06-24\n jaanipäev\n\n"
buttons: []
authorTimestamp: "2024-11-05T12:00:00Z"
authorId: "abc123"
authorFirstName: ""
authorLastName: ""
created: "2024-11-05T12:00:00Z"
result: formatMessage
next: returnResult

returnResult:
return: ${formatMessage.response.body}
next: end
Loading