-
Notifications
You must be signed in to change notification settings - Fork 2
Добавить в WS3 функции прописи чисел и дат на казахском 2 #27
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
8444e3d
bdb608a
413f500
c09b618
4895936
df262ba
fc501ad
9b63c18
f559d45
2cf8497
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,13 @@ namespace Morpher.WebService.V3 | |
| class BadRequestException : Exception | ||
| { | ||
| public int Status { get; } | ||
| public int ErrorCode { get; } | ||
|
|
||
| public BadRequestException(int status, int errorCode) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Конструктор не используется, следовательно, свойство ErrorCode всегда будет 0. |
||
| { | ||
| Status = status; | ||
| ErrorCode = errorCode; | ||
| } | ||
|
|
||
| public BadRequestException(int status) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,10 +43,14 @@ public string GetCardinal(long n, bool useOne) | |
| { | ||
| client.AddParam("n", n.ToString()); | ||
| client.AddParam("use-one", useOne.ToString()); | ||
|
|
||
| var stringResult = client.GetObject<string>("/qazaq/cardinal"); | ||
|
|
||
| return stringResult; | ||
| try | ||
| { | ||
| return client.GetObject<string>("/qazaq/cardinal"); | ||
| } | ||
| catch (BadRequestException e) when (e.ErrorCode == 19) | ||
| { | ||
| throw new OutOfRangeException(nameof(n)); | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -56,9 +60,14 @@ public string GetOrdinal(string cardinal) | |
| { | ||
| client.AddParam("cardinal", cardinal); | ||
|
|
||
| var stringResult = client.GetObject<string>("/qazaq/ordinal"); | ||
|
|
||
| return stringResult; | ||
| try | ||
| { | ||
| return client.GetObject<string>("/qazaq/ordinal"); | ||
| } | ||
| catch (BadRequestException e) when (e.ErrorCode == 15) | ||
| { | ||
| throw new ArgumentNotQazaqException(nameof(cardinal)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -69,8 +78,31 @@ public string GetDate(string date, bool useOne) | |
| client.AddParam("date", date); | ||
| client.AddParam("use-one", useOne.ToString()); | ||
| var stringResult = client.GetObject<string>("/qazaq/date"); | ||
| try | ||
| { | ||
| return client.GetObject<string>("/qazaq/date"); | ||
| } | ||
| catch (BadRequestException e) when (e.ErrorCode == 16) | ||
| { | ||
| throw new QazaqWrongDateException(nameof(date)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return stringResult; | ||
| public string GetDate(DateTime dateTime, bool useOne) | ||
| { | ||
| using (var client = _newClient()) | ||
| { | ||
| client.AddParam("date", dateTime.ToString("yyyy-MM-dd")); | ||
| client.AddParam("use-one", useOne.ToString()); | ||
| try | ||
| { | ||
| return client.GetObject<string>("/qazaq/date"); | ||
| } | ||
| catch (BadRequestException e) when (e.ErrorCode == 16) | ||
| { | ||
| throw new QazaqWrongDateException(nameof(dateTime)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -80,10 +112,19 @@ public string GetDayOfMonth(int day, int month) | |
| { | ||
| client.AddParam("day", day.ToString()); | ||
| client.AddParam("month", month.ToString()); | ||
|
|
||
| var stringResult = client.GetObject<string>("/qazaq/day-of-month"); | ||
|
|
||
| return stringResult; | ||
| try | ||
| { | ||
| return client.GetObject<string>("/qazaq/day-of-month"); | ||
| } | ||
| catch (BadRequestException e) | ||
| { | ||
| switch (e.ErrorCode) | ||
| { | ||
| case 17: throw new QazaqWrongDayOfMonthException(nameof(day)); | ||
| case 18: throw new QazaqWrongMonthException(nameof(month)); | ||
| } | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Morpher.WebService.V3.Qazaq | ||
| { | ||
| public class OutOfRangeException : InvalidArgumentException | ||
| { | ||
| public override string Message => | ||
| "Недопустимое значение параметра n." + | ||
| " Ожидается целое число в диапазоне +/−2 в 63 степени."; | ||
|
|
||
| public OutOfRangeException(string parameterName) | ||
| : base(parameterName) | ||
| { | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Morpher.WebService.V3.Qazaq | ||
| { | ||
| public class QazaqWrongDateException : InvalidArgumentException | ||
| { | ||
| public override string Message => | ||
| "Неправильная дата. Ожидается формат ГГГГ-ММ-ДД."; | ||
|
|
||
| public QazaqWrongDateException(string parameterName) | ||
| : base(parameterName) | ||
| { | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Morpher.WebService.V3.Qazaq | ||
| { | ||
| public class QazaqWrongMonthException : InvalidArgumentException | ||
| { | ||
| public override string Message => | ||
| "Недопустимое значение числового параметра month. Допустимы значения от 1 до 12 включительно."; | ||
|
|
||
| public QazaqWrongMonthException(string parameterName) | ||
| : base(parameterName) | ||
| { | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace Morpher.WebService.V3.Qazaq | ||
| { | ||
| public class QazaqWrongDayOfMonthException : InvalidArgumentException | ||
| { | ||
| public override string Message => | ||
| "Недопустимое значение числового параметра day. Допустимы значения от 1 до 31 включительно."; | ||
|
|
||
| public QazaqWrongDayOfMonthException(string parameterName) | ||
| : base(parameterName) | ||
| { | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Все хорошо, только нужно где-то установить значение ErrorCode. Думаю, лучше это сделать в конструкторе BadRequestException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ок