Skip to content

Commit

Permalink
chore(property): rework of all properties
Browse files Browse the repository at this point in the history
  • Loading branch information
vareversat committed Jul 24, 2024
1 parent 09d19f1 commit 0c6ff29
Show file tree
Hide file tree
Showing 62 changed files with 401 additions and 291 deletions.
4 changes: 2 additions & 2 deletions calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func NewCalendar(
return nil, fmt.Errorf("you must specify a PRODID number")
}
return &calendar{
Begin: properties.NewBlockDelimiterProperty(registries.BEGIN, registries.Vcalendar),
Begin: properties.NewBlockDelimiterProperty(registries.Begin, registries.Vcalendar),
ProdId: properties.NewProductIdProperty(prodId),
Version: properties.NewVersionProperty(calendarVersion),
Method: properties.NewMethodProperty(calendarMethod),
CalScale: properties.NewCalScaleProperty(),
Components: calendarComponents,
End: properties.NewBlockDelimiterProperty(registries.END, registries.Vcalendar),
End: properties.NewBlockDelimiterProperty(registries.End, registries.Vcalendar),
}, nil
}

Expand Down
56 changes: 29 additions & 27 deletions components/alarm_calendar_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ func NewAlarmCalendarComponent(
trigger properties.TriggerProperty,
propertyList ...properties.Property) AlarmCalendarComponent {
return &alarmCalendarComponent{
Begin: properties.NewBlockDelimiterProperty(registries.BEGIN, registries.Valarm),
Begin: properties.NewBlockDelimiterProperty(registries.Begin, registries.Valarm),
Trigger: trigger,
Properties: propertyList,
Action: action,
End: properties.NewBlockDelimiterProperty(registries.END, registries.Valarm),
End: properties.NewBlockDelimiterProperty(registries.End, registries.Valarm),
}
}

func (aC *alarmCalendarComponent) GetProperty(name registries.PropertyNames) properties.Property {
func (aC *alarmCalendarComponent) GetProperty(
name registries.PropertyRegistry,
) properties.Property {
for i := 0; i < len(aC.Properties); i++ {
if aC.Properties[i].GetName() == name {
return aC.Properties[i]
Expand All @@ -46,43 +48,43 @@ func (aC *alarmCalendarComponent) GetProperty(name registries.PropertyNames) pro
return nil
}

func (aC *alarmCalendarComponent) MandatoryProperties() []registries.PropertyNames {
func (aC *alarmCalendarComponent) MandatoryProperties() []registries.PropertyRegistry {
switch aC.Action.GetActionValue() {
case registries.Audio:
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.ACTION,
registries.TRIGGER,
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Action,
registries.Trigger,
}
case registries.Display:
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.ACTION,
registries.TRIGGER,
registries.DESCRIPTION,
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Action,
registries.Trigger,
registries.Description,
}
case registries.Email:
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.ACTION,
registries.TRIGGER,
registries.DESCRIPTION,
registries.SUMMARY,
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Action,
registries.Trigger,
registries.Description,
registries.Summary,
}
default:
return []registries.PropertyNames{registries.BEGIN, registries.END}
return []registries.PropertyRegistry{registries.Begin, registries.End}
}
}

func (aC *alarmCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (aC *alarmCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (aC *alarmCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{registries.DURATION_PROP, registries.REPEAT}
func (aC *alarmCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{registries.DurationProperty, registries.Repeat}
}

func (aC *alarmCalendarComponent) SerializeToICSFormat(output io.Writer) {
Expand Down
10 changes: 5 additions & 5 deletions components/calendar_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ type CalendarComponent interface {
SerializeToICSFormat(output io.Writer)

// MandatoryProperties return the list of the mandatory properties of a CalendarComponent
MandatoryProperties() []registries.PropertyNames
MandatoryProperties() []registries.PropertyRegistry

// GetProperty get a property by his registries.PropertyNames
GetProperty(name registries.PropertyNames) properties.Property
// GetProperty get a property by his registries.PropertyRegistry
GetProperty(name registries.PropertyRegistry) properties.Property

// MutuallyExclusiveProperties return the list of the mutually exclusives properties of a CalendarComponent
// Example : In a VEVENT component, you can't have a DTEND and a DURATION property at the same time
MutuallyExclusiveProperties() []registries.PropertyNames
MutuallyExclusiveProperties() []registries.PropertyRegistry

// MutuallyInclusiveProperties return the list of the mutually inclusive properties of a CalendarComponent
// Example : In a VALARM component, if you set a value for the DURATION property, you have to also set one for the REPEAT property
MutuallyInclusiveProperties() []registries.PropertyNames
MutuallyInclusiveProperties() []registries.PropertyRegistry
}

// CalendarComponents is an array of CalendarComponent
Expand Down
28 changes: 15 additions & 13 deletions components/event_calendar_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,45 @@ func NewEventCalendarComponent(
propertyList ...properties.Property) EventCalendarComponent {
return &eventCalendarComponent{
Begin: properties.NewBlockDelimiterProperty(
registries.BEGIN,
registries.Begin,
registries.Vevent,
),
UID: uid,
DateTimeStamp: dateTimeStamp,
AlarmCalendarComponents: alarmCalendarComponents,
Properties: propertyList,
End: properties.NewBlockDelimiterProperty(
registries.END,
registries.End,
registries.Vevent,
),
}
}

func (eC *eventCalendarComponent) GetProperty(name registries.PropertyNames) properties.Property {
func (eC *eventCalendarComponent) GetProperty(
name registries.PropertyRegistry,
) properties.Property {
for i := 0; i < len(eC.Properties); i++ {
if eC.Properties[i].GetName() == name {
return eC.Properties[i]
}
}
return nil
}
func (eC *eventCalendarComponent) MandatoryProperties() []registries.PropertyNames {
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.UID,
registries.DTSTAMP,
func (eC *eventCalendarComponent) MandatoryProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Uid,
registries.DateTimeStamp,
}
}

func (eC *eventCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{registries.DTEND, registries.DURATION_PROP}
func (eC *eventCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{registries.DateTimeEnd, registries.DurationProperty}
}

func (eC *eventCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (eC *eventCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (eC *eventCalendarComponent) SerializeToICSFormat(output io.Writer) {
Expand Down
2 changes: 1 addition & 1 deletion components/event_calendar_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func TestEventCalendarComponent_GetProperty(t *testing.T) {
summary,
)

prop := component.GetProperty(registries.SUMMARY)
prop := component.GetProperty(registries.Summary)
assert.Equal(t, "Event Summary", prop.GetValue())
}
26 changes: 13 additions & 13 deletions components/freebusy_calendar_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func NewFreeBusyCalendarComponent(
dateTimeStamp properties.DateTimeStampProperty,
propertyList ...properties.Property) FreeBusyCalendarComponent {
return &freeBusyCalendarComponent{
Begin: properties.NewBlockDelimiterProperty(registries.BEGIN, registries.Vfreebusy),
Begin: properties.NewBlockDelimiterProperty(registries.Begin, registries.Vfreebusy),
UID: uid,
DateTimeStamp: dateTimeStamp,
Properties: propertyList,
End: properties.NewBlockDelimiterProperty(registries.END, registries.Vfreebusy),
End: properties.NewBlockDelimiterProperty(registries.End, registries.Vfreebusy),
}
}

func (fC *freeBusyCalendarComponent) GetProperty(
name registries.PropertyNames,
name registries.PropertyRegistry,
) properties.Property {
for i := 0; i < len(fC.Properties); i++ {
if fC.Properties[i].GetName() == name {
Expand All @@ -48,21 +48,21 @@ func (fC *freeBusyCalendarComponent) GetProperty(
return nil
}

func (fC *freeBusyCalendarComponent) MandatoryProperties() []registries.PropertyNames {
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.UID,
registries.DTSTAMP,
func (fC *freeBusyCalendarComponent) MandatoryProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Uid,
registries.DateTimeStamp,
}
}

func (fC *freeBusyCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (fC *freeBusyCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (fC *freeBusyCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (fC *freeBusyCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (fC *freeBusyCalendarComponent) SerializeToICSFormat(output io.Writer) {
Expand Down
28 changes: 15 additions & 13 deletions components/journal_calendar_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ func NewJournalCalendarComponent(
dateTimeStamp properties.DateTimeStampProperty,
propertyList ...properties.Property) JournalCalendarComponent {
return &journalCalendarComponent{
Begin: properties.NewBlockDelimiterProperty(registries.BEGIN, registries.Vjournal),
Begin: properties.NewBlockDelimiterProperty(registries.Begin, registries.Vjournal),
UID: uid,
DateTimeStamp: dateTimeStamp,
Properties: propertyList,
End: properties.NewBlockDelimiterProperty(registries.END, registries.Vjournal),
End: properties.NewBlockDelimiterProperty(registries.End, registries.Vjournal),
}
}

func (jC *journalCalendarComponent) GetProperty(name registries.PropertyNames) properties.Property {
func (jC *journalCalendarComponent) GetProperty(
name registries.PropertyRegistry,
) properties.Property {
for i := 0; i < len(jC.Properties); i++ {
if jC.Properties[i].GetName() == name {
return jC.Properties[i]
Expand All @@ -46,21 +48,21 @@ func (jC *journalCalendarComponent) GetProperty(name registries.PropertyNames) p
return nil
}

func (jC *journalCalendarComponent) MandatoryProperties() []registries.PropertyNames {
return []registries.PropertyNames{
registries.BEGIN,
registries.END,
registries.UID,
registries.DTSTAMP,
func (jC *journalCalendarComponent) MandatoryProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{
registries.Begin,
registries.End,
registries.Uid,
registries.DateTimeStamp,
}
}

func (jC *journalCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (jC *journalCalendarComponent) MutuallyExclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (jC *journalCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyNames {
return []registries.PropertyNames{}
func (jC *journalCalendarComponent) MutuallyInclusiveProperties() []registries.PropertyRegistry {
return []registries.PropertyRegistry{}
}

func (jC *journalCalendarComponent) SerializeToICSFormat(output io.Writer) {
Expand Down
Loading

0 comments on commit 0c6ff29

Please sign in to comment.