Created
May 20, 2015 11:07
-
-
Save atwayne/fbd63914128f0eee30ef to your computer and use it in GitHub Desktop.
services.ongoing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jiaker = window.jiaker || {}; | |
jiaker.services = angular.module('services', ['ngResource', 'ngCordova']); | |
// ------------------------------------ | |
// CityService | |
// ------------------------------------ | |
// GET /city | |
// GET /city/location/{latitude}/{longitude} | |
jiaker.services.factory('CityService', function ($resource) { | |
var city = $resource(jiaker.settings.service + '/city'); | |
var byCoordinate = $resource(jiaker.settings.service + '/city/location/:latitude/:longitude'); | |
return { | |
GetAllCities: function () { | |
return city.query(); | |
}, | |
GetByCoordinate: function (latitude, longitude) { | |
return byCoordinate.get({ latitude: latitude, longitude: longitude }); | |
} | |
} | |
}); | |
// ------------------------------------ | |
// AttachmentService | |
// ------------------------------------ | |
// GET /attachment/{id} | |
// POST /attachment | |
jiaker.services.factory('AttachmentService', function ($resource) { | |
var attachment = $resource(jiaker.settings.service + '/attachment/:id'); | |
return { | |
GetById: function (id) { | |
return remote.get({ id: id }); | |
}, | |
UploadImage: function (imageURI, mimeType, onUploadSuccessfully, onUplodFailed) { | |
if (!mimeType) { | |
mimeType = 'image/jpeg'; | |
} | |
var uploadUrl = jiaker.settings.service + '/attachment'; | |
var options = new FileUploadOptions(); | |
options.fileKey = "file"; | |
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);; | |
options.mimeType = mimeType; | |
var transfer = new FileTransfer(); | |
transfer.upload(imageURI, uploadUrl, onUploadSuccessfully, onUplodFailed, options); | |
} | |
} | |
}); | |
// ------------------------------------ | |
// AvatarService | |
// ------------------------------------ | |
// GET /user/{id}/avatar | |
// POST /user/{id}/avatar | |
jiaker.services.factory('AvatarService', function ($resource, AttachmentService) { | |
var avatar = $resource(jiaker.settings.service + '/user/:id/avatar'); | |
return { | |
GetByUserId: function (id) { | |
return avatar.get({ id: id }); | |
}, | |
SetAvatar: function (userId, imageURI, mimeType, onUploadSuccessfully, onUplodFailed) { | |
var postUploadProcess = function (response) { | |
if (_.isFunction(onUploadSuccessfully)) { | |
onUploadSuccessfully(response); | |
} | |
var record = JSON.parse(response); | |
var userAvatar = avatar.get({ id: userId }); | |
userAvatar.avatarId = record.Id; | |
userAvatar.$save(); | |
} | |
return AttachmentService.UploadImage(imageURI, mimeType, onUploadSuccessfully, onUplodFailed); | |
} | |
}; | |
}); | |
// ------------------------------------ | |
// CategoryService | |
// ------------------------------------ | |
// GET /event/categories | |
// POST /event/categories | |
// GET /place/categories | |
// POST /place/categories | |
// GET /post/categories | |
// POST /post/categories | |
jiaker.services.factory('CategoryService', function ($resource) { | |
var category = $resource(jiaker.settings.service + '/:type/categories'); | |
return { | |
GetByCategoryType: function (categoryType) { | |
return | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment