This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1165 from cocoa-mhlw/feature/survey-submit
調査内容の送信を実装
- Loading branch information
Showing
17 changed files
with
509 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Covid19Radar.Model | ||
{ | ||
public class SurveyContent | ||
{ | ||
[JsonProperty("q1")] | ||
public int Q1 { get; set; } | ||
|
||
[JsonProperty("q2")] | ||
public int Q2 { get; set; } | ||
|
||
[JsonProperty("q3")] | ||
public long Q3 { get; set; } | ||
|
||
[JsonProperty("exposure_data")] | ||
public SurveyExposureData ExposureData { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
using System; | ||
using Chino; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace Covid19Radar.Model | ||
{ | ||
public class SurveyExposureData | ||
{ | ||
[JsonProperty("en_version")] | ||
public string EnVersion { get; set; } | ||
|
||
[JsonProperty("daily_summaries")] | ||
public List<DailySummary> DailySummaryList { get; set; } | ||
|
||
[JsonProperty("exposure_windows")] | ||
public List<ExposureWindow> ExposureWindowList { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
using System; | ||
using Chino; | ||
using Covid19Radar.Model; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Covid19Radar.Repository; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Covid19Radar.Services | ||
{ | ||
public interface ISurveyService | ||
{ | ||
Task<SurveyContent> BuildSurveyContent(int q1, int q2, DateTime q3, bool isExposureDataProvision); | ||
Task<bool> SubmitSurvey(SurveyContent surveyContent); | ||
} | ||
|
||
public class SurveyService : ISurveyService | ||
{ | ||
private readonly IEventLogService _eventLogService; | ||
private readonly IExposureDataRepository _exposureDataRepository; | ||
private readonly AbsExposureNotificationApiService _exposureNotificationApiService; | ||
|
||
public SurveyService( | ||
IEventLogService eventLogService, | ||
IExposureDataRepository exposureDataRepository, | ||
AbsExposureNotificationApiService exposureNotificationApiService | ||
) | ||
{ | ||
_eventLogService = eventLogService; | ||
_exposureDataRepository = exposureDataRepository; | ||
_exposureNotificationApiService = exposureNotificationApiService; | ||
} | ||
|
||
public async Task<SurveyContent> BuildSurveyContent(int q1, int q2, DateTime q3, bool isExposureDataProvision) | ||
{ | ||
var surveyContent = new SurveyContent | ||
{ | ||
Q1 = q1, | ||
Q2 = q2, | ||
Q3 = q3.ToUnixEpoch(), | ||
ExposureData = isExposureDataProvision ? await GetExopsureData() : null | ||
}; | ||
return surveyContent; | ||
} | ||
|
||
private async Task<SurveyExposureData> GetExopsureData() | ||
{ | ||
try | ||
{ | ||
long enVersion = await _exposureNotificationApiService.GetVersionAsync(); | ||
List<DailySummary> dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(); | ||
List<ExposureWindow> exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(); | ||
|
||
var exposureData = new SurveyExposureData | ||
{ | ||
EnVersion = enVersion.ToString(), | ||
DailySummaryList = dailySummaryList, | ||
ExposureWindowList = exposureWindowList | ||
}; | ||
|
||
return exposureData; | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public async Task<bool> SubmitSurvey(SurveyContent surveyContent) | ||
{ | ||
var eventLog = new EventLog | ||
{ | ||
HasConsent = true, | ||
Epoch = DateTime.UtcNow.ToUnixEpoch(), | ||
Type = EventType.Survey.Type, | ||
Subtype = EventType.Survey.SubType, | ||
Content = JObject.FromObject(surveyContent), | ||
}; | ||
|
||
return await _eventLogService.SendAsync(eventLog); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.