Skip to content

Commit

Permalink
Refactor/change api core path name (#72)
Browse files Browse the repository at this point in the history
* refactor: ♻️ renames the API modules folder from 'route' to 'api

Improve the semantic accuracy of the 'routes' folder by renaming it to 'api'.

* refactor: ♻️ add api version

Add the v1 folder to segment modules according to API version.

* revert: ⏪ Revert "refactor: ♻️ add api version"

This reverts commit d5d70b2.

---------

Co-authored-by: Edwin Hernandez <Edwinhern.16@gmail.com>
  • Loading branch information
1001Josias and edwinhern authored Mar 12, 2024
1 parent ac1ecb2 commit 4589e23
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/api-docs/openAPIDocumentGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenApiGeneratorV3, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';

import { healthCheckRegistry } from '@/routes/healthCheck/healthCheckRouter';
import { userRegistry } from '@/routes/user/userRouter';
import { healthCheckRegistry } from '@/api/healthCheck/healthCheckRouter';
import { userRegistry } from '@/api/user/userRouter';

export function generateOpenAPIDocument() {
const registry = new OpenAPIRegistry([healthCheckRegistry, userRegistry]);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StatusCodes } from 'http-status-codes';
import request from 'supertest';

import { User } from '@/api/user/userModel';
import { users } from '@/api/user/userRepository';
import { ServiceResponse } from '@/common/models/serviceResponse';
import { User } from '@/routes/user/userModel';
import { users } from '@/routes/user/userRepository';
import { app } from '@/server';

describe('User API Endpoints', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { StatusCodes } from 'http-status-codes';
import { Mock } from 'vitest';

import { User } from '@/routes/user/userModel';
import { userRepository } from '@/routes/user/userRepository';
import { userService } from '@/routes/user/userService';
import { User } from '@/api/user/userModel';
import { userRepository } from '@/api/user/userRepository';
import { userService } from '@/api/user/userService';

vi.mock('@/routes/user/userRepository');
vi.mock('@/api/user/userRepository');
vi.mock('@/server', () => ({
...vi.importActual('@/server'),
logger: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '@/routes/user/userModel';
import { User } from '@/api/user/userModel';

export const users: User[] = [
{ id: 1, name: 'Alice', email: 'alice@example.com', age: 42, createdAt: new Date(), updatedAt: new Date() },
Expand Down
4 changes: 2 additions & 2 deletions src/routes/user/userRouter.ts → src/api/user/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
import express, { Request, Response, Router } from 'express';
import { z } from 'zod';

import { GetUserSchema, UserSchema } from '@/api/user/userModel';
import { userService } from '@/api/user/userService';
import { createApiResponse } from '@/api-docs/openAPIResponseBuilders';
import { handleServiceResponse, validateRequest } from '@/common/utils/httpHandlers';
import { GetUserSchema, UserSchema } from '@/routes/user/userModel';
import { userService } from '@/routes/user/userService';

export const userRegistry = new OpenAPIRegistry();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { StatusCodes } from 'http-status-codes';

import { User } from '@/api/user/userModel';
import { userRepository } from '@/api/user/userRepository';
import { ResponseStatus, ServiceResponse } from '@/common/models/serviceResponse';
import { User } from '@/routes/user/userModel';
import { userRepository } from '@/routes/user/userRepository';
import { logger } from '@/server';

export const userService = {
Expand Down
4 changes: 2 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import express, { Express } from 'express';
import helmet from 'helmet';
import { pino } from 'pino';

import { healthCheckRouter } from '@/api/healthCheck/healthCheckRouter';
import { userRouter } from '@/api/user/userRouter';
import { openAPIRouter } from '@/api-docs/openAPIRouter';
import errorHandler from '@/common/middleware/errorHandler';
import rateLimiter from '@/common/middleware/rateLimiter';
import requestLogger from '@/common/middleware/requestLogger';
import { env } from '@/common/utils/envConfig';
import { healthCheckRouter } from '@/routes/healthCheck/healthCheckRouter';
import { userRouter } from '@/routes/user/userRouter';

const logger = pino({ name: 'server start' });
const app: Express = express();
Expand Down

0 comments on commit 4589e23

Please sign in to comment.