Mini survey added.

Minor fiexes.
This commit is contained in:
Oliver Hauff 2021-08-01 17:24:15 +02:00
parent ddfea49ea6
commit e321764119
73 changed files with 1628 additions and 185 deletions

View file

@ -6,6 +6,8 @@ using TINK.Repository.Request;
using TINK.Repository.Response;
using TINK.Model.User.Account;
using TINK.Model.Device;
using System.Collections.Generic;
using TINK.Model.MiniSurvey;
namespace TINK.Model.Connector
{
@ -120,14 +122,13 @@ namespace TINK.Model.Connector
Log.ForContext<Command>().Error("Unexpected booking request detected. No user logged in.");
await Task.CompletedTask;
}
public async Task DoReturn(
public async Task<MiniSurveyModel> DoReturn(
Bikes.Bike.BluetoothLock.IBikeInfoMutable bike,
LocationDto location,
ISmartDevice smartDevice)
{
Log.ForContext<Command>().Error("Unexpected returning request detected. No user logged in.");
await Task.CompletedTask;
return await Task.FromResult(new MiniSurveyModel());
}
/// <summary>
@ -143,5 +144,13 @@ namespace TINK.Model.Connector
Log.ForContext<Command>().Error("Unexpected submit feedback request detected. No user logged in.");
await Task.CompletedTask;
}
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public async Task DoSubmitMiniSurvey(IDictionary<string, string> answers)
{
Log.ForContext<Command>().Error("Unexpected submit mini survey request detected. No user logged in.");
await Task.CompletedTask;
}
}
}

View file

@ -7,6 +7,8 @@ using TINK.Repository.Request;
using TINK.Repository.Response;
using TINK.Model.User.Account;
using TINK.Model.Device;
using System.Collections.Generic;
using TINK.Model.MiniSurvey;
namespace TINK.Model.Connector
{
@ -246,7 +248,7 @@ namespace TINK.Model.Connector
/// <param name="bike">Bike to return.</param>
/// <param name="locaton">Position of the bike.</param>
/// <param name="smartDevice">Provides info about hard and software.</param>
public async Task DoReturn(
public async Task<MiniSurveyModel> DoReturn(
Bikes.Bike.BluetoothLock.IBikeInfoMutable bike,
LocationDto location,
ISmartDevice smartDevice)
@ -256,10 +258,10 @@ namespace TINK.Model.Connector
throw new ArgumentNullException("Can not return bike. No bike object available.");
}
ReservationCancelReturnResponse l_oResponse;
ReservationCancelReturnResponse response;
try
{
l_oResponse = (await CopriServer.DoReturn(bike.Id, location, smartDevice, bike.OperatorUri)).GetIsReturnBikeResponseOk(bike.Id);
response = (await CopriServer.DoReturn(bike.Id, location, smartDevice, bike.OperatorUri)).GetIsReturnBikeResponseOk(bike.Id);
}
catch (Exception)
{
@ -268,6 +270,7 @@ namespace TINK.Model.Connector
}
bike.Load(Bikes.Bike.BC.NotifyPropertyChangedLevel.None);
return response?.Create() ?? new MiniSurveyModel();
}
/// <summary>
@ -281,5 +284,10 @@ namespace TINK.Model.Connector
public async Task DoSubmitFeedback(IUserFeedback userFeedback, Uri opertorUri)
=> await CopriServer.DoSubmitFeedback(userFeedback.BikeId, userFeedback.Message, userFeedback.IsBikeBroken, opertorUri);
#endif
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public async Task DoSubmitMiniSurvey(IDictionary<string, string> answers)
=> await CopriServer.DoSubmitMiniSurvey(answers);
}
}

View file

@ -3,6 +3,8 @@ using System.Threading.Tasks;
using TINK.Repository.Request;
using TINK.Model.User.Account;
using TINK.Model.Device;
using System.Collections.Generic;
using TINK.Model.MiniSurvey;
namespace TINK.Model.Connector
{
@ -48,7 +50,7 @@ namespace TINK.Model.Connector
/// <param name="bike">Bike to return.</param>
/// <param name="location">Geolocation of lock when returning bike.</param>
/// <param name="smartDevice">Provides info about hard and software.</param>
Task DoReturn(Bikes.Bike.BluetoothLock.IBikeInfoMutable bike, LocationDto geolocation = null, ISmartDevice smartDevice = null);
Task<MiniSurveyModel> DoReturn(Bikes.Bike.BluetoothLock.IBikeInfoMutable bike, LocationDto geolocation = null, ISmartDevice smartDevice = null);
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
bool IsConnected { get; }
@ -57,6 +59,11 @@ namespace TINK.Model.Connector
string SessionCookie { get; }
Task DoSubmitFeedback(IUserFeedback userFeedback, Uri opertorUri);
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
Task DoSubmitMiniSurvey(IDictionary<string, string> answers);
#if USCSHARP9
/// <summary>
/// Feedback given by user when returning bike.

View file

@ -13,6 +13,8 @@ using IBikeInfoMutable = TINK.Model.Bikes.Bike.BC.IBikeInfoMutable;
using System.Globalization;
using TINK.Model.Station.Operator;
using Xamarin.Forms;
using System.Linq;
using TINK.Model.MiniSurvey;
namespace TINK.Model.Connector
{
@ -507,5 +509,39 @@ namespace TINK.Model.Connector
MaxFeeEuroPerDay = double.TryParse(tariffDesciption?.max_eur_per_day, NumberStyles.Any, CultureInfo.InvariantCulture, out double maxEuroPerDay) ? maxEuroPerDay : double.NaN,
};
}
/// <summary> Creates a survey object from response.</summary>
/// <param name="response">Response to create survey object from.</param>
public static MiniSurveyModel Create(this ReservationCancelReturnResponse response)
{
if (response?.user_miniquery == null)
{
return new MiniSurveyModel();
}
var miniquery = response.user_miniquery;
var survey = new MiniSurveyModel
{
Title = miniquery.title,
Subtitle = miniquery.subtitle,
Footer = miniquery.footer
};
foreach (var question in miniquery?.questions?.OrderBy(x => x.Key) ?? new Dictionary<string, MiniSurveyResponse.Question>().OrderBy(x => x.Key))
{
if (string.IsNullOrEmpty(question.Key.Trim())
|| question.Value.query == null)
{
// Skip invalid entries.
continue;
}
survey.Questions.Add(
question.Key,
new MiniSurveyModel.QuestionModel());
}
return survey;
}
}
}

View file

@ -0,0 +1,40 @@
using System.Collections.Generic;
namespace TINK.Model.MiniSurvey
{
public class MiniSurveyModel
{
public enum Type
{
SingleAnswer,
CustomText
}
public class QuestionModel
{
public QuestionModel()
{
PossibleAnswers = new Dictionary<string, string>();
}
public string Text { get; set; }
public Type Type { get; set; }
public Dictionary<string, string> PossibleAnswers { get; private set; }
}
public MiniSurveyModel()
{
Questions = new Dictionary<string, QuestionModel>();
}
public string Title { get; set; }
public string Subtitle { get; set; }
public string Footer { get; set; }
public Dictionary<string, QuestionModel> Questions { get; }
}
}

View file

@ -421,6 +421,10 @@ namespace TINK.Model
{
new Version(3, 0, 242),
AppResources.ChangeLog3_0_242
},
{
new Version(3, 0, 243),
AppResources.ChangeLog3_0_243
}
};