/
public_party.go
48 lines (40 loc) · 1.02 KB
/
public_party.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package models
import (
"encoding/json"
"github.com/vattle/sqlboiler/types"
)
type PublicParty struct {
Location types.JSON `json:"location"`
RoomCode string `json:"room_code"`
Ended bool `json:"ended"`
Guests *types.JSON `json:"guests,omitempty"`
CurrentTrack *PlayingTrack `json:"current_track,omitempty"`
}
func (p *Party) Public() (PublicParty, error) {
response := PublicParty{
Location: p.Location,
RoomCode: p.RoomCode,
Ended: p.Ended,
}
guests, err := p.Guests()
if err != nil {
return PublicParty{}, err
}
if len(guests) > 0 {
guestsPublic := make([]PublicGuest, 0)
for _, guest := range guests {
guestsPublic = append(guestsPublic, guest.Public())
}
guestsJsonRaw, _ := json.Marshal(guestsPublic)
guestsJson := types.JSON(guestsJsonRaw)
response.Guests = &guestsJson
}
if p.CurrentTrack.Valid {
var track PlayingTrack
err := p.CurrentTrack.Unmarshal(&track)
if err == nil {
response.CurrentTrack = &track
}
}
return response, nil
}