-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from containerish/feat/image-analytics
feat: APIs to add repositories to favorites and store repo pull count
- Loading branch information
Showing
15 changed files
with
233 additions
and
46 deletions.
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
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,73 @@ | ||
package extensions | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/containerish/OpenRegistry/store/v1/types" | ||
"github.com/google/uuid" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
type FavoriteRepositoryRequest struct { | ||
RepositoryID uuid.UUID `json:"repository_id" query:"repository_id"` | ||
UserID uuid.UUID `json:"user_id" query:"user_id"` | ||
} | ||
|
||
func (ext *extension) AddRepositoryToFavorites(ctx echo.Context) error { | ||
ctx.Set(types.HandlerStartTime, time.Now()) | ||
|
||
var body FavoriteRepositoryRequest | ||
if err := ctx.Bind(&body); err != nil { | ||
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{ | ||
"error": err.Error(), | ||
}) | ||
ext.logger.Log(ctx, err).Send() | ||
return echoErr | ||
} | ||
defer ctx.Request().Body.Close() | ||
|
||
err := ext.store.AddRepositoryToFavorites(ctx.Request().Context(), body.RepositoryID, body.UserID) | ||
if err != nil { | ||
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{ | ||
"error": err.Error(), | ||
}) | ||
ext.logger.Log(ctx, err).Send() | ||
return echoErr | ||
} | ||
|
||
echoErr := ctx.JSON(http.StatusOK, echo.Map{ | ||
"message": "repository added to favorites", | ||
}) | ||
ext.logger.Log(ctx, nil).Send() | ||
return echoErr | ||
} | ||
|
||
func (ext *extension) RemoveRepositoryFromFavorites(ctx echo.Context) error { | ||
ctx.Set(types.HandlerStartTime, time.Now()) | ||
|
||
var body FavoriteRepositoryRequest | ||
if err := ctx.Bind(&body); err != nil { | ||
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{ | ||
"error": err.Error(), | ||
}) | ||
ext.logger.Log(ctx, err).Send() | ||
return echoErr | ||
} | ||
defer ctx.Request().Body.Close() | ||
|
||
err := ext.store.RemoveRepositoryFromFavorites(ctx.Request().Context(), body.RepositoryID, body.UserID) | ||
if err != nil { | ||
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{ | ||
"error": err.Error(), | ||
}) | ||
ext.logger.Log(ctx, err).Send() | ||
return echoErr | ||
} | ||
|
||
echoErr := ctx.JSON(http.StatusOK, echo.Map{ | ||
"message": "repository removed from favorites", | ||
}) | ||
ext.logger.Log(ctx, nil).Send() | ||
return echoErr | ||
} |
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
Oops, something went wrong.