-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from liglig99/workouts-microservice
Workouts microservice
- Loading branch information
Showing
21 changed files
with
684 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_sixe = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,84 @@ | ||
{ | ||
"version": "2.0.0", | ||
"problemMatcher": { | ||
"owner": "typescript", | ||
"fileLocation": ["relative", "${workspaceFolder}"], | ||
"pattern":[ | ||
{ | ||
"regexp": "^ERROR in (.*?):(\\d+):(\\d+)", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
}, | ||
{ | ||
"regexp": "(.*)", | ||
"message": 1 | ||
} | ||
], | ||
"background": { | ||
"activeOnStart": false, | ||
"beginsPattern": "^(.*?)building your sources(.*)", | ||
"endsPattern": "^(No errors found.|Found \\d+ error in \\d+ ms.)", | ||
}, | ||
"version": "2.0.0", | ||
"problemMatcher": { | ||
"owner": "typescript", | ||
"fileLocation": ["relative", "${workspaceFolder}"], | ||
"pattern": [ | ||
{ | ||
"regexp": "^ERROR in (.*?):(\\d+):(\\d+)", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3 | ||
}, | ||
{ | ||
"regexp": "(.*)", | ||
"message": 1 | ||
} | ||
], | ||
"background": { | ||
"activeOnStart": false, | ||
"beginsPattern": "^(.*?)building your sources(.*)", | ||
"endsPattern": "^(No errors found.|Found \\d+ error in \\d+ ms.)" | ||
} | ||
}, | ||
"tasks": [ | ||
{ | ||
"label": "Gateway: Dev", | ||
"type": "shell", | ||
"command": "pnpm start:dev gateway", | ||
"group": "none", | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "silent", | ||
"revealProblems": "onProblem", | ||
"focus": false, | ||
"panel": "shared", | ||
"showReuseMessage": true, | ||
"clear": true | ||
}, | ||
"isBackground": true | ||
}, | ||
"tasks": [ | ||
{ | ||
"label": "Gateway: Dev", | ||
"type": "shell", | ||
"command": "pnpm start:dev gateway", | ||
"group": "none", | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "silent", | ||
"revealProblems": "onProblem", | ||
"focus": false, | ||
"panel": "shared", | ||
"showReuseMessage": true, | ||
"clear": true | ||
}, | ||
"isBackground": true, | ||
}, | ||
{ | ||
"label": "Auth: Dev", | ||
"type": "shell", | ||
"command": "pnpm start:dev auth", | ||
"group": "none", | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "silent", | ||
"revealProblems": "onProblem", | ||
"focus": false, | ||
"panel": "shared", | ||
"showReuseMessage": true, | ||
"clear": true | ||
}, | ||
"isBackground": true, | ||
}, | ||
{ | ||
"label": "All: Dev", | ||
"dependsOn": [ | ||
"Gateway: Dev", | ||
"Auth: Dev" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"runOptions": { | ||
"runOn": "folderOpen" | ||
} | ||
} | ||
] | ||
} | ||
{ | ||
"label": "Auth: Dev", | ||
"type": "shell", | ||
"command": "pnpm start:dev auth", | ||
"group": "none", | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "silent", | ||
"revealProblems": "onProblem", | ||
"focus": false, | ||
"panel": "shared", | ||
"showReuseMessage": true, | ||
"clear": true | ||
}, | ||
"isBackground": true | ||
}, | ||
{ | ||
"label": "Workouts: Dev", | ||
"type": "shell", | ||
"command": "pnpm start:dev workouts", | ||
"group": "none", | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "silent", | ||
"revealProblems": "onProblem", | ||
"panel": "shared", | ||
"showReuseMessage": true, | ||
"clear": true | ||
}, | ||
"isBackground": true | ||
}, | ||
{ | ||
"label": "All: Dev", | ||
"dependsOn": ["Gateway: Dev", "Auth: Dev", "Workouts: Dev"], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"runOptions": { | ||
"runOn": "folderOpen" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Body, Controller, Get, Inject, Post, Query } from '@nestjs/common'; | ||
import { GatewayService } from './gateway.service'; | ||
import { ClientProxy } from '@nestjs/microservices'; | ||
import { Public } from '@app/common/lib/auth.guard'; | ||
import { CreateExcerciseDto } from 'apps/workouts/src/dto/create-excercise.dto'; | ||
import { CreateWorkoutDto } from 'apps/workouts/src/dto/create-workout.dto'; | ||
import { CreateWorkoutLogDto } from 'apps/workouts/src/dto/create-workout-log.dto'; | ||
|
||
@Public() //TODO: Remove this line to make this endpoint private | ||
@Controller('workouts') | ||
export class WorkoutsController { | ||
constructor( | ||
private readonly gatewayService: GatewayService, | ||
@Inject('WORKOUTS_SERVICE') private readonly workoutsClient: ClientProxy, | ||
) {} | ||
|
||
@Post('create-excercise') | ||
async createExcercise( | ||
@Body() createExcerciseDto: CreateExcerciseDto, | ||
): Promise<any> { | ||
return this.workoutsClient.send( | ||
{ cmd: 'createExcercise' }, | ||
createExcerciseDto, | ||
); | ||
} | ||
|
||
@Get('excercises') | ||
async getExcercises( | ||
@Query('page') page: number = 1, | ||
@Query('limit') limit: number = 10, | ||
@Query('filter') filter: string = '', | ||
): Promise<any> { | ||
return this.workoutsClient.send( | ||
{ cmd: 'getExcercises' }, | ||
{ page, limit, filter }, | ||
); | ||
} | ||
|
||
@Post('create-workout') | ||
async createWorkout( | ||
@Body() createWorkoutDto: CreateWorkoutDto, | ||
): Promise<any> { | ||
return this.workoutsClient.send({ cmd: 'createWorkout' }, createWorkoutDto); | ||
} | ||
|
||
@Get('workouts') | ||
async getWorkouts( | ||
@Query('page') page: number = 1, | ||
@Query('limit') limit: number = 10, | ||
@Query('filter') filter: string = '', | ||
): Promise<any> { | ||
return this.workoutsClient.send( | ||
{ cmd: 'getWorkouts' }, | ||
{ page, limit, filter }, | ||
); | ||
} | ||
|
||
@Post('save-workout') | ||
async saveWorkout(@Body() workout: CreateWorkoutLogDto): Promise<any> { | ||
return this.workoutsClient.send({ cmd: 'saveWorkout' }, workout); | ||
} | ||
|
||
@Get('workout-logs') | ||
async getWorkoutLogs( | ||
@Query('page') page: number = 1, | ||
@Query('limit') limit: number = 10, | ||
@Query('sortOrder') sortOrder: string = 'desc', | ||
): Promise<any> { | ||
return this.workoutsClient.send( | ||
{ cmd: 'getWorkoutLogs' }, | ||
{ page, limit, sortOrder }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsString } from 'class-validator'; | ||
|
||
export class CreateExcerciseDto { | ||
@IsString() | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Type } from 'class-transformer'; | ||
import { IsDateString, IsInt, IsString, ValidateNested } from 'class-validator'; | ||
|
||
class WorkoutLogExerciseDto { | ||
@IsString() | ||
exercise: string; | ||
|
||
@IsInt() | ||
sets: number; | ||
|
||
@IsInt() | ||
reps: number; | ||
|
||
@IsInt() | ||
weight: number; | ||
} | ||
|
||
export class CreateWorkoutLogDto { | ||
@IsDateString() | ||
startTime: Date; | ||
|
||
@IsDateString() | ||
endTime: Date; | ||
|
||
@ValidateNested({ each: true }) | ||
@Type(() => WorkoutLogExerciseDto) | ||
exercises: WorkoutLogExerciseDto[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Type } from 'class-transformer'; | ||
import { IsInt, IsString, ValidateNested } from 'class-validator'; | ||
|
||
class WorkoutExerciseDto { | ||
@IsString() | ||
exercise: string; | ||
|
||
@IsInt() | ||
sets: number; | ||
|
||
@IsInt() | ||
reps: number; | ||
} | ||
|
||
export class CreateWorkoutDto { | ||
@IsString() | ||
name: string; | ||
|
||
@ValidateNested({ each: true }) | ||
@Type(() => WorkoutExerciseDto) | ||
excercises: WorkoutExerciseDto[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { HydratedDocument } from 'mongoose'; | ||
|
||
export type ExcerciseDocument = HydratedDocument<Excercise>; | ||
|
||
@Schema() | ||
export class Excercise { | ||
@Prop() | ||
name: string; | ||
} | ||
|
||
export const ExcerciseSchema = SchemaFactory.createForClass(Excercise); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { HydratedDocument, Types } from 'mongoose'; | ||
import { Excercise } from './excercise.schema'; | ||
import { Workout } from './workout.schema'; | ||
|
||
export type WorkoutLogDocument = HydratedDocument<WorkoutLog>; | ||
|
||
@Schema() | ||
export class WorkoutLog { | ||
@Prop() | ||
startTime: Date; | ||
|
||
@Prop() | ||
endTime: Date; | ||
|
||
@Prop({ | ||
type: [ | ||
{ | ||
excercise: { type: Types.ObjectId, ref: 'Excercise' }, | ||
sets: Number, | ||
reps: Number, | ||
weight: Number, | ||
}, | ||
], | ||
}) | ||
exercises: { | ||
exercise: Types.ObjectId | Excercise; | ||
sets: number; | ||
reps: number; | ||
weight: number; | ||
}[]; | ||
|
||
@Prop({ type: Types.ObjectId, ref: 'Workout' }) | ||
workout: Types.ObjectId | Workout; | ||
} | ||
|
||
export const WorkoutLogSchema = SchemaFactory.createForClass(WorkoutLog); |
Oops, something went wrong.