github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/datamodel/participants.go (about)

     1  package datamodel
     2  
     3  import (
     4  	rd "github.com/benoitkugler/goACVE/server/core/rawdata"
     5  )
     6  
     7  // regroupe les méthodes partagées par les 'participants' à un séjour :
     8  // equipier, participant, participantsimple
     9  
    10  type Personne interface {
    11  	GetPersonne() AccesPersonne
    12  }
    13  
    14  type Participant interface {
    15  	Personne
    16  	GetCamp() AccesCamp
    17  }
    18  
    19  type Inscrit interface {
    20  	Participant
    21  	GetId() rd.IId
    22  	GetFacture() (AccesFacture, bool)
    23  }
    24  
    25  func (ac AccesParticipant) GetId() rd.IId {
    26  	return rd.IdParticipant(ac.Id)
    27  }
    28  func (ac AccesParticipantsimple) GetId() rd.IId {
    29  	return rd.IdParticipantsimple(ac.Id)
    30  }
    31  func (ac AccesParticipantsimple) GetFacture() (AccesFacture, bool) {
    32  	return AccesFacture{}, false
    33  }
    34  
    35  func ageDebutCamp(ac Participant) rd.AgeDate {
    36  	dateArrivee := ac.GetCamp().RawData().DateDebut
    37  	per := ac.GetPersonne()
    38  	if dateArrivee.Time().IsZero() {
    39  		return per.RawData().AgeDate()
    40  	}
    41  	return rd.CalculeAge(per.RawData().DateNaissance, dateArrivee.Time())
    42  }
    43  
    44  func hasAnniversaire(ac Participant) bool {
    45  	camp := ac.GetCamp().RawData()
    46  	db, df := camp.DateDebut, camp.DateFin
    47  	if db.Time().IsZero() || df.Time().IsZero() {
    48  		return false
    49  	}
    50  	dateNaissance := ac.GetPersonne().RawData().DateNaissance
    51  	if dateNaissance.Time().IsZero() {
    52  		return false
    53  	}
    54  
    55  	return rd.Avant(db, dateNaissance) && rd.Avant(dateNaissance, df)
    56  }
    57  
    58  // AgeDebutCamp renvoie l'âge qu'aura le participant au premier jour du camp
    59  func (ac AccesParticipant) AgeDebutCamp() rd.AgeDate {
    60  	return ageDebutCamp(ac)
    61  }
    62  
    63  // HasAnniversaire renvoie `true` si le participant a son anniversaire pendant le camp.
    64  func (ac AccesParticipant) HasAnniversaire() bool {
    65  	return hasAnniversaire(ac)
    66  }
    67  
    68  // AgeDebutCamp renvoie l'âge qu'aura le participant au premier jour du camp
    69  func (ac AccesParticipantsimple) AgeDebutCamp() rd.AgeDate {
    70  	return ageDebutCamp(ac)
    71  }
    72  
    73  // HasAnniversaire renvoie `true` si le participant a son anniversaire pendant le camp.
    74  func (ac AccesParticipantsimple) HasAnniversaire() bool {
    75  	return hasAnniversaire(ac)
    76  }
    77  
    78  // AgeDebutCamp renvoie l'âge qu'aura le participant au premier jour du camp
    79  func (ac AccesEquipier) AgeDebutCamp() rd.AgeDate {
    80  	return ageDebutCamp(ac)
    81  }
    82  
    83  // HasAnniversaire renvoie `true` si le participant a son anniversaire pendant le camp.
    84  func (ac AccesEquipier) HasAnniversaire() bool {
    85  	return hasAnniversaire(ac)
    86  }