-
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: (api) Evolution models and controllers
Signed-off-by: Jacob Potter <pttr.jcb@gmail.com>
- Loading branch information
1 parent
a58fdfc
commit 418b44c
Showing
43 changed files
with
106,367 additions
and
455 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ go.work | |
|
||
.env | ||
*.env | ||
|
||
.idea |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/WebWizardsDev/poke-db/api/models" | ||
"github.com/gin-gonic/gin" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/clause" | ||
"net/http" | ||
) | ||
|
||
type EvolutionHandler struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewEvolutionHandler(db *gorm.DB) *EvolutionHandler { | ||
return &EvolutionHandler{db: db} | ||
} | ||
|
||
func (e *EvolutionHandler) GetEvolutionChain(c *gin.Context) { | ||
id := c.Param("id") | ||
var evolutionChain models.EvolutionChain | ||
if err := e.db. | ||
Preload(clause.Associations). | ||
Preload("ChainLink."+clause.Associations). | ||
Preload("ChainLink.EvolvesTo."+clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo."+clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo.EvolvesTo."+clause.Associations). | ||
First(&evolutionChain, id).Error; err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": "Evolution Chain not found"}) | ||
return | ||
} | ||
c.JSON(http.StatusOK, evolutionChain) | ||
} | ||
|
||
func (e *EvolutionHandler) ListEvolutionChains(c *gin.Context) { | ||
|
||
var evolutionChains []models.EvolutionChain | ||
|
||
if tx := e.db. | ||
Preload(clause.Associations). | ||
Preload("ChainLink." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolutionDetails." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo.EvolutionDetails." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo.EvolvesTo." + clause.Associations). | ||
Preload("ChainLink.EvolvesTo.EvolvesTo.EvolvesTo.EvolutionDetails." + clause.Associations). | ||
Find(&evolutionChains); tx.Error != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error while listing evolution chains"}) | ||
return | ||
} | ||
c.JSON(http.StatusOK, gin.H{"evolutionChains": evolutionChains}) | ||
|
||
} |
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.