feat(guild): add guild and channel list APIs for frontend browser
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { GuildsService } from './guilds.service';
|
||||
|
||||
@Controller('guilds')
|
||||
export class GuildsController {
|
||||
constructor(private readonly guildsService: GuildsService) {}
|
||||
|
||||
@Get()
|
||||
list() {
|
||||
return this.guildsService.list();
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: Record<string, unknown>) {
|
||||
return { status: 'todo', action: 'create-guild', received: body };
|
||||
return this.guildsService.create(body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { GuildsController } from './guilds.controller';
|
||||
import { Guild } from '../entities/guild.entity';
|
||||
import { GuildsService } from './guilds.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Guild])],
|
||||
controllers: [GuildsController],
|
||||
providers: [GuildsService],
|
||||
exports: [GuildsService],
|
||||
})
|
||||
export class GuildsModule {}
|
||||
|
||||
27
Fabric.Backend.Guild/src/guilds/guilds.service.ts
Normal file
27
Fabric.Backend.Guild/src/guilds/guilds.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Guild } from '../entities/guild.entity';
|
||||
|
||||
@Injectable()
|
||||
export class GuildsService {
|
||||
constructor(
|
||||
@InjectRepository(Guild)
|
||||
private readonly guildRepo: Repository<Guild>,
|
||||
) {}
|
||||
|
||||
list() {
|
||||
return this.guildRepo.find({
|
||||
order: { createdAt: 'DESC' },
|
||||
take: 100,
|
||||
});
|
||||
}
|
||||
|
||||
create(input: Partial<Guild>) {
|
||||
const slug = String(input.slug ?? '').trim();
|
||||
const name = String(input.name ?? '').trim();
|
||||
const ownerUserId = input.ownerUserId ? String(input.ownerUserId) : null;
|
||||
const guild = this.guildRepo.create({ slug, name, ownerUserId });
|
||||
return this.guildRepo.save(guild);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user