Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.49 KB | None | 0 0
  1. // AssignTariff assigns selected tariff to user
  2. func (m *Message) AssignTariff() Message {
  3.     db := ConnectDB(m.DbConnString)
  4.  
  5.     // check if user already has the same tariff as required
  6.     if userHasSameTariff(db, m) {
  7.         return Message{Passed: false, Errors: "You already have tariff \"" + m.Tariff + "\" assigned to username \"" + m.Username + "\"."}
  8.     }
  9.  
  10.     // check if requiered tariff exists
  11.     if tariffNotExists(db, m) {
  12.         return Message{Passed: false, Errors: "Tariff \"" + m.Tariff + "\" doesn't exist in tightring_tariffs table."}
  13.     }
  14.  
  15.     //check if cluster has enough resources for required tariff
  16.     if clusterOutOfResources(db, m) {
  17.         return Message{Passed: false, Errors: "Not enough free resources for assigning tariff \"" + m.Tariff + "\" to username \"" + m.Username + "\""}
  18.     }
  19.  
  20.     // check if user has more already used resources then required tariff allows
  21.     if userHasTooManyResources(db, m) {
  22.         return Message{Passed: false, Errors: "Username \"" + m.Username + "\" has more used resources than tariff \"" + m.Tariff + "\" allows. Please free resources before changing tariff."}
  23.     }
  24.  
  25.     // actualize user's free resources according to newly applied tariff
  26.     //TODO
  27.  
  28.     // actually change tariff in the tightring_users table
  29.     if !changeTariff(db, m) {
  30.         return Message{Passed: false, Errors: "Error assigning tariff to user(something wrong while processing query)"}
  31.     }
  32.  
  33.     return Message{Passed: true, Errors: "Tariff \"" + m.Tariff + "\" successfully assigned to username \"" + m.Username + "\""}
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement