import { Controller, Get, Post, Body, Patch, Param, Delete, Headers, Query } from '@nestjs/common';
import { WebService } from './web.service';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('website(展示端)')
@Controller('web')
export class WebController {
  constructor(private readonly webService: WebService) {}

  @Get('menu')
  getMenus(@Headers('locale') locale?: string) {
    return this.webService.findMenuTree(locale);
  }

  @Get('article/:id')
  getArticleDetail(@Param('id') id: string, @Headers('locale') locale?: string) {
    return this.webService.findArticleDetail(+id, locale);
  }

  @Get('article/count/:id')
  getArticleCount(@Param('id') id: string) {
    return this.webService.setArticleCount(+id);
  }

  @Get('article/near/:id')
  getNearArticle(@Param('id') id: string, @Headers('locale') locale?: string) {
    return this.webService.getNearArticle(+id, locale);
  }

  @Get('category/tree')
  getCategoryTree(@Query('id') id: string, @Headers('locale') locale?: string) {
    return this.webService.getCategoryTreeAndPath(+id, locale);
  }

  @Get('search')
  getArticleWithSearch(@Query('key') key: string, @Headers('locale') locale?: string) {
    return this.webService.searchArticles(key, locale);
  }

  @Get('articleWithCate/:id')
  getArticlesByCate(@Param('id') id: string, @Headers('locale') locale?: string) {
    return this.webService.getArticlesByCate(+id, locale);
  }
}
