Skip to content

Commit

Permalink
Merge pull request #101 from builderscon/topic/issue-98
Browse files Browse the repository at this point in the history
Topic/issue 98
  • Loading branch information
lestrrat authored Jul 10, 2016
2 parents d82d178 + 7ba5635 commit 66315a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
12 changes: 9 additions & 3 deletions octav/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/lestrrat/go-apache-logformat"
"github.com/lestrrat/go-jsval"
"github.com/lestrrat/go-pdebug"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -533,8 +534,8 @@ func doCreateSession(ctx context.Context, w http.ResponseWriter, r *http.Request
return
}

if err := s.Decorate(tx, &v); err != nil {
httpError(w, `LookupSession`, http.StatusInternalServerError, err)
if err := errors.Wrap(s.Decorate(tx, &v), "failed to decorate session with associated data"); err != nil {
httpError(w, `CreateSession`, http.StatusInternalServerError, err)
return
}

Expand Down Expand Up @@ -1106,6 +1107,11 @@ func doListVenue(ctx context.Context, w http.ResponseWriter, r *http.Request, pa
}

func doLookupSession(ctx context.Context, w http.ResponseWriter, r *http.Request, payload model.LookupSessionRequest) {
if pdebug.Enabled {
g := pdebug.Marker("doLookupSession")
defer g.End()
}

tx, err := db.Begin()
if err != nil {
httpError(w, `LookupSession`, http.StatusInternalServerError, err)
Expand All @@ -1120,7 +1126,7 @@ func doLookupSession(ctx context.Context, w http.ResponseWriter, r *http.Request
}

s := service.Session{}
if err := s.Decorate(tx, &v); err != nil {
if err := errors.Wrap(s.Decorate(tx, &v), "failed to decorate session with associated data"); err != nil {
httpError(w, `LookupSession`, http.StatusInternalServerError, err)
return
}
Expand Down
27 changes: 18 additions & 9 deletions octav/service/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/builderscon/octav/octav/db"
"github.com/builderscon/octav/octav/model"
"github.com/builderscon/octav/octav/tools"
"github.com/lestrrat/go-pdebug"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -190,27 +191,35 @@ func (v *Session) LoadByConference(tx *db.Tx, vdbl *db.SessionList, cid string,
}

func (v *Session) Decorate(tx *db.Tx, session *model.Session) error {
if pdebug.Enabled {
g := pdebug.Marker("service.Session.Decorate")
defer g.End()
}
// session must be associated with a conference
conf := model.Conference{}
if err := conf.Load(tx, session.ConferenceID); err != nil {
return errors.Wrap(err, "failed to load conference")
if session.ConferenceID != "" {
conf := model.Conference{}
if err := conf.Load(tx, session.ConferenceID); err != nil {
return errors.Wrap(err, "failed to load conference")
}
session.Conference = &conf
}
session.Conference = &conf

// ... but not necessarily with a room
if session.RoomID != "" {
room := model.Room{}
if err := conf.Load(tx, session.RoomID); err != nil {
if err := room.Load(tx, session.RoomID); err != nil {
return errors.Wrap(err, "failed to load room")
}
session.Room = &room
}

speaker := model.User{}
if err := speaker.Load(tx, session.SpeakerID); err != nil {
return errors.Wrap(err, "failed to load speaker")
if session.SpeakerID != "" {
speaker := model.User{}
if err := speaker.Load(tx, session.SpeakerID); err != nil {
return errors.Wrapf(err, "failed to load speaker '%s'", session.SpeakerID)
}
session.Speaker = &speaker
}
session.Speaker = &speaker

return nil
}
6 changes: 4 additions & 2 deletions octav/sql/octav.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ CREATE TABLE conference_venues (
CREATE TABLE sessions (
oid INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
eid CHAR(64) CHARACTER SET latin1 NOT NULL,
conference_id CHAR(64) CHARACTER SET latin1 NOT NULL,
conference_id CHAR(64) CHARACTER SET latin1,
room_id CHAR(64) CHARACTER SET latin1,
speaker_id CHAR(64) NOT NULL,
speaker_id CHAR(64) CHARACTER SET latin1,
title TEXT NOT NULL,
abstract TEXT,
memo TEXT,
Expand All @@ -124,6 +124,8 @@ CREATE TABLE sessions (
confirmed TINYINT(1) NOT NULL DEFAULT 0,
created_on DATETIME NOT NULL,
modified_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (speaker_id) REFERENCES users(eid) ON DELETE SET NULL,
FOREIGN KEY (conference_id) REFERENCES conferences(eid) ON DELETE SET NULL,
UNIQUE KEY (eid),
KEY(eid, conference_id, room_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Expand Down

0 comments on commit 66315a8

Please sign in to comment.