Compare commits
1 Commits
icon
...
90c64f2ca6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90c64f2ca6 |
@@ -764,6 +764,7 @@ func TestAddAllowanceSimple(t *testing.T) {
|
||||
createTestAllowance(e, "Test Allowance 1", 1000, 1)
|
||||
|
||||
request := map[string]interface{}{
|
||||
"id": 1,
|
||||
"amount": 10,
|
||||
"description": "Added to allowance 1",
|
||||
}
|
||||
@@ -790,6 +791,7 @@ func TestAddAllowanceWithSpillage(t *testing.T) {
|
||||
e.PUT("/user/1/allowance/0").WithJSON(UpdateAllowanceRequest{Weight: 1}).Expect().Status(200)
|
||||
|
||||
request := map[string]interface{}{
|
||||
"id": 1,
|
||||
"amount": 10,
|
||||
"description": "Added to allowance 1",
|
||||
}
|
||||
@@ -814,89 +816,6 @@ func TestAddAllowanceWithSpillage(t *testing.T) {
|
||||
history.Value(0).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
}
|
||||
|
||||
func TestAddAllowanceIdZero(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
createTestAllowance(e, "Test Allowance 1", 1000, 1)
|
||||
|
||||
request := map[string]interface{}{
|
||||
"amount": 10,
|
||||
"description": "Added to allowance 1",
|
||||
}
|
||||
e.POST("/user/1/allowance/0/add").WithJSON(request).Expect().Status(200)
|
||||
|
||||
// Verify the allowance is updated
|
||||
allowances := e.GET("/user/1/allowance").Expect().Status(200).JSON().Array()
|
||||
allowances.Value(0).Object().Value("id").Number().IsEqual(0)
|
||||
allowances.Value(0).Object().Value("progress").Number().InDelta(10.0, 0.01)
|
||||
|
||||
// Verify the history is updated
|
||||
history := e.GET("/user/1/history").Expect().Status(200).JSON().Array()
|
||||
history.Length().IsEqual(1)
|
||||
history.Value(0).Object().Value("allowance").Number().InDelta(10.0, 0.01)
|
||||
history.Value(0).Object().Value("timestamp").String().AsDateTime().InRange(getDelta(time.Now(), 2.0))
|
||||
history.Value(0).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
}
|
||||
|
||||
func TestSubtractAllowanceSimple(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
createTestAllowance(e, "Test Allowance 1", 1000, 1)
|
||||
|
||||
request := map[string]interface{}{
|
||||
"amount": 10,
|
||||
"description": "Added to allowance 1",
|
||||
}
|
||||
e.POST("/user/1/allowance/1/add").WithJSON(request).Expect().Status(200)
|
||||
request["amount"] = -2.5
|
||||
e.POST("/user/1/allowance/1/add").WithJSON(request).Expect().Status(200)
|
||||
|
||||
// Verify the allowance is updated
|
||||
allowances := e.GET("/user/1/allowance").Expect().Status(200).JSON().Array()
|
||||
allowances.Value(1).Object().Value("id").Number().IsEqual(1)
|
||||
allowances.Value(1).Object().Value("progress").Number().InDelta(7.5, 0.01)
|
||||
|
||||
// Verify the history is updated
|
||||
history := e.GET("/user/1/history").Expect().Status(200).JSON().Array()
|
||||
history.Length().IsEqual(2)
|
||||
history.Value(0).Object().Value("allowance").Number().InDelta(10.0, 0.01)
|
||||
history.Value(0).Object().Value("timestamp").String().AsDateTime().InRange(getDelta(time.Now(), 2.0))
|
||||
history.Value(0).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
|
||||
history.Value(1).Object().Value("allowance").Number().InDelta(-2.5, 0.01)
|
||||
history.Value(1).Object().Value("timestamp").String().AsDateTime().InRange(getDelta(time.Now(), 2.0))
|
||||
history.Value(1).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
}
|
||||
|
||||
func TestSubtractllowanceIdZero(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
createTestAllowance(e, "Test Allowance 1", 1000, 1)
|
||||
|
||||
request := map[string]interface{}{
|
||||
"amount": 10,
|
||||
"description": "Added to allowance 1",
|
||||
}
|
||||
e.POST("/user/1/allowance/0/add").WithJSON(request).Expect().Status(200)
|
||||
request["amount"] = -2.5
|
||||
e.POST("/user/1/allowance/0/add").WithJSON(request).Expect().Status(200)
|
||||
|
||||
// Verify the allowance is updated
|
||||
allowances := e.GET("/user/1/allowance").Expect().Status(200).JSON().Array()
|
||||
allowances.Value(0).Object().Value("id").Number().IsEqual(0)
|
||||
allowances.Value(0).Object().Value("progress").Number().InDelta(7.5, 0.01)
|
||||
|
||||
// Verify the history is updated
|
||||
history := e.GET("/user/1/history").Expect().Status(200).JSON().Array()
|
||||
history.Length().IsEqual(2)
|
||||
history.Value(0).Object().Value("allowance").Number().InDelta(10.0, 0.01)
|
||||
history.Value(0).Object().Value("timestamp").String().AsDateTime().InRange(getDelta(time.Now(), 2.0))
|
||||
history.Value(0).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
|
||||
history.Value(1).Object().Value("allowance").Number().InDelta(-2.5, 0.01)
|
||||
history.Value(1).Object().Value("description").String().IsEqual("Added to allowance 1")
|
||||
}
|
||||
|
||||
func getDelta(base time.Time, delta float64) (time.Time, time.Time) {
|
||||
start := base.Add(-time.Duration(delta) * time.Second)
|
||||
end := base.Add(time.Duration(delta) * time.Second)
|
||||
|
||||
@@ -561,41 +561,6 @@ func (db *Db) AddAllowanceAmount(userId int, allowanceId int, request AddAllowan
|
||||
return err
|
||||
}
|
||||
|
||||
if allowanceId == 0 {
|
||||
if remainingAmount < 0 {
|
||||
var userBalance int
|
||||
err = tx.Query("select balance from users where id = ?").
|
||||
Bind(userId).ScanSingle(&userBalance)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if remainingAmount > userBalance {
|
||||
return fmt.Errorf("cannot remove more than the current balance: %d", userBalance)
|
||||
}
|
||||
}
|
||||
err = tx.Query("update users set balance = balance + ? where id = ?").
|
||||
Bind(remainingAmount, userId).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if remainingAmount < 0 {
|
||||
var progress int
|
||||
err = tx.Query("select balance from allowances where id = ? and user_id = ?").
|
||||
Bind(allowanceId, userId).ScanSingle(&progress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if remainingAmount > progress {
|
||||
return fmt.Errorf("cannot remove more than the current allowance balance: %d", progress)
|
||||
}
|
||||
|
||||
err = tx.Query("update allowances set balance = balance + ? where id = ? and user_id = ?").
|
||||
Bind(remainingAmount, allowanceId, userId).Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Fetch the target and progress of the specified allowance
|
||||
var target, progress int
|
||||
err = tx.Query("select target, balance from allowances where id = ? and user_id = ?").
|
||||
@@ -627,7 +592,6 @@ func (db *Db) AddAllowanceAmount(userId int, allowanceId int, request AddAllowan
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
3469
frontend/allowance-planner-v2/package-lock.json
generated
3469
frontend/allowance-planner-v2/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,6 @@
|
||||
"@angular/cli": "^19.0.0",
|
||||
"@angular/compiler-cli": "^19.0.0",
|
||||
"@angular/language-service": "^19.0.0",
|
||||
"@capacitor/assets": "^3.0.5",
|
||||
"@capacitor/cli": "7.2.0",
|
||||
"@ionic/angular-toolkit": "^12.0.0",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
|
||||
@@ -30,10 +30,6 @@ export class SpendllowancePage {
|
||||
amount: ['', Validators.required],
|
||||
description: ['', Validators.required]
|
||||
});
|
||||
|
||||
this.allowanceService.getAllowanceById(this.goalId, this.userId).subscribe(allowance => {
|
||||
this.form.controls['amount'].addValidators([Validators.max(allowance.progress)]);
|
||||
});
|
||||
}
|
||||
|
||||
changeAllowance() {
|
||||
|
||||
@@ -36,7 +36,7 @@ export class AllowancePage implements ViewWillEnter {
|
||||
allowance[0].name = 'Main Allowance';
|
||||
this.allowance$.next(allowance);
|
||||
})
|
||||
}, 50);
|
||||
}, 20);
|
||||
}
|
||||
|
||||
canFinishGoal(allowance: Allowance): boolean {
|
||||
@@ -57,9 +57,6 @@ export class AllowancePage implements ViewWillEnter {
|
||||
for (let allowance of allowanceList) {
|
||||
allowanceTotal += allowance.progress;
|
||||
}
|
||||
if (allowanceTotal === 0) {
|
||||
return 0;
|
||||
}
|
||||
return goal.progress / allowanceTotal * 100;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
<button (click)="completeTask(task.id)">Done</button>
|
||||
<div (click)="updateTask(task.id)" class="item">
|
||||
<div class="name">{{ task.name }}</div>
|
||||
<div class="assigned">{{ usernames[task.assigned ? task.assigned : 0] }}</div>
|
||||
<div
|
||||
class="reward"
|
||||
[ngClass]="{ 'negative': task.reward < 0 }"
|
||||
|
||||
@@ -68,9 +68,3 @@ button {
|
||||
margin-right: 15px;
|
||||
width: 75px;
|
||||
}
|
||||
|
||||
.assigned {
|
||||
color: var(--line-color);
|
||||
margin-left: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import { ViewWillEnter } from '@ionic/angular';
|
||||
})
|
||||
export class TasksPage implements ViewWillEnter {
|
||||
public tasks$: BehaviorSubject<Array<Task>> = new BehaviorSubject<Array<Task>>([]);
|
||||
public usernames = ['', 'See', 'Huffle']
|
||||
|
||||
constructor(
|
||||
private taskService: TaskService,
|
||||
@@ -33,7 +32,7 @@ export class TasksPage implements ViewWillEnter {
|
||||
this.taskService.getTaskList().subscribe(tasks => {
|
||||
this.tasks$.next(tasks);
|
||||
});
|
||||
}, 50);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
createTask() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Allowance } from '../models/allowance';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AllowanceService {
|
||||
private url = 'https://allowanceplanner.seeseepuff.be/api';
|
||||
private url = 'http://localhost:8080/api';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { History } from '../models/history';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HistoryService {
|
||||
private url = 'https://allowanceplanner.seeseepuff.be/api';
|
||||
private url = 'http://localhost:8080/api';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Task } from '../models/task';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskService {
|
||||
private url = 'https://allowanceplanner.seeseepuff.be/api';
|
||||
private url = 'http://localhost:8080/api';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { User } from '../models/user';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
private url = 'https://allowanceplanner.seeseepuff.be/api';
|
||||
private url = 'http://localhost:8080/api';
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getUserList(): Observable<Array<User>> {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB |
Reference in New Issue
Block a user