Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Sep 24, 2024
1 parent ea8a116 commit 644fe66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
12 changes: 12 additions & 0 deletions pkg/helpers/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package helpers

import "math"

func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}

func ToFixed(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(round(num*output)) / output
}
3 changes: 2 additions & 1 deletion pkg/models/recording_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-server/pkg/config"
"github.com/mynaparrot/plugnmeet-server/pkg/dbmodels"
"github.com/mynaparrot/plugnmeet-server/pkg/helpers"
log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/encoding/protojson"
"os"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (m *RecordingModel) addRecordingInfoToDB(r *plugnmeet.RecorderToPlugNmeet,
RoomID: r.RoomId,
RoomSid: v,
RecorderID: r.RecorderId,
Size: float64(r.FileSize),
Size: helpers.ToFixed(float64(r.FileSize), 2),
FilePath: r.FilePath,
RoomCreationTime: roomCreationTime,
}
Expand Down
12 changes: 4 additions & 8 deletions pkg/services/db/room_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ func (s *DatabaseService) UpdateRoomStatus(info *dbmodels.RoomInfo) (int64, erro
update["ended"] = time.Now()
}

var cond interface{}
cond := new(dbmodels.RoomInfo)
if info.ID > 0 {
cond = map[string]interface{}{
"id": info.ID,
}
cond.ID = info.ID
} else if info.RoomId != "" {
cond = map[string]interface{}{
"roomId": info.RoomId,
}
cond.RoomId = info.RoomId
} else {
cond = gorm.Expr("sid = ?", info.Sid)
cond.Sid = info.Sid
}

result := s.db.Model(&dbmodels.RoomInfo{}).Where(cond).Not("is_running = ?", info.IsRunning).Updates(update)
Expand Down

0 comments on commit 644fe66

Please sign in to comment.