예제 #1
0
파일: api.go 프로젝트: amarnus/JustRun.It
func ForkSnippetById(resp http.ResponseWriter, req *http.Request) {
	routeVariables := mux.Vars(req)
	snippetId := routeVariables["snippet_id"]
	session, _ := globalStore.Get(req, "session-name")
	session.Save(req, resp)
	resp = setSessionIDAsCookie(resp, session.ID)
	snippet, err := models.FindSnippetById(snippetId)
	snippet.SessionId = session.ID
	newSnippetId, ok, err := models.CreateSnippet(snippet)
	enc := json.NewEncoder(resp)
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: ok})
	} else {
		ResponseResult := SnippetCreationResponse{newSnippetId}
		enc.Encode(routeinit.ApiResponse{Result: &ResponseResult, Status: ok})
	}
	return
}
예제 #2
0
파일: api.go 프로젝트: amarnus/JustRun.It
func FilterSnippetById(resp http.ResponseWriter, req *http.Request) {
	validated, urlParams, enc, _ := routeinit.InitHandling(req, resp, []string{})
	if !validated {
		return
	}
	snippetId, ok := urlParams["snippet_id"]
	session, _ := globalStore.Get(req, "session-name")
	session.Save(req, resp)
	resp = setSessionIDAsCookie(resp, session.ID)
	if ok != true {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: "Invalid URL", Status: false})
		return
	}
	snippet, err := models.FindSnippetById(snippetId)
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: ok})
	} else {
		enc.Encode(routeinit.ApiResponse{Result: &snippet, Status: true})
	}
	return
}