Skip to content

Add register service#18

Open
Listanuv wants to merge 1 commit intomainfrom
register_service
Open

Add register service#18
Listanuv wants to merge 1 commit intomainfrom
register_service

Conversation

@Listanuv
Copy link
Contributor

No description provided.

import ru.scamburger.Soundger.service.RegisterService;

@RestController
@RequestMapping("/api")
Copy link
Member

Choose a reason for hiding this comment

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

/api/user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ок

} else {
return new ResponseEntity<>("Username exist on server", 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.

при удачной регистрации нужно вернуть в ответе новоиспеченного юзера (в json)

нужна будет новая dto, т.к. нельзя отдавай сущность из базы as-is (как есть), потому что там может быть секретная инфа (по типу пароля, например)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ладно

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bubuntoid
Пока у нас нету у User'a никаких полей кроме логина и пароля и id
DTO с какими данными мне возвращать

Copy link
Member

Choose a reason for hiding this comment

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

давай логин, айди и токен

@@ -0,0 +1,5 @@
package ru.scamburger.Soundger.service;

public interface RegisterService {
Copy link
Member

Choose a reason for hiding this comment

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

UserService

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ок

package ru.scamburger.Soundger.service;

public interface RegisterService {
boolean doRegister(String username, String password);
Copy link
Member

Choose a reason for hiding this comment

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

возвращаемый тип должен быть User

метод предлагаю переименовать в registerUser()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ок

public boolean doRegister(String username, String password) {
AuthToken authToken = new AuthToken();
authToken.setToken(UUID.randomUUID().toString());
authToken.setExpiredAt(new Date(new Date().getTime() + tokenLifetimeInMilliseconds));
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
Member

Choose a reason for hiding this comment

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

он null должен быть в целом, тут по сути вообще никаких действий с этой сущностью (AuthToken) не должно быть

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Мб в данном случае сделать как везде?
Когда регаешься на сайте у тебя также происходит первоначальная авторизация
Бесит такой момент когда зарегался а потом тебе ещё надо авторизироваться

Copy link
Member

Choose a reason for hiding this comment

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

окей, тогда не забудь в новое дто добавить соответствующее поле authToken или просто token

user.setPassword(passwordEncryptor.encryptPassword(password));
authToken.setUser(user);
try {
authTokenDao.saveAuthToken(authToken);
Copy link
Member

Choose a reason for hiding this comment

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

почему сохраняется authToken а не user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Верхний тред чекни

Copy link
Member

Choose a reason for hiding this comment

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

это то понятно, но стремно выходит, что логически ты должен сохранить юзера, а вызывается метод на сохранение токена, давай сделаем userDao.saveUser, он уже в свою очередь токен за собой подтянет (точно так же как saveAuthToken подтягивает юзера)

import java.util.UUID;

@Service
public class RegisterServiceImpl implements RegisterService {
Copy link
Member

Choose a reason for hiding this comment

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

переименовать в след за UserService

Copy link
Contributor 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