generated from parenthesin/microservice-boilerplate-malli
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[wip] add: code submission endpoint #9
Draft
matheusfrancisco
wants to merge
5
commits into
main
Choose a base branch
from
chico/code-submission
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−43
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d14f73
add: code submission endpoint
matheusfrancisco bcd7cef
fix lint
matheusfrancisco 6034998
add: adpater, and controller to submit code execution
matheusfrancisco 5a07925
fix: integration test
matheusfrancisco b7cdb3e
unused binding
matheusfrancisco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
src/codes/clj/contest/submission_runner/adapters/submission.clj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns codes.clj.contest.submission-runner.adapters.submission | ||
(:require [codes.clj.contest.submission-runner.wire.db.submission :as wire.db.submission] | ||
[codes.clj.contest.submission-runner.wire.in.submission :as wire.in.submission])) | ||
|
||
(defn wire->internal | ||
{:malli/schema [:=> [:cat wire.in.submission/Submission] wire.db.submission/Submission]} | ||
[wire] | ||
{:submission/id (-> wire :id) | ||
:submission/code (-> wire :code) | ||
:submission/code_hash (-> wire :code-hash) | ||
:submission/language (-> wire :language) | ||
:submission/test_cases (-> wire :test-cases)}) |
5 changes: 5 additions & 0 deletions
5
src/codes/clj/contest/submission_runner/controllers/submission.clj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns codes.clj.contest.submission-runner.controllers.submission) | ||
|
||
(defn submit-code-execution! | ||
[submission] | ||
(random-uuid)) | ||
12 changes: 8 additions & 4 deletions
12
src/codes/clj/contest/submission_runner/ports/http_in/submission.clj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
(ns codes.clj.contest.submission-runner.ports.http-in.submission) | ||
(ns codes.clj.contest.submission-runner.ports.http-in.submission | ||
(:require [codes.clj.contest.submission-runner.adapters.submission :as adapters.submission] | ||
[codes.clj.contest.submission-runner.controllers.submission :as controllers.submission])) | ||
|
||
(defn submit-code-execution! | ||
[{_submission :parameters | ||
[{{submission :body} :parameters | ||
_components :components}] | ||
{:status 201 | ||
:body {:id (random-uuid)}}) | ||
(let [id (-> submission | ||
(adapters.submission/wire->internal) | ||
(controllers.submission/submit-code-execution!))] | ||
{:status 201})) | ||
|
13 changes: 13 additions & 0 deletions
13
src/codes/clj/contest/submission_runner/wire/db/submission.clj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns codes.clj.contest.submission-runner.wire.db.submission) | ||
|
||
(def Submission | ||
[:map | ||
[:submission/id string?] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UUID? |
||
[:submission/code string?] | ||
[:submission/code_hash string?] | ||
[:submission/language [:enum :clojure]] | ||
[:submission/test_cases | ||
[:map-of :keyword | ||
[:map | ||
[:input :any] | ||
[:output :any]]]]]) |
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
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
44 changes: 44 additions & 0 deletions
44
test/unit/codes/clj/contest/submission_runner/adapters/submission_test.clj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns unit.codes.clj.contest.submission-runner.adapters.submission-test | ||
(:require [clj-commons.digest :as digest] | ||
[clojure.test :refer [deftest is testing use-fixtures]] | ||
[clojure.test.check.clojure-test :refer [defspec]] | ||
[clojure.test.check.properties :as properties] | ||
[codes.clj.contest.submission-runner.adapters.submission :as adapters.submission] | ||
[codes.clj.contest.submission-runner.wire.db.submission :as wire.db.submission] | ||
[codes.clj.contest.submission-runner.wire.in.submission :as wire.in.submission] | ||
[malli.core :as m] | ||
[malli.generator :as mg] | ||
[matcher-combinators.test :refer [match?]] | ||
[parenthesin.helpers.malli :as helpers.malli])) | ||
|
||
(use-fixtures :once helpers.malli/with-intrumentation) | ||
|
||
(defspec wirer->internal-spec 50 | ||
(properties/for-all [code (mg/generator wire.in.submission/Submission)] | ||
(m/validate wire.db.submission/Submission (adapters.submission/wire->internal code)))) | ||
|
||
(def id (random-uuid)) | ||
(def code "(ns runner | ||
(:require [clojure.string :as str])) | ||
(defn my-sum [a b] (+ a b))") | ||
|
||
(def code-submission {:id (str id) | ||
:code code | ||
:code-hash (digest/md5 code) | ||
:language :clojure | ||
:test-cases {:case-1 {:input "(my-sum 1 2)" | ||
:output 3} | ||
:case-2 {:input "(my-sum 2 3)" | ||
:output 5}}}) | ||
|
||
(deftest wire->internal | ||
(testing "adpater to db submission" | ||
(is (match? {:submission/id (str id) | ||
:submission/code code | ||
:submission/code_hash (digest/md5 code) | ||
:submission/language :clojure | ||
:submission/test_cases {:case-1 {:input "(my-sum 1 2)" | ||
:output 3} | ||
:case-2 {:input "(my-sum 2 3)" | ||
:output 5}}} | ||
(adapters.submission/wire->internal code-submission))))) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are generating this just to insert into the database, you can delegate the UUID generation to postgres.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still not 100% clear what we are going to save on postgres
id, code, code-hash, language and test-cases as string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, I think I would store information to be possible to trace back the author, contest and the submission.
I would have an table to the contests (where the base challenge, and test inputs (and demo test inputs) would be stored, another for the authors, another for the submission where you would have the challenge id, author id, and the submission itself, to not store to much data in the database I would keep only the latest submission for each challenge and author, so if I submit and answer for a challenge we update the submission table by author-id and challenge-id with the new code, code-hash and updated date
After I would have a table with the execution results where you could store submission-id, code-hash and the result.
We can whiteboard this later if you want so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to whiteboard this