-
-
Notifications
You must be signed in to change notification settings - Fork 884
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
Creating a LocalImageView, so that front ends have the Person struct. #4631
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1ac246
Creating a LocalImageView, so that front ends have the Person struct.
dessalines 86d7086
Removing local_user from LocalImageView.
dessalines ac1a827
Merge branch 'main' into create_local_image_view
dessalines 7f5e9c0
Add uploader check.
dessalines 58cdf73
Use corepack to pin pnpm version.
dessalines 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"repository": "https://github.com/LemmyNet/lemmy", | ||
"author": "Dessalines", | ||
"license": "AGPL-3.0", | ||
"packageManager": "[email protected]+sha256.46d50ee2afecb42b185ebbd662dc7bdd52ef5be56bf035bb615cab81a75345df", | ||
"scripts": { | ||
"lint": "tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src && prettier --check 'src/**/*.ts'", | ||
"fix": "prettier --write src && eslint --fix src", | ||
|
@@ -27,7 +28,7 @@ | |
"eslint": "^8.57.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.5.0", | ||
"lemmy-js-client": "0.19.4-alpha.16", | ||
"lemmy-js-client": "0.19.4-alpha.18", | ||
"prettier": "^3.2.5", | ||
"ts-jest": "^29.1.0", | ||
"typescript": "^5.4.4" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,61 @@ | ||
use crate::structs::LocalImageView; | ||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; | ||
use diesel_async::RunQueryDsl; | ||
use lemmy_db_schema::{ | ||
newtypes::LocalUserId, | ||
schema::{local_image, local_user, person}, | ||
utils::{get_conn, limit_and_offset, DbPool}, | ||
}; | ||
|
||
impl LocalImageView { | ||
async fn get_all_helper( | ||
pool: &mut DbPool<'_>, | ||
user_id: Option<LocalUserId>, | ||
page: Option<i64>, | ||
limit: Option<i64>, | ||
ignore_page_limits: bool, | ||
) -> Result<Vec<Self>, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
let mut query = local_image::table | ||
.inner_join(local_user::table) | ||
.inner_join(person::table.on(local_user::person_id.eq(person::id))) | ||
.select((local_image::all_columns, person::all_columns)) | ||
.order_by(local_image::published.desc()) | ||
.into_boxed(); | ||
|
||
if let Some(user_id) = user_id { | ||
query = query.filter(local_image::local_user_id.eq(user_id)) | ||
} | ||
|
||
if !ignore_page_limits { | ||
let (limit, offset) = limit_and_offset(page, limit)?; | ||
query = query.limit(limit).offset(offset); | ||
} | ||
|
||
query.load::<LocalImageView>(conn).await | ||
} | ||
|
||
pub async fn get_all_paged_by_local_user_id( | ||
pool: &mut DbPool<'_>, | ||
user_id: LocalUserId, | ||
page: Option<i64>, | ||
limit: Option<i64>, | ||
) -> Result<Vec<Self>, Error> { | ||
Self::get_all_helper(pool, Some(user_id), page, limit, false).await | ||
} | ||
|
||
pub async fn get_all_by_local_user_id( | ||
pool: &mut DbPool<'_>, | ||
user_id: LocalUserId, | ||
) -> Result<Vec<Self>, Error> { | ||
Self::get_all_helper(pool, Some(user_id), None, None, true).await | ||
} | ||
|
||
pub async fn get_all( | ||
pool: &mut DbPool<'_>, | ||
page: Option<i64>, | ||
limit: Option<i64>, | ||
) -> Result<Vec<Self>, Error> { | ||
Self::get_all_helper(pool, None, page, limit, false).await | ||
} | ||
} |
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
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.
Add some asserts here to ensure the correct person is returned. Otherwise looks fine.
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.
K done.