// Entity definition
entity User {
@pk id: int // primary key
@required username: string // required field
@unique email: string // unqiue constraint
role: UserRole = UserRole.USER // refer to enums by Type.Value
// one to many
posts: List<Post> @mappedBy author
}
entity Post {
@pk id: int
title: string
content: string
publishDate: int
published: bool
// many to one
author: User
}
// api endpoint definitions ('controller classes')
api PrivateUsers for User {
generate CRUD // create read update delete
filter search username // GET /users?username=...
}
api PublicUsers for User {
include (username, role, posts) // only return username and role, dont include email
generate READ // only generate read operations for public api
route "users_public"
filter search username
}
//controller class with GetPosts method with optional arguments authorName, authorRole, etc.
api Posts for Post {
generate CRUD
filter search author.username as authorName // ?authorName=...
filter search author.role as authorRole // ?authorRole=...
filter range publishDate // GET /posts?publishDate_min=20050510&publishDate_max=20050510
custom publish(id: int) : PATCH //custom operation PATCH /posts/{id}/publish
} // GET /posts?authorName=gipszjakab&publishDate_min=20050510
// Entity definition
entity User {
@pk id: int // primary key
@required username: string // required field
@unique email: string // unqiue constraint
role: UserRole = UserRole.USER // refer to enums by Type.Value
// one to many
posts: List<Post> @mappedBy author
}
entity Post {
@pk id: int
title: string
content: string
publishDate: int
published: bool
// many to one
author: User
}
// api endpoint definitions ('controller classes')
api PrivateUsers for User {
generate CRUD // create read update delete
filter search username // GET /users?username=...
}
api PublicUsers for User {
include (username, role, posts) // only return username and role, dont include email
generate READ // only generate read operations for public api
route "users_public"
filter search username
}
//controller class with GetPosts method with optional arguments authorName, authorRole, etc.
api Posts for Post {
generate CRUD
filter search author.username as authorName // ?authorName=...
filter search author.role as authorRole // ?authorRole=...
filter range publishDate // GET /posts?publishDate_min=20050510&publishDate_max=20050510
custom publish(id: int) : PATCH //custom operation PATCH /posts/{id}/publish
} // GET /posts?authorName=gipszjakab&publishDate_min=20050510