1
1
package uk.gov.justice.digital.hmpps.organisationsapi.facade
2
2
3
3
import org.springframework.stereotype.Service
4
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreateAddressRequest
5
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreateEmailRequest
4
6
import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreateOrganisationRequest
7
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreatePhoneRequest
8
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreateWebRequest
9
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateAddressRequest
10
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateEmailRequest
5
11
import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateOrganisationRequest
12
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdatePhoneRequest
13
+ import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateWebRequest
6
14
import uk.gov.justice.digital.hmpps.organisationsapi.service.events.OutboundEvent
7
15
import uk.gov.justice.digital.hmpps.organisationsapi.service.events.OutboundEventsService
8
16
import uk.gov.justice.digital.hmpps.organisationsapi.service.events.Source
17
+ import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncAddressService
18
+ import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncEmailService
9
19
import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncOrganisationService
20
+ import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncPhoneService
21
+ import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncWebService
10
22
11
23
/* *
12
24
* This class is a facade over the sync services as a thin layer
@@ -28,16 +40,20 @@ import uk.gov.justice.digital.hmpps.organisationsapi.service.sync.SyncOrganisati
28
40
29
41
@Service
30
42
class SyncFacade (
31
- private val syncService : SyncOrganisationService ,
43
+ private val syncOrganisationService : SyncOrganisationService ,
44
+ private val syncPhoneService : SyncPhoneService ,
45
+ private val syncEmailService : SyncEmailService ,
46
+ private val syncWebService : SyncWebService ,
47
+ private val syncAddressService : SyncAddressService ,
32
48
private val outboundEventsService : OutboundEventsService ,
33
49
) {
34
50
// ================================================================
35
51
// Organisations
36
52
// ================================================================
37
53
38
- fun getOrganisationById (organisationId : Long ) = syncService .getOrganisationById(organisationId)
54
+ fun getOrganisationById (organisationId : Long ) = syncOrganisationService .getOrganisationById(organisationId)
39
55
40
- fun createOrganisation (request : SyncCreateOrganisationRequest ) = syncService .createOrganisation(request)
56
+ fun createOrganisation (request : SyncCreateOrganisationRequest ) = syncOrganisationService .createOrganisation(request)
41
57
.also {
42
58
outboundEventsService.send(
43
59
outboundEvent = OutboundEvent .ORGANISATION_CREATED ,
@@ -47,7 +63,7 @@ class SyncFacade(
47
63
)
48
64
}
49
65
50
- fun updateOrganisation (organisationId : Long , request : SyncUpdateOrganisationRequest ) = syncService .updateOrganisation(organisationId, request)
66
+ fun updateOrganisation (organisationId : Long , request : SyncUpdateOrganisationRequest ) = syncOrganisationService .updateOrganisation(organisationId, request)
51
67
.also {
52
68
outboundEventsService.send(
53
69
outboundEvent = OutboundEvent .ORGANISATION_UPDATED ,
@@ -57,7 +73,7 @@ class SyncFacade(
57
73
)
58
74
}
59
75
60
- fun deleteOrganisation (organisationId : Long ) = syncService .deleteOrganisation(organisationId)
76
+ fun deleteOrganisation (organisationId : Long ) = syncOrganisationService .deleteOrganisation(organisationId)
61
77
.also {
62
78
outboundEventsService.send(
63
79
outboundEvent = OutboundEvent .ORGANISATION_DELETED ,
@@ -66,4 +82,148 @@ class SyncFacade(
66
82
source = Source .NOMIS ,
67
83
)
68
84
}
85
+
86
+ // ================================================================
87
+ // Organisation phone numbers
88
+ // ================================================================
89
+
90
+ fun getPhoneById (organisationPhoneId : Long ) = syncPhoneService.getPhoneById(organisationPhoneId)
91
+
92
+ fun createPhone (request : SyncCreatePhoneRequest ) = syncPhoneService.createPhone(request)
93
+ .also {
94
+ outboundEventsService.send(
95
+ outboundEvent = OutboundEvent .ORGANISATION_PHONE_CREATED ,
96
+ organisationId = it.organisationId,
97
+ identifier = it.organisationPhoneId,
98
+ source = Source .NOMIS ,
99
+ )
100
+ }
101
+
102
+ fun updatePhone (organisationPhoneId : Long , request : SyncUpdatePhoneRequest ) = syncPhoneService.updatePhone(organisationPhoneId, request)
103
+ .also {
104
+ outboundEventsService.send(
105
+ outboundEvent = OutboundEvent .ORGANISATION_PHONE_UPDATED ,
106
+ organisationId = it.organisationId,
107
+ identifier = it.organisationPhoneId,
108
+ source = Source .NOMIS ,
109
+ )
110
+ }
111
+
112
+ fun deletePhone (organisationPhoneId : Long ) = syncPhoneService.deletePhone(organisationPhoneId)
113
+ .also {
114
+ outboundEventsService.send(
115
+ outboundEvent = OutboundEvent .ORGANISATION_PHONE_DELETED ,
116
+ organisationId = it.organisationId,
117
+ identifier = it.organisationPhoneId,
118
+ source = Source .NOMIS ,
119
+ )
120
+ }
121
+
122
+ // ================================================================
123
+ // Organisation email
124
+ // ================================================================
125
+
126
+ fun getEmailById (organisationEmailId : Long ) = syncEmailService.getEmailById(organisationEmailId)
127
+
128
+ fun createEmail (request : SyncCreateEmailRequest ) = syncEmailService.createEmail(request)
129
+ .also {
130
+ outboundEventsService.send(
131
+ outboundEvent = OutboundEvent .ORGANISATION_EMAIL_CREATED ,
132
+ organisationId = it.organisationId,
133
+ identifier = it.organisationEmailId,
134
+ source = Source .NOMIS ,
135
+ )
136
+ }
137
+
138
+ fun updateEmail (organisationEmailId : Long , request : SyncUpdateEmailRequest ) = syncEmailService.updateEmail(organisationEmailId, request)
139
+ .also {
140
+ outboundEventsService.send(
141
+ outboundEvent = OutboundEvent .ORGANISATION_EMAIL_UPDATED ,
142
+ organisationId = it.organisationId,
143
+ identifier = it.organisationEmailId,
144
+ source = Source .NOMIS ,
145
+ )
146
+ }
147
+
148
+ fun deleteEmail (organisationEmailId : Long ) = syncEmailService.deleteEmail(organisationEmailId)
149
+ .also {
150
+ outboundEventsService.send(
151
+ outboundEvent = OutboundEvent .ORGANISATION_EMAIL_DELETED ,
152
+ organisationId = it.organisationId,
153
+ identifier = it.organisationEmailId,
154
+ source = Source .NOMIS ,
155
+ )
156
+ }
157
+
158
+ // ================================================================
159
+ // Organisation web address
160
+ // ================================================================
161
+
162
+ fun getWebById (organisationWebId : Long ) = syncWebService.getWebAddressById(organisationWebId)
163
+
164
+ fun createWeb (request : SyncCreateWebRequest ) = syncWebService.createWeb(request)
165
+ .also {
166
+ outboundEventsService.send(
167
+ outboundEvent = OutboundEvent .ORGANISATION_WEB_CREATED ,
168
+ organisationId = it.organisationId,
169
+ identifier = it.organisationWebAddressId,
170
+ source = Source .NOMIS ,
171
+ )
172
+ }
173
+
174
+ fun updateWeb (organisationWebId : Long , request : SyncUpdateWebRequest ) = syncWebService.updateWeb(organisationWebId, request)
175
+ .also {
176
+ outboundEventsService.send(
177
+ outboundEvent = OutboundEvent .ORGANISATION_WEB_UPDATED ,
178
+ organisationId = it.organisationId,
179
+ identifier = it.organisationWebAddressId,
180
+ source = Source .NOMIS ,
181
+ )
182
+ }
183
+
184
+ fun deleteWeb (organisationWebId : Long ) = syncWebService.deleteWeb(organisationWebId)
185
+ .also {
186
+ outboundEventsService.send(
187
+ outboundEvent = OutboundEvent .ORGANISATION_WEB_DELETED ,
188
+ organisationId = it.organisationId,
189
+ identifier = it.organisationWebAddressId,
190
+ source = Source .NOMIS ,
191
+ )
192
+ }
193
+
194
+ // ================================================================
195
+ // Organisation address
196
+ // ================================================================
197
+
198
+ fun getAddressById (organisationAddressId : Long ) = syncAddressService.getAddressById(organisationAddressId)
199
+
200
+ fun createAddress (request : SyncCreateAddressRequest ) = syncAddressService.createAddress(request)
201
+ .also {
202
+ outboundEventsService.send(
203
+ outboundEvent = OutboundEvent .ORGANISATION_ADDRESS_CREATED ,
204
+ organisationId = it.organisationId,
205
+ identifier = it.organisationAddressId,
206
+ source = Source .NOMIS ,
207
+ )
208
+ }
209
+
210
+ fun updateAddress (organisationAddressId : Long , request : SyncUpdateAddressRequest ) = syncAddressService.updateAddress(organisationAddressId, request)
211
+ .also {
212
+ outboundEventsService.send(
213
+ outboundEvent = OutboundEvent .ORGANISATION_ADDRESS_UPDATED ,
214
+ organisationId = it.organisationId,
215
+ identifier = it.organisationAddressId,
216
+ source = Source .NOMIS ,
217
+ )
218
+ }
219
+
220
+ fun deleteAddress (organisationAddressId : Long ) = syncAddressService.deleteAddress(organisationAddressId)
221
+ .also {
222
+ outboundEventsService.send(
223
+ outboundEvent = OutboundEvent .ORGANISATION_ADDRESS_DELETED ,
224
+ organisationId = it.organisationId,
225
+ identifier = it.organisationAddressId,
226
+ source = Source .NOMIS ,
227
+ )
228
+ }
69
229
}
0 commit comments