From dd68be72eb456d94d34168e7fc99e41f267bff05 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 16 Feb 2024 23:40:32 -0300 Subject: [PATCH] fix: codacy review --- src/database/creature_boost.go | 10 ++++++++++ src/database/event_scheduler.go | 33 +++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/database/creature_boost.go b/src/database/creature_boost.go index a35e692..55d84d6 100644 --- a/src/database/creature_boost.go +++ b/src/database/creature_boost.go @@ -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 ( @@ -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()}) diff --git a/src/database/event_scheduler.go b/src/database/event_scheduler.go index 357796e..66e182d 100644 --- a/src/database/event_scheduler.go +++ b/src/database/event_scheduler.go @@ -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 ( @@ -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())) @@ -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())) @@ -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 { @@ -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 {