I am having a harder time than I would like to admit understanding the JSON documentation.
I would like to convert this JSON result to Scala, but I'm pretty lost. I have tried a lot of things, but I'm still learning Scala as well, so none of it is really worth posting as I'm not even sure if it makes sense.
I am using the Anorm ORM in Scala. The id is a Pk[Long]
public static Result checkName(String clubname){
ObjectNode jresult = Json.newObject();
if (Club.clubExists(clubname)) {
jresult.put("error", "Club Name Exists");
return status(409, jresult); // 409 - Conflict
} else {
jresult.put("status", "OK");
return ok(jresult);
}
}
clubExists in the model:
public static boolean clubExists(String name) {
Club club = find.where().eq("club_name", name).findUnique();
return (club != null);
}
The rest of the model is pretty basic:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "club_seq")
public Long clubId;
@Column(unique=true, length = 50)
public String clubName;
public Long creator;
public DateTime created;
public Club(String clubName, Long creator) {
this.clubName = clubName;
this.creator = creator;
this.created = new DateTime();
}
public static Finder<Long, Club> find = new Finder<Long, Club>(Long.class, Club.class);
public static Club create(String name, Long creator) {
Club club = new Club(name, creator);
club.save();
return club;
}