Skip to content

Commit 383d314

Browse files
feat: Implement initial User, Service, Veil, and Gallery modules including their controllers, services, repositories, and Mongoose schemas.
1 parent 1b3c4cd commit 383d314

11 files changed

Lines changed: 108 additions & 4 deletions

File tree

backend/src/gallery/gallery.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { MongooseModule } from '@nestjs/mongoose';
33
import { GalleryService } from './application/gallery.service';
4+
import { GalleryController } from './presentation/gallery.controller';
45
import { GalleryRepository } from './infrastructure/repositories/gallery.repository';
56
import {
67
GallerySchema,
@@ -13,6 +14,7 @@ import {
1314
{ name: GallerySchemaEntity.name, schema: GallerySchema },
1415
]),
1516
],
17+
controllers: [GalleryController],
1618
providers: [GalleryService, GalleryRepository],
1719
exports: [GalleryService],
1820
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Controller, Get, Post, Body } from '@nestjs/common';
2+
import { GalleryService } from '../application/gallery.service';
3+
import { Gallery } from '../domain/gallery.entity';
4+
5+
@Controller('gallery')
6+
export class GalleryController {
7+
constructor(private readonly galleryService: GalleryService) {}
8+
9+
@Get()
10+
async findAll(): Promise<Gallery[]> {
11+
return this.galleryService.findAll();
12+
}
13+
14+
@Post()
15+
async create(@Body() gallery: Omit<Gallery, 'id' | 'createdAt'>): Promise<Gallery> {
16+
return this.galleryService.create(gallery);
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Controller, Get, Post, Body } from '@nestjs/common';
2+
import { ServiceService } from '../application/service.service';
3+
import { Service } from '../domain/service.entity';
4+
5+
@Controller('services')
6+
export class ServiceController {
7+
constructor(private readonly serviceService: ServiceService) {}
8+
9+
@Get()
10+
async findAll(): Promise<Service[]> {
11+
return this.serviceService.findAll();
12+
}
13+
14+
@Post()
15+
async create(@Body() service: Omit<Service, 'id' | 'createdAt'>): Promise<Service> {
16+
return this.serviceService.create(service);
17+
}
18+
}

backend/src/service/service.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { MongooseModule } from '@nestjs/mongoose';
33
import { ServiceService } from './application/service.service';
4+
import { ServiceController } from './presentation/service.controller';
45
import { ServiceRepository } from './infrastructure/repositories/service.repository';
56
import {
67
ServiceSchema,
@@ -13,6 +14,7 @@ import {
1314
{ name: ServiceSchemaEntity.name, schema: ServiceSchema },
1415
]),
1516
],
17+
controllers: [ServiceController],
1618
providers: [ServiceService, ServiceRepository],
1719
exports: [ServiceService],
1820
})

backend/src/user/application/user.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { UserRepository } from '@user/infrastructure/repositories/user.repositor
66
export class UserService {
77
constructor(private readonly userRepository: UserRepository) {}
88

9+
async findAll(): Promise<User[]> {
10+
return await this.userRepository.findAll();
11+
}
12+
913
async findOrCreate(
1014
telegramId: number,
1115
profile: {
@@ -27,4 +31,8 @@ export class UserService {
2731

2832
return user;
2933
}
34+
35+
async create(user: User): Promise<User> {
36+
return await this.userRepository.create(user);
37+
}
3038
}

backend/src/user/infrastructure/repositories/user.repository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export class UserRepository {
1010
@InjectModel(UserSchemaEntity.name) private userModel: Model<UserDocument>,
1111
) {}
1212

13+
async findAll(): Promise<User[]> {
14+
const docs = await this.userModel.find().exec();
15+
return docs.map((doc) => this.toDomain(doc));
16+
}
17+
1318
async findByTelegramId(telegramId: number): Promise<User | null> {
1419
const doc = await this.userModel.findOne({ telegramId }).exec();
1520
return doc ? this.toDomain(doc) : null;

backend/src/user/infrastructure/schemas/user.schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ export class UserSchemaEntity {
1111
@Prop({ required: true })
1212
firstName: string;
1313

14-
@Prop()
14+
@Prop({ required: true })
1515
lastName: string;
1616

17-
@Prop()
17+
@Prop({ required: true })
1818
username: string;
1919

20-
@Prop()
20+
@Prop({ required: false })
2121
photoUrl: string;
2222

23-
@Prop({ default: 'user', enum: ['user', 'admin'] })
23+
@Prop({ required: true, default: 'user', enum: ['user', 'admin'] })
2424
role: string;
2525
}
2626

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Controller, Get, Post, Body } from '@nestjs/common';
2+
import { UserService } from '../application/user.service';
3+
import { User } from '@user/domain/user.entity';
4+
5+
@Controller('users')
6+
export class UserController {
7+
constructor(private readonly userService: UserService) {}
8+
9+
@Get()
10+
async findAll(): Promise<User[]> {
11+
return this.userService.findAll();
12+
}
13+
14+
@Get('profile')
15+
async getProfile() {
16+
// Placeholder for profile retrieval logic
17+
// In a real app, this would use @Req() or @User() decorator to get the authenticated user
18+
return { message: 'Profile endpoint' };
19+
}
20+
@Post()
21+
async create(@Body() user: User): Promise<User> {
22+
return this.userService.create(user);
23+
}
24+
}

backend/src/user/user.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { MongooseModule } from '@nestjs/mongoose';
33
import { UserService } from './application/user.service';
4+
import { UserController } from './presentation/user.controller';
45
import { UserRepository } from './infrastructure/repositories/user.repository';
56
import {
67
UserSchema,
@@ -13,6 +14,7 @@ import {
1314
{ name: UserSchemaEntity.name, schema: UserSchema },
1415
]),
1516
],
17+
controllers: [UserController],
1618
providers: [UserService, UserRepository],
1719
exports: [UserService],
1820
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Controller, Get, Post, Body } from '@nestjs/common';
2+
import { VeilService } from '../application/veil.service';
3+
import { Veil } from '../domain/veil.entity';
4+
5+
@Controller('veils')
6+
export class VeilController {
7+
constructor(private readonly veilService: VeilService) {}
8+
9+
@Get()
10+
async findAll(): Promise<Veil[]> {
11+
return this.veilService.findAll();
12+
}
13+
14+
@Get('available')
15+
async getAvailable(): Promise<Veil[]> {
16+
return this.veilService.getAvailable();
17+
}
18+
19+
@Post()
20+
async create(@Body() veil: Omit<Veil, 'id' | 'createdAt'>): Promise<Veil> {
21+
return this.veilService.create(veil);
22+
}
23+
}

0 commit comments

Comments
 (0)