Skip to content

Commit

Permalink
Change Favorites to Favourites
Browse files Browse the repository at this point in the history
  • Loading branch information
Buco7854 committed Mar 6, 2023
1 parent d61e164 commit 45f6eb9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
18 changes: 14 additions & 4 deletions api/routes/fav/fav.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ func (r Route) Insert(c echo.Context) error {
return c.JSON(http.StatusBadRequest, api.JSONError{Detail: "The image you provided does not exist."})
}
if pqe.Code == "23505" {
return c.JSON(http.StatusBadRequest, api.JSONError{Detail: "The image you provided is already in the user favourites, consider using /fav/toggle instead."})
return c.JSON(http.StatusBadRequest, api.JSONError{Detail: "The image you provided is already in the user favorites, consider using /fav/toggle instead."})
}
}
return err
}
return c.NoContent(http.StatusNoContent)
return c.JSON(
200,
struct {
State string `json:"state"`
}{"INSERTED"},
)
}

func (r Route) Delete(c echo.Context) error {
Expand All @@ -71,11 +76,16 @@ func (r Route) Delete(c echo.Context) error {
}
if err := r.Database.DeleteImageFromFav(userId, image.Id); err != nil {
if err == sql.ErrNoRows {
return c.JSON(http.StatusBadRequest, api.JSONError{Detail: "The image you provided do not exist or it is not in the user favourites."})
return c.JSON(http.StatusBadRequest, api.JSONError{Detail: "The image you provided do not exist or it is not in the user favorites."})
}
return err
}
return c.NoContent(http.StatusNoContent)
return c.JSON(
200,
struct {
State string `json:"state"`
}{"DELETED"},
)
}

func (r Route) Toggle(c echo.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions api/routes/fav/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ func AddRouter(globals api.Globals, app *echo.Echo) error {
route.Insert,
middleware.JWTWithConfig(globals.JWTConfig),
middlewares.TokenVerification(globals),
middlewares.PermissionsVerification(globals, []string{"manage_favourites"}, middlewares.SkipOrSetUser(true)),
middlewares.PermissionsVerification(globals, []string{"manage_favorites"}, middlewares.SkipOrSetUser(true)),
)
app.DELETE(
"/fav/delete",
route.Delete,
middleware.JWTWithConfig(globals.JWTConfig),
middlewares.TokenVerification(globals),
middlewares.PermissionsVerification(globals, []string{"manage_favourites"}, middlewares.SkipOrSetUser(true)),
middlewares.PermissionsVerification(globals, []string{"manage_favorites"}, middlewares.SkipOrSetUser(true)),
)
app.POST(
"/fav/toggle",
route.Toggle,
middleware.JWTWithConfig(globals.JWTConfig),
middlewares.TokenVerification(globals),
middlewares.PermissionsVerification(globals, []string{"manage_favourites"}, middlewares.SkipOrSetUser(true)),
middlewares.PermissionsVerification(globals, []string{"manage_favorites"}, middlewares.SkipOrSetUser(true)),
)
return nil
}
2 changes: 1 addition & 1 deletion api/routes/image/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getThreeState() []string {
}

func getOrderBy(includeLikedAt bool) []string {
arr := []string{database.Favourites, database.UploadedAt, database.Random}
arr := []string{database.Favorites, database.UploadedAt, database.Random}
if includeLikedAt {
arr = append(arr, database.LikedAt)
}
Expand Down
2 changes: 1 addition & 1 deletion api/routes/image/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func AddRouter(globals api.Globals, app *echo.Echo) error {
route.RouteSelector(true),
middleware.JWTWithConfig(globals.JWTConfig),
middlewares.TokenVerification(globals),
middlewares.PermissionsVerification(globals, []string{"view_favourites"}, middlewares.UIntParamsSkipper("user_id", "target_user_id", true)),
middlewares.PermissionsVerification(globals, []string{"view_favorites"}, middlewares.UIntParamsSkipper("user_id", "target_user_id", true)),
)
return nil
}
2 changes: 1 addition & 1 deletion database/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
)

const (
Favourites = "FAVOURITES"
Favorites = "FAVORITES"
UploadedAt = "UPLOADED_AT"
LikedAt = "LIKED_AT"
Random = "RANDOM"
Expand Down
8 changes: 4 additions & 4 deletions database/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (database Database) FetchImages(
userId uint,
) (ImageRows, error) {
var parameters []any
query := "SELECT DISTINCT Q.signature,Q.extension,Q.image_id,Q.favourites,Q.dominant_color,Q.source,Q.uploaded_at,Q.is_nsfw,Q.width,Q.height,"
query := "SELECT DISTINCT Q.signature,Q.extension,Q.image_id,Q.favorites,Q.dominant_color,Q.source,Q.uploaded_at,Q.is_nsfw,Q.width,Q.height,"
if userId != 0 {
query += "Q.liked_at,"
}
Expand All @@ -38,7 +38,7 @@ func (database Database) FetchImages(
if userId != 0 {
query += "FavImages.liked_at,"
}
query += "(SELECT COUNT(image_id) from FavImages WHERE image_id=Images.image_id) as favourites " +
query += "(SELECT COUNT(image_id) from FavImages WHERE image_id=Images.image_id) as favorites " +
"FROM Images JOIN LinkedTags ON Images.image_id=LinkedTags.image_id JOIN Tags ON Tags.id=LinkedTags.tag_id "
if userId != 0 {
query += fmt.Sprintf("JOIN FavImages ON FavImages.image_id=Images.image_id AND FavImages.user_id=$%v ", len(parameters)+1)
Expand Down Expand Up @@ -92,7 +92,7 @@ func (database Database) FetchImages(
&imageRow.Signature,
&imageRow.Extension,
&imageRow.ImageId,
&imageRow.Favourites,
&imageRow.Favorites,
&imageRow.DominantColor,
&imageRow.Source,
&imageRow.UploadedAt,
Expand All @@ -109,7 +109,7 @@ func (database Database) FetchImages(
&imageRow.Signature,
&imageRow.Extension,
&imageRow.ImageId,
&imageRow.Favourites,
&imageRow.Favorites,
&imageRow.DominantColor,
&imageRow.Source,
&imageRow.UploadedAt,
Expand Down
6 changes: 3 additions & 3 deletions database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ImageRow struct {
Signature string `field:"signature" json:"signature"`
Extension string `field:"extension" json:"extension"`
ImageId uint `field:"image_id" json:"image_id"`
Favourites uint `field:"favourites" json:"favourites"`
Favorites uint `field:"favorites" json:"favorites"`
DominantColor string `field:"dominant_color" json:"dominant_color"`
Source *string `field:"source" json:"source"`
UploadedAt string `field:"uploaded_at" json:"uploaded_at"`
Expand Down Expand Up @@ -46,7 +46,7 @@ type Image struct {
Signature string `json:"signature"`
Extension string `json:"extension"`
ImageId uint `json:"image_id"`
Favourites uint `json:"favourites"`
Favorites uint `json:"favorites"`
DominantColor string `json:"dominant_color"`
Source *string `json:"source"`
UploadedAt string `json:"uploaded_at"`
Expand All @@ -68,7 +68,7 @@ func (ir ImageRows) GetImage(ImageId uint) Image {
im.Signature,
im.Extension,
im.ImageId,
im.Favourites,
im.Favorites,
im.DominantColor,
im.Source,
im.UploadedAt,
Expand Down

0 comments on commit 45f6eb9

Please sign in to comment.