Skip to content

Commit

Permalink
N21-1860 refactor course sync (#4980)
Browse files Browse the repository at this point in the history
- use interface to generalize methods to find groups
- splitting groupUc
  • Loading branch information
IgorCapCoder authored May 13, 2024
1 parent cc32266 commit ed28265
Show file tree
Hide file tree
Showing 19 changed files with 1,779 additions and 1,868 deletions.
19 changes: 11 additions & 8 deletions apps/server/src/modules/group/controller/group.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Authenticate, CurrentUser, ICurrentUser } from '@modules/authentication';
import { Group } from '@modules/group';
import { Controller, ForbiddenException, Get, HttpStatus, Param, Query, UnauthorizedException } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { Page } from '@shared/domain/domainobject';
import { IFindQuery } from '@shared/domain/interface';
import { IFindOptions } from '@shared/domain/interface';
import { ErrorResponse } from '@src/core/error/dto';
import { GroupUc } from '../uc';
import { ClassGroupUc, GroupUc } from '../uc';
import { ClassInfoDto, ResolvedGroupDto } from '../uc/dto';
import {
ClassCallerParams,
Expand All @@ -24,7 +25,7 @@ import { GroupResponseMapper } from './mapper';
@Authenticate('jwt')
@Controller('groups')
export class GroupController {
constructor(private readonly groupUc: GroupUc) {}
constructor(private readonly groupUc: GroupUc, private readonly classGroupUc: ClassGroupUc) {}

@ApiOperation({ summary: 'Get a list of classes and groups of type class for the current user.' })
@ApiResponse({ status: HttpStatus.OK, type: ClassInfoSearchListResponse })
Expand All @@ -38,13 +39,12 @@ export class GroupController {
@Query() callerParams: ClassCallerParams,
@CurrentUser() currentUser: ICurrentUser
): Promise<ClassInfoSearchListResponse> {
const board: Page<ClassInfoDto> = await this.groupUc.findAllClasses(
const board: Page<ClassInfoDto> = await this.classGroupUc.findAllClasses(
currentUser.userId,
currentUser.schoolId,
filterParams.type,
callerParams.calledFrom,
pagination.skip,
pagination.limit,
pagination,
sortingQuery.sortBy,
sortingQuery.sortOrder
);
Expand Down Expand Up @@ -86,13 +86,16 @@ export class GroupController {
@Query() pagination: GroupPaginationParams,
@Query() params: GroupParams
): Promise<GroupListResponse> {
const query: IFindQuery = { pagination, nameQuery: params.nameQuery };
const options: IFindOptions<Group> = { pagination };

const groups: Page<ResolvedGroupDto> = await this.groupUc.getAllGroups(
currentUser.userId,
currentUser.schoolId,
query,
options,
params.nameQuery,
params.availableGroupsForCourseSync
);

const response: GroupListResponse = GroupResponseMapper.mapToGroupListResponse(groups, pagination);

return response;
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/group/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './group';
export * from './group-user';
export * from './group-types';
export { GroupDeletedEvent } from './event';
export { GroupFilter } from './interface';
10 changes: 10 additions & 0 deletions apps/server/src/modules/group/domain/interface/group-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GroupTypes } from '@modules/group';
import { EntityId } from '@shared/domain/types';

export interface GroupFilter {
userId?: EntityId;
schoolId?: EntityId;
systemId?: EntityId;
groupTypes?: GroupTypes[];
nameQuery?: string;
}
1 change: 1 addition & 0 deletions apps/server/src/modules/group/domain/interface/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { GroupFilter } from './group-filter';
4 changes: 2 additions & 2 deletions apps/server/src/modules/group/group-api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Module } from '@nestjs/common';
import { LoggerModule } from '@src/core/logger';
import { GroupController } from './controller';
import { GroupModule } from './group.module';
import { GroupUc } from './uc';
import { ClassGroupUc, GroupUc } from './uc';

@Module({
imports: [
Expand All @@ -26,6 +26,6 @@ import { GroupUc } from './uc';
LearnroomModule,
],
controllers: [GroupController],
providers: [GroupUc],
providers: [GroupUc, ClassGroupUc],
})
export class GroupApiModule {}
Loading

0 comments on commit ed28265

Please sign in to comment.