示例#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
}