Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions src/cardset/application/cardset.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,22 @@ export class CardsetUseCase {
category: req.category,
});

const visibleCardsets: Cardset[] = [];
for (const cardset of items) {
if (cardset.visibility === Visibility.PUBLIC) {
visibleCardsets.push(cardset);
continue;
}
if (isNaN(userId)) continue;
const hasPrivate = items.some((c) => c.visibility !== Visibility.PUBLIC);
let myGroupIds = new Set<number>();
if (hasPrivate && !isNaN(userId)) {
try {
const inGroup = await this.groupGrpcClient.isUserInGroup(
cardset.groupId,
userId,
myGroupIds = await this.groupGrpcClient.getMyGroupIds(userId);
} catch (err) {
this.logger.error(
`[findAllPaged] 그룹 목록 조회 실패 (userId=${userId}): ${err instanceof Error ? err.message : String(err)}`,
);
if (inGroup) visibleCardsets.push(cardset);
} catch {
// 그룹 조회 실패 시 해당 카드셋 제외
}
}

const visibleCardsets = items.filter(
(c) => c.visibility === Visibility.PUBLIC || myGroupIds.has(c.groupId),
);

const ids = visibleCardsets.map((c) => c.id);

if (ids.length === 0) {
Expand Down Expand Up @@ -237,23 +235,20 @@ export class CardsetUseCase {
}[]
> {
const cardsets = await this.cardsetRepository.findAll();
const visibleCardsets: Cardset[] = [];
for (const cardset of cardsets) {
if (cardset.visibility === Visibility.PUBLIC) {
visibleCardsets.push(cardset);
continue;
}
if (isNaN(userId)) continue;
const hasPrivate = cardsets.some((c) => c.visibility !== Visibility.PUBLIC);
let myGroupIds = new Set<number>();
if (hasPrivate && !isNaN(userId)) {
try {
const inGroup = await this.groupGrpcClient.isUserInGroup(
cardset.groupId,
userId,
myGroupIds = await this.groupGrpcClient.getMyGroupIds(userId);
} catch (err) {
this.logger.error(
`[findAll] 그룹 목록 조회 실패 (userId=${userId}): ${err instanceof Error ? err.message : String(err)}`,
);
if (inGroup) visibleCardsets.push(cardset);
} catch {
// 그룹 조회 실패 시 해당 카드셋 제외
}
}
const visibleCardsets = cardsets.filter(
(c) => c.visibility === Visibility.PUBLIC || myGroupIds.has(c.groupId),
);

const ids = visibleCardsets.map((c) => c.id);
const [metadataMap, likedMap, bookmarkedMap, managersMap] =
Expand Down Expand Up @@ -536,19 +531,20 @@ export class CardsetUseCase {
userId: number,
): Promise<Cardset[]> {
const cardsets = await this.cardsetRepository.findByIds(cardSetIds);
const viewable: Cardset[] = [];
for (const cardset of cardsets) {
if (cardset.visibility === Visibility.PUBLIC) {
viewable.push(cardset);
} else {
const inGroup = await this.groupGrpcClient.isUserInGroup(
cardset.groupId,
userId,
const hasPrivate = cardsets.some((c) => c.visibility !== Visibility.PUBLIC);
let myGroupIds = new Set<number>();
if (hasPrivate && !isNaN(userId)) {
try {
myGroupIds = await this.groupGrpcClient.getMyGroupIds(userId);
} catch (err) {
this.logger.error(
`[getCardSetsByIds] 그룹 목록 조회 실패 (userId=${userId}): ${err instanceof Error ? err.message : String(err)}`,
);
if (inGroup) viewable.push(cardset);
}
}
return viewable;
return cardsets.filter(
(c) => c.visibility === Visibility.PUBLIC || myGroupIds.has(c.groupId),
);
}

async updateCardCount(
Expand Down
10 changes: 10 additions & 0 deletions src/cardset/infrastructure/grpc/group-grpc.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface GroupCommandService {
groupId: number;
userId: number;
}): Observable<{ exists: boolean }>;
getMyGroup(data: { userId: number }): Observable<{ groupId: number[] }>;
}

@Injectable()
Expand Down Expand Up @@ -40,4 +41,13 @@ export class GroupGrpcClient implements OnModuleInit {
);
return result.exists;
}

async getMyGroupIds(userId: number): Promise<Set<number>> {
console.log('[getMyGroupIds] request userId:', userId);
const result = await firstValueFrom(
this.groupService.getMyGroup({ userId }),
);
console.log('[getMyGroupIds] raw result:', JSON.stringify(result));
return new Set((result.groupId ?? []).map(Number));
}
}
24 changes: 22 additions & 2 deletions src/proto/group.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ syntax = "proto3";

package group.v1;


option java_multiple_files = true;
option java_package = "flipnote.group.grpc.v1";
option java_outer_classname = "GroupServiceProto";

service GroupCommandService {
rpc GetGroupName (GetGroupNameRequest) returns (GetGroupNameResponse);
rpc CheckUserInGroup (CheckUserInGroupRequest) returns (CheckUserInGroupResponse);

// 그룹 이름 조회
rpc GetGroupName(GetGroupNameRequest) returns (GetGroupNameResponse);

// 그룹 내 유저 존재 여부 확인
rpc CheckUserInGroup(CheckUserInGroupRequest) returns (CheckUserInGroupResponse);

// 내 그룹 전체 조회
rpc GetMyGroup(GetMyGroupRequest) returns (GetMyGroupResponse);
}

message GetGroupNameRequest {
Expand All @@ -23,3 +35,11 @@ message CheckUserInGroupRequest {
message CheckUserInGroupResponse {
bool exists = 1;
}

message GetMyGroupRequest {
int64 user_id = 1;
}

message GetMyGroupResponse {
repeated int64 group_id = 1;
}
Loading