Reputation: 23
I'm trying to find some concrete examples with google cloud end points and objectify. I've already found some with either end-points or objectify but none that combines both of them.
Upvotes: 1
Views: 369
Reputation: 4870
Same problem than you when I started to learn objectify and endpoints.
Here is a tuto from website (Sorry that's in french): http://blog.xebia.fr/2014/06/23/google-app-engine-cloud-endpoint-creer-notre-api-v2-et-lutiliser-avec-angularjs/
EDIT: You can find in english, this amazing website which explain in details my code below : http://rominirani.com/2014/08/26/gradle-tutorial-part-9-cloud-endpoints-persistence-android-studio/
In simple, you have to have three classes:
Your object :
@Entity
@Index
public class User {
@Id private String num_portable;
private Boolean sexe;
private int date_naissance;
//Constructeur par défaut (Obligatoire pour Objectify)
public User(){}
public User (String num_portable, Boolean sexe, int date_naissance){
this.num_portable=num_portable; //Numéro de portable user
this.sexe=sexe;
this.date_naissance=date_naissance;
}
/**
* GETTER
*/
public String getId(){
return num_portable;
}
public String getNum_portable() {
return num_portable;
}
public Boolean getsexe(){
return sexe;
}
public int getdate_naissance(){
return date_naissance;
}
/**
* SETTER
*/
public void setsexe(Boolean sexe){
this.sexe=sexe;
}
public void setdate_naissance(int date_naissance){
this.date_naissance=date_naissance;
}
}
Your class to do CRUD operations:
public class UserCRUD {
private static UserCRUD user_crud = null;
private static final Logger log = Logger.getLogger(UserCRUD.class.getName());
static {
ObjectifyService.register(User.class);
}
private UserCRUD (){
}
public static synchronized UserCRUD getInstance() {
if (null == user_crud) {
user_crud = new UserCRUD();
}
return user_crud;
}
public User findUser(String NumeroPhone) {
User user = ofy().load().type(User.class).id(NumeroPhone).now();
return user;
}
}
Your endpoint class, which called by your endpoint (when you generated endpoint API):
@Api(
name = "userendpoint",
version = "v1"
)
public class UserEndPoint {
@ApiMethod(name = "FindUser", httpMethod = ApiMethod.HttpMethod.GET)
public User getUser(@Named("numero_portable") String NumPortable){
return UserCRUD.getInstance().findUser(NumPortable);
}
}
Hope that will help you,
Upvotes: 2