From 7615db75feb0d11ea31ec85e6b6827c81534ec2a Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 20:03:57 +0100 Subject: [PATCH 01/12] Update GetUserById path --- api/openapi/archive/openapi-0.2.0.yaml | 459 +++++++++++++++++++++++++ api/openapi/openapi.yaml | 2 +- internal/api/handlers/users_handler.go | 2 +- 3 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 api/openapi/archive/openapi-0.2.0.yaml diff --git a/api/openapi/archive/openapi-0.2.0.yaml b/api/openapi/archive/openapi-0.2.0.yaml new file mode 100644 index 0000000..843167f --- /dev/null +++ b/api/openapi/archive/openapi-0.2.0.yaml @@ -0,0 +1,459 @@ +openapi: 3.0.0 +info: + description: "This is the API specification for the ScheduleTogether Backend." + version: 0.1.0 + title: ScheduleTogether Backend + termsOfService: http://zervo.org/terms/ + contact: + email: contact@dev.zervo.org + license: + name: AGPL 3.0 + url: https://www.gnu.org/licenses/agpl-3.0.html +tags: + - name: account + description: Everything related to account management + externalDocs: + description: Find out more + url: https://git.zervo.org/ScheduleTogether/Backend/src/branch/main/internal/api/handlers/account_handler.go + - name: users + description: Everything related to user management + externalDocs: + description: Find out more + url: https://git.zervo.org/ScheduleTogether/Backend/src/branch/main/internal/api/handlers/users_handler.go + - name: friends + description: Everything related to friends management + externalDocs: + description: Find out more + url: https://git.zervo.org/ScheduleTogether/Backend/src/branch/main/internal/api/handlers/friends_handler.go +paths: + /account/register: + post: + tags: + - account + summary: Register a new user account + description: "Used to register a new user account. By default, newly created unverified accounts will be deleted after a while. To fully complete registration, an account verify request must be sent following the registration request." + operationId: registerAccount + requestBody: + $ref: "#/components/requestBodies/AccountRegister" + responses: + "400": + description: Request body validation failed + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Registration successful + content: + application/json: + schema: + $ref: "#/components/schemas/AccountRegisterResponse" + /account/verify: + post: + tags: + - account + summary: Verify a registered account + description: "Used to verify a newly registered user account. AKA complete user account registration." + operationId: verifyAccount + requestBody: + $ref: "#/components/requestBodies/AccountVerify" + responses: + "200": + description: Verification successful + content: + application/json: + schema: + $ref: "#/components/schemas/CommonMessage" + "400": + description: Invalid UUID or verification token + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + /account/signin: + post: + tags: + - account + summary: Sign in to an existing user account + description: "Used to retrieve a session (jwt) token for a user account, that can in turn be used to authenticate subsequent requests." + operationId: signinAccount + requestBody: + $ref: "#/components/requestBodies/AccountSignin" + responses: + "401": + description: Authentication failed + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "400": + description: Request body validation failed + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Signed in successfully + content: + application/json: + schema: + $ref: "#/components/schemas/AccountSigninResponse" + /account/logout: + post: + tags: + - account + summary: Log out of a user account + description: "Used to invalidate a user account session (aka log out) based on context. REQUIRES: Authentication." + operationId: logoutAccount + responses: + "401": + description: Unauthorized + "200": + description: Successfully logged out + content: + application/json: + schema: + $ref: "#/components/schemas/CommonMessage" + + /users: + get: + tags: + - users + summary: Get all users + description: "WILL BE PAGINATED IN THE FUTURE. Get all available users on the instance. REQUIRES: Authentication, GetAllUsers permission." + operationId: getUsers + responses: + "500": + description: Something went wrong + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "401": + description: Unauthorized + "200": + description: Successfully got all users + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllUsersResponse" + /users/id/{userId}: + get: + tags: + - users + summary: Get user by internal ID + description: "Get user information about one account by internal user account ID. REQUIRES: Authentication, GetUserById permission." + operationId: getUserById + parameters: + - in: path + name: userId + schema: + type: integer + required: true + description: Numeric internal ID of the user to get + responses: + "401": + description: Unauthorized + "400": + description: Invalid parameters + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "404": + description: User not found + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Successfully got user + content: + application/json: + schema: + $ref: "#/components/schemas/DetailedUser" + /users/uuid/{userUuid}: + get: + tags: + - users + summary: Get user by UUID + description: "Get user information about one account by public user account UUID. REQUIRES: Authentication, GetUserByUuid permission." + operationId: getUserByUuid + parameters: + - in: path + name: userUuid + schema: + type: string + required: true + description: UUID of user to get + responses: + "401": + description: Unauthorized + "400": + description: Invalid parameters + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "404": + description: User not found + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Successfully got user + content: + application/json: + schema: + $ref: "#/components/schemas/DetailedUser" + /users/self: + get: + tags: + - users + summary: Get own user by session + description: "Get user information about the account which was used to authenticate the request. REQUIRES: Authentication, GetOwnUser permission." + operationId: getOwnUser + responses: + "401": + description: Unauthorized + "200": + description: Successfully got user + content: + application/json: + schema: + $ref: "#/components/schemas/DetailedUser" + + /friends/add: + post: + tags: + - friends + summary: Create a friend request + description: "Create (AKA send) a friend request to another user account. The request is sent from the account used to perform this POST to the provided target account. REQUIRES: Authentication, SendFriendRequest permission." + operationId: addFriend + requestBody: + $ref: "#/components/requestBodies/FriendAdd" + responses: + "401": + description: Unauthorized + "400": + description: User does not exist, Already friends with user or Request already sent + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Friend request added successfully + content: + application/json: + schema: + $ref: "#/components/schemas/CommonMessage" + /friends/accept: + post: + tags: + - friends + summary: Accept an incoming friend request + description: "Accept an incoming friend request to your user account, from another user account. The request is accepted by the account used to perform this POST request. REQUIRES: Authentication, AcceptFriendRequest permission." + operationId: acceptFriend + requestBody: + $ref: "#/components/requestBodies/FriendAccept" + responses: + "401": + description: Unauthorized + "400": + description: User does not exist, You are already friends with user or Friend request not found + content: + application/json: + schema: + $ref: "#/components/schemas/CommonError" + "200": + description: Friend request accepted successfully + content: + application/json: + schema: + $ref: "#/components/schemas/CommonMessage" + /friends: + get: + tags: + - friends + summary: Get current incoming friend requests + description: "Get all current incoming friend requests to the user account used to authorize this POST request. REQUIRES: Authentication, GetOwnFriendRequests permission." + operationId: getFriendRequests + responses: + "401": + description: Unauthorized + "200": + description: Retrieved all incoming friend requests successfully + content: + application/json: + schema: + $ref: "#/components/schemas/FriendGetRequestsResponse" + +externalDocs: + description: Find out more about ScheduleTogether + url: https://git.zervo.org/ScheduleTogether + +servers: + - url: http://localhost:8080 + - url: https://stbackend.swagger.io/v2 + +components: + requestBodies: + AccountRegister: + content: + application/json: + schema: + $ref: "#/components/schemas/AccountRegisterRequest" + AccountVerify: + content: + application/json: + schema: + $ref: "#/components/schemas/AccountVerifyRequest" + AccountSignin: + content: + application/json: + schema: + $ref: "#/components/schemas/AccountSigninRequest" + FriendAdd: + content: + application/json: + schema: + $ref: "#/components/schemas/FriendAddRequest" + FriendAccept: + content: + application/json: + schema: + $ref: "#/components/schemas/FriendAcceptRequest" + + schemas: + CommonError: + type: object + properties: + error: + type: string + description: A string describing the error + CommonMessage: + type: object + properties: + message: + type: string + description: A message + + DetailedUser: + type: object + properties: + id: + type: integer + description: Internal user ID + uuid: + type: string + description: Public unique user identifier + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + verified: + type: boolean + friends: + type: array + items: + type: string + + AccountRegisterRequest: + type: object + properties: + firstName: + type: string + lastName: + type: string + username: + type: string + minLength: 5 + maxLength: 18 + email: + type: string + password: + type: string + minLength: 8 + maxLength: 128 + AccountRegisterResponse: + type: object + properties: + message: + type: string + description: A message describing the result + uuid: + type: string + description: The UUID of the newly created user + mustVerify: + type: boolean + description: Whether or not user needs to send account verify request to complete registration + AccountVerifyRequest: + type: object + properties: + uuid: + type: string + description: The UUID of the user account to verify + token: + type: string + description: The verification token + AccountSigninRequest: + type: object + properties: + username: + type: string + password: + type: string + AccountSigninResponse: + type: object + properties: + token: + type: string + description: The token to be used for authenticating all requests for this session + + GetAllUsersResponse: + type: array + items: + $ref: "#/components/schemas/DetailedUser" + + FriendRequest: + type: object + properties: + created_at: + type: string + description: Timestamp at which the friend request was created + source_username: + type: string + description: The username of the requesting user + source_uuid: + type: string + description: The UUID of the requesting user + target_uuid: + description: The UUID of the receiving user + FriendAddRequest: + type: object + properties: + username: + type: string + description: The username of the target user + FriendAcceptRequest: + type: object + properties: + uuid: + type: string + description: The UUID of the user from which you want to accept a friend request + FriendGetRequestsResponse: + type: object + properties: + amount: + type: integer + description: The amount of incoming friend requests + requests: + type: array + items: + $ref: "#/components/schemas/FriendRequest" + \ No newline at end of file diff --git a/api/openapi/openapi.yaml b/api/openapi/openapi.yaml index 85ecff5..843167f 100644 --- a/api/openapi/openapi.yaml +++ b/api/openapi/openapi.yaml @@ -137,7 +137,7 @@ paths: application/json: schema: $ref: "#/components/schemas/GetAllUsersResponse" - /users/{userId}: + /users/id/{userId}: get: tags: - users diff --git a/internal/api/handlers/users_handler.go b/internal/api/handlers/users_handler.go index 779e827..a2d07e8 100755 --- a/internal/api/handlers/users_handler.go +++ b/internal/api/handlers/users_handler.go @@ -36,7 +36,7 @@ import ( func UsersHandler_RegisterRoutes(party iris.Party) { party.Use(middlewares.Authenticate()) // only allow authenticated users for following endpoints party.Get("/", middlewares.Authorize(perms.GetAllUsers), UsersGet_Handler) - party.Get("/:id", middlewares.Authorize(perms.GetUserById), UsersGetById_Handler) + party.Get("/id/:id", middlewares.Authorize(perms.GetUserById), UsersGetById_Handler) party.Get("/uuid/:uuid", middlewares.Authorize(perms.GetUserByUuid), UsersGetByUuid_Handler) party.Get("/self", middlewares.Authorize(perms.GetOwnUser), UsersGetSelf_Handler) } From a878a4cc202446a1b8c906951f029febb67323d1 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 20:38:44 +0100 Subject: [PATCH 02/12] Update CI --- .forgejo/workflows/build.yaml | 1 - build/ci/build.yaml => .forgejo/workflows/build.yml | 3 ++- build/ci/build.yml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) delete mode 120000 .forgejo/workflows/build.yaml rename build/ci/build.yaml => .forgejo/workflows/build.yml (85%) create mode 120000 build/ci/build.yml diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml deleted file mode 120000 index 03a5712..0000000 --- a/.forgejo/workflows/build.yaml +++ /dev/null @@ -1 +0,0 @@ -../../build/ci/build.yaml \ No newline at end of file diff --git a/build/ci/build.yaml b/.forgejo/workflows/build.yml similarity index 85% rename from build/ci/build.yaml rename to .forgejo/workflows/build.yml index 37b7b18..b400d0a 100644 --- a/build/ci/build.yaml +++ b/.forgejo/workflows/build.yml @@ -1,8 +1,9 @@ on: [push] - jobs: build: runs-on: docker + container: + image: golang:latest steps: - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main. diff --git a/build/ci/build.yml b/build/ci/build.yml new file mode 120000 index 0000000..18818e6 --- /dev/null +++ b/build/ci/build.yml @@ -0,0 +1 @@ +../../.forgejo/workflows/build.yml \ No newline at end of file From 3e27ef76cab36cb3ba3c63848b6bdc3b0d094196 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 20:52:44 +0100 Subject: [PATCH 03/12] Debug CI --- .forgejo/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index b400d0a..fdcc653 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -5,6 +5,7 @@ jobs: container: image: golang:latest steps: + - run: ls - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main. - uses: actions/upload-artifact@v3 From c69be14277dffcc0c012e3fcac973a837230d637 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 20:53:47 +0100 Subject: [PATCH 04/12] Debug CI x2 --- .forgejo/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index fdcc653..084ea03 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -5,8 +5,7 @@ jobs: container: image: golang:latest steps: - - run: ls - - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main. + - run: ls && go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main. - uses: actions/upload-artifact@v3 with: From 98dc96b2db2d17920d84446de02136fd5d6e24e0 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:23:15 +0100 Subject: [PATCH 05/12] Debug CI x3 --- .forgejo/workflows/build.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 084ea03..31eb429 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -5,8 +5,13 @@ jobs: container: image: golang:latest steps: - - run: ls && go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main. - + - uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: '/workspace/ScheduleTogether/Backend/go.mod' + - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go + - uses: actions/upload-artifact@v3 with: name: build-artifact From 28907f0fd18c06b50a20000167693a2b64d80ec6 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:24:48 +0100 Subject: [PATCH 06/12] Debug CI x4 --- .forgejo/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 31eb429..c177945 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -5,7 +5,6 @@ jobs: container: image: golang:latest steps: - - uses: actions/checkout@v4 - name: Setup go uses: actions/setup-go@v5 with: From 062b10a36720bda0c1cdee9b2fb441e38a254745 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:33:16 +0100 Subject: [PATCH 07/12] Debug CI x5 --- .forgejo/workflows/build.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index c177945..d8f5d6d 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -5,13 +5,15 @@ jobs: container: image: golang:latest steps: - - name: Setup go - uses: actions/setup-go@v5 - with: - go-version-file: '/workspace/ScheduleTogether/Backend/go.mod' - - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go + # Step 1: Check out the code + - uses: actions/checkout@v4 + # Step 2: Set the working directory and build the project + - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go + working-directory: ./Backend + + # Step 3: Upload the build artifact - uses: actions/upload-artifact@v3 with: name: build-artifact - path: ./stbackend \ No newline at end of file + path: ./Backend/stbackend \ No newline at end of file From 932c99fbd3224eb883907b8a395b1ba4a75e7cc7 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:34:36 +0100 Subject: [PATCH 08/12] Debug CI x6 --- .forgejo/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index d8f5d6d..79169de 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -6,7 +6,7 @@ jobs: image: golang:latest steps: # Step 1: Check out the code - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 # Step 2: Set the working directory and build the project - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go From 144ab179e913182e46040349d035f21de9aefee1 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:40:47 +0100 Subject: [PATCH 09/12] Debug CI x7 --- .forgejo/workflows/build.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 79169de..15da773 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -2,17 +2,20 @@ on: [push] jobs: build: runs-on: docker - container: - image: golang:latest steps: # Step 1: Check out the code - uses: actions/checkout@v3 - # Step 2: Set the working directory and build the project + # Step 2: Set up go environment + - uses: actions/setup-go@v5 + with: + go-version-file: './Backend/go.mod' + + # Step 3: Set the working directory and build the project - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go working-directory: ./Backend - # Step 3: Upload the build artifact + # Step 4: Upload the build artifact - uses: actions/upload-artifact@v3 with: name: build-artifact From 0d0537c2ed78796aa91a982a72c7ad16b254a0dc Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:43:09 +0100 Subject: [PATCH 10/12] Debug CI x8 --- .forgejo/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 15da773..fa414ab 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v3 # Step 2: Set up go environment - - uses: actions/setup-go@v5 + - uses: actions/setup-go@v4 with: go-version-file: './Backend/go.mod' From e7acd85aef1c9041f541575542d163fbcbe8fe94 Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:46:13 +0100 Subject: [PATCH 11/12] Debug CI x9 --- .forgejo/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index fa414ab..9391efb 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -9,7 +9,7 @@ jobs: # Step 2: Set up go environment - uses: actions/setup-go@v4 with: - go-version-file: './Backend/go.mod' + go-version-file: '/workspace/ScheduleTogether/Backend/go.mod' # Step 3: Set the working directory and build the project - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go From 0f3f80cd20d129599526a17d59c9bbfba965765e Mon Sep 17 00:00:00 2001 From: zervo Date: Thu, 5 Dec 2024 21:48:05 +0100 Subject: [PATCH 12/12] Debug CI x10 (COMBO!) --- .forgejo/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml index 9391efb..f549748 100644 --- a/.forgejo/workflows/build.yml +++ b/.forgejo/workflows/build.yml @@ -13,7 +13,7 @@ jobs: # Step 3: Set the working directory and build the project - run: go build -x -v -o=stbackend -buildvcs=true ./cmd/stbackend/main.go - working-directory: ./Backend + working-directory: /workspace/ScheduleTogether/Backend # Step 4: Upload the build artifact - uses: actions/upload-artifact@v3