Dump changes
This commit is contained in:
parent
e12550a643
commit
aac2ea1b74
25 changed files with 129 additions and 76 deletions
|
|
@ -1,83 +0,0 @@
|
|||
package appointment
|
||||
|
||||
import (
|
||||
"brainbuffer/pkg/brainbuffer/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
type inMemoryRepository struct {
|
||||
db map[int64]*Appointment
|
||||
idCounter int64
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) Save(appointment *Appointment) error {
|
||||
repo.idCounter++
|
||||
appointment.ID = repo.idCounter
|
||||
repo.db[repo.idCounter] = appointment
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) FindByID(id int64) (*Appointment, error) {
|
||||
if v, ok := repo.db[id]; ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) GetAllByTask(taskId int64, page repository.Page) (Appointments, error) {
|
||||
taskAppointments := make(Appointments, 0)
|
||||
|
||||
for _, val := range repo.db {
|
||||
if val.TaskID == taskId {
|
||||
taskAppointments = append(taskAppointments, val)
|
||||
}
|
||||
}
|
||||
|
||||
return taskAppointments, nil
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) GetAllByTasks(taskIds []int64, page repository.Page) (Appointments, error) {
|
||||
taskAppointments := make(Appointments, 0)
|
||||
|
||||
for _, val := range repo.db {
|
||||
if _, found := findInIntSlice(val.TaskID, taskIds); found {
|
||||
taskAppointments = append(taskAppointments, val)
|
||||
}
|
||||
}
|
||||
|
||||
return taskAppointments, nil
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) GetAllByTasksBefore(taskIds []int64, beforeTime time.Time, page repository.Page) (Appointments, error) {
|
||||
taskAppointments := make(Appointments, 0)
|
||||
|
||||
for _, val := range repo.db {
|
||||
if _, found := findInIntSlice(val.TaskID, taskIds); found && val.Time.Before(beforeTime) {
|
||||
taskAppointments = append(taskAppointments, val)
|
||||
}
|
||||
}
|
||||
|
||||
return taskAppointments, nil
|
||||
}
|
||||
|
||||
func (repo *inMemoryRepository) DeleteAllByTask(taskId int64) error {
|
||||
for id, v := range repo.db {
|
||||
if v.TaskID == taskId {
|
||||
delete(repo.db, id)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func findInIntSlice(val int64, slice []int64) (int, bool) {
|
||||
for i, v := range slice {
|
||||
if v == val {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
|
||||
return -1, false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue