11import { setupArticles } from '@articles/articles.module' ;
2- import {
3- ArticleFeedQuerySchema ,
4- DeleteArticleResponse ,
5- InsertArticleSchema ,
6- ListArticlesQuerySchema ,
7- ReturnedArticleListSchema ,
8- ReturnedArticleResponseSchema ,
9- UpdateArticleSchema ,
10- } from '@articles/articles.schema' ;
112import { Elysia , t } from 'elysia' ;
123import {
13- AddCommentSchema ,
14- DeleteCommentResponse ,
15- ReturnedCommentResponse ,
16- ReturnedCommentsResponse ,
17- } from './comments/comments.schema' ;
4+ ArticleResponseDto ,
5+ CreateArticleDto ,
6+ ListArticlesQueryDto ,
7+ ListArticlesResponseDto ,
8+ UpdateArticleDto ,
9+ } from './dto' ;
10+ import { CommentResponseDto , CreateCommentDto } from '@comments/dto' ;
1811
1912export const articlesController = new Elysia ( ) . use ( setupArticles ) . group (
2013 '/articles' ,
@@ -35,8 +28,8 @@ export const articlesController = new Elysia().use(setupArticles).group(
3528 ) ,
3629 } ) ,
3730 {
38- query : ListArticlesQuerySchema ,
39- response : ReturnedArticleListSchema ,
31+ query : ListArticlesQueryDto ,
32+ response : ListArticlesResponseDto ,
4033 detail : {
4134 summary : 'List Articles' ,
4235 } ,
@@ -51,8 +44,8 @@ export const articlesController = new Elysia().use(setupArticles).group(
5144 ) ,
5245 {
5346 beforeHandle : app . store . authService . requireLogin ,
54- body : InsertArticleSchema ,
55- response : ReturnedArticleResponseSchema ,
47+ body : CreateArticleDto ,
48+ response : ArticleResponseDto ,
5649 detail : {
5750 summary : 'Create Article' ,
5851 security : [
@@ -75,8 +68,8 @@ export const articlesController = new Elysia().use(setupArticles).group(
7568 } ) ,
7669 {
7770 beforeHandle : app . store . authService . requireLogin ,
78- query : ArticleFeedQuerySchema ,
79- response : ReturnedArticleListSchema ,
71+ query : ListArticlesQueryDto ,
72+ response : ListArticlesResponseDto ,
8073 detail : {
8174 summary : 'Artifle Feed' ,
8275 security : [
@@ -97,7 +90,7 @@ export const articlesController = new Elysia().use(setupArticles).group(
9790 ) ,
9891 ) ,
9992 {
100- response : ReturnedArticleResponseSchema ,
93+ response : ArticleResponseDto ,
10194 detail : {
10295 summary : 'Get Article' ,
10396 } ,
@@ -113,8 +106,8 @@ export const articlesController = new Elysia().use(setupArticles).group(
113106 ) ,
114107 {
115108 beforeHandle : app . store . authService . requireLogin ,
116- body : UpdateArticleSchema ,
117- response : ReturnedArticleResponseSchema ,
109+ body : UpdateArticleDto ,
110+ response : ArticleResponseDto ,
118111 detail : {
119112 summary : 'Update Article' ,
120113 security : [
@@ -127,14 +120,14 @@ export const articlesController = new Elysia().use(setupArticles).group(
127120 )
128121 . delete (
129122 '/:slug' ,
130- async ( { params, store, request } ) =>
131- store . articlesService . deleteArticle (
123+ async ( { params, store, request } ) => {
124+ await store . articlesService . deleteArticle (
132125 params . slug ,
133126 await store . authService . getUserIdFromHeader ( request . headers ) ,
134- ) ,
127+ ) ;
128+ } ,
135129 {
136130 beforeHandle : app . store . authService . requireLogin ,
137- response : DeleteArticleResponse ,
138131 detail : {
139132 summary : 'Delete Article' ,
140133 security : [
@@ -157,11 +150,8 @@ export const articlesController = new Elysia().use(setupArticles).group(
157150 } ,
158151 {
159152 beforeHandle : app . store . authService . requireLogin ,
160- params : t . Object ( {
161- slug : t . String ( ) ,
162- } ) ,
163- body : AddCommentSchema ,
164- response : ReturnedCommentResponse ,
153+ body : CreateCommentDto ,
154+ response : CommentResponseDto ,
165155 detail : {
166156 summary : 'Add Comment to Article' ,
167157 } ,
@@ -181,10 +171,9 @@ export const articlesController = new Elysia().use(setupArticles).group(
181171 } ;
182172 } ,
183173 {
184- params : t . Object ( {
185- slug : t . String ( ) ,
174+ response : t . Object ( {
175+ comments : t . Array ( CommentResponseDto ) ,
186176 } ) ,
187- response : ReturnedCommentsResponse ,
188177 detail : {
189178 summary : 'Get Comments from Article' ,
190179 } ,
@@ -198,15 +187,13 @@ export const articlesController = new Elysia().use(setupArticles).group(
198187 Number . parseInt ( params . id , 10 ) ,
199188 await store . authService . getUserIdFromHeader ( request . headers ) ,
200189 ) ;
201- return { } ;
202190 } ,
203191 {
204192 beforeHandle : app . store . authService . requireLogin ,
205193 params : t . Object ( {
206194 slug : t . String ( ) ,
207195 id : t . String ( ) ,
208196 } ) ,
209- response : DeleteCommentResponse ,
210197 detail : {
211198 summary : 'Delete Comment' ,
212199 } ,
@@ -221,7 +208,7 @@ export const articlesController = new Elysia().use(setupArticles).group(
221208 ) ,
222209 {
223210 beforeHandle : app . store . authService . requireLogin ,
224- response : ReturnedArticleResponseSchema ,
211+ response : ArticleResponseDto ,
225212 detail : {
226213 summary : 'Favorite Article' ,
227214 security : [
@@ -241,7 +228,7 @@ export const articlesController = new Elysia().use(setupArticles).group(
241228 ) ,
242229 {
243230 beforeHandle : app . store . authService . requireLogin ,
244- response : ReturnedArticleResponseSchema ,
231+ response : ArticleResponseDto ,
245232 detail : {
246233 summary : 'Unfavorite Article' ,
247234 security : [
0 commit comments