Skip to content

Commit

Permalink
Merge branch 'main' into chore/less-boilerplate-ios
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Oct 22, 2023
2 parents 43ffb20 + c2cb0eb commit 23be7be
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 259 deletions.
4 changes: 2 additions & 2 deletions server/backend/cron/average_rating_computation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func computeAverageForDishesInCafeteriasTags(c *CronService) {
}

func computeAverageCafeteriaTags(c *CronService) {
var results []model.CafeteriaRatingTagsAverage
var results []model.CafeteriaRatingTagAverage
err := c.db.Raw("SELECT cr.cafeteriaID as cafeteriaID, crt.tagID as tagID, AVG(crt.points) as average, MAX(crt.points) as max, MIN(crt.points) as min, STD(crt.points) as std" +
" FROM cafeteria_rating cr" +
" JOIN cafeteria_rating_tag crt ON cr.cafeteriaRating = crt.correspondingRating" +
Expand All @@ -68,7 +68,7 @@ func computeAverageCafeteriaTags(c *CronService) {
if err != nil {
log.WithError(err).Error("while precomputing average cafeteria tags.")
} else if len(results) > 0 {
if err := c.db.Where("1=1").Delete(&model.CafeteriaRatingTagsAverage{}).Error; err != nil {
if err := c.db.Where("1=1").Delete(&model.CafeteriaRatingTagAverage{}).Error; err != nil {
log.WithError(err).Error("Error while deleting old averages in the table.")
}

Expand Down
10 changes: 5 additions & 5 deletions server/backend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
// deviceBuffer stores all recent device calls in a buffer and flushes them to the database periodically
type deviceBuffer struct {
lock sync.Mutex
devices map[string]*model.Devices // key is uuid
devices map[string]*model.Device // key is uuid
}

func newDeviceBuffer() *deviceBuffer {
return &deviceBuffer{
lock: sync.Mutex{},
devices: make(map[string]*model.Devices),
devices: make(map[string]*model.Device),
}
}

Expand All @@ -47,7 +47,7 @@ func (b *deviceBuffer) add(deviceID string, method string, osVersion string, app
if _, exists := b.devices[deviceID]; exists {
b.devices[deviceID].Counter++
} else {
b.devices[deviceID] = &model.Devices{
b.devices[deviceID] = &model.Device{
UUID: deviceID,
LastAccess: time.Now(),
LastAPI: method,
Expand All @@ -62,7 +62,7 @@ func (b *deviceBuffer) add(deviceID string, method string, osVersion string, app
func (b *deviceBuffer) flush(tx *gorm.DB) error {
b.lock.Lock()
defer b.lock.Unlock()
devices := make([]*model.Devices, 0, len(b.devices))
devices := make([]*model.Device, 0, len(b.devices))
for _, device := range b.devices {
devices = append(devices, device)
}
Expand All @@ -86,7 +86,7 @@ func (b *deviceBuffer) flush(tx *gorm.DB) error {
if err != nil {
log.WithError(err).Error("failed to flush device buffer")
}
b.devices = make(map[string]*model.Devices)
b.devices = make(map[string]*model.Device)
return nil
}

Expand Down
97 changes: 90 additions & 7 deletions server/backend/migration/20220126230000.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,107 @@
package migration

import (
"github.com/TUM-Dev/Campus-Backend/server/model"
"github.com/go-gormigrate/gormigrate/v2"
"github.com/guregu/null"
"gorm.io/gorm"
)

// RoomfinderRooms struct is a row record of the roomfinder_rooms table in the tca database
type RoomfinderRooms struct {
RoomID int64 `gorm:"primary_key;column:room_id;type:int;" json:"room_id"`
RoomCode null.String `gorm:"column:room_code;type:varchar(32);" json:"room_code"`
BuildingNr null.String `gorm:"column:building_nr;type:varchar(8);" json:"building_nr"`
ArchID null.String `gorm:"column:arch_id;type:varchar(16);" json:"arch_id"`
Info null.String `gorm:"column:info;type:varchar(64);" json:"info"`
Address null.String `gorm:"column:address;type:varchar(128);" json:"address"`
PurposeID null.Int `gorm:"column:purpose_id;type:int;" json:"purpose_id"`
Purpose null.String `gorm:"column:purpose;type:varchar(64);" json:"purpose"`
Seats null.Int `gorm:"column:seats;type:int;" json:"seats"`
UtmZone null.String `gorm:"column:utm_zone;type:varchar(4);" json:"utm_zone"`
UtmEasting null.String `gorm:"column:utm_easting;type:varchar(32);" json:"utm_easting"`
UtmNorthing null.String `gorm:"column:utm_northing;type:varchar(32);" json:"utm_northing"`
UnitID null.Int `gorm:"column:unit_id;type:int;" json:"unit_id"`
DefaultMapID null.Int `gorm:"column:default_map_id;type:int;" json:"default_map_id"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderRooms) TableName() string {
return "roomfinder_rooms"
}

// RoomfinderBuilding2area struct is a row record of the roomfinder_building2area table in the tca database
type RoomfinderBuilding2area struct {
BuildingNr string `gorm:"primary_key;column:building_nr;type:varchar(8);" json:"building_nr"`
AreaID int32 `gorm:"column:area_id;type:int;" json:"area_id"`
Campus string `gorm:"column:campus;type:char;size:1;" json:"campus"`
Name string `gorm:"column:name;type:varchar(32);" json:"name"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderBuilding2area) TableName() string {
return "roomfinder_building2area"
}

// RoomfinderBuildings struct is a row record of the roomfinder_buildings table in the tca database
type RoomfinderBuildings struct {
BuildingNr string `gorm:"primary_key;column:building_nr;type:varchar(8);" json:"building_nr"`
UtmZone null.String `gorm:"column:utm_zone;type:varchar(4);" json:"utm_zone"`
UtmEasting null.String `gorm:"column:utm_easting;type:varchar(32);" json:"utm_easting"`
UtmNorthing null.String `gorm:"column:utm_northing;type:varchar(32);" json:"utm_northing"`
DefaultMapID null.Int `gorm:"column:default_map_id;type:int;" json:"default_map_id"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderBuildings) TableName() string {
return "roomfinder_buildings"
}

// RoomfinderBuildings2gps struct is a row record of the roomfinder_buildings2gps table in the tca database
type RoomfinderBuildings2gps struct {
ID string `gorm:"primary_key;column:id;type:varchar(8);" json:"id"`
Latitude null.String `gorm:"column:latitude;type:varchar(30);" json:"latitude"`
Longitude null.String `gorm:"column:longitude;type:varchar(30);" json:"longitude"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderBuildings2gps) TableName() string {
return "roomfinder_buildings2gps"
}

// RoomfinderBuildings2maps struct is a row record of the roomfinder_buildings2maps table in the tca database
type RoomfinderBuildings2maps struct {
BuildingNr string `gorm:"primary_key;column:building_nr;type:varchar(8);" json:"building_nr"`
MapID int64 `gorm:"primary_key;column:map_id;type:int;" json:"map_id"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderBuildings2maps) TableName() string {
return "roomfinder_buildings2maps"
}

// RoomfinderRooms2maps struct is a row record of the roomfinder_rooms2maps table in the tca database
type RoomfinderRooms2maps struct {
RoomID int64 `gorm:"primary_key;column:room_id;type:int;" json:"room_id"`
MapID int64 `gorm:"primary_key;column:map_id;type:int;" json:"map_id"`
}

// TableName sets the insert table name for this struct type
func (r *RoomfinderRooms2maps) TableName() string {
return "roomfinder_rooms2maps"
}

// migrate20220126230000
// adds a fulltext index to the roomfinder_rooms table
func (m TumDBMigrator) migrate20220126230000() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20220126230000",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(
&model.RoomfinderRooms{},
&model.RoomfinderBuilding2area{},
&model.RoomfinderBuildings2gps{},
&model.RoomfinderBuildings2maps{},
&model.RoomfinderRooms{},
&model.RoomfinderRooms2maps{},
&RoomfinderRooms{},
&RoomfinderBuilding2area{},
&RoomfinderBuildings2gps{},
&RoomfinderBuildings2maps{},
&RoomfinderRooms2maps{},
); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion server/backend/migration/20220713000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (m TumDBMigrator) migrate20220713000000() *gormigrate.Migration {
&model.CafeteriaRating{},
&model.CafeteriaRatingAverage{},
&model.CafeteriaRatingTag{},
&model.CafeteriaRatingTagsAverage{},
&model.CafeteriaRatingTagAverage{},
&model.CafeteriaRatingTagOption{},
&model.Dish{},
&model.DishesOfTheWeek{},
Expand Down
1 change: 0 additions & 1 deletion server/backend/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (m TumDBMigrator) Migrate() error {
if m.shouldAutoMigrate {
log.Info("Using automigration")
err := m.database.AutoMigrate(
&model.TopNews{},
&model.Crontab{},
&model.File{},
&model.NewsSource{},
Expand Down
6 changes: 3 additions & 3 deletions server/model/cafeteria_rating_tag_average.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package model

// CafeteriaRatingTagsAverage stores all precomputed values for the cafeteria ratings
type CafeteriaRatingTagsAverage struct {
// CafeteriaRatingTagAverage stores all precomputed values for the cafeteria ratings
type CafeteriaRatingTagAverage struct {
CafeteriaRatingTagsAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingTagsAverage;type:int;not null;" json:"canteenRatingTagsAverage"`
CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"canteenID"`
TagID int64 `gorm:"column:tagID;foreignKey:cafeteriaRatingTagOption;type:int;not null;" json:"tagID"`
Expand All @@ -12,6 +12,6 @@ type CafeteriaRatingTagsAverage struct {
}

// TableName sets the insert table name for this struct type
func (n *CafeteriaRatingTagsAverage) TableName() string {
func (n *CafeteriaRatingTagAverage) TableName() string {
return "cafeteria_rating_tag_average"
}
File renamed without changes.
4 changes: 2 additions & 2 deletions server/model/devices.go → server/model/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/guregu/null"
)

// Devices struct is a row record of the devices table in the tca database
type Devices struct {
// Device struct is a row record of the devices table in the tca database
type Device struct {
Device int64 `gorm:"primary_key;AUTO_INCREMENT;column:device;type:int;" json:"device"`
Member null.Int `gorm:"column:member;type:int;" json:"member"`
UUID string `gorm:"column:uuid;type:varchar(50);" json:"uuid"`
Expand Down
6 changes: 3 additions & 3 deletions server/model/ios_device_request_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import "time"
// containing the RequestID and the data.
type IOSDeviceRequestLog struct {
RequestID string `gorm:"primary_key;default:UUID()" json:"requestId"`
DeviceID string `json:"deviceId" gorm:"size:200;not null"`
Device IOSDevice `json:"device" gorm:"constraint:OnDelete:CASCADE;"`
RequestType string `json:"requestType" gorm:"not null;type:enum ('CAMPUS_TOKEN_REQUEST');"`
DeviceID string `gorm:"size:200;not null" json:"deviceId"`
Device IOSDevice `gorm:"constraint:OnDelete:CASCADE;" json:"device"`
RequestType string `gorm:"not null;type:enum ('CAMPUS_TOKEN_REQUEST');" json:"requestType"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"createdAt"`
}
File renamed without changes.
29 changes: 0 additions & 29 deletions server/model/roomfinder_building2area.go

This file was deleted.

35 changes: 0 additions & 35 deletions server/model/roomfinder_buildings.go

This file was deleted.

35 changes: 0 additions & 35 deletions server/model/roomfinder_buildings2gps.go

This file was deleted.

27 changes: 0 additions & 27 deletions server/model/roomfinder_buildings2maps.go

This file was deleted.

30 changes: 0 additions & 30 deletions server/model/roomfinder_maps.go

This file was deleted.

Loading

0 comments on commit 23be7be

Please sign in to comment.