<commit_before>/*
 * Service for more Detail from java
 */

var Service = Class(function(){
  var request = require('request');

  var API_REQUEST = request.defaults({
    baseUrl : 'http://' + C('api_host') + ':8080/' + C('api_host_part') + '-1.0.0-SNAPSHOT/api/1.0/'
  });

  function getRequst(url,data){
    var deferred = getDefer();
    API_REQUEST(url + "?" + toQueryString(data),function(err, response, body){
      if(err){
        deferred.reject(err)
      }else if(response && (response.statusCode == 200 || response.statusCode == 201)){
        var res = "";
        try{
          try{
            deferred.resolve(JSON.parse(body));
          }catch(e){
            deferred.resolve(body);
          }
        }catch(e){
          deferred.reject(e)
        }
      }
    })
    return deferred.promise;
  }

  return {
    /*Course API*/
    getAllCourses : function(data){
      return getRequst('course/retrieve', extend({_returntype : "detail"}, data));
    },

    getCourseById : function(data){
      return getRequst('course/retrieve',  extend({_returntype : "detail"}, data));
    },

    getCourseOrderByWeight : function(data){
      return getRequst('course/retrieve',  extend({_returntype : "detail", _desc:true ,_ordertype : 'int' , _orderby : 'weight'}, data));
    },

    getCoursesByTag : function(data){
      return getRequst('course/retrieve', extend({_returntype : "detail"}, data));
    },

    getCoursesByPartnerId : function(data){
      return getRequst('course/retrieve', extend({_returntype:'detail'}, data))
    },

    searchCourses : function(data){
      return getRequst('course/search' , extend({_returntype : "detail"}, data));
    },

    setCourseData : function(data){
      return getRequst('course/update', data);
    },

    addCourse : function(data){
      return getRequst('course/create', data);
    },

    /*Resource API*/

    getResourcesByCourseId : function(data){
      return getRequst('resource/retrieve' , extend({_returntype : "detail" ,_orderby : "weight", _ordertype:"int", _desc: false}, data));
    },

    getResourceById : function(data){
      return getRequst('resource/retrieve', extend({_returntype : "detail" }, data));
    },

    addResource : function(data){
      return getRequest('resource/create' , data);
    },

    /*Partner API*/
    getAllPartners : function(data){
      return getRequst('partner/retrieve', extend({_returntype:'detail'}, data));
    },

    getPartnerById : function(data){
      return getRequst('partner/retrieve', extend({_returntype:'detail'}, data));
    },

    addPartner : function(data){
      return getRequst('partner/create' , data);
    },

    // deletePartners : function(){
    //   return
    // }

    /*Teaacher API*/

    getALlTeachers : function(data){
      return getRequst('teacher/retrieve', extend({_returntype:'detail'}, data));
    },

    getTeachersByCourseId : function(data){
      return getRequst('teacher/retrieve', extend({_returntype:'detail'}, data));
    },

    addTeacher : function(data){
      return getRequst('teacher/create' , data);
    },

    /*User API*/
    createUser : function(data){
      return getRequst('user/create',data);
    },

    loginUser : function(data){
      return getRequst('user/login',data);
    },

    checkEmail : function(data){
      return getRequst('user/retrieve',data);
    },

    getUserById : function(data){
      return getRequst('user/retrieve', extend({'_returntype':'detail'} ,data))
    },<commit_msg>fix bug by wangpengfei<commit_after>/*
 * Service for more Detail from java
 */

var Service = Class(function(){
  var request = require('request');

  var API_REQUEST = request.defaults({
    baseUrl : 'http://' + C('api_host') + ':8080/' + C('api_host_part') + '-1.0.0-SNAPSHOT/api/1.0/'
  });

  function getRequst(url,data){
    var deferred = getDefer();
    API_REQUEST(url + "?" + toQueryString(data),function(err, response, body){
      if(err){
        deferred.reject(err)
      }else if(response && (response.statusCode == 200 || response.statusCode == 201)){
        var res = "";
        try{
          try{
            deferred.resolve(JSON.parse(body));
          }catch(e){
            deferred.resolve(body);
          }
        }catch(e){
          deferred.reject(e)
        }
      }
    })
    return deferred.promise;
  }

  return {
    /*Course API*/
    getAllCourses : function(data){
      return getRequst('course/retrieve', extend({_returntype : "detail"}, data));
    },

    getCourseById : function(data){
      return getRequst('course/retrieve',  extend({_returntype : "detail"}, data));
    },

    getCourseOrderByWeight : function(data){
      return getRequst('course/retrieve',  extend({_returntype : "detail", _desc:true ,_ordertype : 'int' , _orderby : 'weight'}, data));
    },

    getCoursesByTag : function(data){
      return getRequst('course/retrieve', extend({_returntype : "detail"}, data));
    },

    getCoursesByPartnerId : function(data){
      return getRequst('course/retrieve', extend({_returntype:'detail'}, data))
    },

    searchCourses : function(data){
      return getRequst('course/search' , extend({_returntype : "detail"}, data));
    },

    setCourseData : function(data){
      return getRequst('course/update', data);
    },

    addCourse : function(data){
      return getRequst('course/create', data);
    },

    /*Resource API*/

    getResourcesByCourseId : function(data){
      return getRequst('resource/retrieve' , extend({_returntype : "detail" ,_orderby : "weight", _ordertype:"int", _desc: false}, data));
    },

    getResourceById : function(data){
      return getRequst('resource/retrieve', extend({_returntype : "detail" }, data));
    },

    addResource : function(data){
      return getRequest('resource/create' , data);
    },

    /*Partner API*/
    getAllPartners : function(data){
      return getRequst('partner/retrieve', extend({_returntype:'detail'}, data));
    },

    getPartnerById : function(data){
      return getRequst('partner/retrieve', extend({_returntype:'detail'}, data));
    },

    addPartner : function(data){
      return getRequst('partner/create' , data);
    },

    deletePartnerById : function(data){
      return getRequst('partner/delete', data);
    },

    /*Teaacher API*/

    getALlTeachers : function(data){
      return getRequst('teacher/retrieve', extend({_returntype:'detail'}, data));
    },

    getTeachersByCourseId : function(data){
      return getRequst('teacher/retrieve', extend({_returntype:'detail'}, data));
    },

    addTeacher : function(data){
      return getRequst('teacher/create' , data);
    },

    /*User API*/
    createUser : function(data){
      return getRequst('user/create',data);
    },

    loginUser : function(data){
      return getRequst('user/login',data);
    },

    checkEmail : function(data){
      return getRequst('user/retrieve',data);
    },

    getUserById : function(data){
      return getRequst('user/retrieve', extend({'_returntype':'detail'} ,data))
    },
{'fraction_non_alphanumeric': 0.16097491852061782, 'fraction_numerical': 0.0042510982003684285, 'mean_word_length': 3.117852975495916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7189426', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2175, 'n_words': 397}