예제 #1
0
파일: notes.go 프로젝트: celioreyes/notes
//Note : Grabs Note by the ID
func (nc *NotesController) Note(c *gin.Context) {
	resp := response.New(c)
	defer resp.Render()

	noteID, err := strconv.Atoi(c.Param("noteId"))

	if err != nil {
		resp.AddErrorDetail(400, err)
		return
	}

	note, err := services.Note(noteID)

	if err != nil {
		resp.AddErrorDetail(500, err)
		return
	}

	resp.SetResponse(200, note)
	return
}
예제 #2
0
파일: notes.go 프로젝트: celioreyes/notes
//DeleteNote : Deletes a note from the database
func (nc *NotesController) DeleteNote(c *gin.Context) {
	resp := response.New(c)
	defer resp.Render()

	noteID, err := strconv.Atoi(c.Param("noteId"))

	if err != nil {
		resp.AddErrorDetail(400, err)
		resp.StatusCode = 400
		return
	}

	err = services.DeleteNote(noteID)

	if err != nil {
		resp.AddErrorDetail(400, err)
		resp.StatusCode = 400
		return
	}

	resp.SetResponse(200, gin.H{"message": "Successfully Deleted Note"})
	return
}