1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Database and data model to be used by servers and clients
23 # A beer, with a name and description
33 # Description on the Web site
36 redef fun to_s
do return "<{name}: {desc}>"
39 # A collection of beer-related events
43 # New beers on the menu
44 var new_beers
= new Array[Beer]
46 # Beers that have left the menu
47 var gone_beers
= new Array[Beer]
49 # Beers that are on the menu today, and yesterday
50 var fix_beers
= new Array[Beer]
52 # Get a human pretty `Array[String]` version of `self`
53 fun to_email_content
: Array[String]
55 var content
= new Array[String]
58 for beer
in self.new_beers
do
59 content
.add
"+ {beer.name}: {beer.desc}"
63 for beer
in self.gone_beers
do
64 content
.add
"- {beer.name}: {beer.desc}"
68 for beer
in self.fix_beers
do
69 content
.add
" {beer.name}: {beer.desc}"
75 # Get a pretty and short version of `self`
76 fun to_email_title
: String
79 var new_beers_name
= new Array[String]
80 for beer
in self.new_beers
do new_beers_name
.add beer
.name
82 if not new_beers_name
.is_empty
then
83 return " (+ {new_beers_name.join(", ")})"
90 # Basic user public information
94 # ID of this user in the DB
100 redef fun to_s
do return "<{class_name} {id} '{name}'>"
103 # User public information in reference to a user (medium details level)
104 class UserAndFollowing
107 # Basic user information
110 # Favorite beers as a string
113 # Is the reference user following `user`?
116 # Is the reference user followed by `user`?
119 # Time of the last check in, if `followed`
120 var last_check_in
: nullable String = null
123 # Review by `author` on a `beer`
127 # Basic author information
130 # Basic beer information
136 # Text content of this review, may be empty
140 # Statistics of the reviews on `beer`
144 # Basic beer information
147 # Average rating out of 5
150 # Number of reviews used for these statistics
154 # Beer information in reference to a user (medium detail level)
158 # Basic beer information
161 # Global statistics on `beer`
162 var global
: nullable BeerStats
164 # Statistics on `beer` among followed users only
165 var followed
: nullable BeerStats
167 # Rating left by the referenced user, if any
168 var user_rating
: nullable Int
170 # Do we predict this `beer` to go quickly?
171 var will_go_fast
: Bool
173 # Data of appearance of this batch TODO
176 # Is this beer new since the last work day?
179 # Has this beer been here since the last work day?
182 # Has this beer left the menu since the last work day?
185 # Noteworthy comments on this beer, often relative to a user
186 var badges
: nullable Array[BeerBadge] = null is writable
189 # Noteworthy comment on a beer
190 abstract class BeerBadge
194 # A beer is the favorite of `users`
195 class FavoriteBeerBadge
199 # Name of the user fan of the beer
200 var users
= new Array[String]
203 # A beer is similar to `beers`
204 class SimilarBeerBadge
208 # Names of the similar beers
209 var beers
= new Array[String]
212 # This beer is the best on the menu
218 # Result of a login or signup request upon success
222 # Basic user information
229 # Report pushed to followed_followers when a user checks in or out
234 var users
= new Array[User]
237 # Daily menu notifications
238 class DailyNotification
241 # All beers on the menu today
242 var beers
: Array[BeerAndRatings]
245 # Server or API usage error
250 # Error message that can be shown to the user
251 var user_message
: nullable String
254 # Client sent an invalid token
255 class BenitluxTokenError
261 # Is `self` a valid user name?
264 if length
< 4 or length
> 16 then return false
267 if c
.is_whitespace
or c
.code_point
== 0xFFFD then return false
273 # Is `self` a valid password?
274 fun pass_is_ok
: Bool do return length
>= 6
276 # Hashed Benitlux password
277 fun pass_hash
: String do return (to_s
+benitlux_salt
).md5
280 # Salt used on passwords
282 # Should be refined by user modules.
283 fun benitlux_salt
: String do return "Vive le ben!"