feat(sql): model function to allow user to request image properties based on events
This commit is contained in:
@ -53,8 +53,8 @@ func getUserIdFromImage(ctx context.Context, dbPool *sql.DB, imageId uuid.UUID)
|
|||||||
return userImages[0].UserID, nil
|
return userImages[0].UserID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m UserModel) ListWithProperties(ctx context.Context, userId uuid.UUID) ([]ImageWithProperties, error) {
|
func getListImagesStmt() SelectStatement {
|
||||||
listWithPropertiesStmt := SELECT(
|
return SELECT(
|
||||||
UserImages.ID.AS("ImageWithProperties.ID"),
|
UserImages.ID.AS("ImageWithProperties.ID"),
|
||||||
Image.ID,
|
Image.ID,
|
||||||
Image.ImageName,
|
Image.ImageName,
|
||||||
@ -84,15 +84,26 @@ func (m UserModel) ListWithProperties(ctx context.Context, userId uuid.UUID) ([]
|
|||||||
LEFT_JOIN(ImageContacts, ImageContacts.ImageID.EQ(UserImages.ImageID)).
|
LEFT_JOIN(ImageContacts, ImageContacts.ImageID.EQ(UserImages.ImageID)).
|
||||||
LEFT_JOIN(Contacts, Contacts.ID.EQ(ImageContacts.ContactID)).
|
LEFT_JOIN(Contacts, Contacts.ID.EQ(ImageContacts.ContactID)).
|
||||||
LEFT_JOIN(ImageNotes, ImageNotes.ImageID.EQ(UserImages.ImageID)).
|
LEFT_JOIN(ImageNotes, ImageNotes.ImageID.EQ(UserImages.ImageID)).
|
||||||
LEFT_JOIN(Notes, Notes.ID.EQ(ImageNotes.NoteID))).
|
LEFT_JOIN(Notes, Notes.ID.EQ(ImageNotes.NoteID)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m UserModel) ListImageWithProperties(ctx context.Context, userId uuid.UUID, imageId uuid.UUID) (ImageWithProperties, error) {
|
||||||
|
listImagePropertiesStmt := getListImagesStmt().
|
||||||
|
WHERE(UserImages.ImageID.EQ(UUID(imageId)))
|
||||||
|
|
||||||
|
image := ImageWithProperties{}
|
||||||
|
err := listImagePropertiesStmt.QueryContext(ctx, m.dbPool, &image)
|
||||||
|
|
||||||
|
return image, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m UserModel) ListWithProperties(ctx context.Context, userId uuid.UUID) ([]ImageWithProperties, error) {
|
||||||
|
listWithPropertiesStmt := getListImagesStmt().
|
||||||
WHERE(UserImages.UserID.EQ(UUID(userId)))
|
WHERE(UserImages.UserID.EQ(UUID(userId)))
|
||||||
|
|
||||||
images := []ImageWithProperties{}
|
images := []ImageWithProperties{}
|
||||||
err := listWithPropertiesStmt.QueryContext(ctx, m.dbPool, &images)
|
err := listWithPropertiesStmt.QueryContext(ctx, m.dbPool, &images)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return images, err
|
|
||||||
}
|
|
||||||
return images, err
|
return images, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user