Skip to content

Commit

Permalink
before graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit18singh committed Mar 19, 2017
1 parent fcc8331 commit 67b081a
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class DashBoardController {
lastUpdated: currentDate,
setPriority: TaskReminder.Priority.LOW
])
println "note:"+taskInstance.taskNote
println "DC:"+taskInstance.dateCreated
println "LD:"+taskInstance.lastUpdated
println "prio:"+taskInstance.setPriority
println "author:"+taskInstance.creatorName
taskInstance.save()
redirect(action: 'index')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,86 @@
package com.expensetracker.Settings

import com.expensetracker.Profile.Profile
import com.expensetracker.SpringSecurity.SecUser
import grails.plugin.springsecurity.annotation.Secured

import com.expensetracker.Learn.Learn

class SettingsController {

def springSecurityService

@Secured(['ROLE_USER'])
def index() { }

def savelearn(String newWord, String newMeaning) {

println params
def userId = SecUser.get(springSecurityService.currentUser.id)
def search = Learn.findByWord(newWord)

if(search){
Learn learnInstance = Learn.get(search.id)
learnInstance.count++
redirect(action: 'learn')
} else {
Learn learnInstance = new Learn(word: newWord, meaning: newMeaning, count: 0L, author: userId)
learnInstance.save()
redirect(action:'learn')

}
}

def learn() {}

def password() {}

def changePassword(String current_password, String new_password, String confirm_password) {

println params
SecUser activeUser = springSecurityService.currentUser
def password_old = current_password
if(!springSecurityService.passwordEncoder.isPasswordValid(activeUser.getPassword(), password_old, null)) {
render "incorrect"

}else {
SecUser changePassword = SecUser.get(springSecurityService.currentUser.id)
changePassword.password = new_password
render "password changed successfully"
}
}

def profile() {

def currentUser = SecUser.get(springSecurityService.currentUser.id)
Profile viewProfileInstance = Profile.findByEmail(currentUser)
println viewProfileInstance
render(view: 'profile', model:[profileDetails: viewProfileInstance])
}

def saveUpdated(String fullname, String username, String gender, Long contact) {

def genderStatus

Profile profileInstance = Profile.findByEmail(SecUser.get(springSecurityService.currentUser.id))
profileInstance.userName = username
profileInstance.contactNumber = contact
profileInstance.fullName = fullname

if(gender == 'Male') {
genderStatus = Profile.Gender.MALE
} else {
genderStatus = Profile.Gender.FEMALE
}

profileInstance.gender = genderStatus

profileInstance.save()
redirect(controller:'settings', action: 'profile')
}

def updateProfile() {

[edited: Profile.findByEmail(SecUser.get(springSecurityService.currentUser.id))]
}
}
140 changes: 129 additions & 11 deletions grails-app/controllers/com/expensetracker/Wallet/WalletController.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package com.expensetracker.Wallet

import com.expensetracker.Expense.Expense
import com.expensetracker.Learn.Learn
import com.expensetracker.Profile.Profile
import com.expensetracker.SpringSecurity.SecUser
import grails.plugin.springsecurity.annotation.Secured

import java.text.BreakIterator

class WalletController {


def springSecurityService


@Secured(['ROLE_USER'])
def index() {}

def learning(String purpose) {
def learning(String purpose, Long amount) {

List<String> deduct = ["bought","purchased","buy","paid"]
List<String> add = ["got","added","credited","gain", "gained"]
List d = Learn.findAllWhere(meaning:'debit')
List deduct = []

d.each { abc ->
deduct.add(abc.word)
}

List c = Learn.findAllWhere(meaning:'credit')
List gain = []

c.each { abc ->
gain.add(abc.word)
}

println purpose
List<String> words = new ArrayList<String>();
BreakIterator breakIterator = BreakIterator.getWordInstance();
breakIterator.setText(purpose);
Expand All @@ -26,14 +45,113 @@ class WalletController {
}
}

println words
println words.size()

def learnInstance = Learn.list().word
println learnInstance

if(words.size()>1) {

if(!learnInstance.contains(words.get(0))){
redirect(controller:'wallet', action: 'learn')
return
} else {
if(!Collections.disjoint(deduct, words)) {

def currentUserId = SecUser.get(springSecurityService.currentUser.id)
def currentDate = new Date()
println "here"
println "amount here:"+amount

Expense expenseInstance = new Expense([
transactionPurpose: purpose,
transactionAmount: amount,
author: currentUserId,
dateCreated: currentDate,
lastUpdated: currentDate,
transactionType: Expense.TransactionType.DEBIT
])

Profile profileInstance = Profile.get(springSecurityService.currentUser.id)
profileInstance.walletAmount -= amount

if(!Collections.disjoint(deduct, words)) {
render "result is a case of deduction"
} else if(!Collections.disjoint(add, words)) {
render "result is a case of addition"
} else {
render "illegal statement."
println profileInstance.walletAmount

profileInstance.save()

if(learnInstance.contains(words.get(2))){
def search = Learn.findByWord(words.get(2))
Learn learnInstanceIncrement = Learn.get(search.id)
learnInstanceIncrement.count++
redirect(controller:'dashBoard',action:'index')
return
} else {
redirect(controller:'wallet', action:'learn')
return
}
println "reached outside"
expenseInstance.save()
println "saved 1"
redirect(controller: 'dashBoard',action:'index')
} else if(!Collections.disjoint(gain, words)) {

def currentUserId = SecUser.get(springSecurityService.currentUser.id)
def currentDate = new Date()
println "here"
println "amount here:"+amount

Expense expenseInstance = new Expense([
transactionPurpose: purpose,
transactionAmount: amount,
author: currentUserId,
dateCreated: currentDate,
lastUpdated: currentDate,
transactionType: Expense.TransactionType.CREDIT
])

Profile profileInstance = Profile.get(springSecurityService.currentUser.id)
profileInstance.walletAmount += amount

println profileInstance.walletAmount

profileInstance.save()
println "saved status: $profileInstance"
if(learnInstance.contains(words.get(2))){
def search = Learn.findByWord(words.get(2))
Learn learnInstanceIncrement = Learn.get(search.id)
learnInstanceIncrement.count++
redirect(controller:'dashBoard',action:'index')
return
} else {
redirect(controller:'wallet', action:'learn')
return
}
println "reached outside"
expenseInstance.save()
println "saved 2"
redirect(controller: 'dashBoard',action:'index')
} else {
render "illegal statement."
return
}
}
}


}

def savelearn(String newWord, String newMeaning) {

println params
def userId = SecUser.get(springSecurityService.currentUser.id)
Learn learnInstance = new Learn(word: newWord, meaning: newMeaning, count: 1L, author: userId)
learnInstance.save()
println learnInstance.word
println learnInstance.meaning
println learnInstance.count
println learnInstance.author
redirect(controller:'wallet',action:'index')
}

def learn() {}
}
20 changes: 20 additions & 0 deletions grails-app/domain/com/expensetracker/Expense/Expense.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
package com.expensetracker.Expense

import com.expensetracker.SpringSecurity.SecUser

class Expense {

Long transactionAmount
String transactionPurpose
Date dateCreated
Date lastUpdated
SecUser author
TransactionType transactionType

static constraints = {
transactionAmount min: 0l, matches:"[0-9]+",blank:false
transactionPurpose blank: false, nullable:false
}

enum TransactionType{
DEBIT(1),CREDIT(2)
final int id

TransactionType(int id) {
this.id = id
}
}
}
10 changes: 10 additions & 0 deletions grails-app/domain/com/expensetracker/Learn/Learn.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.expensetracker.Learn

import com.expensetracker.SpringSecurity.SecUser

class Learn {

String word
String meaning
Long count
SecUser author

static constraints = {
word blank: false, nullable: false
meaning blank: false, nullable: false
count min: 1L
}
}
2 changes: 1 addition & 1 deletion grails-app/views/dashBoard/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<g:if test="resu">
<p>Hello ${resu.userName}</p>
<p>Hello ${resu.userName} you have ${resu.walletAmount} Rs. left in your wallet.</p>
<a href="/logout">Logout</a><br>
<g:link controller="dashBoard" action="reminder">Add Reminder</g:link><br>
<g:link controller="wallet" action="index">Expense</g:link>
Expand Down
8 changes: 8 additions & 0 deletions grails-app/views/settings/index.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head></head>
<body>
<g:link controller="settings" action="learn">Learn</g:link><br>
<g:link controller="settings" action="profile">Profile</g:link><br>
<g:link controller="settings" action="password">Change Password</g:link>
</body>
</html>
11 changes: 11 additions & 0 deletions grails-app/views/settings/learn.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>
</head>
<body>
<g:form controller="settings" action="savelearn" method="post">
<g:textField name="newWord"/>
<g:textField name="newMeaning"/>
<g:submitButton name="save" value="save"/>
</g:form>
</body>
</html>
11 changes: 11 additions & 0 deletions grails-app/views/settings/password.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head></head>
<body>
<g:form controller="settings" action="changePassword" method="post">
<g:passwordField name="current_password"/>
<g:passwordField name="new_password"/>
<g:passwordField name="confirm_password"/>
<g:submitButton name="save" value="save"/>
</g:form>
</body>
</html>
14 changes: 14 additions & 0 deletions grails-app/views/settings/profile.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head></head>
<body>
<g:if test="${profileDetails}">
<p>Full Name: ${profileDetails.fullName}</p>
<p>User Name: ${profileDetails.userName}</p>
<p>Gender: ${profileDetails.gender}</p>
<p>Contact: ${profileDetails.contactNumber}</p>
<p>Email: ${profileDetails.email.username}</p>
<p>Wallet Amount: ${profileDetails.walletAmount}</p>
<g:link controller="settings" action="updateProfile">Edit</g:link>
</g:if>
</body>
</html>
17 changes: 17 additions & 0 deletions grails-app/views/settings/updateProfile.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
</head>
<body>
<g:form controller="settings" action="saveUpdated">
<g:textField name="fullname" value="${edited.fullName}"/>
<g:textField name="username" value="${edited.userName}"/>
<g:textField name="contact" value="${edited.contactNumber}"/>
<select class="form-control" name="gender" id="gender" required="required">
<option disabled selected value="">--Select a status--</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<g:submitButton name="save" value="save"/>
</g:form>
</body>
</html>
3 changes: 2 additions & 1 deletion grails-app/views/wallet/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
</head>
<body>
<g:form controller="wallet" action="learning" method="post">
<g:textArea name="purpose" class="form-control"/>
<g:textArea name="amount" placeholder="amount"/>
<g:textArea name="purpose" class="form-control" placeholder="eg: purchased mango"/>
<g:submitButton name="submit" class="save"/>
</g:form>
</body>
Expand Down
Loading

0 comments on commit 67b081a

Please sign in to comment.