diff --git a/backend/controllers/frame.go b/backend/controllers/frame.go index 20e9b6a..9714060 100644 --- a/backend/controllers/frame.go +++ b/backend/controllers/frame.go @@ -16,7 +16,7 @@ func ListFrame(writer http.ResponseWriter, request *http.Request, params httprou gdb := database.Connect() defer database.Close(gdb) - var frame []models.Frame + var frames []models.Frame queryParams := request.URL.Query() @@ -40,14 +40,20 @@ func ListFrame(writer http.ResponseWriter, request *http.Request, params httprou return } - result := gdb.Model(&models.Frame{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&frame) + result := gdb.Model(&models.Frame{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&frames) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(frame) + + var framesPublic []models.FramePublic + for _, frame := range frames { + framesPublic = append(framesPublic, models.FramePublic{Frame: frame}) + } + + json.NewEncoder(writer).Encode(framesPublic) } } @@ -67,7 +73,7 @@ func GetFrame(writer http.ResponseWriter, request *http.Request, params httprout } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(frame) + json.NewEncoder(writer).Encode(models.FramePublic{Frame: frame}) } } diff --git a/backend/controllers/game.go b/backend/controllers/game.go index 1f542de..d49b7fc 100644 --- a/backend/controllers/game.go +++ b/backend/controllers/game.go @@ -57,7 +57,13 @@ func ListGame(writer http.ResponseWriter, request *http.Request, params httprout } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(games) + + var gamesPublic []models.GamePublic + for _, game := range games { + gamesPublic = append(gamesPublic, models.GamePublic{Game: game}) + } + + json.NewEncoder(writer).Encode(gamesPublic) return } } @@ -78,7 +84,7 @@ func GetGame(writer http.ResponseWriter, request *http.Request, params httproute } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(game) + json.NewEncoder(writer).Encode(models.GamePublic{Game: game}) return } } diff --git a/backend/controllers/godot_version.go b/backend/controllers/godot_version.go index 8222c3f..dddceb6 100644 --- a/backend/controllers/godot_version.go +++ b/backend/controllers/godot_version.go @@ -16,7 +16,7 @@ func ListGodotVersion(writer http.ResponseWriter, request *http.Request, params gdb := database.Connect() defer database.Close(gdb) - var godotVersion []models.GodotVersion + var godotVersions []models.GodotVersion queryParams := request.URL.Query() @@ -44,14 +44,20 @@ func ListGodotVersion(writer http.ResponseWriter, request *http.Request, params return } - result := gdb.Model(&models.GodotVersion{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&godotVersion) + result := gdb.Model(&models.GodotVersion{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&godotVersions) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(godotVersion) + + var godotVersionsPublic []models.GodotVersionPublic + for _, godotversion := range godotVersions { + godotVersionsPublic = append(godotVersionsPublic, models.GodotVersionPublic{GodotVersion: godotversion}) + } + + json.NewEncoder(writer).Encode(godotVersionsPublic) } } @@ -71,7 +77,7 @@ func GetGodotVersion(writer http.ResponseWriter, request *http.Request, params h } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(godotVersion) + json.NewEncoder(writer).Encode(models.GodotVersionPublic{GodotVersion: godotVersion}) } } diff --git a/backend/controllers/level.go b/backend/controllers/level.go index 3d19e30..2bd98bd 100644 --- a/backend/controllers/level.go +++ b/backend/controllers/level.go @@ -16,7 +16,7 @@ func ListLevel(writer http.ResponseWriter, request *http.Request, params httprou gdb := database.Connect() defer database.Close(gdb) - var level []models.Level + var levels []models.Level queryParams := request.URL.Query() @@ -36,14 +36,20 @@ func ListLevel(writer http.ResponseWriter, request *http.Request, params httprou return } - result := gdb.Model(&models.Level{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&level) + result := gdb.Model(&models.Level{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&levels) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(level) + + var levelsPublic []models.LevelPublic + for _, level := range levels { + levelsPublic = append(levelsPublic, models.LevelPublic{Level: level}) + } + + json.NewEncoder(writer).Encode(levelsPublic) } } @@ -63,7 +69,7 @@ func GetLevel(writer http.ResponseWriter, request *http.Request, params httprout } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(level) + json.NewEncoder(writer).Encode(models.LevelPublic{Level: level}) } } diff --git a/backend/controllers/object.go b/backend/controllers/object.go index 464379a..a7ff184 100644 --- a/backend/controllers/object.go +++ b/backend/controllers/object.go @@ -16,7 +16,7 @@ func ListObject(writer http.ResponseWriter, request *http.Request, params httpro gdb := database.Connect() defer database.Close(gdb) - var object []models.Object + var objects []models.Object queryParams := request.URL.Query() @@ -42,14 +42,20 @@ func ListObject(writer http.ResponseWriter, request *http.Request, params httpro return } - result := gdb.Model(&models.Object{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&object) + result := gdb.Model(&models.Object{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&objects) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(object) + + var objectsPublic []models.ObjectPublic + for _, object := range objects { + objectsPublic = append(objectsPublic, models.ObjectPublic{Object: object}) + } + + json.NewEncoder(writer).Encode(objectsPublic) } } @@ -69,7 +75,7 @@ func GetObject(writer http.ResponseWriter, request *http.Request, params httprou } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(object) + json.NewEncoder(writer).Encode(models.ObjectPublic{Object: object}) } } diff --git a/backend/controllers/object_name.go b/backend/controllers/object_name.go index 5971a87..612d422 100644 --- a/backend/controllers/object_name.go +++ b/backend/controllers/object_name.go @@ -16,7 +16,7 @@ func ListObjectName(writer http.ResponseWriter, request *http.Request, params ht gdb := database.Connect() defer database.Close(gdb) - var objectName []models.ObjectName + var objectNames []models.ObjectName queryParams := request.URL.Query() @@ -36,14 +36,20 @@ func ListObjectName(writer http.ResponseWriter, request *http.Request, params ht return } - result := gdb.Model(&models.ObjectName{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&objectName) + result := gdb.Model(&models.ObjectName{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&objectNames) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(objectName) + + var objectNamesPublic []models.ObjectNamePublic + for _, objectname := range objectNames { + objectNamesPublic = append(objectNamesPublic, models.ObjectNamePublic{ObjectName: objectname}) + } + + json.NewEncoder(writer).Encode(objectNamesPublic) } } @@ -63,7 +69,7 @@ func GetObjectName(writer http.ResponseWriter, request *http.Request, params htt } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(objectName) + json.NewEncoder(writer).Encode(models.ObjectNamePublic{ObjectName: objectName}) } } diff --git a/backend/controllers/object_state.go b/backend/controllers/object_state.go index c747e82..c9f9dfb 100644 --- a/backend/controllers/object_state.go +++ b/backend/controllers/object_state.go @@ -16,7 +16,7 @@ func ListObjectState(writer http.ResponseWriter, request *http.Request, params h gdb := database.Connect() defer database.Close(gdb) - var objectState []models.ObjectState + var objectStates []models.ObjectState queryParams := request.URL.Query() @@ -36,14 +36,20 @@ func ListObjectState(writer http.ResponseWriter, request *http.Request, params h return } - result := gdb.Model(&models.ObjectState{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&objectState) + result := gdb.Model(&models.ObjectState{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&objectStates) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(objectState) + + var objectStatesPublic []models.ObjectStatePublic + for _, objectstate := range objectStates { + objectStatesPublic = append(objectStatesPublic, models.ObjectStatePublic{ObjectState: objectstate}) + } + + json.NewEncoder(writer).Encode(objectStatesPublic) } } @@ -63,7 +69,7 @@ func GetObjectState(writer http.ResponseWriter, request *http.Request, params ht } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(objectState) + json.NewEncoder(writer).Encode(models.ObjectStatePublic{ObjectState: objectState}) } } diff --git a/backend/controllers/os.go b/backend/controllers/os.go index d1710d1..b8a8450 100644 --- a/backend/controllers/os.go +++ b/backend/controllers/os.go @@ -16,7 +16,7 @@ func ListOS(writer http.ResponseWriter, request *http.Request, params httprouter gdb := database.Connect() defer database.Close(gdb) - var os []models.OS + var oses []models.OS queryParams := request.URL.Query() @@ -36,14 +36,20 @@ func ListOS(writer http.ResponseWriter, request *http.Request, params httprouter return } - result := gdb.Model(&models.OS{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&os) + result := gdb.Model(&models.OS{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&oses) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(os) + + var osesPublic []models.OSPublic + for _, os := range oses { + osesPublic = append(osesPublic, models.OSPublic{OS: os}) + } + + json.NewEncoder(writer).Encode(osesPublic) } } @@ -63,7 +69,7 @@ func GetOS(writer http.ResponseWriter, request *http.Request, params httprouter. } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(os) + json.NewEncoder(writer).Encode(models.OSPublic{OS: os}) } } diff --git a/backend/controllers/player.go b/backend/controllers/player.go index 2950939..5ab06cb 100644 --- a/backend/controllers/player.go +++ b/backend/controllers/player.go @@ -16,7 +16,7 @@ func ListPlayer(writer http.ResponseWriter, request *http.Request, params httpro gdb := database.Connect() defer database.Close(gdb) - var player []models.Player + var players []models.Player queryParams := request.URL.Query() @@ -38,14 +38,20 @@ func ListPlayer(writer http.ResponseWriter, request *http.Request, params httpro return } - result := gdb.Model(&models.Player{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&player) + result := gdb.Model(&models.Player{}).Where(whereClause).Order("ID asc").Limit(limit).Offset(offset).Find(&players) if result.Error != nil { utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(player) + + var playersPublic []models.PlayerPublic + for _, player := range players { + playersPublic = append(playersPublic, models.PlayerPublic{Player: player}) + } + + json.NewEncoder(writer).Encode(playersPublic) } } @@ -65,7 +71,7 @@ func GetPlayer(writer http.ResponseWriter, request *http.Request, params httprou } else { writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(player) + json.NewEncoder(writer).Encode(models.PlayerPublic{Player: player}) } } diff --git a/backend/controllers/user.go b/backend/controllers/user.go index eeebc25..5f810d3 100644 --- a/backend/controllers/user.go +++ b/backend/controllers/user.go @@ -46,12 +46,15 @@ func ListUser(writer http.ResponseWriter, request *http.Request, params httprout utils.JSONErrorOutput(writer, http.StatusBadRequest, result.Error.Error()) return } else { - for i := range users { - users[i].Password = "" - } writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(users) + + var usersPublic []models.UserPublic + for _, user := range users { + usersPublic = append(usersPublic, models.UserPublic{User: user}) + } + + json.NewEncoder(writer).Encode(usersPublic) } } @@ -69,10 +72,9 @@ func GetUser(writer http.ResponseWriter, request *http.Request, params httproute writer.WriteHeader(http.StatusNotFound) return } else { - user.Password = "" writer.Header().Set("Content-Type", "application/json") writer.WriteHeader(http.StatusOK) - json.NewEncoder(writer).Encode(user) + json.NewEncoder(writer).Encode(models.UserPublic{User: user}) } } diff --git a/backend/models/frame.go b/backend/models/frame.go index 81c7d20..62e2565 100644 --- a/backend/models/frame.go +++ b/backend/models/frame.go @@ -6,12 +6,20 @@ import ( type Frame struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - GameID uint64 `json:"game_id" gorm:"not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + GameID uint64 `json:"game_id,omitempty" gorm:"not null"` Game Game `json:"game" gorm:"not null"` Coins uint64 `json:"coins" gorm:";not null"` - Points uint64 `json:"points" gorm:"not null"` - FPS uint8 `json:"fps" gorm:"not null"` + Points uint64 `json:"points,omitempty" gorm:"not null"` + FPS uint8 `json:"fps,omitempty" gorm:"not null"` ElapsedTime uint64 `json:"elapsed_time" gorm:"not null"` - Objects []Object `json:"objects"` + Objects []Object `json:"objects,omitempty"` +} + +type FramePublic struct { + Frame + Game bool `json:"game,omitempty"` + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/game.go b/backend/models/game.go index dbf271b..8b637e1 100644 --- a/backend/models/game.go +++ b/backend/models/game.go @@ -9,25 +9,36 @@ import ( type Game struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - PlayerID *uint64 `json:"player_id"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + PlayerID *uint64 `json:"player_id,omitempty"` Player Player `json:"player"` - LevelID uint64 `json:"level_id" gorm:"not null"` + LevelID uint64 `json:"level_id,omitempty" gorm:"not null"` Level Level `json:"level" gorm:"not null"` - OSID uint64 `json:"os_id" gorm:"not null"` + OSID uint64 `json:"os_id,omitempty" gorm:"not null"` OS OS `json:"os" gorm:"not null"` - GodotVersionID uint64 `json:"godot_version_id" gorm:"not null"` + GodotVersionID uint64 `json:"godot_version_id,omitempty" gorm:"not null"` GodotVersion GodotVersion `json:"godot_version" gorm:"not null"` - ProcessorCount uint64 `json:"processor_count" gorm:"not null"` - ScreenCount uint8 `json:"screen_count" gorm:"not null"` - ScreenDPI uint8 `json:"screen_dpi" gorm:"not null"` - ScreenSize string `json:"screen_size" gorm:"not null"` - MachineId string `json:"machine_id" gorm:"not null"` - Locale string `json:"locale" gorm:"not null"` - GameVersion string `json:"game_version" gorm:"not null"` + ProcessorCount uint64 `json:"processor_count,omitempty" gorm:"not null"` + ScreenCount uint8 `json:"screen_count,omitempty" gorm:"not null"` + ScreenDPI uint8 `json:"screen_dpi,omitempty" gorm:"not null"` + ScreenSize string `json:"screen_size,omitempty" gorm:"not null"` + MachineId string `json:"machine_id,omitempty" gorm:"not null"` + Locale string `json:"locale,omitempty" gorm:"not null"` + GameVersion string `json:"game_version,omitempty" gorm:"not null"` Won bool `json:"won" gorm:"not null"` - Timestamp uint64 `json:"timestamp" gorm:"not null"` - Frames []Frame `json:"frames"` + Timestamp uint64 `json:"timestamp,omitempty" gorm:"not null"` + Frames []Frame `json:"frames,omitempty"` +} + +type GamePublic struct { + Game + Player bool `json:"player,omitempty"` + Level bool `json:"level,omitempty"` + OS bool `json:"os,omitempty"` + GodotVersion bool `json:"godot_version,omitempty"` + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } func (game *Game) Validate() error { diff --git a/backend/models/godot_version.go b/backend/models/godot_version.go index 4e0bb43..1ee0e26 100644 --- a/backend/models/godot_version.go +++ b/backend/models/godot_version.go @@ -4,14 +4,21 @@ import "gorm.io/gorm" type GodotVersion struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Major uint8 `json:"major" gorm:"not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Major uint8 `json:"major,omitempty" gorm:"not null"` Minor uint8 `json:"minor" gorm:"not null"` Patch uint8 `json:"patch" gorm:"not null"` - Hex uint64 `json:"hex" gorm:"not null"` - Status string `json:"status" gorm:"not null"` - Build string `json:"build" gorm:"not null"` - Year uint16 `json:"year" gorm:"not null"` - Hash string `json:"hash" gorm:"unique;size:40;not null"` - String string `json:"string" gorm:"unique;not null"` + Hex uint64 `json:"hex,omitempty" gorm:"not null"` + Status string `json:"status,omitempty" gorm:"not null"` + Build string `json:"build,omitempty" gorm:"not null"` + Year uint16 `json:"year,omitempty" gorm:"not null"` + Hash string `json:"hash,omitempty" gorm:"unique;size:40;not null"` + String string `json:"string,omitempty" gorm:"unique;not null"` +} + +type GodotVersionPublic struct { + GodotVersion + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/level.go b/backend/models/level.go index b7197ea..1b18380 100644 --- a/backend/models/level.go +++ b/backend/models/level.go @@ -4,6 +4,13 @@ import "gorm.io/gorm" type Level struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Name string `json:"name" gorm:"unique;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Name string `json:"name,omitempty" gorm:"unique;not null"` +} + +type LevelPublic struct { + Level + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/object.go b/backend/models/object.go index 3a9f733..90577d9 100644 --- a/backend/models/object.go +++ b/backend/models/object.go @@ -4,17 +4,29 @@ import "gorm.io/gorm" type Object struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - FrameID uint64 `json:"frame_id" gorm:"not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + FrameID uint64 `json:"frame_id,omitempty" gorm:"not null"` Frame Frame `json:"frame" gorm:"not null"` - ObjectNameID uint64 `json:"-" gorm:"not null"` - ObjectName ObjectName `json:"-" gorm:"not null"` - ObjectStateID uint64 `json:"-" gorm:"not null"` - ObjectState ObjectState `json:"-" gorm:"not null"` - Name string `json:"name" gorm:"-:all"` - State string `json:"state" gorm:"-:all"` + ObjectNameID uint64 `json:"object_name_id" gorm:"not null"` + ObjectName ObjectName `json:"object_name" gorm:"not null"` + ObjectStateID uint64 `json:"object_state_id" gorm:"not null"` + ObjectState ObjectState `json:"object_state" gorm:"not null"` + Name string `json:"name,omitempty" gorm:"-:all"` + State string `json:"state,omitempty" gorm:"-:all"` PositionX float64 `json:"position_x" gorm:"not null"` PositionY float64 `json:"position_y" gorm:"not null"` VelocityX float64 `json:"velocity_x" gorm:"not null"` VelocityY float64 `json:"velocity_y" gorm:"not null"` } + +type ObjectPublic struct { + Object + Frame bool `json:"frame,omitempty"` + ObjectName bool `json:"object_name,omitempty"` + ObjectState bool `json:"object_state,omitempty"` + Name bool `json:"name,omitempty"` + State bool `json:"state,omitempty"` + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` +} diff --git a/backend/models/object_name.go b/backend/models/object_name.go index f7aec1f..750206f 100644 --- a/backend/models/object_name.go +++ b/backend/models/object_name.go @@ -4,6 +4,13 @@ import "gorm.io/gorm" type ObjectName struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Name string `json:"name" gorm:"unique;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Name string `json:"name,omitempty" gorm:"unique;not null"` +} + +type ObjectNamePublic struct { + ObjectName + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/object_state.go b/backend/models/object_state.go index eaaf72f..da23e18 100644 --- a/backend/models/object_state.go +++ b/backend/models/object_state.go @@ -4,6 +4,13 @@ import "gorm.io/gorm" type ObjectState struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Name string `json:"name" gorm:"unique;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Name string `json:"name,omitempty" gorm:"unique;not null"` +} + +type ObjectStatePublic struct { + ObjectState + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/os.go b/backend/models/os.go index 1ad4dc2..8f50868 100644 --- a/backend/models/os.go +++ b/backend/models/os.go @@ -4,6 +4,13 @@ import "gorm.io/gorm" type OS struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Name string `json:"name" gorm:"unique;size:8;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Name string `json:"name,omitempty" gorm:"unique;size:8;not null"` +} + +type OSPublic struct { + OS + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/player.go b/backend/models/player.go index 0f88250..3572b8e 100644 --- a/backend/models/player.go +++ b/backend/models/player.go @@ -4,8 +4,15 @@ import "gorm.io/gorm" type Player struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - RUT string `json:"rut" gorm:"unique;size:9;not null"` - Name string `json:"name" gorm:"not null"` - Email string `json:"email" gorm:"unique;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + RUT string `json:"rut,omitempty" gorm:"unique;size:9;not null"` + Name string `json:"name,omitempty" gorm:"not null"` + Email string `json:"email,omitempty" gorm:"unique;not null"` +} + +type PlayerPublic struct { + Player + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` } diff --git a/backend/models/user.go b/backend/models/user.go index 6e019b1..1b33b0a 100644 --- a/backend/models/user.go +++ b/backend/models/user.go @@ -7,14 +7,23 @@ import ( type User struct { gorm.Model - ID uint64 `json:"ID" gorm:"primaryKey"` - Name string `json:"name" gorm:"not null"` - Username string `json:"username" gorm:"unique; not null"` - Email string `json:"email" gorm:"unique;not null"` + ID uint64 `json:"ID,omitempty" gorm:"primaryKey"` + Name string `json:"name,omitempty" gorm:"not null"` + Username string `json:"username,omitempty" gorm:"unique; not null"` + Email string `json:"email,omitempty" gorm:"unique;not null"` Password string `json:"password,omitempty" gorm:"not null"` NewPassword string `json:"new_password,omitempty" gorm:"-:all"` } +type UserPublic struct { + User + Password bool `json:"password,omitempty"` + NewPassword bool `json:"new_password,omitempty"` + CreatedAt bool `json:"CreatedAt,omitempty"` + UpdatedAt bool `json:"UpdatedAt,omitempty"` + DeletedAt bool `json:"DeletedAt,omitempty"` +} + func (user *User) HashPassword(password string) error { bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) if err != nil {