Skip to content

Commit

Permalink
Merge pull request #54 from daithihearn/alexa-model-refactor
Browse files Browse the repository at this point in the history
refactor: poorly named model objects
  • Loading branch information
daithihearn authored Nov 3, 2023
2 parents b2f3aab + f6367d8 commit b6c9aba
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.0
1.18.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package ie.daithi.electricityprices.model.alexa

import ie.daithi.electricityprices.utils.alexaSkillFormatter
import java.time.LocalDateTime
import java.util.UUID

data class AlexaResponse(
val version: String = "1.0",
val response: AlexaResponseBody
val uid: String = UUID.randomUUID().toString(),
val updateDate: String = LocalDateTime.now().format(alexaSkillFormatter),
val titleText: String,
val mainText: String,
val redirectionUrl: String = "https://elec.daithiapp.com/"
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package ie.daithi.electricityprices.model.alexa

import ie.daithi.electricityprices.utils.alexaSkillFormatter
import java.time.LocalDateTime
import java.util.UUID

data class AlexaSkillResponse(
val uid: String = UUID.randomUUID().toString(),
val updateDate: String = LocalDateTime.now().format(alexaSkillFormatter),
val titleText: String,
val mainText: String,
val redirectionUrl: String = "https://elec.daithiapp.com/"
val version: String = "1.0",
val response: AlexaResponseBody
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ie.daithi.electricityprices.utils

import ie.daithi.electricityprices.model.alexa.AlexaSkillResponse
import ie.daithi.electricityprices.model.alexa.AlexaResponse
import java.time.LocalDateTime

fun wrapInSkillResponse(
message: String,
title: String,
dateTime: LocalDateTime = LocalDateTime.now(),
): AlexaSkillResponse {
return AlexaSkillResponse(
): AlexaResponse {
return AlexaResponse(
updateDate = dateTime.format(alexaSkillFormatter),
titleText = title,
mainText = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AlexaSkillController(
ApiResponse(responseCode = "200", description = "Request successful")
)
@ResponseBody
fun getFullFeed(@RequestParam(value = "lang", required = false) lang: String?): AlexaSkillResponse {
fun getFullFeed(@RequestParam(value = "lang", required = false) lang: String?): AlexaResponse {
val resolvedLocale = lang?.let { Locale.forLanguageTag(it) } ?: Locale.forLanguageTag("es")
return wrapInSkillResponse(
message = alexSkillService.getFullFeed(resolvedLocale),
Expand All @@ -57,7 +57,7 @@ class AlexaSkillController(
ApiResponse(responseCode = "200", description = "Request successful")
)
@ResponseBody
fun processAlexaRequest(@RequestBody rawBody: String, request: HttpServletRequest): AlexaResponse {
fun processAlexaRequest(@RequestBody rawBody: String, request: HttpServletRequest): AlexaSkillResponse {
// Map the rawBody to an AlexaRequest object using the jackson mapper
val body = mapper.readValue(rawBody, AlexaRequest::class.java)

Expand Down Expand Up @@ -97,6 +97,6 @@ class AlexaSkillController(
}
val outputSpeech = OutputSpeech(text = response.first)
val responseBody = AlexaResponseBody(outputSpeech = outputSpeech, shouldEndSession = response.second)
return AlexaResponse(response = responseBody)
return AlexaSkillResponse(response = responseBody)
}
}

0 comments on commit b6c9aba

Please sign in to comment.