feat: getting new lists onto the frontend
This commit is contained in:
@ -143,16 +143,26 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listsWithImages, err := userModel.ListWithImages(r.Context(), userId)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
fmt.Fprintf(w, "Something went wrong")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type ImagesReturn struct {
|
type ImagesReturn struct {
|
||||||
UserImages []models.UserImageWithImage
|
UserImages []models.UserImageWithImage
|
||||||
ImageProperties []models.TypedProperties
|
ImageProperties []models.TypedProperties
|
||||||
ProcessingImages []models.UserProcessingImage
|
ProcessingImages []models.UserProcessingImage
|
||||||
|
Lists []models.ListsWithImages
|
||||||
}
|
}
|
||||||
|
|
||||||
imagesReturn := ImagesReturn{
|
imagesReturn := ImagesReturn{
|
||||||
UserImages: images,
|
UserImages: images,
|
||||||
ImageProperties: models.GetTypedImageProperties(imageProperties),
|
ImageProperties: models.GetTypedImageProperties(imageProperties),
|
||||||
ProcessingImages: processingImages,
|
ProcessingImages: processingImages,
|
||||||
|
Lists: listsWithImages,
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonImages, err := json.Marshal(imagesReturn)
|
jsonImages, err := json.Marshal(imagesReturn)
|
||||||
|
@ -316,6 +316,26 @@ func (m UserModel) GetUserImages(ctx context.Context, userId uuid.UUID) ([]UserI
|
|||||||
return userImages, err
|
return userImages, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListsWithImages struct {
|
||||||
|
model.Lists
|
||||||
|
|
||||||
|
Images []model.ImageLists
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m UserModel) ListWithImages(ctx context.Context, userId uuid.UUID) ([]ListsWithImages, error) {
|
||||||
|
stmt := SELECT(Lists.AllColumns, ImageLists.AllColumns).
|
||||||
|
FROM(
|
||||||
|
Lists.
|
||||||
|
INNER_JOIN(ImageLists, ImageLists.ListID.EQ(Lists.ID)),
|
||||||
|
).
|
||||||
|
WHERE(Lists.UserID.EQ(UUID(userId)))
|
||||||
|
|
||||||
|
lists := []ListsWithImages{}
|
||||||
|
err := stmt.QueryContext(ctx, m.dbPool, &lists)
|
||||||
|
|
||||||
|
return lists, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserModel(db *sql.DB) UserModel {
|
func NewUserModel(db *sql.DB) UserModel {
|
||||||
return UserModel{dbPool: db}
|
return UserModel{dbPool: db}
|
||||||
}
|
}
|
||||||
|
@ -186,10 +186,27 @@ const userProcessingImageValidator = strictObject({
|
|||||||
|
|
||||||
export type UserImage = InferOutput<typeof dataTypeValidator>;
|
export type UserImage = InferOutput<typeof dataTypeValidator>;
|
||||||
|
|
||||||
|
const listValidator = strictObject({
|
||||||
|
ID: pipe(string(), uuid()),
|
||||||
|
UserID: pipe(string(), uuid()),
|
||||||
|
CreatedAt: pipe(string()),
|
||||||
|
Name: string(),
|
||||||
|
Description: nullable(string()),
|
||||||
|
|
||||||
|
Images: array(
|
||||||
|
strictObject({
|
||||||
|
ID: pipe(string(), uuid()),
|
||||||
|
ImageID: pipe(string(), uuid()),
|
||||||
|
ListID: pipe(string(), uuid()),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
const imageRequestValidator = strictObject({
|
const imageRequestValidator = strictObject({
|
||||||
UserImages: array(userImageValidator),
|
UserImages: array(userImageValidator),
|
||||||
ImageProperties: array(dataTypeValidator),
|
ImageProperties: array(dataTypeValidator),
|
||||||
ProcessingImages: array(userProcessingImageValidator),
|
ProcessingImages: array(userProcessingImageValidator),
|
||||||
|
Lists: array(listValidator),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type JustTheImageWhatAreTheseNames = InferOutput<
|
export type JustTheImageWhatAreTheseNames = InferOutput<
|
||||||
|
Reference in New Issue
Block a user