2727namespace OCA \DAV \Controller ;
2828
2929use DateTimeImmutable ;
30- use OCA \DAV \Db \AbsenceMapper ;
3130use OCA \DAV \ResponseDefinitions ;
3231use OCA \DAV \Service \AbsenceService ;
3332use OCP \AppFramework \Db \DoesNotExistException ;
3635use OCP \AppFramework \Http \DataResponse ;
3736use OCP \AppFramework \OCSController ;
3837use OCP \IRequest ;
38+ use OCP \IUserManager ;
3939use OCP \IUserSession ;
4040use OCP \User \IAvailabilityCoordinator ;
4141
4242/**
4343 * @psalm-import-type DAVOutOfOfficeData from ResponseDefinitions
44+ * @psalm-import-type DAVCurrentOutOfOfficeData from ResponseDefinitions
4445 */
4546class OutOfOfficeController extends OCSController {
4647
4748 public function __construct (
4849 string $ appName ,
4950 IRequest $ request ,
50- private AbsenceMapper $ absenceMapper ,
51+ private IUserManager $ userManager ,
5152 private ?IUserSession $ userSession ,
5253 private AbsenceService $ absenceService ,
5354 private IAvailabilityCoordinator $ coordinator ,
@@ -59,15 +60,45 @@ public function __construct(
5960 * Get the currently configured out-of-office data of a user.
6061 *
6162 * @param string $userId The user id to get out-of-office data for.
62- * @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData , array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
63+ * @return DataResponse<Http::STATUS_OK, DAVCurrentOutOfOfficeData , array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
6364 *
6465 * 200: Out-of-office data
6566 * 404: No out-of-office data was found
6667 */
6768 #[NoAdminRequired]
6869 public function getCurrentOutOfOfficeData (string $ userId ): DataResponse {
70+ $ user = $ this ->userManager ->get ($ userId );
71+ if ($ user === null ) {
72+ return new DataResponse (null , Http::STATUS_NOT_FOUND );
73+ }
74+ try {
75+ $ data = $ this ->absenceService ->getCurrentAbsence ($ user );
76+ if ($ data === null ) {
77+ return new DataResponse (null , Http::STATUS_NOT_FOUND );
78+ }
79+ } catch (DoesNotExistException ) {
80+ return new DataResponse (null , Http::STATUS_NOT_FOUND );
81+ }
82+
83+ return new DataResponse ($ data ->jsonSerialize ());
84+ }
85+
86+ /**
87+ * Get the configured out-of-office data of a user.
88+ *
89+ * @param string $userId The user id to get out-of-office data for.
90+ * @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
91+ *
92+ * 200: Out-of-office data
93+ * 404: No out-of-office data was found
94+ */
95+ #[NoAdminRequired]
96+ public function getOutOfOffice (string $ userId ): DataResponse {
6997 try {
70- $ data = $ this ->absenceMapper ->findByUserId ($ userId );
98+ $ data = $ this ->absenceService ->getAbsence ($ userId );
99+ if ($ data === null ) {
100+ return new DataResponse (null , Http::STATUS_NOT_FOUND );
101+ }
71102 } catch (DoesNotExistException ) {
72103 return new DataResponse (null , Http::STATUS_NOT_FOUND );
73104 }
0 commit comments