Skip to content

Commit

Permalink
Merge pull request #39 from louiiuol/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Louis Godlewski authored Sep 5, 2020
2 parents 0655f0c + bfec62c commit de1ec71
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 100 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run:
npm ci --prefix application/web-ui
env:
CI: true
- name: Install
run: npm install --prefix application/web-ui
- name: Test
run: npm test --prefix application/web-ui
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ public Set<ConfessionViewDto> getConfessions(@PathVariable("id") Long jarId) {
return service.getJarConfessions(jarId);
}

@PutMapping("/{jarId}/confessions/{confessionId}")
@PreAuthorize("@validatorService.isActive(#jarId) and @validatorService.isJarMember(#jarId)")
public void updateConfession(@PathVariable("jarId") Long jarId, @PathVariable("confessionId") Long confessionId, @Valid @RequestBody ConfessDto dto) {
service.updateConfession(confessionId, dto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import dev.louiiuol.jarit.api.validators.jar.confess.OwnConfess;
import dev.louiiuol.jarit.business.dtos.EntityIdDto;
Expand All @@ -17,6 +18,7 @@
public class ConfessDto {

@NotBlank
@Size(max = 20)
private String swear;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
* <li> void {@link #updateMemberBalance( Long user, Long jar, Double balance )}
* <li> void {@link #removeMember(Long jar, Long user )}
* </ul>
* Reports:
* Confessions:
* <ul>
* <li> ConfessionViewDto {@link #confess(Long jar, Long user, ConfessDto input)}
* <li> Set {@link #getJarConfessions(Long jarId)}
* <li> void {@link #updateConfession(Long confessionId, ConfessDto dto)}
* </ul>
*/
public interface JarService {
Expand Down Expand Up @@ -98,13 +100,21 @@ public interface JarService {
*/
public void confess(Long jarId, ConfessDto dto);


/**
* Returns all jars in database (used by admin)
* @return {@code List<JarPreviewDto>} All Jars from database
* @return {@code PageDto<JarPreviewDto>} All Jars from database
*/
public PageDto<JarPreviewDto> getAll(int page, int size, String order, String sort);

public Set<ConfessionViewDto> getJarConfessions(Long jarId);
/**
* Returns all confessions of specific jar
* @return {@code Set<ConfessionViewDto>} All confessions of specific jar
*/
public Set<ConfessionViewDto> getJarConfessions(Long jarId);

/**
* Update specific confession
*/
public void updateConfession(Long confessionId, ConfessDto dto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,17 @@ public Set<ConfessionViewDto> getJarConfessions(Long jarId) {
return dtos;
}

@Override
public void updateConfession(Long confessionId, ConfessDto dto) {
Confession confession = confessionRepo.findById(confessionId)
.orElseThrow(ResourceNotFoundException::new);
mapper().map(dto, confession);
confessionRepo.save(confession);
}

private Double getJarBalance(List<Member> members) {
return new HashSet<>(members).stream().reduce(0.0, (accumulator, member) -> accumulator + member.getBalance(),
return new HashSet<>(members).stream()
.reduce(0.0, (accumulator, member) -> accumulator + member.getBalance(),
Double::sum);
}

Expand All @@ -159,7 +168,8 @@ private Double confessionCost(Jar jar) {
}

private void memberConfess(Long id, Double cost) {
Member member = memberRepo.findById(id).orElseThrow(ResourceNotFoundException::new);
Member member = memberRepo.findById(id)
.orElseThrow(ResourceNotFoundException::new);
Double newBalance = Double.sum(member.getBalance(), cost);
member.setBalance(newBalance);
memberRepo.save(member);
Expand Down
6 changes: 5 additions & 1 deletion application/web-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { JarCreatedComponent } from './components/views/jar-details/jar-created/
import { JarActiveComponent } from './components/views/jar-details/jar-active/jar-active.component';
import { JarOverComponent } from './components/views/jar-details/jar-over/jar-over.component';
import { PayComponent } from './components/views/jar-details/jar-over/pay/pay.component';
import { ConfessionUpdateComponent } from './components/views/jar-details/jar-active/confession-update/confession-update.component';
import { TitleShortenerPipe } from './services/pipes/title-shortener.pipe';

@NgModule({
declarations: [
Expand All @@ -59,6 +61,7 @@ import { PayComponent } from './components/views/jar-details/jar-over/pay/pay.co
AssociationOfficeComponent,
AssociationCreateComponent,
DescriptionFormatterPipe,
TitleShortenerPipe,
JarCreateComponent,
MembersUpdateComponent,
JarPreviewComponent,
Expand All @@ -68,7 +71,8 @@ import { PayComponent } from './components/views/jar-details/jar-over/pay/pay.co
JarCreatedComponent,
JarActiveComponent,
JarOverComponent,
PayComponent
PayComponent,
ConfessionUpdateComponent
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<button mat-icon-button id="close-dialog" color="primary" aria-label="close tinee dialog">
<app-icon (click)="close()" class="icon xs" name="close"></app-icon>
<button mat-icon-button id='close-dialog' color='primary' aria-label='close tinee dialog'>
<app-icon (click)='close()' class='icon xs' name='close'></app-icon>
</button>
<h3 mat-dialog-title class="header">Confess</h3>
<h3 mat-dialog-title class='header'>Confess</h3>
<form>
<p class='legend'>What did you sworn about ?</p>
<mat-form-field>
<mat-label>Confess</mat-label>
<input matInput placeholder="Damn it !" [formControl]="confession" required>
<mat-error *ngIf="confession.invalid">That's not a confession !</mat-error>
<input matInput placeholder='Damn it !' [formControl]='confessionControl' required>
<mat-error *ngIf='confessionControl.invalid'>That's not a confession !</mat-error>
</mat-form-field>
<button color="primary" mat-raised-button (click)="confess()">Confess</button>
<button color='primary' mat-raised-button
disabled='{{confessionControl.invalid}}' (click)='confess()'>Confess</button>
</form>
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Component, ViewChild, ElementRef, Inject } from '@angular/core';
import { JarDialogData } from 'src/app/models/jar/jar-data.dialog';
import { Component, Inject } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Patterns } from 'src/app/services/forms/utils';
import { Confess } from 'src/app/models/jar/confession/confess-model';
import { ConfessionService } from 'src/app/services/domain/jar/member/confession.service';
import { JarDetails } from 'src/app/models';
import { JarDetails, Confess, JarDialogData } from 'src/app/models';
import { FormFactory } from 'src/app/services';

@Component({
selector: 'app-confess',
Expand All @@ -15,23 +13,21 @@ import { JarDetails } from 'src/app/models';
})
export class ConfessComponent {

@ViewChild('confessionInput', { static: false }) confessionInput: ElementRef<HTMLInputElement>;

get jar(): JarDetails { return this.data.jar; }
get reporterId(): number { return this.jar.members.find(member => member.userId === this.data.user).id; }

readonly confession = new FormControl('', [Validators.required, Validators.pattern(Patterns.alphanumeric)]);
readonly confessionControl = new FormControl('', [Validators.required, Validators.pattern(Patterns.alphanumeric)]);

constructor(
private snackBar: MatSnackBar, private dialogRef: MatDialogRef<ConfessComponent>,
@Inject(MAT_DIALOG_DATA) private data: JarDialogData, private confessionService: ConfessionService) {}
private dialogRef: MatDialogRef<ConfessComponent>, @Inject(MAT_DIALOG_DATA) private data: JarDialogData,
private formFactory: FormFactory, private confessionService: ConfessionService) { }

confess(): void {
const confess = new Confess(this.confession.value, this.reporterId, this.jar.id);
const confess = new Confess(this.confessionControl.value, this.reporterId, this.jar.id);
this.confessionService.confess(confess, this.jar.id).subscribe( () => {
this.dialogRef.close(confess);
this.snackBar.open('Confession added with success !', 'close', { duration: 3000 });
}, err => this.snackBar.open(err, 'close', { duration: 3000 } ));
this.formFactory.handleSuccessMessages('Confession added with success !');
}, err => this.formFactory.handleErrorMessages(err));
}

close = (): void => this.dialogRef.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
.has-icon {
.icon { margin-right: .5rem; margin-left: .5rem; }
}
.open-details {
transition: color .8s ease;
&:hover svg {
color: white;
.hoverable {
border-radius: 50%;
transition: all .6s ease;
&:hover {
background: currentColor;
svg { fill: white; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { JarService } from 'src/app/services/domain/jar/jar.service';
import { UserService } from 'src/app/services/domain/user/user.service';
import { AssociationService } from 'src/app/services/domain/association/association.service';
import { FormFactory } from 'src/app/services';
import { UserView, MemberDetails, JarCreate } from 'src/app/models';
import { UserView, MemberDetails, JarCreate, MemberCreate } from 'src/app/models';
import { ErrorMessages, Patterns } from 'src/app/services/forms/utils';
import { JarForm } from 'src/app/services/forms/groups';
import { JarCreateData } from 'src/app/models/utils/dialog/jar-create-data.dialog';
Expand Down Expand Up @@ -99,7 +99,14 @@ export class JarCreateComponent implements OnInit {
}

private jarInfos = () => new JarCreate(this.title.value, this.maxAmount.value,
this.closingDate.value, this.addressee.value.id, this.memberService.mapMembers(this.members),
this.closingDate.value, this.addressee.value.id, this.mapMembers(this.members),
this.author.id, this.referenceCost.value, this.description.value)

private mapMembers = (members: MemberDetails[]): MemberCreate[] => {
const result = [];
for (const member of members) {
result.push(new MemberCreate(member.userId, member.admin));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h4 class='title is-primary'>{{jar.title}}</h4>
<section class='vertical-aside'>
<app-icon id='owner' avatar="true" name="{{jar.author.avatar}}"
class="icon xs helped" matTooltip="{{jar.author.username}} created this jar"></app-icon>
<a *ngIf="isOpenable && !(jarState == 'PAYED')" [routerLink]="['/jars', jar.id]" class='open-details is-primary'>
<a *ngIf="isOpenable && !(jarState == 'PAYED')" [routerLink]="['/jars', jar.id]" class='hoverable is-primary'>
<app-icon class='icon xs' name='visible' ></app-icon>
</a>
<a *ngIf="!isOpenable && !(jarState == 'PAYED')" class=' disabled is-primary'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,5 @@ mat-card {
justify-content: space-evenly;
align-items: center;
& > * { margin: .25rem auto; }
.open-details {
border-radius: 50%;
transition: background .6s ease;
&:hover {background: currentColor;}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input } from '@angular/core';
import { UserView, JarView } from 'src/app/models';
import { JarView } from 'src/app/models';
import { JarHelperService } from 'src/app/services/domain/jar/Jar-helper.service';
import { JarState } from 'src/app/models/jar/jar-state.model';

@Component({
selector: 'app-jar-preview',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<button mat-icon-button id='close-dialog' color='primary' aria-label='close tinee dialog'>
<app-icon (click)='close()' class='icon xs' name='close'></app-icon>
</button>
<h3 mat-dialog-title class='header'>Update your confession</h3>
<form>
<p class='legend'>That wasn't what you said ?</p>
<mat-form-field>
<mat-label>Confession</mat-label>
<input matInput placeholder='Damn it !' [formControl]='confessionControl' required>
<mat-error *ngIf='confessionControl.invalid'>That's not a confession !</mat-error>
</mat-form-field>
<button color='primary' mat-raised-button
disabled='{{confessionControl.invalid}}' (click)='update()'>update</button>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h3 { padding: 2rem 3rem !important;}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ConfessionUpdateComponent } from './confession-update.component';

describe('ConfessionUpdateComponent', () => {
let component: ConfessionUpdateComponent;
let fixture: ComponentFixture<ConfessionUpdateComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ConfessionUpdateComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ConfessionUpdateComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, Inject } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Patterns } from 'src/app/services/forms/utils';
import { ConfessionService } from 'src/app/services/domain/jar/member/confession.service';
import { ConfessionUpdateDialogData, Confess } from 'src/app/models';
import { FormFactory } from 'src/app/services';

@Component({
selector: 'app-confession-update',
templateUrl: './confession-update.component.html',
styleUrls: ['./confession-update.component.scss']
})
export class ConfessionUpdateComponent {

readonly confessionControl = new FormControl(this.data.confession.swear,
[Validators.required, Validators.pattern(Patterns.alphanumeric)]);

constructor(
private formFactory: FormFactory, private dialogRef: MatDialogRef<ConfessionUpdateComponent>,
@Inject(MAT_DIALOG_DATA) private data: ConfessionUpdateDialogData, private confessionService: ConfessionService) { }


update(): void {
const confess = new Confess(this.confessionControl.value, this.data.confession.author.id, this.data.jarId);
this.confessionService.updateConfession(this.data.jarId, confess, this.data.confession.id)
.subscribe(() => {
this.dialogRef.close(this.confessionControl.value);
this.formFactory.handleSuccessMessages('Confession updated with success !');
}, err => this.formFactory.handleErrorMessages(err));
}

close = (): void => this.dialogRef.close();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@
<p *ngIf='confessionsCount === 0' class="empty">No swears were confessed here yet !</p>
<div id='confession-table' class='table-content' *ngIf='confessionsCount > 0 && !!confessionsList'>
<div class="wrapper" *ngFor='let confession of confessionsList'>
<p class="legend date">{{confession.date | date:'short'}}</p>
<p class="legend date helped" matTooltip="{{confession.date | date:'short'}}">{{confession.date | date:'HH:mm'}}</p>
<mat-card>
<h4 class='is-accent'>{{confession.swear}}</h4>
<p class='legend'>confessed by</p>
<span class="has-icon author">
<app-icon name='{{confession.author.avatar}}' class='icon avatar' avatar='true'></app-icon>
<span class='is-primary'>{{confession.author.username}}</span>
</span>
<h4 class='is-accent'>{{confession.swear | titleShortener }}</h4>
<div class="wrap">
<em class='legend'>confessed by</em>
<span class="has-icon author">
<span class='is-primary'>{{confession.author.username}}</span>
<app-icon name='{{confession.author.avatar}}' class='icon avatar' avatar='true'></app-icon>
</span>
</div>
</mat-card>
<a class='is-accent hoverable pointed' (click)='updateConfession(confession)' *ngIf='ownConfession(confession)'>
<app-icon class='icon xs' name='edit'></app-icon>
</a>
</div>
<hr class='spacer'>
</div>
Expand Down
Loading

0 comments on commit de1ec71

Please sign in to comment.