currentEventCalculation

This commit is contained in:
2024-11-30 13:11:55 +01:00
parent 5de13e8a2b
commit 620e615e72
8 changed files with 89 additions and 7 deletions
@@ -1,6 +1,7 @@
package com.sasiedzi.event.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.sasiedzi.event.domain.enumeration.TransactionType;
import jakarta.persistence.*;
import java.io.Serializable;
@@ -42,6 +43,19 @@ public class Transaction implements Serializable {
@JsonIgnoreProperties(value = { "transaction", "event", "registration" }, allowSetters = true)
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
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
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.repository.RegistrationRepository;
import com.sasiedzi.event.repository.UserRepository;
import com.sasiedzi.event.service.EventService;
import com.sasiedzi.event.service.UserService;
import com.sasiedzi.event.service.dto.AdminUserDTO;
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
@@ -51,12 +52,17 @@ public class RegistrationResource {
@Autowired
private UserRepository userRepository;
@Autowired
private EventService eventService;
public RegistrationResource(RegistrationRepository registrationRepository, UserRepository userRepository) {
this.registrationRepository = registrationRepository;
this.userRepository = userRepository;
}
private static Long currentEventId = 2601L;
private Long getCurrentEventId() {
return eventService.getCurrentEventId();
}
@Autowired
CurrentUserHolder currentUser;
@@ -72,7 +78,8 @@ public class RegistrationResource {
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration, Principal principal)
throws URISyntaxException {
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");
}
@@ -110,7 +117,8 @@ public class RegistrationResource {
@Valid @RequestBody Registration registration
) throws URISyntaxException {
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");
}
@@ -149,7 +157,8 @@ public class RegistrationResource {
@NotNull @RequestBody Registration registration
) throws URISyntaxException {
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");
}
@@ -232,7 +241,8 @@ public class RegistrationResource {
public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) {
Registration registration = registrationRepository.findById(id).get();
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");
}
@@ -19,6 +19,7 @@ export default class AccountService {
if (res.data && res.data.activeProfiles) {
this.store.setRibbonOnProfiles(res.data['display-ribbon-on-profiles']);
this.store.setActiveProfiles(res.data.activeProfiles);
this.store.setCurrentEventId(res.data.currentEventId);
}
return true;
} catch (error) {
@@ -10,6 +10,7 @@ import type { IRegistration } from '@/shared/model/registration.model';
import RegistrationService from '@/entities/registration/registration.service';
import UserService from '@/entities/user/user.service';
import type AccountService from '@/account/account.service';
import { useStore } from '@/store';
// import type EventService from '@/account/account.service';
export default defineComponent({
@@ -33,10 +34,18 @@ export default defineComponent({
const event: Ref<IEvent> = ref({});
const sortedAndIndexedRegistrations: Ref<IRegistration[]> = ref([]);
let store = useStore();
const retrieveEvent = async (eventId: string) => {
try {
console.log('event' + eventId);
let currentEventId = '' + store.currentEventId;
if (eventId == 'useCurrentEventId') {
eventId = currentEventId;
console.log('event2' + eventId);
}
const res = await eventService().find(eventId);
isCurrentEvent.value = eventId == '2601';
isCurrentEvent.value = eventId == currentEventId;
event.value = res;
// sortedAndIndexedRegistrations.value = res.registrations;
sortedAndIndexedRegistrations.value = res.registrations.sort(
+2 -1
View File
@@ -5,6 +5,7 @@ const Error = () => import('@/core/error/error.vue');
import admin from '@/router/admin';
import entities from '@/router/entities';
import pages from '@/router/pages';
// import { useStore } from '@/store';
import { Authority } from '@/shared/security/authority';
const EventDetails = () => import('@/entities/event/event-details.vue');
const Event = () => import('@/entities/event/event.vue');
@@ -17,7 +18,7 @@ export const createRouter = () =>
path: '/',
name: 'CurrentEventView',
component: EventDetails,
meta: { authorities: [Authority.USER], eventId: '2601' },
meta: { authorities: [Authority.USER], eventId: 'useCurrentEventId' },
},
{
path: '/forbidden',
@@ -7,6 +7,7 @@ export interface AccountStateStorable {
profilesLoaded: boolean;
ribbonOnProfiles: string;
activeProfiles: string;
currentEventId: number;
}
export const defaultAccountState: AccountStateStorable = {
@@ -16,6 +17,7 @@ export const defaultAccountState: AccountStateStorable = {
profilesLoaded: false,
ribbonOnProfiles: '',
activeProfiles: '',
currentEventId: 0,
};
export const useAccountStore = defineStore('main', {
@@ -46,5 +48,8 @@ export const useAccountStore = defineStore('main', {
setRibbonOnProfiles(ribbon) {
this.ribbonOnProfiles = ribbon;
},
setCurrentEventId(currentEventId) {
this.currentEventId = currentEventId;
},
},
});