This commit is contained in:
2024-11-05 10:11:11 +01:00
parent 59bd5f6b78
commit c2bf40c1a4
80 changed files with 7291 additions and 1 deletions
@@ -0,0 +1,173 @@
package com.sasiedzi.event.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sasiedzi.event.domain.enumeration.ChargeType;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* A Charge.
*/
@Entity
@Table(name = "charge")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Charge implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "charge_date", nullable = false)
private LocalDate chargeDate;
@NotNull
@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false)
private ChargeType type;
@NotNull
@Column(name = "amount", precision = 21, scale = 2, nullable = false)
private BigDecimal amount;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = { "registrations" }, allowSetters = true)
private Event event;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = { "user", "event" }, allowSetters = true)
private Registration registration;
@ManyToOne(fetch = FetchType.LAZY)
private User user;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Charge id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public LocalDate getChargeDate() {
return this.chargeDate;
}
public Charge chargeDate(LocalDate chargeDate) {
this.setChargeDate(chargeDate);
return this;
}
public void setChargeDate(LocalDate chargeDate) {
this.chargeDate = chargeDate;
}
public ChargeType getType() {
return this.type;
}
public Charge type(ChargeType type) {
this.setType(type);
return this;
}
public void setType(ChargeType type) {
this.type = type;
}
public BigDecimal getAmount() {
return this.amount;
}
public Charge amount(BigDecimal amount) {
this.setAmount(amount);
return this;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Event getEvent() {
return this.event;
}
public void setEvent(Event event) {
this.event = event;
}
public Charge event(Event event) {
this.setEvent(event);
return this;
}
public Registration getRegistration() {
return this.registration;
}
public void setRegistration(Registration registration) {
this.registration = registration;
}
public Charge registration(Registration registration) {
this.setRegistration(registration);
return this;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public Charge user(User user) {
this.setUser(user);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Charge)) {
return false;
}
return getId() != null && getId().equals(((Charge) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Charge{" +
"id=" + getId() +
", chargeDate='" + getChargeDate() + "'" +
", type='" + getType() + "'" +
", amount=" + getAmount() +
"}";
}
}
@@ -0,0 +1,192 @@
package com.sasiedzi.event.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
/**
* A Event.
*/
@Entity
@Table(name = "event")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "name", nullable = false)
private String name;
@NotNull
@Column(name = "date", nullable = false)
private LocalDate date;
@Column(name = "players_limit")
private Integer playersLimit;
@Column(name = "cost", precision = 21, scale = 2)
private BigDecimal cost;
@Lob
@Column(name = "comment")
private String comment;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
@JsonIgnoreProperties(value = { "user", "event" }, allowSetters = true)
private Set<Registration> registrations = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Event id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public Event name(String name) {
this.setName(name);
return this;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getDate() {
return this.date;
}
public Event date(LocalDate date) {
this.setDate(date);
return this;
}
public void setDate(LocalDate date) {
this.date = date;
}
public Integer getPlayersLimit() {
return this.playersLimit;
}
public Event playersLimit(Integer playersLimit) {
this.setPlayersLimit(playersLimit);
return this;
}
public void setPlayersLimit(Integer playersLimit) {
this.playersLimit = playersLimit;
}
public BigDecimal getCost() {
return this.cost;
}
public Event cost(BigDecimal cost) {
this.setCost(cost);
return this;
}
public void setCost(BigDecimal cost) {
this.cost = cost;
}
public String getComment() {
return this.comment;
}
public Event comment(String comment) {
this.setComment(comment);
return this;
}
public void setComment(String comment) {
this.comment = comment;
}
public Set<Registration> getRegistrations() {
return this.registrations;
}
public void setRegistrations(Set<Registration> registrations) {
if (this.registrations != null) {
this.registrations.forEach(i -> i.setEvent(null));
}
if (registrations != null) {
registrations.forEach(i -> i.setEvent(this));
}
this.registrations = registrations;
}
public Event registrations(Set<Registration> registrations) {
this.setRegistrations(registrations);
return this;
}
public Event addRegistrations(Registration registration) {
this.registrations.add(registration);
registration.setEvent(this);
return this;
}
public Event removeRegistrations(Registration registration) {
this.registrations.remove(registration);
registration.setEvent(null);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Event)) {
return false;
}
return getId() != null && getId().equals(((Event) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Event{" +
"id=" + getId() +
", name='" + getName() + "'" +
", date='" + getDate() + "'" +
", playersLimit=" + getPlayersLimit() +
", cost=" + getCost() +
", comment='" + getComment() + "'" +
"}";
}
}
@@ -0,0 +1,170 @@
package com.sasiedzi.event.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
/**
* A Registration.
*/
@Entity
@Table(name = "registration")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Registration implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@NotNull
@Column(name = "date_time", nullable = false)
private ZonedDateTime dateTime;
@NotNull
@Column(name = "active", nullable = false)
private Boolean active;
@Column(name = "player_name")
private String playerName;
@Lob
@Column(name = "comment")
private String comment;
@ManyToOne(fetch = FetchType.LAZY)
private User user;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = { "registrations" }, allowSetters = true)
private Event event;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return this.id;
}
public Registration id(Long id) {
this.setId(id);
return this;
}
public void setId(Long id) {
this.id = id;
}
public ZonedDateTime getDateTime() {
return this.dateTime;
}
public Registration dateTime(ZonedDateTime dateTime) {
this.setDateTime(dateTime);
return this;
}
public void setDateTime(ZonedDateTime dateTime) {
this.dateTime = dateTime;
}
public Boolean getActive() {
return this.active;
}
public Registration active(Boolean active) {
this.setActive(active);
return this;
}
public void setActive(Boolean active) {
this.active = active;
}
public String getPlayerName() {
return this.playerName;
}
public Registration playerName(String playerName) {
this.setPlayerName(playerName);
return this;
}
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public String getComment() {
return this.comment;
}
public Registration comment(String comment) {
this.setComment(comment);
return this;
}
public void setComment(String comment) {
this.comment = comment;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public Registration user(User user) {
this.setUser(user);
return this;
}
public Event getEvent() {
return this.event;
}
public void setEvent(Event event) {
this.event = event;
}
public Registration event(Event event) {
this.setEvent(event);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Registration)) {
return false;
}
return getId() != null && getId().equals(((Registration) o).getId());
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Registration{" +
"id=" + getId() +
", dateTime='" + getDateTime() + "'" +
", active='" + getActive() + "'" +
", playerName='" + getPlayerName() + "'" +
", comment='" + getComment() + "'" +
"}";
}
}
@@ -0,0 +1,9 @@
package com.sasiedzi.event.domain.enumeration;
/**
* The ChargeType enumeration.
*/
public enum ChargeType {
CHARGE,
PAYMENT,
}
@@ -0,0 +1,4 @@
/**
* This package file was generated by JHipster
*/
package com.sasiedzi.event.domain.enumeration;
@@ -0,0 +1,40 @@
package com.sasiedzi.event.repository;
import com.sasiedzi.event.domain.Charge;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Charge entity.
*/
@Repository
public interface ChargeRepository extends JpaRepository<Charge, Long> {
@Query("select charge from Charge charge where charge.user.login = ?#{authentication.name}")
List<Charge> findByUserIsCurrentUser();
default Optional<Charge> findOneWithEagerRelationships(Long id) {
return this.findOneWithToOneRelationships(id);
}
default List<Charge> findAllWithEagerRelationships() {
return this.findAllWithToOneRelationships();
}
default Page<Charge> findAllWithEagerRelationships(Pageable pageable) {
return this.findAllWithToOneRelationships(pageable);
}
@Query(value = "select charge from Charge charge left join fetch charge.user", countQuery = "select count(charge) from Charge charge")
Page<Charge> findAllWithToOneRelationships(Pageable pageable);
@Query("select charge from Charge charge left join fetch charge.user")
List<Charge> findAllWithToOneRelationships();
@Query("select charge from Charge charge left join fetch charge.user where charge.id =:id")
Optional<Charge> findOneWithToOneRelationships(@Param("id") Long id);
}
@@ -0,0 +1,12 @@
package com.sasiedzi.event.repository;
import com.sasiedzi.event.domain.Event;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Event entity.
*/
@SuppressWarnings("unused")
@Repository
public interface EventRepository extends JpaRepository<Event, Long> {}
@@ -0,0 +1,45 @@
package com.sasiedzi.event.repository;
import com.sasiedzi.event.domain.Registration;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* Spring Data JPA repository for the Registration entity.
*/
@Repository
public interface RegistrationRepository extends JpaRepository<Registration, Long> {
@Query("select registration from Registration registration where registration.user.login = ?#{authentication.name}")
List<Registration> findByUserIsCurrentUser();
default Optional<Registration> findOneWithEagerRelationships(Long id) {
return this.findOneWithToOneRelationships(id);
}
default List<Registration> findAllWithEagerRelationships() {
return this.findAllWithToOneRelationships();
}
default Page<Registration> findAllWithEagerRelationships(Pageable pageable) {
return this.findAllWithToOneRelationships(pageable);
}
@Query(
value = "select registration from Registration registration left join fetch registration.user left join fetch registration.event",
countQuery = "select count(registration) from Registration registration"
)
Page<Registration> findAllWithToOneRelationships(Pageable pageable);
@Query("select registration from Registration registration left join fetch registration.user left join fetch registration.event")
List<Registration> findAllWithToOneRelationships();
@Query(
"select registration from Registration registration left join fetch registration.user left join fetch registration.event where registration.id =:id"
)
Optional<Registration> findOneWithToOneRelationships(@Param("id") Long id);
}
@@ -0,0 +1,114 @@
package com.sasiedzi.event.service;
import com.sasiedzi.event.domain.Event;
import com.sasiedzi.event.repository.EventRepository;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Service Implementation for managing {@link com.sasiedzi.event.domain.Event}.
*/
@Service
@Transactional
public class EventService {
private static final Logger LOG = LoggerFactory.getLogger(EventService.class);
private final EventRepository eventRepository;
public EventService(EventRepository eventRepository) {
this.eventRepository = eventRepository;
}
/**
* Save a event.
*
* @param event the entity to save.
* @return the persisted entity.
*/
public Event save(Event event) {
LOG.debug("Request to save Event : {}", event);
return eventRepository.save(event);
}
/**
* Update a event.
*
* @param event the entity to save.
* @return the persisted entity.
*/
public Event update(Event event) {
LOG.debug("Request to update Event : {}", event);
return eventRepository.save(event);
}
/**
* Partially update a event.
*
* @param event the entity to update partially.
* @return the persisted entity.
*/
public Optional<Event> partialUpdate(Event event) {
LOG.debug("Request to partially update Event : {}", event);
return eventRepository
.findById(event.getId())
.map(existingEvent -> {
if (event.getName() != null) {
existingEvent.setName(event.getName());
}
if (event.getDate() != null) {
existingEvent.setDate(event.getDate());
}
if (event.getPlayersLimit() != null) {
existingEvent.setPlayersLimit(event.getPlayersLimit());
}
if (event.getCost() != null) {
existingEvent.setCost(event.getCost());
}
if (event.getComment() != null) {
existingEvent.setComment(event.getComment());
}
return existingEvent;
})
.map(eventRepository::save);
}
/**
* Get all the events.
*
* @return the list of entities.
*/
@Transactional(readOnly = true)
public List<Event> findAll() {
LOG.debug("Request to get all Events");
return eventRepository.findAll();
}
/**
* Get one event by id.
*
* @param id the id of the entity.
* @return the entity.
*/
@Transactional(readOnly = true)
public Optional<Event> findOne(Long id) {
LOG.debug("Request to get Event : {}", id);
return eventRepository.findById(id);
}
/**
* Delete the event by id.
*
* @param id the id of the entity.
*/
public void delete(Long id) {
LOG.debug("Request to delete Event : {}", id);
eventRepository.deleteById(id);
}
}
@@ -0,0 +1,189 @@
package com.sasiedzi.event.web.rest;
import com.sasiedzi.event.domain.Charge;
import com.sasiedzi.event.repository.ChargeRepository;
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.sasiedzi.event.domain.Charge}.
*/
@RestController
@RequestMapping("/api/charges")
@Transactional
public class ChargeResource {
private static final Logger LOG = LoggerFactory.getLogger(ChargeResource.class);
private static final String ENTITY_NAME = "charge";
@Value("${jhipster.clientApp.name}")
private String applicationName;
private final ChargeRepository chargeRepository;
public ChargeResource(ChargeRepository chargeRepository) {
this.chargeRepository = chargeRepository;
}
/**
* {@code POST /charges} : Create a new charge.
*
* @param charge the charge to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new charge, or with status {@code 400 (Bad Request)} if the charge has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<Charge> createCharge(@Valid @RequestBody Charge charge) throws URISyntaxException {
LOG.debug("REST request to save Charge : {}", charge);
if (charge.getId() != null) {
throw new BadRequestAlertException("A new charge cannot already have an ID", ENTITY_NAME, "idexists");
}
charge = chargeRepository.save(charge);
return ResponseEntity.created(new URI("/api/charges/" + charge.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, charge.getId().toString()))
.body(charge);
}
/**
* {@code PUT /charges/:id} : Updates an existing charge.
*
* @param id the id of the charge to save.
* @param charge the charge to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated charge,
* or with status {@code 400 (Bad Request)} if the charge is not valid,
* or with status {@code 500 (Internal Server Error)} if the charge couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<Charge> updateCharge(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody Charge charge
) throws URISyntaxException {
LOG.debug("REST request to update Charge : {}, {}", id, charge);
if (charge.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, charge.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!chargeRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
charge = chargeRepository.save(charge);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, charge.getId().toString()))
.body(charge);
}
/**
* {@code PATCH /charges/:id} : Partial updates given fields of an existing charge, field will ignore if it is null
*
* @param id the id of the charge to save.
* @param charge the charge to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated charge,
* or with status {@code 400 (Bad Request)} if the charge is not valid,
* or with status {@code 404 (Not Found)} if the charge is not found,
* or with status {@code 500 (Internal Server Error)} if the charge couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Charge> partialUpdateCharge(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody Charge charge
) throws URISyntaxException {
LOG.debug("REST request to partial update Charge partially : {}, {}", id, charge);
if (charge.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, charge.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!chargeRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<Charge> result = chargeRepository
.findById(charge.getId())
.map(existingCharge -> {
if (charge.getChargeDate() != null) {
existingCharge.setChargeDate(charge.getChargeDate());
}
if (charge.getType() != null) {
existingCharge.setType(charge.getType());
}
if (charge.getAmount() != null) {
existingCharge.setAmount(charge.getAmount());
}
return existingCharge;
})
.map(chargeRepository::save);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, charge.getId().toString())
);
}
/**
* {@code GET /charges} : get all the charges.
*
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of charges in body.
*/
@GetMapping("")
public List<Charge> getAllCharges(@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload) {
LOG.debug("REST request to get all Charges");
if (eagerload) {
return chargeRepository.findAllWithEagerRelationships();
} else {
return chargeRepository.findAll();
}
}
/**
* {@code GET /charges/:id} : get the "id" charge.
*
* @param id the id of the charge to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the charge, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<Charge> getCharge(@PathVariable("id") Long id) {
LOG.debug("REST request to get Charge : {}", id);
Optional<Charge> charge = chargeRepository.findOneWithEagerRelationships(id);
return ResponseUtil.wrapOrNotFound(charge);
}
/**
* {@code DELETE /charges/:id} : delete the "id" charge.
*
* @param id the id of the charge to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCharge(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Charge : {}", id);
chargeRepository.deleteById(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,169 @@
package com.sasiedzi.event.web.rest;
import com.sasiedzi.event.domain.Event;
import com.sasiedzi.event.repository.EventRepository;
import com.sasiedzi.event.service.EventService;
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.sasiedzi.event.domain.Event}.
*/
@RestController
@RequestMapping("/api/events")
public class EventResource {
private static final Logger LOG = LoggerFactory.getLogger(EventResource.class);
private static final String ENTITY_NAME = "event";
@Value("${jhipster.clientApp.name}")
private String applicationName;
private final EventService eventService;
private final EventRepository eventRepository;
public EventResource(EventService eventService, EventRepository eventRepository) {
this.eventService = eventService;
this.eventRepository = eventRepository;
}
/**
* {@code POST /events} : Create a new event.
*
* @param event the event to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new event, or with status {@code 400 (Bad Request)} if the event has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<Event> createEvent(@Valid @RequestBody Event event) throws URISyntaxException {
LOG.debug("REST request to save Event : {}", event);
if (event.getId() != null) {
throw new BadRequestAlertException("A new event cannot already have an ID", ENTITY_NAME, "idexists");
}
event = eventService.save(event);
return ResponseEntity.created(new URI("/api/events/" + event.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, event.getId().toString()))
.body(event);
}
/**
* {@code PUT /events/:id} : Updates an existing event.
*
* @param id the id of the event to save.
* @param event the event to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated event,
* or with status {@code 400 (Bad Request)} if the event is not valid,
* or with status {@code 500 (Internal Server Error)} if the event couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<Event> updateEvent(@PathVariable(value = "id", required = false) final Long id, @Valid @RequestBody Event event)
throws URISyntaxException {
LOG.debug("REST request to update Event : {}, {}", id, event);
if (event.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, event.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!eventRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
event = eventService.update(event);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, event.getId().toString()))
.body(event);
}
/**
* {@code PATCH /events/:id} : Partial updates given fields of an existing event, field will ignore if it is null
*
* @param id the id of the event to save.
* @param event the event to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated event,
* or with status {@code 400 (Bad Request)} if the event is not valid,
* or with status {@code 404 (Not Found)} if the event is not found,
* or with status {@code 500 (Internal Server Error)} if the event couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Event> partialUpdateEvent(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody Event event
) throws URISyntaxException {
LOG.debug("REST request to partial update Event partially : {}, {}", id, event);
if (event.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, event.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!eventRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<Event> result = eventService.partialUpdate(event);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, event.getId().toString())
);
}
/**
* {@code GET /events} : get all the events.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of events in body.
*/
@GetMapping("")
public List<Event> getAllEvents() {
LOG.debug("REST request to get all Events");
return eventService.findAll();
}
/**
* {@code GET /events/:id} : get the "id" event.
*
* @param id the id of the event to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the event, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<Event> getEvent(@PathVariable("id") Long id) {
LOG.debug("REST request to get Event : {}", id);
Optional<Event> event = eventService.findOne(id);
return ResponseUtil.wrapOrNotFound(event);
}
/**
* {@code DELETE /events/:id} : delete the "id" event.
*
* @param id the id of the event to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteEvent(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Event : {}", id);
eventService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
.build();
}
}
@@ -0,0 +1,194 @@
package com.sasiedzi.event.web.rest;
import com.sasiedzi.event.domain.Registration;
import com.sasiedzi.event.repository.RegistrationRepository;
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import tech.jhipster.web.util.HeaderUtil;
import tech.jhipster.web.util.ResponseUtil;
/**
* REST controller for managing {@link com.sasiedzi.event.domain.Registration}.
*/
@RestController
@RequestMapping("/api/registrations")
@Transactional
public class RegistrationResource {
private static final Logger LOG = LoggerFactory.getLogger(RegistrationResource.class);
private static final String ENTITY_NAME = "registration";
@Value("${jhipster.clientApp.name}")
private String applicationName;
private final RegistrationRepository registrationRepository;
public RegistrationResource(RegistrationRepository registrationRepository) {
this.registrationRepository = registrationRepository;
}
/**
* {@code POST /registrations} : Create a new registration.
*
* @param registration the registration to create.
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new registration, or with status {@code 400 (Bad Request)} if the registration has already an ID.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PostMapping("")
public ResponseEntity<Registration> createRegistration(@Valid @RequestBody Registration registration) throws URISyntaxException {
LOG.debug("REST request to save Registration : {}", registration);
if (registration.getId() != null) {
throw new BadRequestAlertException("A new registration cannot already have an ID", ENTITY_NAME, "idexists");
}
registration = registrationRepository.save(registration);
return ResponseEntity.created(new URI("/api/registrations/" + registration.getId()))
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, registration.getId().toString()))
.body(registration);
}
/**
* {@code PUT /registrations/:id} : Updates an existing registration.
*
* @param id the id of the registration to save.
* @param registration the registration to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated registration,
* or with status {@code 400 (Bad Request)} if the registration is not valid,
* or with status {@code 500 (Internal Server Error)} if the registration couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PutMapping("/{id}")
public ResponseEntity<Registration> updateRegistration(
@PathVariable(value = "id", required = false) final Long id,
@Valid @RequestBody Registration registration
) throws URISyntaxException {
LOG.debug("REST request to update Registration : {}, {}", id, registration);
if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, registration.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!registrationRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
registration = registrationRepository.save(registration);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, registration.getId().toString()))
.body(registration);
}
/**
* {@code PATCH /registrations/:id} : Partial updates given fields of an existing registration, field will ignore if it is null
*
* @param id the id of the registration to save.
* @param registration the registration to update.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated registration,
* or with status {@code 400 (Bad Request)} if the registration is not valid,
* or with status {@code 404 (Not Found)} if the registration is not found,
* or with status {@code 500 (Internal Server Error)} if the registration couldn't be updated.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
public ResponseEntity<Registration> partialUpdateRegistration(
@PathVariable(value = "id", required = false) final Long id,
@NotNull @RequestBody Registration registration
) throws URISyntaxException {
LOG.debug("REST request to partial update Registration partially : {}, {}", id, registration);
if (registration.getId() == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
if (!Objects.equals(id, registration.getId())) {
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
}
if (!registrationRepository.existsById(id)) {
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
}
Optional<Registration> result = registrationRepository
.findById(registration.getId())
.map(existingRegistration -> {
if (registration.getDateTime() != null) {
existingRegistration.setDateTime(registration.getDateTime());
}
if (registration.getActive() != null) {
existingRegistration.setActive(registration.getActive());
}
if (registration.getPlayerName() != null) {
existingRegistration.setPlayerName(registration.getPlayerName());
}
if (registration.getComment() != null) {
existingRegistration.setComment(registration.getComment());
}
return existingRegistration;
})
.map(registrationRepository::save);
return ResponseUtil.wrapOrNotFound(
result,
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, registration.getId().toString())
);
}
/**
* {@code GET /registrations} : get all the registrations.
*
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of registrations in body.
*/
@GetMapping("")
public List<Registration> getAllRegistrations(
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
) {
LOG.debug("REST request to get all Registrations");
if (eagerload) {
return registrationRepository.findAllWithEagerRelationships();
} else {
return registrationRepository.findAll();
}
}
/**
* {@code GET /registrations/:id} : get the "id" registration.
*
* @param id the id of the registration to retrieve.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the registration, or with status {@code 404 (Not Found)}.
*/
@GetMapping("/{id}")
public ResponseEntity<Registration> getRegistration(@PathVariable("id") Long id) {
LOG.debug("REST request to get Registration : {}", id);
Optional<Registration> registration = registrationRepository.findOneWithEagerRelationships(id);
return ResponseUtil.wrapOrNotFound(registration);
}
/**
* {@code DELETE /registrations/:id} : delete the "id" registration.
*
* @param id the id of the registration to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteRegistration(@PathVariable("id") Long id) {
LOG.debug("REST request to delete Registration : {}", id);
registrationRepository.deleteById(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
.build();
}
}