1
0
Fork 0

refactor(training): use golang style of naming (do not repeat pacakge name in struct/func names)

This commit is contained in:
Vojtěch Mareš 2024-06-23 13:13:44 +02:00
parent e0f401f0a9
commit c3795dba6a
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
12 changed files with 232 additions and 232 deletions

View file

@ -6,14 +6,14 @@ import (
)
type InMemoryTrainingRepository struct {
trainings map[TrainingID]Training
trainings map[ID]Training
lock sync.RWMutex
ai int
}
func NewInMemoryTrainingRepository() *InMemoryTrainingRepository {
return &InMemoryTrainingRepository{
trainings: make(map[TrainingID]Training),
trainings: make(map[ID]Training),
ai: 1,
}
}
@ -28,7 +28,7 @@ func (r *InMemoryTrainingRepository) Create(training *Training) error {
return nil
}
func (r *InMemoryTrainingRepository) FindByID(id TrainingID) (*Training, error) {
func (r *InMemoryTrainingRepository) FindByID(id ID) (*Training, error) {
r.lock.RLock()
defer r.lock.RUnlock()
@ -58,7 +58,7 @@ func (r *InMemoryTrainingRepository) Update(training *Training) error {
return nil
}
func (r *InMemoryTrainingRepository) Delete(id TrainingID) error {
func (r *InMemoryTrainingRepository) Delete(id ID) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -71,23 +71,23 @@ func (r *InMemoryTrainingRepository) Delete(id TrainingID) error {
return nil
}
type InMemoryTrainingDateRepository struct {
trainingDates map[TrainingDateID]TrainingDate
trainingToDates map[TrainingID][]TrainingDateID
type InMemoryDateRepository struct {
trainingDates map[DateID]Date
trainingToDates map[ID][]DateID
lock sync.RWMutex
ai int
}
func NewInMemoryTrainingDateRepository() *InMemoryTrainingDateRepository {
return &InMemoryTrainingDateRepository{
trainingDates: make(map[TrainingDateID]TrainingDate),
trainingToDates: make(map[TrainingID][]TrainingDateID),
func NewInMemoryDateRepository() *InMemoryDateRepository {
return &InMemoryDateRepository{
trainingDates: make(map[DateID]Date),
trainingToDates: make(map[ID][]DateID),
ai: 1,
}
}
func (r *InMemoryTrainingDateRepository) Create(trainingID TrainingID, trainingDate *TrainingDate) error {
func (r *InMemoryDateRepository) Create(trainingID ID, trainingDate *Date) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -100,7 +100,7 @@ func (r *InMemoryTrainingDateRepository) Create(trainingID TrainingID, trainingD
return nil
}
func (r *InMemoryTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingDate, error) {
func (r *InMemoryDateRepository) FindByID(id DateID) (*Date, error) {
r.lock.RLock()
defer r.lock.RUnlock()
@ -111,11 +111,11 @@ func (r *InMemoryTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingD
return &date, nil
}
func (r *InMemoryTrainingDateRepository) FindAll() ([]TrainingDate, error) {
func (r *InMemoryDateRepository) FindAll() ([]Date, error) {
r.lock.RLock()
defer r.lock.RUnlock()
dates := make([]TrainingDate, len(r.trainingDates))
dates := make([]Date, len(r.trainingDates))
for _, date := range r.trainingDates {
dates = append(dates, date)
}
@ -123,11 +123,11 @@ func (r *InMemoryTrainingDateRepository) FindAll() ([]TrainingDate, error) {
return dates, nil
}
func (r *InMemoryTrainingDateRepository) FindAllByTrainingID(trainingID TrainingID) ([]TrainingDate, error) {
func (r *InMemoryDateRepository) FindAllByTrainingID(trainingID ID) ([]Date, error) {
r.lock.RLock()
defer r.lock.RUnlock()
dates := make([]TrainingDate, 0)
dates := make([]Date, 0)
for _, id := range r.trainingToDates[trainingID] {
dates = append(dates, r.trainingDates[id])
}
@ -135,12 +135,12 @@ func (r *InMemoryTrainingDateRepository) FindAllByTrainingID(trainingID Training
return dates, nil
}
func (r *InMemoryTrainingDateRepository) FindUpcomingByTrainingID(trainingID TrainingID) ([]TrainingDate, error) {
func (r *InMemoryDateRepository) FindUpcomingByTrainingID(trainingID ID) ([]Date, error) {
r.lock.RLock()
defer r.lock.RUnlock()
now := time.Now()
var dates []TrainingDate
var dates []Date
for _, id := range r.trainingToDates[trainingID] {
date := r.trainingDates[id]
if date.Date.After(now) {
@ -151,7 +151,7 @@ func (r *InMemoryTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
return dates, nil
}
func (r *InMemoryTrainingDateRepository) Update(trainingDate *TrainingDate) error {
func (r *InMemoryDateRepository) Update(trainingDate *Date) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -161,7 +161,7 @@ func (r *InMemoryTrainingDateRepository) Update(trainingDate *TrainingDate) erro
return nil
}
func (r *InMemoryTrainingDateRepository) Delete(id TrainingDateID) error {
func (r *InMemoryDateRepository) Delete(id DateID) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -182,23 +182,23 @@ func (r *InMemoryTrainingDateRepository) Delete(id TrainingDateID) error {
return nil
}
type InMemoryTrainingDateAttendeeRepository struct {
attendees map[TrainingDateAttendeeID]TrainingDateAttendee
dateToAttendees map[TrainingDateID][]TrainingDateAttendeeID
type InMemoryAttendeeRepository struct {
attendees map[AttendeeID]Attendee
dateToAttendees map[DateID][]AttendeeID
lock sync.RWMutex
ai int
}
func NewInMemoryTrainingDateAttendeeRepository() *InMemoryTrainingDateAttendeeRepository {
return &InMemoryTrainingDateAttendeeRepository{
attendees: make(map[TrainingDateAttendeeID]TrainingDateAttendee),
dateToAttendees: make(map[TrainingDateID][]TrainingDateAttendeeID),
func NewInMemoryAttendeeRepository() *InMemoryAttendeeRepository {
return &InMemoryAttendeeRepository{
attendees: make(map[AttendeeID]Attendee),
dateToAttendees: make(map[DateID][]AttendeeID),
ai: 1,
}
}
func (r *InMemoryTrainingDateAttendeeRepository) Create(trainingDateID TrainingDateID, attendee *TrainingDateAttendee) error {
func (r *InMemoryAttendeeRepository) Create(trainingDateID DateID, attendee *Attendee) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -212,7 +212,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) Create(trainingDateID TrainingD
return nil
}
func (r *InMemoryTrainingDateAttendeeRepository) FindByID(id TrainingDateAttendeeID) (*TrainingDateAttendee, error) {
func (r *InMemoryAttendeeRepository) FindByID(id AttendeeID) (*Attendee, error) {
r.lock.RLock()
defer r.lock.RUnlock()
@ -223,11 +223,11 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindByID(id TrainingDateAttende
return &attendee, nil
}
func (r *InMemoryTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttendee, error) {
func (r *InMemoryAttendeeRepository) FindAll() ([]Attendee, error) {
r.lock.RLock()
defer r.lock.RUnlock()
attendees := make([]TrainingDateAttendee, len(r.attendees))
attendees := make([]Attendee, len(r.attendees))
for _, attendee := range r.attendees {
attendees = append(attendees, attendee)
}
@ -235,11 +235,11 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttend
return attendees, nil
}
func (r *InMemoryTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainingDateID TrainingDateID) ([]TrainingDateAttendee, error) {
func (r *InMemoryAttendeeRepository) FindAllByTrainingDateID(trainingDateID DateID) ([]Attendee, error) {
r.lock.RLock()
defer r.lock.RUnlock()
attendees := make([]TrainingDateAttendee, 0)
attendees := make([]Attendee, 0)
for _, id := range r.dateToAttendees[trainingDateID] {
attendees = append(attendees, r.attendees[id])
}
@ -247,7 +247,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
return attendees, nil
}
func (r *InMemoryTrainingDateAttendeeRepository) Update(attendee *TrainingDateAttendee) error {
func (r *InMemoryAttendeeRepository) Update(attendee *Attendee) error {
r.lock.Lock()
defer r.lock.Unlock()
@ -257,7 +257,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) Update(attendee *TrainingDateAt
return nil
}
func (r *InMemoryTrainingDateAttendeeRepository) Delete(id TrainingDateAttendeeID) error {
func (r *InMemoryAttendeeRepository) Delete(id AttendeeID) error {
r.lock.Lock()
defer r.lock.Unlock()