Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bay 2.0 #14

Open
luin opened this issue Jul 7, 2018 · 4 comments
Open

Bay 2.0 #14

luin opened this issue Jul 7, 2018 · 4 comments

Comments

@luin
Copy link
Member

luin commented Jul 7, 2018

目标

  1. 满足企业级应用开发;
  2. First-class support for TypeScript;
  3. 自由灵活,可以支持多种范式,如 DDD;
  4. 不造轮子!

Sample

import {controller, httpPost, Controller, requestBody, requestParam, httpGet} from 'bay'
import {inject} from 'inversify'
import {IUserService} from '../applications'
import {User, IUserRepository} from '../domain/models/user'
import {Email, UUID} from '../domain/shared'
import TYPES from '../types'

@controller('/users')
export default class UserController extends Controller {
  constructor (
    @inject(TYPES.IUserService) private userService: IUserService,
    @inject(TYPES.IUserRepository) private userRepository: IUserRepository,
  ) {}

  @httpPost('/')
  private async create (
    @requestBody() body: {email: string, password: string}
  ): Promise<User> {
    const user = await this.userService.createUser(
      new Email(body.email),
      body.password
    )
    return user
  }

  @httpGet('/:uuid')
  private async getUser (@requestParam('uuid') uuid: string) {
    const user = await this.userRepository.getByUUID(new UUID(uuid))
    if (user === null) {
      this.throwNotFound('User not exists')
    }
    return user
  }
}
@NeoyeElf
Copy link

好像Java的Spring Boot😂

@luoyjx
Copy link
Contributor

luoyjx commented Jul 24, 2018

tom says good!

竟然直接从 0.x 跳到了 2.0!

话说~

this.throw(HTTP_CODE.NotFound, 'User not exists')

这样会不会通用点~

@lovio
Copy link

lovio commented Nov 20, 2018

非常棒!进展如何了?

1 similar comment
@leafduo
Copy link
Contributor

leafduo commented Mar 4, 2019

非常棒!进展如何了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants