fix after review

This commit is contained in:
ggmaleva 2021-02-19 15:02:50 +03:00
parent 0cf22dee7a
commit d4bfba8978
2 changed files with 31 additions and 13 deletions

View File

@ -1,8 +1,21 @@
package com.rbkmoney.orgmanager.entity;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
@ -28,7 +41,7 @@ public class MemberEntity implements Serializable {
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(
name = "member_to_organization",
joinColumns = @JoinColumn(name = "member_id"),

View File

@ -1,5 +1,6 @@
package com.rbkmoney.orgmanager.service;
import com.rbkmoney.bouncer.context.v1.User;
import com.rbkmoney.bouncer.ctx.ContextFragment;
import com.rbkmoney.bouncer.ctx.ContextFragmentType;
import com.rbkmoney.orgmanagement.AuthContextProviderSrv;
@ -11,8 +12,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.springframework.stereotype.Service;
import java.util.Optional;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@ -22,16 +22,21 @@ public class AuthContextService implements AuthContextProviderSrv.Iface {
private final MemberConverter memberConverter;
@Override
public ContextFragment getUserContext(String id) throws UserNotFound, TException {
Optional<MemberEntity> entity = memberRepository.findById(id);
if (entity.isEmpty()) {
throw new UserNotFound();
}
MemberEntity member = entity.get();
@Transactional(readOnly = true)
public ContextFragment getUserContext(String id) throws TException {
com.rbkmoney.bouncer.context.v1.ContextFragment contextFragment =
new com.rbkmoney.bouncer.context.v1.ContextFragment();
User user = getUser(id);
contextFragment.setUser(user);
TSerializer tSerializer = new TSerializer();
return new ContextFragment()
.setType(ContextFragmentType.v1_thrift_binary)
.setContent(tSerializer.serialize(memberConverter.toThrift(member)));
.setContent(tSerializer.serialize(contextFragment));
}
private User getUser(String id) throws UserNotFound {
MemberEntity member = memberRepository.findById(id)
.orElseThrow(UserNotFound::new);
return memberConverter.toThrift(member);
}
}