Skip to content
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

Get all info user #93 #93

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Get all info user #93 #93

wants to merge 13 commits into from

Conversation

VladNesterov
Copy link
Collaborator

No description provided.

@VladNesterov VladNesterov self-assigned this Jun 15, 2020
@VladNesterov VladNesterov changed the title Get all info user Get all info user #93 Jun 15, 2020
@VladNesterov VladNesterov linked an issue Jun 15, 2020 that may be closed by this pull request
@@ -11,3 +11,15 @@ class ReceiptNotFoundException(val fn: String, val fd: String, val fp: String)
@ResponseStatus(code = HttpStatus.FORBIDDEN)
class AuthorizationFailedException(login: String, cause: Throwable? = null)
: FnsException("Login with phone $login failed", cause)

@ResponseStatus(code = HttpStatus.CONFLICT)
class UserWasExistException(userName: String, cause: Throwable? = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserAlreadyExistsException

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

исправил

throw UserWasExistException(name, e)
} catch (c: HttpClientErrorException.BadRequest) {
throw IncorrectEmailException(email, c)
} catch (d: HttpServerErrorException.InternalServerError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InternalServerError возникает буквально в любой непонятной ситуации.
Не всякий IE (InternalError) - это неправильный номер.

Есть варианты как понять что дело именно в номере?
Может, там приходит текст в ответ с описанием

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переделал


@Throws(IOException::class)
override fun handleError(httpResponse: ClientHttpResponse) {
when {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Внутри when какой то бесполезный код

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поправил

}

fun login(login: String, password: String) {
fun login(phone: String, password: String): ResponseEntity<UserResponseLoginFnsDto>? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут нужно возвращать просто UserResponseLoginDto

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

исправил

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделал


@Throws(IOException::class)
override fun handleError(httpResponse: ClientHttpResponse) {
if (httpResponse.statusCode == HttpStatus.NO_CONTENT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если hasError всегда возвращает false, то разве он сюда вообще зайдет когда нибудь?

package space.shefer.receipt.fnssdk.dto


class UserResponseLoginFnsDto {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переименуй FnsLoginResponse

} else if (responseEntity.statusCode == HttpStatus.INTERNAL_SERVER_ERROR) {
throw IncorrectPhoneException(phone)
}
} catch (e: Exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем ловить Exception? какие ошибки мы тут ожидаем?

Copy link
Collaborator Author

@VladNesterov VladNesterov Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ловлю UnsupportedOperationException, подозреваю что это дублирование кода, так как все ошибки я уже отработал в ResponseErrorHandleFNS

if (authHeader != null) {
return fnsUserService.getUserByToken(authHeader.substring(authHeader.indexOf(" ") + 1));
}
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не null а 404 нужно

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

или 403

FnsLoginResponse responseEntity = fnsReceiptWebClient.login(userLoginDto.getPhone(), userLoginDto.getPassword());
if (responseEntity != null) {
UserProfile userProfile = userProfileRepository.getByPhone(userLoginDto.getPhone());
if (userProfile != null && userProfile.getUpdatedAt() == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем проверка updatedAt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

изменил. Она тут не нужна, забыл убрать, логику переделал.

@RequestMapping(value = "/users/me", method = RequestMethod.GET)
public UserSignUpDto getInfoByToken(@Nullable @RequestHeader("Authorization") String authHeader) {
if (authHeader != null) {
return fnsUserService.getUserByToken(authHeader.substring(authHeader.indexOf(" ") + 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authHeader.substring(authHeader.indexOf(" ") + 1)
вынести в новый метод getTokenFromAuthHeader(String header)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделал

String::class.java
)
FnsLoginResponse::class.java
).body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поставь тут !! и в методе возвращаемый тип сделай без вопросика

Copy link
Collaborator Author

@VladNesterov VladNesterov Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Расскажи подробнее, что это и как. Я даже не знаю как это загуглить)

URI("$HOST/v1/mobile/users/signup"),
HttpMethod.POST,
HttpEntity("""{"email":"$email","name":"$name","phone":"$phone"}""", headers),
String::class.java
)
if (responseEntity.statusCode == HttpStatus.CONFLICT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сначала нужно проверить что если 2XX, то сразу return. иначе начинать перебиравть ифами ошибки

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сделал


@Throws(IOException::class)
override fun handleError(httpResponse: ClientHttpResponse) {
if (httpResponse.statusCode == HttpStatus.NO_CONTENT) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот код обрабатывает ошибки
а еще код в тоже обрабатываает эти же самые ошибки

нужно чтобы обрабатывалось все в FnsReceiptWebClient::signUp, а тут ничего не обрабатывалось
перенеси логику отсюда туда
hasError должен всегда возвращать false

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перенес

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Получение полной инфы о юзере
2 participants