Fix null field in member role

This commit is contained in:
ggmaleva 2021-03-26 19:20:37 +03:00
parent 6a9cd975ff
commit 593f4fd00d
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
2 changed files with 5 additions and 11 deletions

View File

@ -8,25 +8,19 @@ import com.rbkmoney.swag.organizations.model.RoleId;
import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
@Service
public class MemberRoleConverter {
public MemberRoleEntity toEntity(MemberRole role, String orgId) {
Optional<MemberRoleScope> scope = Optional.ofNullable(role.getScope());
MemberRoleScope scope = role.getScope();
return MemberRoleEntity.builder()
.id(UUID.randomUUID().toString())
.organizationId(orgId)
.resourceId(scope
.map(MemberRoleScope::getResourceId)
.orElse(null))
.resourceId(Objects.nonNull(scope) ? scope.getResourceId() : null)
.roleId(role.getRoleId().toString())
.scopeId(scope
.map(MemberRoleScope::getId)
.map(Objects::toString)
.orElse(null))
.scopeId(Objects.nonNull(scope) ? scope.getId().toString() : null)
.build();
}

View File

@ -30,8 +30,8 @@ CREATE TABLE IF NOT EXISTS org_manager.member_role
id CHARACTER VARYING NOT NULL,
organization_id CHARACTER VARYING NOT NULL,
role_id CHARACTER VARYING NOT NULL,
scope_id CHARACTER VARYING NOT NULL,
resource_id CHARACTER VARYING NOT NULL,
scope_id CHARACTER VARYING,
resource_id CHARACTER VARYING,
CONSTRAINT member_role_pkey PRIMARY KEY (id)
);