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

Feature/material #68

Closed
wants to merge 20 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/server/workspace/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { WorkspaceModule } from './workspace/workspace.module';
import { OrganisationModule } from './organisation/organisation.module';
import { MaterialModule} from './material/material.module'
import { ScheduleModule } from './schedule/schedule.module';

@Module({
imports: [
AuthModule,
UserModule,
WorkspaceModule,
MaterialModule,
ScheduleModule,
OrganisationModule,
ConfigModule.forRoot({ envFilePath: ['.env'] }),
MongooseModule.forRoot('mongodb://localhost/cc'),
Expand Down
3 changes: 3 additions & 0 deletions src/server/workspace/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { User } from '../schemas/user.schema';
import { UserService } from '../user/user.service';
import { CreateUserDto } from './dto/create-user.dto';


@Injectable()
export class AuthService {
constructor(
Expand All @@ -21,6 +22,8 @@ export class AuthService {
const user = {
sub: findUser._id,
role: findUser.role,
workspaces: findUser.workspaces,
organisation: findUser.organisation,
username: findUser.username,
accessToken: this.jwtService.sign({
sub: findUser._id,
Expand Down
37 changes: 37 additions & 0 deletions src/server/workspace/src/material/dto/create-material.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IsNotEmpty, IsOptional, IsString, IsUrl, isBoolean } from 'class-validator';

//this class just encapsulates data and does validation

Check failure on line 3 in src/server/workspace/src/material/dto/create-material.dto.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'IsOptional' is defined but never used
export class CreateMaterialDto{

Check failure on line 5 in src/server/workspace/src/material/dto/create-material.dto.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'IsUrl' is defined but never used
//this is the type

Check failure on line 6 in src/server/workspace/src/material/dto/create-material.dto.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'isBoolean' is defined but never used
//either 3d model orpdf
@IsNotEmpty()
//@isBoolean(true)
type: boolean;

//this is the workspace id
@IsNotEmpty()
@IsString()
workspace_id: string;

//this is the lecturer id
@IsNotEmpty()
@IsString()
lecturer_id: string;

//this is the title of the material
@IsNotEmpty()
@IsString()
title: string;

//this is the description of the material
@IsNotEmpty()
@IsString()
description: string;

//this is the filepath of the material
@IsNotEmpty()
@IsString()
file_path: string;

}
15 changes: 15 additions & 0 deletions src/server/workspace/src/material/dto/update-material.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IsOptional, IsString, IsUrl } from 'class-validator';

export class UpdateMaterialDto {
@IsString()
@IsOptional()
file_path?: string;

@IsUrl()
@IsOptional()
title?: string;

@IsUrl()
@IsOptional()
description?: string;
}
94 changes: 94 additions & 0 deletions src/server/workspace/src/material/material.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// import { Test, TestingModule } from '@nestjs/testing';
// import { MaterialController } from './material.controller';
// import { MaterialService } from './material.service';
// import { CreateMaterialDto } from './dto/create-material.dto';
// import { UpdateMaterialDto } from './dto/update-material.dto';

// describe('MaterialController', () => {
// let controller: MaterialController;
// let service: MaterialService;

// beforeEach(async () => {
// const module: TestingModule = await Test.createTestingModule({
// controllers: [MaterialController],
// providers: [
// {
// provide: MaterialService,
// useValue: {
// create: jest.fn(),
// findOne: jest.fn(),
// findAllByWorkspaceId: jest.fn(),
// update: jest.fn(),
// delete: jest.fn(),
// },
// },
// ],
// }).compile();

// controller = module.get<MaterialController>(MaterialController);
// service = module.get<MaterialService>(MaterialService);
// });

// describe('create', () => {
// it('should call the create method of the service', async () => {
// const createMaterialDto: CreateMaterialDto = {
// // Provide necessary properties for CreateMaterialDto
// title: 'Test Material',
// workspace_id: 'test-workspace-id',
// lecturer_id: 'test-lecturer-id',
// description: 'Test Topic',
// type: true,
// file_path: 'www.path.com'
// };

// await controller.create(createMaterialDto);

// expect(service.create).toHaveBeenCalledWith(createMaterialDto);
// });
// });

// describe('findOne', () => {
// it('should call the findOne method of the service', async () => {
// const id = 'test-id';

// await controller.findOne(id);

// expect(service.findOne).toHaveBeenCalledWith(id);
// });
// });

// describe('findAllByWorkspaceId', () => {
// it('should call the findAllByWorkspaceId method of the service', async () => {
// const workspaceId = 'test-workspace-id';

// await controller.findAllByWorkspaceId(workspaceId);

// expect(service.findAllByWorkspaceId).toHaveBeenCalledWith(workspaceId);
// });
// });

// describe('update', () => {
// it('should call the update method of the service', async () => {
// const id = 'test-id';
// const updateMaterialDto: UpdateMaterialDto = {
// // Provide necessary properties for UpdateMaterialDto
// title: 'Updated Material',
// // Add other properties as needed
// };

// await controller.update(id, updateMaterialDto);

// expect(service.update).toHaveBeenCalledWith(id, updateMaterialDto);
// });
// });

// describe('delete', () => {
// it('should call the delete method of the service', async () => {
// const id = 'test-id';

// await controller.delete(id);

// expect(service.delete).toHaveBeenCalledWith(id);
// });
// });
// });
51 changes: 51 additions & 0 deletions src/server/workspace/src/material/material.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//this will handle all the http reqs and the responses

import {
Get,
Put,
Body,
Post,
Param,
Delete,
Controller,
} from '@nestjs/common';

import { MaterialService } from './material.service';
import { CreateMaterialDto } from './dto/create-material.dto';
import { UpdateMaterialDto } from './dto/update-material.dto';
import { Material } from '../schemas/material.schema';

@Controller('materials')
export class MaterialController {
constructor(private readonly materialService: MaterialService) {}


@Post()
async create(@Body() createMaterialDto: CreateMaterialDto) {
return this.materialService.create(createMaterialDto);
}

@Get(':id')
async findOne(@Param('id') id: string) {
return this.materialService.findOne(id);
}

@Get('workspace/:workspaceId')
async findAllByWorkspaceId(@Param('workspaceId') workspaceId: string): Promise<Material[]> {
return this.materialService.findAllByWorkspaceId(workspaceId);
}

@Put(':id')
async update(
@Param('id') id: string,
@Body() updateMaterialDto: UpdateMaterialDto,
) {
return this.materialService.update(id, updateMaterialDto);
}

@Delete(':id')
async delete(@Param('id') id: string) {
return this.materialService.delete(id);
}
}

23 changes: 23 additions & 0 deletions src/server/workspace/src/material/material.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//this will encapsulate the functionality and components

import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

import {
Material,
MaterialSchema,
} from '../schemas/material.schema';
import { MaterialService } from './material.service';
import { MaterialController } from './material.controller';

@Module({
imports: [
MongooseModule.forFeature([
{ name: Material.name, schema: MaterialSchema },
]),
],
providers: [MaterialService],
controllers: [MaterialController],
exports: [MaterialService],
})
export class MaterialModule {}
Loading
Loading