(function () { 'use strict'; var serviceId = 'showboardsAdminDataContext'; angular.module('showboardsAdmin').factory(serviceId, ['$q', '$http', 'showboardsAdminConfig', datacontext]); function datacontext($q, $http, config, $modal) { var service = { getAllMyShowboards: getAllMyShowboards, createShowboard: createShowboard, updateShowboard: updateShowboard, getShowboardById: getShowboardById, createShowboardItem: createShowboardItem, updateShowboardItem: updateShowboardItem, deleteShowboard: deleteShowboard, getShowcases: getShowcases, updateShowboardView: updateShowboardView, updateShowboardItemView: updateShowboardItemView, reportShowboard: reportShowboard, getNewShowboardReports: getNewShowboardReports, reportShowboardItem: reportShowboardItem, updateShowboardItemReport: updateShowboardItemReport, favouriteShowboardItem: favouriteShowboardItem, pinShowboard: pinShowboard, likeShowboardItem: likeShowboardItem, likeShowboard: likeShowboard, withdrawShowboardItem: withdrawShowboardItem }; return service; function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } function getAllMyShowboards() { var request = $http({ method: "get", url: config.showboardsUrl + 'api/showboardsmanager', }); return (request.then(handleSuccess, handleError)); } function createShowboard(showboard) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboardsmanager', data: showboard }); return (request.then(handleSuccess, handleError)); } function updateShowboard(showboard) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboardsmanager/' + showboard.id, data: showboard }); return (request.then(handleSuccess, handleError)); } function deleteShowboard(showboard) { var request = $http({ method: "delete", url: config.showboardsUrl + 'api/showboardsmanager/' + showboard.id, }); return (request.then(handleSuccess, handleError)); } function getShowboardById(showboardId) { var request = $http({ method: "get", url: config.showboardsUrl + 'api/showboardsmanager/' + showboardId, }); return (request.then(handleSuccess, handleError)); } function createShowboardItem(showboard) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboarditems', data: showboard }); return (request.then(handleSuccess, handleError)); } function updateShowboardItem(showboardItem) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboarditems/' + showboardItem.id, data: showboardItem }); return (request.then(handleSuccess, handleError)); } function withdrawShowboardItem(showboardItem) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboarditemsmanager/withdrawn/' + showboardItem.id, data: showboardItem }); return (request.then(handleSuccess, handleError)); } function updateShowboardView(showboard) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboardsmanager/numtimesviewed/' + showboard.id, }); return (request.then(handleSuccess, handleError)); } function updateShowboardItemView(showboardItem) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboarditems/numtimesviewed/' + showboardItem.id, }); return (request.then(handleSuccess, handleError)); } function reportShowboard(showboard, reason) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboardissuereports', data: { reportedShowBoardId: showboard.id, reason: reason } }); return (request.then(handleSuccess, handleError)); } function reportShowboardItem(showboardItem, reason) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboarditemissuereports', data: { reportedShowBoardItemId: showboardItem.id, reason: reason, reasonComment: showboardItem.reasonComment } }); return (request.then(handleSuccess, handleError)); } function updateShowboardItemReport(showboardItem) { var request = $http({ method: "put", url: config.showboardsUrl + 'api/showboarditemissuereports', data: showboardItem }); return (request.then(handleSuccess, handleError)); } function getNewShowboardReports(showboardItem) { var request = $http({ method: "get", url: config.showboardsUrl + 'api/showboardissuereports/new', }); return (request.then(handleSuccess, handleError)); } function favouriteShowboardItem(showboardItem) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboarditems/favourites', data: showboardItem }); return (request.then(handleSuccess, handleError)); } function likeShowboardItem(showboardItem) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboarditems/likes', data: showboardItem }); return (request.then(handleSuccess, handleError)); } function likeShowboard(showboard) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboards/likes', data: showboard }); return (request.then(handleSuccess, handleError)); } function pinShowboard(showboard) { var request = $http({ method: "post", url: config.showboardsUrl + 'api/showboards/pinned', data: showboard }); return (request.then(handleSuccess, handleError)); } //get all showcases for the user function getShowcases() { //if not get from server and add to cache var request = $http({ method: "get", url: myShowcaseSiteUrl + 'api/showcase/' }); return (request.then(function (response) { return response.data; }, handleError)); } } })();