-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added host preferences and calendars
Hosts can now be created, along with their time preferences and calendars
- Loading branch information
1 parent
ac51c2a
commit b36a964
Showing
18 changed files
with
605 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
DROP TABLE IF EXISTS candidates; | ||
DROP TABLE IF EXISTS host_meetings; | ||
DROP TABLE IF EXISTS time_preferences; | ||
DROP TABLE IF EXISTS hosts; | ||
DROP TABLE IF EXISTS meetings; | ||
DROP TABLE IF EXISTS calendar_hosts; | ||
DROP TABLE IF EXISTS calendars; | ||
DROP TABLE IF EXISTS hosts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package repository | ||
|
||
import ( | ||
"github.com/rise8-us/neverl8/model" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type HostRepositoryInterface interface { | ||
CreateHost(host *model.Host) (*model.Host, error) | ||
GetHostByID(id uint) (*model.Host, error) | ||
GetAllHosts() ([]model.Host, error) | ||
CreateTimePreference(timePreference *model.TimePreference) (*model.TimePreference, error) | ||
CreateCalendar(calendar *model.Calendar, host *model.Host) (*model.Calendar, error) | ||
} | ||
|
||
// HostRepository handles CRUD operations for hosts and their time preferences. | ||
type HostRepository struct { | ||
db *gorm.DB | ||
} | ||
|
||
// NewHostRepository creates a new instance of HostRepository. | ||
func NewHostRepository(db *gorm.DB) *HostRepository { | ||
return &HostRepository{db: db} | ||
} | ||
|
||
func (r *HostRepository) CreateHost(host *model.Host) (*model.Host, error) { | ||
if err := r.db.Create(host).Error; err != nil { | ||
return nil, err | ||
} | ||
|
||
return host, nil | ||
} | ||
|
||
func (r *HostRepository) GetHostByID(id uint) (*model.Host, error) { | ||
var host model.Host | ||
if err := r.db.Preload("TimePreferences").Preload("Calendars").Preload("Meetings").First(&host, id).Error; err != nil { | ||
return nil, err | ||
} | ||
return &host, nil | ||
} | ||
|
||
func (r *HostRepository) GetAllHosts() ([]model.Host, error) { | ||
var Host []model.Host | ||
if err := r.db.Preload("TimePreferences").Preload("Calendars").Preload("Meetings").Find(&Host).Error; err != nil { | ||
return nil, err | ||
} | ||
return Host, nil | ||
} | ||
|
||
// Adds a new TimePreference to the database for a Host. | ||
func (r *HostRepository) CreateTimePreference(timePreference *model.TimePreference) (*model.TimePreference, error) { | ||
if err := r.db.Create(timePreference).Error; err != nil { | ||
return nil, err | ||
} | ||
|
||
return timePreference, nil | ||
} | ||
|
||
func (r *HostRepository) CreateCalendar(calendar *model.Calendar, host *model.Host) (*model.Calendar, error) { | ||
if err := r.db.Create(calendar).Error; err != nil { | ||
return nil, err | ||
} | ||
|
||
// Create the association between Host and Calendar | ||
err := r.db.Model(host).Association("Calendars").Append(&calendar) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return calendar, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package host | ||
|
||
import ( | ||
"github.com/rise8-us/neverl8/model" | ||
repository "github.com/rise8-us/neverl8/repository" | ||
) | ||
|
||
type HostService struct { | ||
hostRepo repository.HostRepositoryInterface | ||
} | ||
|
||
func NewHostService(hostRepo repository.HostRepositoryInterface) *HostService { | ||
return &HostService{hostRepo} | ||
} | ||
|
||
func (s *HostService) CreateHost(host *model.Host) (*model.Host, error) { | ||
return s.hostRepo.CreateHost(host) | ||
} | ||
|
||
func (s *HostService) GetAllHosts() ([]model.Host, error) { | ||
return s.hostRepo.GetAllHosts() | ||
} | ||
|
||
func (s *HostService) GetHostByID(id uint) (*model.Host, error) { | ||
return s.hostRepo.GetHostByID(id) | ||
} | ||
|
||
func (s *HostService) CreateTimePreference(timePreference *model.TimePreference) (*model.TimePreference, error) { | ||
return s.hostRepo.CreateTimePreference(timePreference) | ||
} | ||
|
||
func (s *HostService) CreateCalendar(calendar *model.Calendar, host *model.Host) (*model.Calendar, error) { | ||
return s.hostRepo.CreateCalendar(calendar, host) | ||
} |
Oops, something went wrong.