Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-4100 - Create Demo School Endpoint #4365

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
000aa92
implement module skeleton for school creation
uidp Aug 29, 2023
e519c08
implementation
hoeppner-dataport Sep 11, 2023
21adc94
chore: changed test-setup-account password
hoeppner-dataport Sep 11, 2023
ad9d1e1
chore: adapted email-domain of demo-users
hoeppner-dataport Sep 11, 2023
2e0bb36
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 11, 2023
209860b
chore: removed import of uncommited file
hoeppner-dataport Sep 11, 2023
df90d95
chore: changes to fix tests
hoeppner-dataport Sep 12, 2023
f8590fb
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 12, 2023
a44f416
chore: add tests to lesson repo
hoeppner-dataport Sep 12, 2023
ca9ff6e
chore: increase coverage for course.service
hoeppner-dataport Sep 12, 2023
d9655df
chore: added test for demo school service
hoeppner-dataport Sep 12, 2023
2433464
chore: add test do demo school service
hoeppner-dataport Sep 13, 2023
634f427
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 13, 2023
94ce4f4
chore: extended test for demo school service
hoeppner-dataport Sep 13, 2023
7e29d6f
chore: add test to demo school service spec
hoeppner-dataport Sep 20, 2023
1dd9aa2
chore: cleanup demo school service
hoeppner-dataport Sep 20, 2023
08113f7
chore: fix test
hoeppner-dataport Sep 20, 2023
0974e4a
fix: generate password and put it into creation protocol
hoeppner-dataport Sep 20, 2023
d20b83f
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 20, 2023
26898a3
fix: merge issues solved
hoeppner-dataport Sep 20, 2023
77ca491
chore: use unpredictable random uuid generator
hoeppner-dataport Sep 20, 2023
3957f7d
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 20, 2023
7008cb3
chore: adapt to name change of "School" to "SchoolEntity"
hoeppner-dataport Sep 20, 2023
9ff9779
chore: fixes
hoeppner-dataport Sep 20, 2023
f6e095c
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 20, 2023
98236e1
chore: fix demoSchoolModule schoolModule usage
hoeppner-dataport Sep 20, 2023
5deacb3
chore: fix lesson repo test
hoeppner-dataport Sep 20, 2023
b821b63
chore: remove outcommented code
hoeppner-dataport Sep 20, 2023
61da413
add test for createLesson
hoeppner-dataport Sep 20, 2023
73e3fe6
chore: add test for demo-school-uc
hoeppner-dataport Sep 20, 2023
5420f78
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 20, 2023
290a85d
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 25, 2023
7394bc1
fix: response mapping
hoeppner-dataport Sep 25, 2023
dd1c93f
implement postfix generation for email-addresses
hoeppner-dataport Sep 25, 2023
c57610b
chore: fix - feature flag check
hoeppner-dataport Sep 25, 2023
340d942
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 25, 2023
c0649c0
chore: fix tests
hoeppner-dataport Sep 25, 2023
0734e57
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 25, 2023
ab6bc70
chore: fix tests
hoeppner-dataport Sep 25, 2023
14fb065
chore: remove unnecessary logging
hoeppner-dataport Sep 25, 2023
6a79e83
chore: fix uc test
hoeppner-dataport Sep 25, 2023
51e8d3b
chore: add tests for demo-school-response
hoeppner-dataport Sep 26, 2023
c040616
chore: add controller test
hoeppner-dataport Sep 26, 2023
7926d01
chore: remove optional mark
hoeppner-dataport Sep 26, 2023
ae51bf8
chore: add test for loggable
hoeppner-dataport Sep 26, 2023
621fa61
chore: fix issues due to type changes
hoeppner-dataport Sep 26, 2023
c9bb38a
chore: fix types
hoeppner-dataport Sep 26, 2023
9719f48
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 26, 2023
0ebc650
chore: add key property to tests
hoeppner-dataport Sep 26, 2023
7b0c433
chore: add list of allowed entity types for creation protocol
hoeppner-dataport Sep 27, 2023
58a477a
chore: switch entity type from sting to enum
hoeppner-dataport Sep 27, 2023
eb90a62
chore: use enum in response, too
hoeppner-dataport Sep 27, 2023
c935cc1
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Sep 27, 2023
ef0c7da
chore: add info for using enum in response
hoeppner-dataport Sep 27, 2023
f185e38
Merge branch 'main' into BC-4100-create-demo-school
Metauriel Sep 29, 2023
fd0b550
chore: remove unneeded comments
hoeppner-dataport Sep 29, 2023
69ebf49
Merge branch 'BC-4100-create-demo-school' of github.com:hpi-schul-clo…
hoeppner-dataport Sep 29, 2023
2430549
Merge branch 'main' into BC-4100-create-demo-school
Metauriel Oct 4, 2023
4a8964c
chore: trigger redeploy
hoeppner-dataport Oct 4, 2023
f322ab6
Merge branch 'BC-4100-create-demo-school' of github.com:hpi-schul-clo…
hoeppner-dataport Oct 4, 2023
09acad6
chore: trigger redeploy
hoeppner-dataport Oct 4, 2023
dcce382
Merge branch 'main' into BC-4100-create-demo-school
hoeppner-dataport Oct 6, 2023
655f8f3
Merge branch 'main' into BC-4100-create-demo-school
Metauriel Oct 25, 2023
a3dd94d
fix module imports
Metauriel Oct 27, 2023
5f82aa8
Merge branch 'main' into BC-4100-create-demo-school
Metauriel Oct 27, 2023
f3a0296
rename feature flag
Metauriel Oct 27, 2023
3f1a7f3
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Nov 17, 2023
09b7397
chore: fix lint issue
hoeppner-dataport Nov 17, 2023
cbb2b19
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Nov 20, 2023
42c0ea8
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Nov 20, 2023
e372761
chore: fix imports
hoeppner-dataport Nov 20, 2023
16c5417
fix: import in test on lesson service
hoeppner-dataport Nov 20, 2023
17b96b7
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
hoeppner-dataport Nov 20, 2023
230b4f4
Merge branch 'main' into BC-4100-create-demo-school
Metauriel Jan 19, 2024
34005b4
linter fixes
Metauriel Jan 19, 2024
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
24 changes: 24 additions & 0 deletions apps/server/src/modules/demo/controller/demo-school.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, ForbiddenException, Post } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { DemoSchoolUc } from '../uc';
import { DemoSchoolResponse } from './dto';

@ApiTags('Demo School')
@Authenticate('jwt')
@Controller('demo-schools')
export class DemoSchoolController {
constructor(private readonly demoSchoolUc: DemoSchoolUc) {}

@ApiOperation({ summary: 'Create a demo school.' })
@ApiResponse({ status: 200, type: DemoSchoolResponse })
@ApiResponse({ status: 403, type: ForbiddenException })
@Post()
async createDemoSchool(@CurrentUser() currentUser: ICurrentUser): Promise<DemoSchoolResponse> {
const school = await this.demoSchoolUc.createSchool(currentUser.userId);
const response = new DemoSchoolResponse(school);

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';

export class DemoSchoolResponse {
constructor({ id }: DemoSchoolResponse) {
this.id = id;
}

@ApiProperty({
pattern: '[a-f0-9]{24}',
})
id: string;
}
1 change: 1 addition & 0 deletions apps/server/src/modules/demo/controller/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './demo-school.response';
13 changes: 13 additions & 0 deletions apps/server/src/modules/demo/demo-api.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from '@src/core/logger';
import { AuthorizationModule } from '..';
import { DemoSchoolController } from './controller/demo-school.controller';
import { DemoModule } from './demo.module';
import { DemoSchoolUc } from './uc';

@Module({
imports: [DemoModule, LoggerModule, AuthorizationModule],
controllers: [DemoSchoolController],
providers: [DemoSchoolUc],
})
export class DemoApiModule {}
11 changes: 11 additions & 0 deletions apps/server/src/modules/demo/demo.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from '@src/core/logger';
import { DemoSchoolRepo } from './repo/demo-school.repo';
import { DemoSchoolService } from './service/demo-school.service';

@Module({
imports: [LoggerModule],
providers: [DemoSchoolService, DemoSchoolRepo],
exports: [DemoSchoolService],
})
export class DemoModule {}
18 changes: 18 additions & 0 deletions apps/server/src/modules/demo/domain/demo-school.do.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { EntityId } from '@shared/domain';
import { DomainObject } from '@shared/domain/domain-object'; // fix import if it is avaible

export class DemoSchool extends DomainObject<DemoSchoolProps> {
get createdAt(): Date {
return this.props.createdAt;
}

get updatedAt(): Date {
return this.props.updatedAt;
}
}

export interface DemoSchoolProps {
id: EntityId;
createdAt: Date;
updatedAt: Date;
}
5 changes: 5 additions & 0 deletions apps/server/src/modules/demo/domain/demo-school.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BaseEntityWithTimestamps } from '@shared/domain';

export class DemoSchoolEntity extends BaseEntityWithTimestamps {
// maybe we should even use the regular School entity
}
2 changes: 2 additions & 0 deletions apps/server/src/modules/demo/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './demo-school.do';
export * from './demo-school.entity';
2 changes: 2 additions & 0 deletions apps/server/src/modules/demo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './demo.module';
export * from './service/demo-school.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EntityId } from '@shared/domain';
import { CrudOperation } from '@shared/types';
import { LogMessage, Loggable } from '@src/core/logger';

export class DemoSchoolCreateLoggable implements Loggable {
constructor(private readonly userId: EntityId) {}

getLogMessage(): LogMessage {
return {
message: 'Creating demo school',
data: {
operation: CrudOperation.CREATE,
userId: this.userId,
},
};
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/demo/loggable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './demo-school-create.loggable';
13 changes: 13 additions & 0 deletions apps/server/src/modules/demo/repo/demo-school.repo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityManager } from '@mikro-orm/mongodb';
import { Injectable } from '@nestjs/common';
import { DemoSchool } from '../domain';

@Injectable()
export class DemoSchoolRepo {
constructor(private readonly em: EntityManager) {}

async save(school: DemoSchool): Promise<void> {
// TODO map to entity and actually persist
return Promise.resolve();
}
}
21 changes: 21 additions & 0 deletions apps/server/src/modules/demo/service/demo-school.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from '@nestjs/common';
import { ObjectId } from 'bson';
import { DemoSchool } from '../domain';
import { DemoSchoolRepo } from '../repo/demo-school.repo';

@Injectable()
export class DemoSchoolService {
constructor(private readonly repo: DemoSchoolRepo) {}

async createSchool(): Promise<DemoSchool> {
const school = new DemoSchool({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include a name with a DEMO_ prefix.
Because in case we want to find the demo schools later we have a easier time :)

id: new ObjectId().toHexString(),
createdAt: new Date(),
updatedAt: new Date(),
});

await this.repo.save(school);

return school;
}
}
28 changes: 28 additions & 0 deletions apps/server/src/modules/demo/uc/demo-school.uc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain';
import { Logger } from '@src/core/logger';
import { AuthorizationService } from '@src/modules/authorization';
import { DemoSchool } from '../domain';
import { DemoSchoolCreateLoggable } from '../loggable';
import { DemoSchoolService } from '../service/demo-school.service';

@Injectable()
export class DemoSchoolUc {
constructor(
private readonly logger: Logger,
private readonly demoSchoolService: DemoSchoolService,
private readonly authorizationService: AuthorizationService
) {
this.logger.setContext(DemoSchoolUc.name);
}

async createSchool(userId: EntityId): Promise<DemoSchool> {
this.logger.debug(new DemoSchoolCreateLoggable(userId));

// TODO check permission

const school = await this.demoSchoolService.createSchool();

return school;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/demo/uc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './demo-school.uc';
2 changes: 2 additions & 0 deletions apps/server/src/modules/server/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { VideoConferenceApiModule } from '@src/modules/video-conference/video-co
import connectRedis from 'connect-redis';
import session from 'express-session';
import { RedisClient } from 'redis';
import { DemoApiModule } from '../demo/demo-api.module';
import { ServerController } from './controller/server.controller';
import { serverConfig } from './server.config';

Expand Down Expand Up @@ -70,6 +71,7 @@ const serverModules = [
ToolApiModule,
UserLoginMigrationApiModule,
BoardApiModule,
DemoApiModule,
];

export const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
Expand Down