Skip to content

Instantly share code, notes, and snippets.

@ZergsLaw
Created April 16, 2020 14:50
Show Gist options
  • Select an option

  • Save ZergsLaw/5a46dac5f35de201714ab3bb613760ba to your computer and use it in GitHub Desktop.

Select an option

Save ZergsLaw/5a46dac5f35de201714ab3bb613760ba to your computer and use it in GitHub Desktop.
func (svc *service) createProjectFrom(params project.CreateProjectParams, authUser *app.AuthUser) middleware.Responder {
ctx, log, _ := fromRequest(params.HTTPRequest, authUser)
id, err := svc.project.CreateProject(ctx, *authUser, app.DirID(params.Args.Dir), string(params.Args.Name))
switch {
case err == nil:
return project.NewCreateProjectOK().WithPayload(&project.CreateProjectOKBody{ID: models.ProjectID(id)})
case errors.Is(err, app.ErrAccessDenied):
return errCreateProject(log, err, http.StatusNotAcceptable)
case errors.Is(err, app.ErrNotFound):
return errCreateProject(log, err, http.StatusNotFound)
default:
return errCreateProject(log, err, http.StatusInternalServerError)
}
}
func (svc *service) createProjectTo(params project.CreateProjectParams, authUser *app.AuthUser) (*project.CreateProjectOKBody ,error) {
ctx := fromRequest(params.HTTPRequest, authUser)
id, err := svc.project.CreateProject(ctx, *authUser, app.DirID(params.Args.Dir), string(params.Args.Name))
if err != nil {
return nil, err
}
return &project.CreateProjectOKBody{ID: models.ProjectID(id)}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment