diff --git a/app/Http/Controllers/Contacts/GiftController.php b/app/Http/Controllers/Contacts/GiftController.php new file mode 100644 index 00000000000..600c70c7dad --- /dev/null +++ b/app/Http/Controllers/Contacts/GiftController.php @@ -0,0 +1,124 @@ +gifts() + ->orderBy('created_at', 'asc') + ->paginate(); + + return GiftResource::collection($gifts); + } + + /** + * Get the detail of a given gift. + * + * @param Request $request + * @param Gift $gift + * @return GiftResource|\Illuminate\Http\JsonResponse + */ + public function show(Request $request, Contact $contact, Gift $gift) + { + return new GiftResource($gift); + } + + /** + * Store the gift. + * + * @param Request $request + * @return GiftResource|\Illuminate\Http\JsonResponse + */ + public function store(Request $request, Contact $contact) + { + $gift = app(CreateGift::class)->execute( + $request->except(['account_id', 'contact_id']) + + [ + 'account_id' => auth()->user()->account_id, + 'contact_id' => $contact->id, + ] + ); + + return new GiftResource($gift); + } + + /** + * Update the gift. + * + * @param Request $request + * @param Gift $gift + * @return GiftResource|\Illuminate\Http\JsonResponse + */ + public function update(Request $request, Contact $contact, Gift $gift) + { + $gift = app(UpdateGift::class)->execute( + $request->except(['account_id', 'contact_id', 'gift_id']) + + [ + 'account_id' => auth()->user()->account_id, + 'contact_id' => $contact->id, + 'gift_id' => $gift->id, + ] + ); + + return new GiftResource($gift); + } + + /** + * Associate a photo to the gift. + * + * @param Request $request + * @param Gift $gift + * @param Photo $photo + * @return GiftResource|\Illuminate\Http\JsonResponse + */ + public function associate(Request $request, Contact $contact, Gift $gift, Photo $photo) + { + $gift = app(AssociatePhotoToGift::class)->execute([ + 'account_id' => auth()->user()->account_id, + 'gift_id' => $gift->id, + 'photo_id' => $photo->id, + ]); + + return new GiftResource($gift); + } + + /** + * Delete a gift. + * + * @param Request $request + * @param Gift $gift + * @return \Illuminate\Http\JsonResponse + */ + public function destroy(Request $request, Contact $contact, Gift $gift) + { + app(DestroyGift::class)->execute([ + 'account_id' => auth()->user()->account_id, + 'gift_id' => $gift->id, + ]); + + return $this->respondObjectDeleted($gift->id); + } +} diff --git a/resources/js/components/people/gifts/CreateGift.vue b/resources/js/components/people/gifts/CreateGift.vue index 80b7488d33f..2b50d5cfed1 100644 --- a/resources/js/components/people/gifts/CreateGift.vue +++ b/resources/js/components/people/gifts/CreateGift.vue @@ -242,6 +242,10 @@ export default { }, props: { + hash: { + type: String, + default: '', + }, contactId: { type: Number, default: 0, @@ -386,7 +390,8 @@ export default { } const method = this.gift ? 'put' : 'post'; - const url = this.gift ? 'api/gifts/'+this.gift.id : 'api/gifts'; + const url = `people/${this.hash}/gifts${this.gift ? '/'+this.gift.id : ''}`; + const vm = this; axios[method](url, this.newGift) @@ -417,7 +422,7 @@ export default { return this.$refs.upload.forceFileUpload() .then(photo => { if (photo !== undefined) { - axios.put('api/gifts/'+response.data.data.id+'/photo/'+photo.id); + axios.put(`people/${this.hash}/gifts/${response.data.data.id}/photo/${photo.id}`); response.data.data.photos.push(photo); } return response; @@ -437,7 +442,7 @@ export default { }, deletePhoto(photo) { - axios.delete('api/photos/' + photo.id) + axios.delete(`people/${this.hash}/photos/${photo.id}`) .then(response => { this.photos.splice(this.photos.indexOf(photo), 1); if (this.photos.length == 0) { diff --git a/resources/js/components/people/gifts/Gifts.vue b/resources/js/components/people/gifts/Gifts.vue index 687a3f62f4a..22b975b468e 100644 --- a/resources/js/components/people/gifts/Gifts.vue +++ b/resources/js/components/people/gifts/Gifts.vue @@ -17,6 +17,7 @@