mirror of
https://github.com/valitydev/org-manager.git
synced 2024-11-06 00:15:23 +00:00
fix after review
This commit is contained in:
parent
0cf22dee7a
commit
d4bfba8978
@ -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"),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user