-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding outline for games (#12)
- Loading branch information
1 parent
25a555f
commit 0c0b692
Showing
133 changed files
with
13,878 additions
and
5 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
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,49 @@ | ||
package api | ||
|
||
import ( | ||
"gcstatus/internal/resources" | ||
"gcstatus/internal/usecases" | ||
"gcstatus/pkg/s3" | ||
"gcstatus/pkg/utils" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type GameHandler struct { | ||
gameService *usecases.GameService | ||
userService *usecases.UserService | ||
} | ||
|
||
func NewGameHandler( | ||
gameService *usecases.GameService, | ||
userService *usecases.UserService, | ||
) *GameHandler { | ||
return &GameHandler{ | ||
gameService: gameService, | ||
userService: userService, | ||
} | ||
} | ||
|
||
func (h *GameHandler) FindBySlug(c *gin.Context) { | ||
slug := c.Param("slug") | ||
user, err := utils.Auth(c, h.userService.GetUserByID) | ||
if err != nil { | ||
RespondWithError(c, http.StatusUnauthorized, "Unauthorized: "+err.Error()) | ||
return | ||
} | ||
|
||
game, err := h.gameService.FindBySlug(slug, user.ID) | ||
if err != nil { | ||
RespondWithError(c, http.StatusInternalServerError, "Failed to fetch game: "+err.Error()) | ||
return | ||
} | ||
|
||
transformedGame := resources.TransformGame(game, s3.GlobalS3Client) | ||
|
||
response := resources.Response{ | ||
Data: transformedGame, | ||
} | ||
|
||
c.JSON(http.StatusOK, response) | ||
} |
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,69 @@ | ||
package db | ||
|
||
import ( | ||
"errors" | ||
"gcstatus/internal/domain" | ||
"gcstatus/internal/ports" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
type GameRepositoryMySQL struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewGameRepositoryMySQL(db *gorm.DB) ports.GameRepository { | ||
return &GameRepositoryMySQL{db: db} | ||
} | ||
|
||
func (h *GameRepositoryMySQL) FindBySlug(slug string, userID uint) (domain.Game, error) { | ||
var game domain.Game | ||
if err := h.db.Preload("Categories.Category"). | ||
Preload("Genres.Genre"). | ||
Preload("Tags.Tag"). | ||
Preload("Platforms.Platform"). | ||
Preload("Languages.Language"). | ||
Preload("Requirements.RequirementType"). | ||
Preload("Crack.Cracker"). | ||
Preload("Crack.Protection"). | ||
Preload("Torrents.TorrentProvider"). | ||
Preload("Publishers.Publisher"). | ||
Preload("Developers.Developer"). | ||
Preload("Reviews.User.Profile"). | ||
Preload("Critics.Critic"). | ||
Preload("Stores.Store"). | ||
Preload("Galleries"). | ||
Preload("DLCs.Galleries"). | ||
Preload("DLCs.Platforms.Platform"). | ||
Preload("DLCs.Stores.Store"). | ||
Preload("Comments", "parent_id IS NULL"). | ||
Preload("Comments.Hearts"). | ||
Preload("Comments.User"). | ||
Preload("Comments.Replies.User"). | ||
Preload("Support"). | ||
Preload("Views"). | ||
Preload("Hearts"). | ||
Where("slug = ?", slug). | ||
First(&game). | ||
Error; err != nil { | ||
return game, err | ||
} | ||
|
||
var view domain.Viewable | ||
if err := h.db.Where("viewable_id = ? AND viewable_type = ? AND user_id = ?", game.ID, "games", userID).First(&view).Error; err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
view = domain.Viewable{ | ||
ViewableID: game.ID, | ||
ViewableType: "games", | ||
UserID: userID, | ||
} | ||
if err := h.db.Create(&view).Error; err != nil { | ||
return game, err | ||
} | ||
} else { | ||
return game, err | ||
} | ||
} | ||
|
||
return game, nil | ||
} |
Oops, something went wrong.