Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][API] Create a privacy metrics job #72

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Create a privacy metrics job #72

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Member

youen commented Mar 31, 2024

Description

Create a privacy metrics job.

Request

Method

POST

URL

/jobs/metrics/privacy

Request Parameters

Parameter Description Required Example
id UUID. The id of the new job. Yes bcf13e3d-e3b7-4d6d-8059-e75a8b2d3e60

Request Body

{
  "kind": "privacy_metrics",
  "parameters": {
    "table": "table_name",
    "columns": ["column_name"]
  }
}

Result

Result parameters

N/A

Result Body

{
  "id": "bcf13e3d-e3b7-4d6d-8059-e75a8b2d3e60",
  "kind": "privacy_metrics",
  "created_at": "2023-03-08T12:34:56.789Z",
  "status": "enqueued",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "table": "table_name",
    "columns": ["column_name"]
  },
  "current_progress": null
}

Example Curl Request

Request

curl -X POST \
  http://localhost:8080/jobs/metrics/privacy \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "bcf13e3d-e3b7-4d6d-8059-e75a8b2d3e60",
    "kind": "privacy_metrics",
    "parameters": {
      "table": "table_name",
      "columns": ["column_name"]
    }
  }'

Curl Response

{
  "id": "bcf13e3d-e3b7-4d6d-8059-e75a8b2d3e60",
  "kind": "privacy_metrics",
  "created_at": "2023-03-08T12:34:56.789Z",
  "status": "enqueued",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "table": "table_name",
    "columns": ["column_name"]
  },
  "current_progress": null
}

Go server

Struct

type PrivacyMetricsJobCreateRequest struct {
	ID          string                    `json:"id"`
	Kind        JobKind                   `json:"kind"`
	Parameters  PrivacyMetricsParameters  `json:"parameters"` 
}

Handler

func (s *Server) CreatePrivacyMetricsJob(w http.ResponseWriter, r *http.Request) {
	var req PrivacyMetricsJobCreateRequest

	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		http.Error(w, "failed to parse request body", http.StatusBadRequest)
		return
	}

	resp, err := s.db.CreatePrivacyMetricsJob(r.Context(), req)
	if err != nil {
		http.Error(w, "failed to create job", http.StatusInternalServerError)
		return
	}

	if err := json.NewEncoder(w).Encode(resp); err != nil {
		http.Error(w, "failed to encode response", http.StatusInternalServerError)
		return
	}
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant