Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Created September 16, 2020 20:04
Show Gist options
  • Save DaisukeNagata/0bf2f8d2ccd88c066d5cab4353974eba to your computer and use it in GitHub Desktop.
Save DaisukeNagata/0bf2f8d2ccd88c066d5cab4353974eba to your computer and use it in GitHub Desktop.
SwiftUI_timeCheck by AWS Lambda
struct LoginResModel: Decodable {
var statusCode: Int
var body: String
}
private func timeCheck(year: Int, month: Int, day: Int, hour:Int, minute: Int) {
urlTimeCheck = "https://7tslpj7nwg.execute-api.ap-northeast-1.amazonaws.com/default/DateTime?year=\(year)&month=\(month)&day=\(day)&hour=\(hour)&minute=\(minute)"
let encodeUrlString: String = urlTimeCheck.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
guard let url = URL(string: encodeUrlString) else { return }
var request = URLRequest(url: url)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
cancellable = URLSession.shared.dataTaskPublisher(for: request)
.map { $0.data }
.decode(type: LoginResModel.self, decoder: JSONDecoder())
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
break
case .failure(let error):
print(error)
}
}, receiveValue: { login in
print(login.body)
})
}
@DaisukeNagata
Copy link
Author

AWS Mapping Template

{
    "year": "$input.params('year')",
    "month": "$input.params('month')",
    "day": "$input.params('day')",
    "hour": "$input.params('hour')",
    "minute": "$input.params('minute')"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment