Skip to content

Commit

Permalink
fix: codacy review
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Feb 17, 2024
1 parent 08a515a commit dd68be7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/database/creature_boost.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package database provides functionalities for interacting with the database of the system,
// including operations to fetch and update data about boosted creatures and bosses. This package
// encapsulates all SQL queries and data manipulations, making maintenance and future development
// easier.
package database

import (
Expand Down Expand Up @@ -44,6 +48,12 @@ func checkAndUpdateBoostedCreatureData(db *sql.DB, creatureRaceID *uint32, bossR
return nil
}

// HandleBoostedCreature checks for updated boosted creature and boss race IDs in the database,
// updates the provided race IDs if they are different, and responds with the current boosted creature
// and boss race IDs. It takes a Gin context, a database connection, and pointers to the creature and boss
// race IDs as arguments. If there is an error in checking or updating the boosted creature data,
// it responds with an internal server error. Otherwise, it responds with a JSON containing the
// boosted creature status and the current race IDs for the creature and boss.
func HandleBoostedCreature(c *gin.Context, db *sql.DB, creatureRaceID *uint32, bossRaceID *uint32) {
if err := checkAndUpdateBoostedCreatureData(db, creatureRaceID, bossRaceID); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down
33 changes: 21 additions & 12 deletions src/database/event_scheduler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Package database provides functionalities for interacting with the database of the system,
// including operations to fetch and update data about boosted creatures and bosses. This package
// encapsulates all SQL queries and data manipulations, making maintenance and future development
// easier.
package database

import (
Expand All @@ -13,36 +17,36 @@ import (
"github.com/opentibiabr/login-server/src/logger"
)

type Events struct {
type events struct {
XMLName xml.Name `xml:"events"`
Events []Event `xml:"event"`
Events []event `xml:"event"`
}

type Description struct {
type description struct {
Text string `xml:"description,attr"`
}

type Event struct {
type event struct {
Name string `xml:"name,attr"`
StartDate string `xml:"startdate,attr"`
EndDate string `xml:"enddate,attr"`
Colors Colors `xml:"colors"`
Description Description `xml:"description"`
Details Details `xml:"details"`
Colors colors `xml:"colors"`
Description description `xml:"description"`
Details details `xml:"details"`
}

type Colors struct {
type colors struct {
Light string `xml:"colorlight,attr"`
Dark string `xml:"colordark,attr"`
}

type Details struct {
type details struct {
DisplayPriority string `xml:"displaypriority,attr"`
IsSeasonal string `xml:"isseasonal,attr"`
SpecialEvent string `xml:"specialevent,attr"`
}

func loadEventsSchedule(filePath string) (*Events, error) {
func loadEventsSchedule(filePath string) (*events, error) {
xmlFile, err := os.Open(filePath)
if err != nil {
logger.Error(fmt.Errorf(err.Error()))
Expand All @@ -56,7 +60,7 @@ func loadEventsSchedule(filePath string) (*Events, error) {
return nil, err
}

var events Events
var events events
err = xml.Unmarshal(byteValue, &events)
if err != nil {
logger.Error(fmt.Errorf(err.Error()))
Expand All @@ -81,7 +85,7 @@ func parseDateString(dateStr string) int {
return 0
}

func processEvents(events *Events) []map[string]interface{} {
func processEvents(events *events) []map[string]interface{} {
eventList := make([]map[string]interface{}, 0)

for _, event := range events.Events {
Expand Down Expand Up @@ -111,6 +115,11 @@ func processEvents(events *Events) []map[string]interface{} {
return eventList
}

// HandleEventSchedule loads and processes an event schedule from a specified XML file.
// It takes a Gin context and a string path to the event XML file as arguments.
// If the event schedule is loaded and processed successfully, it sends back a JSON response
// with the list of events and the last update timestamp.
// If there is an error loading or processing the event schedule, it responds with an internal server error.
func HandleEventSchedule(c *gin.Context, eventPath string) {
events, err := loadEventsSchedule(eventPath)
if err != nil {
Expand Down

0 comments on commit dd68be7

Please sign in to comment.