Skip to content

Commit

Permalink
Merge pull request #14 from fga-eps-mds/feat#66/adds-subject
Browse files Browse the repository at this point in the history
[FEAT] Adiciona EndPoints Relativos às Disciplinas e Remove os Relativos aos Starting Points (fga-eps-mds/2024.2-ARANDU-DOC#66)
  • Loading branch information
dartmol203 authored Jan 19, 2025
2 parents 3ff7726 + c94ea69 commit d65e516
Show file tree
Hide file tree
Showing 28 changed files with 1,032 additions and 1,020 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "calcmaker",
"name": "studio-api",
"version": "0.0.1",
"description": "",
"author": "",
Expand Down
10 changes: 5 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { HttpModule } from '@nestjs/axios';
import { ContentModule } from './content/content.module';
import * as Joi from 'joi';
import { ContentModule } from './content/content.module';
import { JourneyModule } from './journey/journey.module';
import { SubjectModule } from './subject/subject.module';
import { TrailModule } from './trail/trail.module';
import { PointModule } from './start_point/point.module';

@Module({
imports: [
Expand All @@ -25,10 +25,10 @@ import { PointModule } from './start_point/point.module';
inject: [ConfigService],
}),
HttpModule,
SubjectModule,
ContentModule,
JourneyModule,
TrailModule,
PointModule,
TrailModule
],
controllers: [],
providers: [],
Expand Down
4 changes: 2 additions & 2 deletions src/journey/dtos/create-journey.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class CreateJourneyDto {
description: string;

@ApiProperty({
example: 'id-do-start-point',
example: 'id-da-disciplina',
required: false
})
@IsOptional()
@IsMongoId()
pointId?: string;
subjectId?: string;
}
2 changes: 1 addition & 1 deletion src/journey/dtos/updateJourneyOrder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface JourneyInterface {
_id: string;
title?: string;
point?: string;
subject?: string;
createdAt?: string;
updatedAt?: string;
__v?: string;
Expand Down
14 changes: 7 additions & 7 deletions src/journey/journey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ export class JourneyController {
})
@Post()
async create(@Body() body: CreateJourneyDto) {
const pointId = body.pointId;
const subjectId = body.subjectId;

if (!pointId) {
throw new NotFoundException('Point ID not provided in body');
if (!subjectId) {
throw new NotFoundException('Subject ID not provided in body');
}

return this.journeyService.create(body, pointId);
return this.journeyService.create(body, subjectId);
}
@Get()
async findAll() {
return this.journeyService.findAll();
}

@Get('point/:id')
async findByPointId(@Param('id') pointId: string) {
return this.journeyService.findByPointId(pointId);
@Get('subjects/:id')
async findBySubjectId(@Param('id') subjectId: string) {
return this.journeyService.findBySubjectId(subjectId);
}

@Get(':id')
Expand Down
8 changes: 4 additions & 4 deletions src/journey/journey.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { HttpModule } from '@nestjs/axios';
import { forwardRef, Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { SubjectModule } from '../subject/subject.module';
import { JourneyController } from './journey.controller';
import { JourneySchema } from './journey.schema';
import { JourneyService } from './journey.service';
import { HttpModule } from '@nestjs/axios';
import { JourneyController } from './journey.controller';
import { PointModule } from 'src/start_point/point.module';

@Module({
imports: [
HttpModule,
MongooseModule.forFeature([{ name: 'Journey', schema: JourneySchema }]),
forwardRef(() => PointModule),
forwardRef(() => SubjectModule),
],
providers: [JourneyService],
controllers: [JourneyController],
Expand Down
4 changes: 2 additions & 2 deletions src/journey/journey.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const JourneySchema = new mongoose.Schema(
{
title: { type: String, required: true },
description: { type: String },
point: { type: mongoose.Schema.Types.ObjectId, ref: 'Point' },
subject: { type: mongoose.Schema.Types.ObjectId, ref: 'Subject' },
trails: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Trail' }],
order: { type: Number, default: 0 },
},
Expand All @@ -14,7 +14,7 @@ export const JourneySchema = new mongoose.Schema(
export interface Journey extends mongoose.Document {
title: string;
description?: string;
point: mongoose.Schema.Types.ObjectId;
subject: mongoose.Schema.Types.ObjectId;
trails?: mongoose.Types.ObjectId[];
order: { type: number; default: 0 };
}
30 changes: 14 additions & 16 deletions src/journey/journey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,40 @@ import { HttpService } from '@nestjs/axios';
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { Journey } from './journey.schema';
import { Subject } from '../subject/subject.schema';
import { SubjectService } from '../subject/subject.service';
import { CreateJourneyDto } from './dtos/create-journey.dto';
import { Point } from '../start_point/point.schema';
import { PointService } from 'src/start_point/point.service';
import { JourneyInterface } from './dtos/updateJourneyOrder';
import { Journey } from './journey.schema';

@Injectable()
export class JourneyService {
private readonly logger = new Logger(JourneyService.name);

constructor(
@InjectModel('Journey') private readonly journeyModel: Model<Journey>,
@InjectModel('Point') private readonly pointModel: Model<Point>,
private readonly pointService: PointService,
@InjectModel('Subject') private readonly subjectModel: Model<Subject>,
private readonly subjectService: SubjectService,
private readonly httpService: HttpService,
) {}

async create(
createJourneyDto: CreateJourneyDto,
pointId: string,
subjectId: string,
): Promise<Journey> {
const pointExist = await this.pointModel.findById(pointId).exec();
if (!pointExist) {
throw new NotFoundException(`Point with ID ${pointId} not found`);
}
const subjectExist = await this.subjectModel.findById(subjectId).exec();
if (!subjectExist) throw new NotFoundException(`Subject with ID ${subjectId} not found`);

const newJourney = new this.journeyModel({
...createJourneyDto,
point: pointId,
order: pointExist.journeys.length + 1,
subject: subjectId,
order: subjectExist.journeys.length + 1,
});

const savedJourney = await newJourney.save();

await this.pointService.addJourneyToPoint(
pointId,
await this.subjectService.addJourneyToSubject(
subjectId,
savedJourney._id.toString(),
);

Expand All @@ -48,8 +46,8 @@ export class JourneyService {
return this.journeyModel.find().exec();
}

async findByPointId(pointId: string): Promise<Journey[]> {
return this.journeyModel.find({ point: pointId }).exec();
async findBySubjectId(subjectId: string): Promise<Journey[]> {
return this.journeyModel.find({ subject: subjectId }).exec();
}

async findById(id: string): Promise<Journey> {
Expand Down
32 changes: 0 additions & 32 deletions src/start_point/dtos/create-start-point.dto.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/start_point/dtos/manageStartPointJourney.dto.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/start_point/dtos/update-point.dto.ts

This file was deleted.

109 changes: 0 additions & 109 deletions src/start_point/point.controller.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/start_point/point.module.ts

This file was deleted.

Loading

0 comments on commit d65e516

Please sign in to comment.