Compare commits

..

No commits in common. "920971c6408863df2ba78bc74bb59b1823fe0c30" and "dc09022919036dbdf54167bb6b97d7eede326f17" have entirely different histories.

6 changed files with 27 additions and 86 deletions

View File

@ -69,11 +69,7 @@ public class AccountManagementService {
command.getPasswordConfirmation(), command.getPasswordConfirmation(),
command.getStatus(), command.getStatus(),
command.getRoleRefs(), command.getRoleRefs(),
AccountInfo.builder() AccountInfo.of(command.getNickname(), command.getAvatar(), command.getSex()),
.nickname(command.getNickname())
.avatar(command.getAvatar())
.sex(command.getSex())
.build(),
adminAuthLogic.getLoginIdAsLong()); adminAuthLogic.getLoginIdAsLong());
accountRepository.save(account); accountRepository.save(account);
} }

View File

@ -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.Email;
import xyz.zhouxy.plusone.system.domain.model.account.MobilePhone; 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.Password;
import xyz.zhouxy.plusone.system.domain.model.account.Sex;
import xyz.zhouxy.plusone.system.domain.model.account.Username; import xyz.zhouxy.plusone.system.domain.model.account.Username;
/** /**
@ -81,9 +82,7 @@ public class RegisterAccountService {
Password.newPassword(command.getPassword(), command.getReenteredPassword()), Password.newPassword(command.getPassword(), command.getReenteredPassword()),
AccountStatus.AVAILABLE, AccountStatus.AVAILABLE,
Set.of(DEFAULT_ROLE_ID), Set.of(DEFAULT_ROLE_ID),
AccountInfo.builder() AccountInfo.of(command.getNickname(), null, Sex.UNSET));
.nickname(command.getNickname())
.build());
accountRepository.save(accountToSave); accountRepository.save(accountToSave);
} }

View File

@ -93,19 +93,11 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
} }
public void setAccountInfo(Nickname nickname, URL avatar, Sex sex) { public void setAccountInfo(Nickname nickname, URL avatar, Sex sex) {
this.accountInfo = AccountInfo.builder() this.accountInfo = AccountInfo.of(nickname, avatar, sex);
.nickname(nickname)
.avatar(avatar)
.sex(sex)
.build();
} }
public void setAccountInfo(String nickname, String avatar, Sex sex) { public void setAccountInfo(String nickname, String avatar, Sex sex) {
this.accountInfo = AccountInfo.builder() this.accountInfo = AccountInfo.of(nickname, avatar, sex);
.nickname(nickname)
.avatar(avatar)
.sex(sex)
.build();
} }
/** /**

View File

@ -5,9 +5,7 @@ import java.net.URL;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nonnull; import lombok.Getter;
import javax.annotation.Nullable;
import lombok.ToString; import lombok.ToString;
import xyz.zhouxy.plusone.domain.IValueObject; import xyz.zhouxy.plusone.domain.IValueObject;
@ -19,19 +17,30 @@ import xyz.zhouxy.plusone.domain.IValueObject;
@ToString @ToString
public class AccountInfo implements IValueObject { public class AccountInfo implements IValueObject {
@Nullable
private final Nickname nickname; private final Nickname nickname;
@Nullable
private final URL avatar; private final URL avatar;
@Nonnull private final @Getter Sex sex;
private final 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.nickname = nickname;
this.avatar = avatar; this.avatar = avatar;
this.sex = Objects.nonNull(sex) ? sex : Sex.UNSET; 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() { public Optional<Nickname> getNickname() {
return Optional.ofNullable(nickname); return Optional.ofNullable(nickname);
} }
@ -39,54 +48,4 @@ public class AccountInfo implements IValueObject {
public Optional<URL> getAvatar() { public Optional<URL> getAvatar() {
return Optional.ofNullable(avatar); 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);
}
}
} }

View File

@ -1,7 +1,5 @@
package xyz.zhouxy.plusone.system.domain.model.account; package xyz.zhouxy.plusone.system.domain.model.account;
import javax.annotation.Nonnull;
import xyz.zhouxy.plusone.commons.util.Enumeration; import xyz.zhouxy.plusone.commons.util.Enumeration;
import xyz.zhouxy.plusone.domain.IValueObject; 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> * @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
*/ */
public class Sex extends Enumeration<Sex> implements IValueObject { public class Sex extends Enumeration<Sex> implements IValueObject {
@Nonnull
public static final Sex UNSET = new Sex(0, "未设置"); public static final Sex UNSET = new Sex(0, "未设置");
@Nonnull
public static final Sex MALE = new Sex(1, "男性"); public static final Sex MALE = new Sex(1, "男性");
@Nonnull
public static final Sex FEMALE = new Sex(2, "女性"); public static final Sex FEMALE = new Sex(2, "女性");
private Sex(int value, String name) { private Sex(int value, String name) {

View File

@ -176,6 +176,10 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
@Override @Override
protected final Account mapRow(ResultSet rs) throws SQLException { protected final Account mapRow(ResultSet rs) throws SQLException {
long accountId = rs.getLong("id"); long accountId = rs.getLong("id");
AccountInfo accountInfo = AccountInfo.of(
rs.getString("nickname"),
rs.getString("avatar"),
Sex.of(rs.getInt("sex")));
return new Account( return new Account(
accountId, accountId,
rs.getString("username"), rs.getString("username"),
@ -183,11 +187,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
rs.getString("mobile_phone"), rs.getString("mobile_phone"),
Password.of(rs.getString("password"), rs.getString("salt")), Password.of(rs.getString("password"), rs.getString("salt")),
AccountStatus.of(rs.getInt("status")), AccountStatus.of(rs.getInt("status")),
AccountInfo.builder() accountInfo,
.nickname(rs.getString("nickname"))
.avatar(rs.getString("avatar"))
.sex(Sex.of(rs.getInt("sex")))
.build(),
this.accountRoleDAO.selectRoleIdsByAccountId(accountId), this.accountRoleDAO.selectRoleIdsByAccountId(accountId),
rs.getLong("created_by"), rs.getLong("created_by"),
rs.getLong("updated_by"), rs.getLong("updated_by"),