Skip to content

Commit 9a0a8a3

Browse files
Merge pull request #55 from NYCU-SDC/feat/CORE-200-add-oauth-connect-api
[CORE-200] Add Oauth Connect Qestion API
2 parents c0b9691 + 3234a27 commit 9a0a8a3

3 files changed

Lines changed: 48 additions & 35 deletions

File tree

src/forms/models.tsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace CoreSystem.Forms {
184184
@doc("File upload")
185185
uploadFile: "UPLOAD_FILE",
186186

187-
@doc("Linear scale/rating (1-5, 1-10, etc.)")
187+
@doc("Linear scale/rating (0-10 or 1-10, etc.)")
188188
linearScale: "LINEAR_SCALE",
189189

190190
@doc("Rating (e.g., star rating)")
@@ -303,10 +303,10 @@ namespace CoreSystem.Forms {
303303
@doc("Background icon for the linear scale option.")
304304
icon?: string;
305305

306-
@doc("Minimum value of the linear scale.")
306+
@doc("Minimum value of the linear scale, can be 0 or 1.")
307307
minVal: int32;
308308

309-
@doc("Maximum value of the linear scale.")
309+
@doc("Maximum value of the linear scale, can be between 2 and 10.")
310310
maxVal: int32;
311311

312312
@doc("Label for the minimum value.")

src/responses/models.tsp

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,17 @@ namespace CoreSystem.Responses {
4141
value: int32;
4242
}
4343

44-
@example(#{
45-
questionId: "2b2bc4f4-71c1-478b-9e36-516eac6b36c3",
46-
questionType: CoreSystem.Forms.QuestionTypes.oauthConnect,
47-
provider: CoreSystem.Auth.OAuthProviders.google,
48-
callback: "https://example.com/oauth/callback",
49-
})
50-
@doc("Request model for initiating an OAuth answer")
51-
model OauthAnswerRequest {
44+
@example(#{ questionId: "2b2bc4f4-71c1-478b-9e36-516eac6b36c3", questionType: CoreSystem.Forms.QuestionTypes.oauthConnect, avatarUrl: "https://example.com/avatar.jpg", username: "JohnDoe" })
45+
@doc("Response model for an OAuth answer")
46+
model OauthAnswerJSON {
5247
@doc("The question being answered.")
5348
questionId: uuid;
5449

5550
@doc("The type of the question being answered.")
5651
questionType: CoreSystem.Forms.QuestionTypes.oauthConnect;
5752

58-
@doc("The OAuth provider to use.")
59-
provider: CoreSystem.Auth.OAuthProviders;
60-
61-
@doc("The callback URL for the OAuth flow.")
62-
callback: string;
63-
64-
@doc("The redirect URL after OAuth completion.")
65-
redirect?: string;
66-
}
67-
68-
@example(#{ questionId: "2b2bc4f4-71c1-478b-9e36-516eac6b36c3", avatar_url: "https://example.com/avatar.jpg", username: "JohnDoe" })
69-
@doc("Response model for an OAuth answer")
70-
model OauthAnswerJSON {
71-
@doc("The question being answered.")
72-
questionId: uuid;
73-
7453
@doc("The avatar URL from the OAuth provider.")
75-
avatar_url: string;
54+
avatarUrl: string;
7655

7756
@doc("The username from the OAuth provider.")
7857
username: string;
@@ -83,17 +62,11 @@ namespace CoreSystem.Responses {
8362
answers: #[
8463
#{ questionId: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd", questionType: CoreSystem.Forms.QuestionTypes.shortText, value: #["John Doe"] },
8564
#{ questionId: "2b2bc4f4-71c1-478b-9e36-516eac6b36c3", questionType: CoreSystem.Forms.QuestionTypes.linearScale, value: 4 },
86-
#{
87-
questionId: "3c3cd5f5-82d2-589c-af47-627fbd7c47d4",
88-
questionType: CoreSystem.Forms.QuestionTypes.oauthConnect,
89-
provider: CoreSystem.Auth.OAuthProviders.google,
90-
callback: "https://example.com/oauth/callback",
91-
}
9265
],
9366
})
9467
model AnswersRequest {
9568
@doc("The answers to be saved. Can contain a partial subset for drafts or the full set for submission.")
96-
answers: (AnswerJSON | ScaleAnswerJSON | OauthAnswerRequest)[];
69+
answers: (AnswerJSON | ScaleAnswerJSON)[];
9770
}
9871

9972
@doc("Request model for uploading files as answers to a specific question in a response.")
@@ -114,6 +87,18 @@ namespace CoreSystem.Responses {
11487
id: uuid;
11588
}
11689

90+
@doc("Response model for updating a form response")
91+
model UpdateResponse {
92+
@doc("The response's unique identifier.")
93+
id: uuid;
94+
95+
@doc("The last updated timestamp of the response.")
96+
updatedAt: utcDateTime;
97+
98+
@doc("The updated answer data.")
99+
answers: (AnswerJSON | ScaleAnswerJSON | OauthAnswerJSON)[];
100+
}
101+
117102
@doc("Response model for a single response in list view")
118103
model ResponseJSON {
119104
@doc("The response's unique identifier.")

src/responses/operations.tsp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ namespace CoreSystem.Responses {
3131
@patch(#{ implicitOptionality: true })
3232
op updateFormResponse(@path id: uuid, @body req: AnswersRequest): {
3333
@statusCode statusCode: 200;
34+
@body response: UpdateResponse;
35+
};
36+
37+
@summary("Connect OAuth Account")
38+
@doc("Initiate OAuth flow for connecting an account to answer a question. This endpoint redirects (302) to the OAuth provider's authorization page. After authorization, the OAuth profile data (username, avatar_url) is stored as the answer and can be fetched via GET /responses/{responseId}/questions/{questionId}.")
39+
@route("/oauth/questions/{provider}")
40+
@get
41+
op connectOauthAccount(
42+
@path
43+
@doc("The OAuth provider to connect with (github or google).")
44+
provider: CoreSystem.Auth.OAuthProviders,
45+
46+
@query
47+
@doc("The response ID to associate this OAuth answer with.")
48+
responseId: uuid,
49+
50+
@query
51+
@doc("The question ID being answered.")
52+
questionId: uuid,
53+
54+
@query
55+
@doc("Optional redirect URL after OAuth completion.")
56+
r?: string,
57+
):
58+
{
59+
@statusCode statusCode: 302;
60+
} | {
61+
@statusCode statusCode: 404;
3462
};
3563

3664
@summary("Upload Question Files")

0 commit comments

Comments
 (0)