Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/rfb/bootstrap/RfbBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Optional;
import java.util.UUID;

/**
Expand Down Expand Up @@ -62,6 +63,10 @@ private void initData() {
rfbUser.addAuthority(authorityRepository.findOne("ROLE_ORGANIZER"));
userRepository.save(rfbUser);

User runner = Optional.ofNullable(
userRepository.findOneByLogin("runner")
).orElseThrow(()->new IllegalArgumentException("User runner not found")).get();

//load data
RfbLocation aleAndWitch = getRfbLocation("St Pete - Ale and the Witch", DayOfWeek.MONDAY.getValue());

Expand All @@ -71,6 +76,8 @@ private void initData() {
RfbEvent aleEvent = getRfbEvent(aleAndWitch);

getRfbEventAttendance(rfbUser, aleEvent);
getRfbEventAttendance(rfbUser, aleEvent);// adding two attendance for this user
getRfbEventAttendance(runner, aleEvent);// adding two attendance for this user

RfbLocation ratc = getRfbLocation("St Pete - Right Around The Corner", DayOfWeek.TUESDAY.getValue());

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/rfb/service/RfbLocationService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.rfb.service;

import com.rfb.service.dto.RfbLocationDTO;
import com.rfb.service.dto.location.RfbLeaderForLocationDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
* Service Interface for managing RfbLocation.
*/
Expand Down Expand Up @@ -39,4 +42,6 @@ public interface RfbLocationService {
* @param id the id of the entity
*/
void delete(Long id);

List<RfbLeaderForLocationDTO> getRfbLeaderForLocation(Long locationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.rfb.service.dto.location;

import java.util.Objects;

public class RfbLeaderForLocationDTO {

private String userName;
private int totalRuns;

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public int getTotalRuns() {
return totalRuns;
}

public void setTotalRuns(int totalRuns) {
this.totalRuns = totalRuns;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RfbLeaderForLocationDTO that = (RfbLeaderForLocationDTO) o;
return getTotalRuns() == that.getTotalRuns() &&
Objects.equals(getUserName(), that.getUserName());
}

@Override
public int hashCode() {

return Objects.hash(getUserName(), getTotalRuns());
}
}
79 changes: 64 additions & 15 deletions src/main/java/com/rfb/service/impl/RfbLocationServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
package com.rfb.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.rfb.domain.RfbLocation;
import com.rfb.domain.User;
import com.rfb.repository.RfbLocationRepository;
import com.rfb.service.RfbLocationService;
import com.rfb.service.dto.RfbLocationDTO;
import com.rfb.service.dto.location.RfbLeaderForLocationDTO;
import com.rfb.service.mapper.RfbLocationMapper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Service Implementation for managing RfbLocation.
*/
@Service
@Transactional
public class RfbLocationServiceImpl implements RfbLocationService{
public class RfbLocationServiceImpl implements RfbLocationService {

private final Logger log = LoggerFactory.getLogger(RfbLocationServiceImpl.class);

private final RfbLocationRepository rfbLocationRepository;
@Autowired
private RfbLocationRepository rfbLocationRepository;

private final RfbLocationMapper rfbLocationMapper;
@Autowired
private RfbLocationMapper rfbLocationMapper;

public RfbLocationServiceImpl(RfbLocationRepository rfbLocationRepository, RfbLocationMapper rfbLocationMapper) {
this.rfbLocationRepository = rfbLocationRepository;
this.rfbLocationMapper = rfbLocationMapper;
}

/**
* Save a rfbLocation.
Expand All @@ -46,10 +52,10 @@ public RfbLocationDTO save(RfbLocationDTO rfbLocationDTO) {
}

/**
* Get all the rfbLocations.
* Get all the rfbLocations.
*
* @param pageable the pagination information
* @return the list of entities
* @param pageable the pagination information
* @return the list of entities
*/
@Override
@Transactional(readOnly = true)
Expand All @@ -60,10 +66,10 @@ public Page<RfbLocationDTO> findAll(Pageable pageable) {
}

/**
* Get one rfbLocation by id.
* Get one rfbLocation by id.
*
* @param id the id of the entity
* @return the entity
* @param id the id of the entity
* @return the entity
*/
@Override
@Transactional(readOnly = true)
Expand All @@ -74,13 +80,56 @@ public RfbLocationDTO findOne(Long id) {
}

/**
* Delete the rfbLocation by id.
* Delete the rfbLocation by id.
*
* @param id the id of the entity
* @param id the id of the entity
*/
@Override
public void delete(Long id) {
log.debug("Request to delete RfbLocation : {}", id);
rfbLocationRepository.delete(id);
}

@Transactional(readOnly = true)
public List<RfbLeaderForLocationDTO> getRfbLeaderForLocation(Long locationId) {
if (locationId == null) {
throw new IllegalArgumentException("location id not informed");
}
RfbLocation location = getOneLocation(locationId);
if (location == null) {
throw new IllegalArgumentException("location id not informed");
}

Map<Long, RfbLeaderForLocationDTO> userInfoMap = Maps.newHashMap();
location.getRvbEvents().stream()
.forEach(event -> event.getRfbEventAttendances().stream()
.forEach(evAtt -> {
User user = evAtt.getUser();
Long userId = user.getId();
RfbLeaderForLocationDTO dto = userInfoMap.get(userId);
int totalRuns = 1;
if (dto == null) {
dto = new RfbLeaderForLocationDTO();
String name = user.getFirstName();
String lastName = user.getLastName();
if (StringUtils.isNoneBlank(lastName)) {
name = lastName + ", " + name;
}
dto.setUserName(name);
dto.setTotalRuns(totalRuns);
} else {
totalRuns += 1;
}
dto.setTotalRuns(totalRuns);
userInfoMap.put(userId, dto);
}));
List<RfbLeaderForLocationDTO> values = Lists.newArrayList(userInfoMap.values());
Collections.sort(values, Comparator.comparingInt(RfbLeaderForLocationDTO::getTotalRuns));
Collections.reverse(values);
return values;
}

protected RfbLocation getOneLocation(Long locationId) {
return rfbLocationRepository.findOne(locationId);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/rfb/web/rest/RfbLocationResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.codahale.metrics.annotation.Timed;
import com.rfb.service.RfbLocationService;
import com.rfb.service.dto.RfbLocationDTO;
import com.rfb.service.dto.location.RfbLeaderForLocationDTO;
import com.rfb.web.rest.util.HeaderUtil;
import com.rfb.web.rest.util.PaginationUtil;
import io.github.jhipster.web.util.ResponseUtil;
Expand Down Expand Up @@ -122,4 +123,12 @@ public ResponseEntity<Void> deleteRfbLocation(@PathVariable Long id) {
rfbLocationService.delete(id);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build();
}

@Timed
@GetMapping("/rfb-locations/{id}/leaders")
public ResponseEntity<List<RfbLeaderForLocationDTO>> getRfbLeaderForLocation(@PathVariable Long id) {
log.debug("REST request to get RfbLocation : {}", id);
List<RfbLeaderForLocationDTO> rfbLocationDTO = rfbLocationService.getRfbLeaderForLocation(id);
return new ResponseEntity<>(rfbLocationDTO, HttpStatus.OK);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/.h2.server.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#H2 Server Properties
#Sat Nov 04 14:07:31 EDT 2017
0=JHipster H2 (Memory)|org.h2.Driver|jdbc\:h2\:mem\:rfbloyalty|rfbloyalty
#Fri May 25 14:37:31 BRT 2018
0=JHipster H2 (Memory)|org.h2.Driver|jdbc\:h2\:file\:~/temp/dabases/rfbloyalty/rfbloyalty|rfbloyalty
webAllowOthers=true
webPort=8082
webSSL=false
31 changes: 15 additions & 16 deletions src/main/webapp/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import './vendor.ts';

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Ng2Webstorage } from 'ng2-webstorage';
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {Ng2Webstorage} from 'ng2-webstorage';

import { RfbloyaltySharedModule, UserRouteAccessService } from './shared';
import { RfbloyaltyHomeModule } from './home/home.module';
import { RfbloyaltyAdminModule } from './admin/admin.module';
import { RfbloyaltyAccountModule } from './account/account.module';
import { RfbloyaltyEntityModule } from './entities/entity.module';

import { customHttpProvider } from './blocks/interceptor/http.provider';
import { PaginationConfig } from './blocks/config/uib-pagination.config';

// jhipster-needle-angular-add-module-import JHipster will add new module here
import {RfbloyaltySharedModule, UserRouteAccessService} from './shared';
import {RfbloyaltyHomeModule} from './home';
import {RfbloyaltyAdminModule} from './admin/admin.module';
import {RfbloyaltyAccountModule} from './account/account.module';
import {RfbloyaltyEntityModule} from './entities/entity.module';

import {customHttpProvider} from './blocks/interceptor/http.provider';
import {PaginationConfig} from './blocks/config/uib-pagination.config';
import {
ErrorComponent,
FooterComponent,
JhiMainComponent,
LayoutRoutingModule,
NavbarComponent,
FooterComponent,
ProfileService,
PageRibbonComponent,
ErrorComponent
ProfileService
} from './layouts';

// jhipster-needle-angular-add-module-import JHipster will add new module here

@NgModule({
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {PaginationConfig} from '../../blocks/config/uib-pagination.config';
})
export class RfbLocationComponent implements OnInit, OnDestroy {

currentAccount: any;
currentAccount: any;
rfbLocations: RfbLocation[];
error: any;
success: any;
Expand Down Expand Up @@ -53,24 +53,28 @@ currentAccount: any;
this.rfbLocationService.query({
page: this.page - 1,
size: this.itemsPerPage,
sort: this.sort()}).subscribe(
sort: this.sort()
}).subscribe(
(res: ResponseWrapper) => this.onSuccess(res.json, res.headers),
(res: ResponseWrapper) => this.onError(res.json)
);
}

loadPage(page: number) {
if (page !== this.previousPage) {
this.previousPage = page;
this.transition();
}
}

transition() {
this.router.navigate(['/rfb-location'], {queryParams:
{
page: this.page,
size: this.itemsPerPage,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}
this.router.navigate(['/rfb-location'], {
queryParams:
{
page: this.page,
size: this.itemsPerPage,
sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc')
}
});
this.loadAll();
}
Expand All @@ -83,6 +87,7 @@ currentAccount: any;
}]);
this.loadAll();
}

ngOnInit() {
this.loadAll();
this.principal.identity().then((account) => {
Expand All @@ -98,6 +103,7 @@ currentAccount: any;
trackId(index: number, item: RfbLocation) {
return item.id;
}

registerChangeInRfbLocations() {
this.eventSubscriber = this.eventManager.subscribe('rfbLocationListModification', (response) => this.loadAll());
}
Expand All @@ -117,6 +123,7 @@ currentAccount: any;
// this.page = pagingParams.page;
this.rfbLocations = data;
}

private onError(error) {
this.alertService.error(error.message, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {RfbLocationDeletePopupComponent} from './rfb-location-delete-dialog.comp
@Injectable()
export class RfbLocationResolvePagingParams implements Resolve<any> {

constructor(private paginationUtil: JhiPaginationUtil) {}
constructor(private paginationUtil: JhiPaginationUtil) {
}

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const page = route.queryParams['page'] ? route.queryParams['page'] : '1';
Expand All @@ -21,7 +22,7 @@ export class RfbLocationResolvePagingParams implements Resolve<any> {
page: this.paginationUtil.parsePage(page),
predicate: this.paginationUtil.parsePredicate(sort),
ascending: this.paginationUtil.parseAscending(sort)
};
};
}
}

Expand Down
Loading