-
-
Save chebykinn/6f88c03680167c4dc286f1b6226341f9 to your computer and use it in GitHub Desktop.
Implementation of POST todo handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TodosPost - Add new todo note | |
func (s *TodosApiService) TodosPost( | |
ctx *core.MifyRequestContext, todoNoteCreateRequest openapi.TodoNoteCreateRequest) (openapi.ServiceResponse, error) { | |
todoSvc := apputil.GetServiceExtra(ctx.ServiceContext()).TodoService | |
note, err := todoSvc.CreateTodo(ctx, domain.TodoNote{ | |
Title: todoNoteCreateRequest.Title, | |
Description: todoNoteCreateRequest.Description, | |
}) | |
if err != nil { | |
// Pass some user friendly error to user instead of internal one, | |
// which will be available in service logs. Since we don't expect | |
// any errors here, we return Internal Server Error, which is catch-all | |
// for all unknown bad things. These kind of errors will be reported in | |
// metrics and it's easy to set alerts for them. | |
return openapi.Response(http.StatusInternalServerError, openapi.Error{ | |
Code: strconv.Itoa(http.StatusInternalServerError), | |
Message: "Failed to create todo note", | |
}), err | |
} | |
return openapi.Response(http.StatusOK, handlers.MakeAPITodoNote(note)), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment