Compare commits
No commits in common. "920971c6408863df2ba78bc74bb59b1823fe0c30" and "dc09022919036dbdf54167bb6b97d7eede326f17" have entirely different histories.
920971c640
...
dc09022919
|
@ -69,11 +69,7 @@ public class AccountManagementService {
|
|||
command.getPasswordConfirmation(),
|
||||
command.getStatus(),
|
||||
command.getRoleRefs(),
|
||||
AccountInfo.builder()
|
||||
.nickname(command.getNickname())
|
||||
.avatar(command.getAvatar())
|
||||
.sex(command.getSex())
|
||||
.build(),
|
||||
AccountInfo.of(command.getNickname(), command.getAvatar(), command.getSex()),
|
||||
adminAuthLogic.getLoginIdAsLong());
|
||||
accountRepository.save(account);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import xyz.zhouxy.plusone.system.domain.model.account.AccountStatus;
|
|||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Password;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Username;
|
||||
|
||||
/**
|
||||
|
@ -81,9 +82,7 @@ public class RegisterAccountService {
|
|||
Password.newPassword(command.getPassword(), command.getReenteredPassword()),
|
||||
AccountStatus.AVAILABLE,
|
||||
Set.of(DEFAULT_ROLE_ID),
|
||||
AccountInfo.builder()
|
||||
.nickname(command.getNickname())
|
||||
.build());
|
||||
AccountInfo.of(command.getNickname(), null, Sex.UNSET));
|
||||
accountRepository.save(accountToSave);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,19 +93,11 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
|||
}
|
||||
|
||||
public void setAccountInfo(Nickname nickname, URL avatar, Sex sex) {
|
||||
this.accountInfo = AccountInfo.builder()
|
||||
.nickname(nickname)
|
||||
.avatar(avatar)
|
||||
.sex(sex)
|
||||
.build();
|
||||
this.accountInfo = AccountInfo.of(nickname, avatar, sex);
|
||||
}
|
||||
|
||||
public void setAccountInfo(String nickname, String avatar, Sex sex) {
|
||||
this.accountInfo = AccountInfo.builder()
|
||||
.nickname(nickname)
|
||||
.avatar(avatar)
|
||||
.sex(sex)
|
||||
.build();
|
||||
this.accountInfo = AccountInfo.of(nickname, avatar, sex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,9 +5,7 @@ import java.net.URL;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
|
||||
|
@ -19,19 +17,30 @@ import xyz.zhouxy.plusone.domain.IValueObject;
|
|||
@ToString
|
||||
public class AccountInfo implements IValueObject {
|
||||
|
||||
@Nullable
|
||||
private final Nickname nickname;
|
||||
@Nullable
|
||||
private final URL avatar;
|
||||
@Nonnull
|
||||
private final Sex sex;
|
||||
private final @Getter Sex sex;
|
||||
|
||||
private AccountInfo(@Nullable Nickname nickname, @Nullable URL avatar, @Nullable Sex sex) {
|
||||
private AccountInfo(Nickname nickname, URL avatar, Sex sex) {
|
||||
this.nickname = nickname;
|
||||
this.avatar = avatar;
|
||||
this.sex = Objects.nonNull(sex) ? sex : Sex.UNSET;
|
||||
}
|
||||
|
||||
public static AccountInfo of(Nickname nickname, URL avatar, Sex sex) {
|
||||
return new AccountInfo(nickname, avatar, sex);
|
||||
}
|
||||
|
||||
public static AccountInfo of(String nickname, String avatar, Sex sex) {
|
||||
URL avatarURL;
|
||||
try {
|
||||
avatarURL = Objects.nonNull(avatar) ? new URL(avatar) : null;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return new AccountInfo(Nickname.ofNullable(nickname), avatarURL, sex);
|
||||
}
|
||||
|
||||
public Optional<Nickname> getNickname() {
|
||||
return Optional.ofNullable(nickname);
|
||||
}
|
||||
|
@ -39,54 +48,4 @@ public class AccountInfo implements IValueObject {
|
|||
public Optional<URL> getAvatar() {
|
||||
return Optional.ofNullable(avatar);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Sex getSex() {
|
||||
return this.sex;
|
||||
}
|
||||
|
||||
// Builder
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Nickname nickname;
|
||||
private URL avatar;
|
||||
private Sex sex;
|
||||
|
||||
public Builder nickname(@Nullable Nickname nickname) {
|
||||
this.nickname = nickname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nickname(@Nullable String nickname) {
|
||||
return nickname(Nickname.ofNullable(nickname));
|
||||
}
|
||||
|
||||
public Builder avatar(@Nullable URL avatar) {
|
||||
this.avatar = avatar;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder avatar(@Nullable String avatar) {
|
||||
URL avatarURL;
|
||||
try {
|
||||
avatarURL = Objects.nonNull(avatar) ? new URL(avatar) : null;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return avatar(avatarURL);
|
||||
}
|
||||
|
||||
public Builder sex(@Nullable Sex sex) {
|
||||
this.sex = sex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountInfo build() {
|
||||
return new AccountInfo(this.nickname, this.avatar, this.sex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
|
||||
|
@ -11,11 +9,8 @@ import xyz.zhouxy.plusone.domain.IValueObject;
|
|||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public class Sex extends Enumeration<Sex> implements IValueObject {
|
||||
@Nonnull
|
||||
public static final Sex UNSET = new Sex(0, "未设置");
|
||||
@Nonnull
|
||||
public static final Sex MALE = new Sex(1, "男性");
|
||||
@Nonnull
|
||||
public static final Sex FEMALE = new Sex(2, "女性");
|
||||
|
||||
private Sex(int value, String name) {
|
||||
|
|
|
@ -176,6 +176,10 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
@Override
|
||||
protected final Account mapRow(ResultSet rs) throws SQLException {
|
||||
long accountId = rs.getLong("id");
|
||||
AccountInfo accountInfo = AccountInfo.of(
|
||||
rs.getString("nickname"),
|
||||
rs.getString("avatar"),
|
||||
Sex.of(rs.getInt("sex")));
|
||||
return new Account(
|
||||
accountId,
|
||||
rs.getString("username"),
|
||||
|
@ -183,11 +187,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
rs.getString("mobile_phone"),
|
||||
Password.of(rs.getString("password"), rs.getString("salt")),
|
||||
AccountStatus.of(rs.getInt("status")),
|
||||
AccountInfo.builder()
|
||||
.nickname(rs.getString("nickname"))
|
||||
.avatar(rs.getString("avatar"))
|
||||
.sex(Sex.of(rs.getInt("sex")))
|
||||
.build(),
|
||||
accountInfo,
|
||||
this.accountRoleDAO.selectRoleIdsByAccountId(accountId),
|
||||
rs.getLong("created_by"),
|
||||
rs.getLong("updated_by"),
|
||||
|
|
Loading…
Reference in New Issue