Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.1

Check warning on line 1 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

no-empty-servers

Servers must be present.
info:

Check warning on line 2 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

info-license

Info object should contain `license` field.
title: Borg API
version: 0.0.1
Expand All @@ -7,7 +7,7 @@

paths:
/api/users:
post:

Check warning on line 10 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-operationId

Operation object should contain `operationId` field.
summary: Create a user
requestBody:
required: true
Expand All @@ -15,11 +15,11 @@
application/json:
schema:
$ref: "#/components/schemas/NewUser"
responses:

Check warning on line 18 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-4xx-response

Operation must have at least one `4XX` response.
"201":
description: Created user
/api/users/{id}:
get:

Check warning on line 22 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-operationId

Operation object should contain `operationId` field.
summary: Get a user by ID
parameters:
- name: id
Expand All @@ -27,7 +27,7 @@
required: true
schema:
type: integer
responses:

Check warning on line 30 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-4xx-response

Operation must have at least one `4XX` response.
"200":
description: OK
content:
Expand All @@ -35,7 +35,7 @@
schema:
$ref: "#/components/schemas/User"

delete:

Check warning on line 38 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-operationId

Operation object should contain `operationId` field.
summary: Delete a user by ID
parameters:
- name: id
Expand All @@ -43,11 +43,11 @@
required: true
schema:
type: integer
responses:

Check warning on line 46 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-4xx-response

Operation must have at least one `4XX` response.
"204":
description: Deleted successfully

put:

Check warning on line 50 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-operationId

Operation object should contain `operationId` field.
summary: Update a user
parameters:
- name: id
Expand All @@ -61,9 +61,15 @@
application/json:
schema:
$ref: "#/components/schemas/UpdateUser"
security:
- BearerAuth: []
responses:

Check warning on line 66 in api/openapi.yaml

View workflow job for this annotation

GitHub Actions / check-spec

operation-4xx-response

Operation must have at least one `4XX` response.
"200":
description: Updated user
content:
application/json:
schema:
$ref: "#/components/schemas/User"
/api/users/{id}/posts:
get:
summary: Get posts of user with ID
Expand Down Expand Up @@ -218,6 +224,8 @@
required: true
schema:
type: integer
security:
- BearerAuth: []
responses:
"204":
description: Deleted successfully
Expand All @@ -235,6 +243,8 @@
application/json:
schema:
$ref: "#/components/schemas/UpdatePost"
security:
- BearerAuth: []
responses:
"200":
description: Updated user
Expand Down
68 changes: 43 additions & 25 deletions internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions internal/db/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ INSERT INTO statuses (
$1, $2, $3, $4, $5, $6
);

-- name: UpdateStatusById :one
UPDATE statuses
SET content = $2, updated_at = CURRENT_TIMESTAMP
WHERE id = $1
RETURNING *;

-- name: DeleteStatusByID :exec
DELETE FROM statuses WHERE id = $1;

Expand Down Expand Up @@ -189,3 +195,21 @@ JOIN accounts a ON s.account_id = a.id
JOIN follows f ON a.id = f.target_account_id
WHERE f.account_id = $1 AND s.in_reply_to_id IS NULL
ORDER BY s.created_at DESC;

-- name: GetCommentsByPostId :many
SELECT
s.id,
s.created_at,
s.updated_at,
s.content,
s.account_id,
s.in_reply_to_id
FROM statuses s
WHERE s.in_reply_to_id = $1
ORDER BY s.created_at ASC;

-- name: UpdateAccountById :one
UPDATE accounts
SET display_name = COALESCE($2, display_name), updated_at = CURRENT_TIMESTAMP
WHERE id = $1
RETURNING *;
115 changes: 115 additions & 0 deletions internal/db/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions internal/repository/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repository

import (
"context"
"database/sql"

"github.com/kibirisu/borg/internal/db"
)
Expand All @@ -15,6 +16,7 @@ type AccountRepository interface {
GetFollowers(context.Context, int) ([]db.Account, error)
GetFollowing(context.Context, int) ([]db.Account, error)
GetPosts(context.Context, int) ([]db.GetStatusesByAccountIdRow, error)
Update(context.Context, int, *string) (db.Account, error)
}

type accountRepository struct {
Expand Down Expand Up @@ -80,3 +82,22 @@ func (r *accountRepository) GetPosts(
) ([]db.GetStatusesByAccountIdRow, error) {
return r.q.GetStatusesByAccountId(ctx, int32(id))
}

// Update implements AccountRepository.
func (r *accountRepository) Update(
ctx context.Context,
id int,
bio *string,
) (db.Account, error) {
var displayName sql.NullString
if bio != nil {
displayName = sql.NullString{
String: *bio,
Valid: true,
}
}
return r.q.UpdateAccountById(ctx, db.UpdateAccountByIdParams{
ID: int32(id),
DisplayName: displayName,
})
}
22 changes: 22 additions & 0 deletions internal/repository/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ type StatusRepository interface {
Add(context.Context, db.AddStatusParams) error
GetByID(context.Context, int) (db.Status, error)
GetByURI(context.Context, string) (db.Status, error)
Update(context.Context, int, string) (db.Status, error)
GetShares(context.Context, int) ([]db.Status, error)
GetLocalStatuses(context.Context) ([]db.GetLocalStatusesRow, error)
GetByIDWithMetadata(context.Context, int) (db.GetStatusByIdWithMetadataRow, error)
GetSharedPostsByAccountId(context.Context, int) ([]db.GetSharedPostsByAccountIdRow, error)
GetTimelinePostsByAccountId(context.Context, int) ([]db.GetTimelinePostsByAccountIdRow, error)
GetCommentsByPostId(context.Context, int) ([]db.GetCommentsByPostIdRow, error)
DeleteByID(context.Context, int32) error
}

Expand Down Expand Up @@ -49,6 +51,18 @@ func (r *statusRepository) GetByURI(ctx context.Context, uri string) (db.Status,
return r.q.GetStatusByURI(ctx, uri)
}

// Update implements StatusRepository.
func (r *statusRepository) Update(
ctx context.Context,
id int,
content string,
) (db.Status, error) {
return r.q.UpdateStatusById(ctx, db.UpdateStatusByIdParams{
ID: int32(id),
Content: content,
})
}

// GetById implements StatusRepository.
func (r *statusRepository) GetByIDWithMetadata(
ctx context.Context,
Expand Down Expand Up @@ -83,6 +97,14 @@ func (r *statusRepository) GetTimelinePostsByAccountId(
return r.q.GetTimelinePostsByAccountId(ctx, int32(accountID))
}

// GetCommentsByPostId implements StatusRepository.
func (r *statusRepository) GetCommentsByPostId(
ctx context.Context,
postID int,
) ([]db.GetCommentsByPostIdRow, error) {
return r.q.GetCommentsByPostId(ctx, sql.NullInt32{Int32: int32(postID), Valid: true})
}

// DeleteByURI implements StatusRepository.
func (r *statusRepository) DeleteByID(ctx context.Context, id int32) error {
return r.q.DeleteStatusByID(ctx, id)
Expand Down
Loading
Loading