Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AssignTariff assigns selected tariff to user
- func (m *Message) AssignTariff() Message {
- db := ConnectDB(m.DbConnString)
- // check if user already has the same tariff as required
- if userHasSameTariff(db, m) {
- return Message{Passed: false, Errors: "You already have tariff \"" + m.Tariff + "\" assigned to username \"" + m.Username + "\"."}
- }
- // check if requiered tariff exists
- if tariffNotExists(db, m) {
- return Message{Passed: false, Errors: "Tariff \"" + m.Tariff + "\" doesn't exist in tightring_tariffs table."}
- }
- //check if cluster has enough resources for required tariff
- if clusterOutOfResources(db, m) {
- return Message{Passed: false, Errors: "Not enough free resources for assigning tariff \"" + m.Tariff + "\" to username \"" + m.Username + "\""}
- }
- // check if user has more already used resources then required tariff allows
- if userHasTooManyResources(db, m) {
- return Message{Passed: false, Errors: "Username \"" + m.Username + "\" has more used resources than tariff \"" + m.Tariff + "\" allows. Please free resources before changing tariff."}
- }
- // actualize user's free resources according to newly applied tariff
- //TODO
- // actually change tariff in the tightring_users table
- if !changeTariff(db, m) {
- return Message{Passed: false, Errors: "Error assigning tariff to user(something wrong while processing query)"}
- }
- return Message{Passed: true, Errors: "Tariff \"" + m.Tariff + "\" successfully assigned to username \"" + m.Username + "\""}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement