currentEventCalculation
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.sasiedzi.event.domain;
|
package com.sasiedzi.event.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.sasiedzi.event.domain.enumeration.TransactionType;
|
import com.sasiedzi.event.domain.enumeration.TransactionType;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -42,6 +43,19 @@ public class Transaction implements Serializable {
|
|||||||
@JsonIgnoreProperties(value = { "transaction", "event", "registration" }, allowSetters = true)
|
@JsonIgnoreProperties(value = { "transaction", "event", "registration" }, allowSetters = true)
|
||||||
private Set<TransactionItem> transactionItems = new HashSet<>();
|
private Set<TransactionItem> transactionItems = new HashSet<>();
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private UserAccount beneficiary;
|
||||||
|
|
||||||
|
@JsonProperty("beneficiary")
|
||||||
|
public UserAccount getBeneficiary() {
|
||||||
|
return beneficiary;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("beneficiary")
|
||||||
|
public void setBeneficiary(UserAccount beneficiary) {
|
||||||
|
this.beneficiary = beneficiary;
|
||||||
|
}
|
||||||
|
|
||||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|||||||
@@ -323,6 +323,29 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getCurrentEventId() {
|
||||||
|
List<Event> allEvents = eventRepository.findAll();
|
||||||
|
Event currentEvent = allEvents
|
||||||
|
.stream()
|
||||||
|
.filter(event -> event.getDate() != null && event.getDate().isAfter(LocalDate.now()))
|
||||||
|
.min(Comparator.comparing(Event::getDate))
|
||||||
|
.orElse(null);
|
||||||
|
if (currentEvent == null) {
|
||||||
|
Event latestEvent = allEvents
|
||||||
|
.stream()
|
||||||
|
.filter(event -> event.getDate() != null)
|
||||||
|
.max(Comparator.comparing(Event::getDate))
|
||||||
|
.orElse(null);
|
||||||
|
if (latestEvent != null) {
|
||||||
|
return latestEvent.getId();
|
||||||
|
} else {
|
||||||
|
return -1L;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return currentEvent.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TransactionItemRepository transactionItemRepository;
|
TransactionItemRepository transactionItemRepository;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.sasiedzi.event.web.rest;
|
||||||
|
|
||||||
|
import com.sasiedzi.event.service.EventService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.actuate.info.Info;
|
||||||
|
import org.springframework.boot.actuate.info.InfoContributor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MyInfoContributor implements InfoContributor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
EventService eventService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contribute(Info.Builder builder) {
|
||||||
|
builder.withDetail("currentEventId", eventService.getCurrentEventId());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import com.sasiedzi.event.domain.Registration;
|
|||||||
import com.sasiedzi.event.domain.User;
|
import com.sasiedzi.event.domain.User;
|
||||||
import com.sasiedzi.event.repository.RegistrationRepository;
|
import com.sasiedzi.event.repository.RegistrationRepository;
|
||||||
import com.sasiedzi.event.repository.UserRepository;
|
import com.sasiedzi.event.repository.UserRepository;
|
||||||
|
import com.sasiedzi.event.service.EventService;
|
||||||
import com.sasiedzi.event.service.UserService;
|
import com.sasiedzi.event.service.UserService;
|
||||||
import com.sasiedzi.event.service.dto.AdminUserDTO;
|
import com.sasiedzi.event.service.dto.AdminUserDTO;
|
||||||
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
|
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
|
||||||
@@ -51,12 +52,17 @@ public class RegistrationResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EventService eventService;
|
||||||
|
|
||||||
public RegistrationResource(RegistrationRepository registrationRepository, UserRepository userRepository) {
|
public RegistrationResource(RegistrationRepository registrationRepository, UserRepository userRepository) {
|
||||||
this.registrationRepository = registrationRepository;
|
this.registrationRepository = registrationRepository;
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long currentEventId = 2601L;
|
private Long getCurrentEventId() {
|
||||||
|
return eventService.getCurrentEventId();
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CurrentUserHolder currentUser;
|
CurrentUserHolder currentUser;
|
||||||
@@ -72,7 +78,8 @@ public class RegistrationResource {
|
|||||||
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal)
|
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal)
|
||||||
throws URISyntaxException {
|
throws URISyntaxException {
|
||||||
if (
|
if (
|
||||||
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
|
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") &&
|
||||||
|
!registration.getEvent().getId().equals(getCurrentEventId())
|
||||||
) {
|
) {
|
||||||
throw new AccessDeniedException("Registration is closed for this event");
|
throw new AccessDeniedException("Registration is closed for this event");
|
||||||
}
|
}
|
||||||
@@ -110,7 +117,8 @@ public class RegistrationResource {
|
|||||||
@Valid @RequestBody Registration registration
|
@Valid @RequestBody Registration registration
|
||||||
) throws URISyntaxException {
|
) throws URISyntaxException {
|
||||||
if (
|
if (
|
||||||
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
|
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") &&
|
||||||
|
!registration.getEvent().getId().equals(getCurrentEventId())
|
||||||
) {
|
) {
|
||||||
throw new AccessDeniedException("Registration is closed for this event");
|
throw new AccessDeniedException("Registration is closed for this event");
|
||||||
}
|
}
|
||||||
@@ -149,7 +157,8 @@ public class RegistrationResource {
|
|||||||
@NotNull @RequestBody Registration registration
|
@NotNull @RequestBody Registration registration
|
||||||
) throws URISyntaxException {
|
) throws URISyntaxException {
|
||||||
if (
|
if (
|
||||||
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
|
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") &&
|
||||||
|
!registration.getEvent().getId().equals(getCurrentEventId())
|
||||||
) {
|
) {
|
||||||
throw new AccessDeniedException("Registration is closed for this event");
|
throw new AccessDeniedException("Registration is closed for this event");
|
||||||
}
|
}
|
||||||
@@ -232,7 +241,8 @@ public class RegistrationResource {
|
|||||||
public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) {
|
public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) {
|
||||||
Registration registration = registrationRepository.findById(id).get();
|
Registration registration = registrationRepository.findById(id).get();
|
||||||
if (
|
if (
|
||||||
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") && !registration.getEvent().getId().equals(currentEventId)
|
!currentUser.getAdminUser().getAuthorities().contains("ROLE_ADMIN") &&
|
||||||
|
!registration.getEvent().getId().equals(getCurrentEventId())
|
||||||
) {
|
) {
|
||||||
throw new AccessDeniedException("Registration is closed for this event");
|
throw new AccessDeniedException("Registration is closed for this event");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export default class AccountService {
|
|||||||
if (res.data && res.data.activeProfiles) {
|
if (res.data && res.data.activeProfiles) {
|
||||||
this.store.setRibbonOnProfiles(res.data['display-ribbon-on-profiles']);
|
this.store.setRibbonOnProfiles(res.data['display-ribbon-on-profiles']);
|
||||||
this.store.setActiveProfiles(res.data.activeProfiles);
|
this.store.setActiveProfiles(res.data.activeProfiles);
|
||||||
|
this.store.setCurrentEventId(res.data.currentEventId);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import type { IRegistration } from '@/shared/model/registration.model';
|
|||||||
import RegistrationService from '@/entities/registration/registration.service';
|
import RegistrationService from '@/entities/registration/registration.service';
|
||||||
import UserService from '@/entities/user/user.service';
|
import UserService from '@/entities/user/user.service';
|
||||||
import type AccountService from '@/account/account.service';
|
import type AccountService from '@/account/account.service';
|
||||||
|
import { useStore } from '@/store';
|
||||||
// import type EventService from '@/account/account.service';
|
// import type EventService from '@/account/account.service';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -33,10 +34,18 @@ export default defineComponent({
|
|||||||
const event: Ref<IEvent> = ref({});
|
const event: Ref<IEvent> = ref({});
|
||||||
const sortedAndIndexedRegistrations: Ref<IRegistration[]> = ref([]);
|
const sortedAndIndexedRegistrations: Ref<IRegistration[]> = ref([]);
|
||||||
|
|
||||||
|
let store = useStore();
|
||||||
|
|
||||||
const retrieveEvent = async (eventId: string) => {
|
const retrieveEvent = async (eventId: string) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('event' + eventId);
|
||||||
|
let currentEventId = '' + store.currentEventId;
|
||||||
|
if (eventId == 'useCurrentEventId') {
|
||||||
|
eventId = currentEventId;
|
||||||
|
console.log('event2' + eventId);
|
||||||
|
}
|
||||||
const res = await eventService().find(eventId);
|
const res = await eventService().find(eventId);
|
||||||
isCurrentEvent.value = eventId == '2601';
|
isCurrentEvent.value = eventId == currentEventId;
|
||||||
event.value = res;
|
event.value = res;
|
||||||
// sortedAndIndexedRegistrations.value = res.registrations;
|
// sortedAndIndexedRegistrations.value = res.registrations;
|
||||||
sortedAndIndexedRegistrations.value = res.registrations.sort(
|
sortedAndIndexedRegistrations.value = res.registrations.sort(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const Error = () => import('@/core/error/error.vue');
|
|||||||
import admin from '@/router/admin';
|
import admin from '@/router/admin';
|
||||||
import entities from '@/router/entities';
|
import entities from '@/router/entities';
|
||||||
import pages from '@/router/pages';
|
import pages from '@/router/pages';
|
||||||
|
// import { useStore } from '@/store';
|
||||||
import { Authority } from '@/shared/security/authority';
|
import { Authority } from '@/shared/security/authority';
|
||||||
const EventDetails = () => import('@/entities/event/event-details.vue');
|
const EventDetails = () => import('@/entities/event/event-details.vue');
|
||||||
const Event = () => import('@/entities/event/event.vue');
|
const Event = () => import('@/entities/event/event.vue');
|
||||||
@@ -17,7 +18,7 @@ export const createRouter = () =>
|
|||||||
path: '/',
|
path: '/',
|
||||||
name: 'CurrentEventView',
|
name: 'CurrentEventView',
|
||||||
component: EventDetails,
|
component: EventDetails,
|
||||||
meta: { authorities: [Authority.USER], eventId: '2601' },
|
meta: { authorities: [Authority.USER], eventId: 'useCurrentEventId' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/forbidden',
|
path: '/forbidden',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface AccountStateStorable {
|
|||||||
profilesLoaded: boolean;
|
profilesLoaded: boolean;
|
||||||
ribbonOnProfiles: string;
|
ribbonOnProfiles: string;
|
||||||
activeProfiles: string;
|
activeProfiles: string;
|
||||||
|
currentEventId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultAccountState: AccountStateStorable = {
|
export const defaultAccountState: AccountStateStorable = {
|
||||||
@@ -16,6 +17,7 @@ export const defaultAccountState: AccountStateStorable = {
|
|||||||
profilesLoaded: false,
|
profilesLoaded: false,
|
||||||
ribbonOnProfiles: '',
|
ribbonOnProfiles: '',
|
||||||
activeProfiles: '',
|
activeProfiles: '',
|
||||||
|
currentEventId: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAccountStore = defineStore('main', {
|
export const useAccountStore = defineStore('main', {
|
||||||
@@ -46,5 +48,8 @@ export const useAccountStore = defineStore('main', {
|
|||||||
setRibbonOnProfiles(ribbon) {
|
setRibbonOnProfiles(ribbon) {
|
||||||
this.ribbonOnProfiles = ribbon;
|
this.ribbonOnProfiles = ribbon;
|
||||||
},
|
},
|
||||||
|
setCurrentEventId(currentEventId) {
|
||||||
|
this.currentEventId = currentEventId;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user