mirror of https://github.com/elunez/eladmin
return event
parent
33aaa6a32b
commit
186b685ab5
|
@ -23,10 +23,14 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
public class EntityNotFoundException extends RuntimeException {
|
||||
|
||||
public EntityNotFoundException(Class clazz, String field, String val) {
|
||||
public EntityNotFoundException(Class<?> clazz, String field, String val) {
|
||||
super(EntityNotFoundException.generateMessage(clazz.getSimpleName(), field, val));
|
||||
}
|
||||
|
||||
public EntityNotFoundException(Class<?> clazz, String field, Long val) {
|
||||
super(EntityNotFoundException.generateMessage(clazz.getSimpleName(), field, "" + val));
|
||||
}
|
||||
|
||||
private static String generateMessage(String entity, String field, String val) {
|
||||
return StringUtils.capitalize(entity)
|
||||
+ " with " + field + " " + val + " does not exist";
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
-- Add tags column to event table
|
||||
ALTER TABLE event
|
||||
add column poster_image varchar(255),
|
||||
ADD COLUMN tags VARCHAR(255) NULL COMMENT 'Tags stored as comma-delimited string';
|
2
pom.xml
2
pom.xml
|
@ -29,7 +29,7 @@
|
|||
<logback.version>1.2.9</logback.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>17</java.version>
|
||||
<fastjson2.version>2.0.54</fastjson2.version>
|
||||
<druid.version>1.2.19</druid.version>
|
||||
<commons-pool2.version>2.11.1</commons-pool2.version>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright 2019-2025 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.srr.converter;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
import javax.persistence.Converter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Converter to store List<String> as a comma-delimited string in database
|
||||
* @author Chanheng
|
||||
* @date 2025-05-26
|
||||
*/
|
||||
@Converter
|
||||
public class StringListConverter implements AttributeConverter<List<String>, String> {
|
||||
|
||||
private static final String DELIMITER = ",";
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(List<String> stringList) {
|
||||
if (stringList == null || stringList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return String.join(DELIMITER, stringList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertToEntityAttribute(String string) {
|
||||
if (string == null || string.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return new ArrayList<>(Arrays.asList(string.split(DELIMITER)));
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.srr.domain;
|
||||
|
||||
import com.srr.converter.StringListConverter;
|
||||
import com.srr.enumeration.EventStatus;
|
||||
import com.srr.enumeration.Format;
|
||||
import lombok.Data;
|
||||
|
@ -24,6 +25,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
|
|||
import javax.persistence.*;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Convert;
|
||||
import org.hibernate.annotations.*;
|
||||
import java.sql.Timestamp;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
@ -138,6 +140,13 @@ public class Event implements Serializable {
|
|||
@Column(name = "`allow_wait_list`")
|
||||
private boolean allowWaitList;
|
||||
|
||||
@Column(name = "`poster_image`")
|
||||
private String posterImage;
|
||||
|
||||
@Column(name = "`tags`")
|
||||
@Convert(converter = StringListConverter.class)
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "event_co_host_player",
|
||||
joinColumns = {@JoinColumn(name = "event_id",referencedColumnName = "id")},
|
||||
|
|
|
@ -93,6 +93,11 @@ public class EventDto implements Serializable {
|
|||
@ApiModelProperty(value = "Number of groups")
|
||||
private Integer groupCount;
|
||||
|
||||
private String posterImage;
|
||||
|
||||
@ApiModelProperty(value = "Co-host players")
|
||||
private List<PlayerDto> coHostPlayers;
|
||||
|
||||
@ApiModelProperty(value = "Tags")
|
||||
private List<String> tags;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.srr.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class JoinEventDto {
|
||||
private Long playerId;
|
||||
@NotNull
|
||||
private Long eventId;
|
||||
private Long teamId;
|
||||
}
|
|
@ -15,26 +15,31 @@
|
|||
*/
|
||||
package com.srr.rest;
|
||||
|
||||
import me.zhengjie.annotation.Log;
|
||||
import com.srr.domain.Event;
|
||||
import com.srr.service.EventService;
|
||||
import com.srr.dto.EventDto;
|
||||
import com.srr.dto.EventQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import com.srr.dto.JoinEventDto;
|
||||
import com.srr.enumeration.EventStatus;
|
||||
import com.srr.service.EventService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.annotation.Log;
|
||||
import me.zhengjie.utils.PageResult;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import me.zhengjie.utils.PageResult;
|
||||
import com.srr.dto.EventDto;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author Chanheng
|
||||
* @website https://eladmin.vip
|
||||
* @date 2025-05-18
|
||||
**/
|
||||
@RestController
|
||||
|
@ -64,8 +69,8 @@ public class EventController {
|
|||
@ApiOperation("Add event")
|
||||
@PreAuthorize("@el.check('event:add')")
|
||||
public ResponseEntity<Object> createEvent(@Validated @RequestBody Event resources) {
|
||||
eventService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
final var result = eventService.create(resources);
|
||||
return new ResponseEntity<>(result, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
|
@ -73,8 +78,24 @@ public class EventController {
|
|||
@ApiOperation("Modify event")
|
||||
@PreAuthorize("@el.check('event:edit')")
|
||||
public ResponseEntity<Object> updateEvent(@Validated @RequestBody Event resources) {
|
||||
eventService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
final var result = eventService.update(resources);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/{id}/status/{status}")
|
||||
@Log("Update event status")
|
||||
@ApiOperation("Update event status")
|
||||
@PreAuthorize("@el.check('event:edit')")
|
||||
public ResponseEntity<Object> updateEventStatus(
|
||||
@PathVariable Long id,
|
||||
@PathVariable EventStatus status) {
|
||||
final var result = eventService.updateStatus(id, status);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> joinEvent(@PathVariable Long id, @RequestBody JoinEventDto joinEventDto) {
|
||||
final EventDto result = eventService.joinEvent(joinEventDto);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.srr.service;
|
|||
import com.srr.domain.Event;
|
||||
import com.srr.dto.EventDto;
|
||||
import com.srr.dto.EventQueryCriteria;
|
||||
import com.srr.enumeration.EventStatus;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -59,13 +60,15 @@ public interface EventService {
|
|||
* Create
|
||||
* @param resources /
|
||||
*/
|
||||
void create(Event resources);
|
||||
EventDto create(Event resources);
|
||||
|
||||
/**
|
||||
* Edit
|
||||
* @param resources /
|
||||
*/
|
||||
void update(Event resources);
|
||||
EventDto update(Event resources);
|
||||
|
||||
EventDto updateStatus(Long id, EventStatus status);
|
||||
|
||||
/**
|
||||
* Multi-select delete
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
package com.srr.service.impl;
|
||||
|
||||
import com.srr.domain.Event;
|
||||
import com.srr.enumeration.EventStatus;
|
||||
import me.zhengjie.exception.EntityNotFoundException;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -30,18 +32,22 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import me.zhengjie.utils.PageResult;
|
||||
|
||||
/**
|
||||
* @author Chanheng
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @author Chanheng
|
||||
* @date 2025-05-18
|
||||
**/
|
||||
@Service
|
||||
|
@ -72,17 +78,36 @@ public class EventServiceImpl implements EventService {
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(Event resources) {
|
||||
eventRepository.save(resources);
|
||||
public EventDto create(Event resources) {
|
||||
resources.setStatus(EventStatus.DRAFT);
|
||||
final var result = eventRepository.save(resources);
|
||||
return eventMapper.toDto(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Event resources) {
|
||||
public EventDto update(Event resources) {
|
||||
Event event = eventRepository.findById(resources.getId()).orElseGet(Event::new);
|
||||
ValidationUtil.isNull(event.getId(), "Event", "id", resources.getId());
|
||||
event.copy(resources);
|
||||
eventRepository.save(event);
|
||||
final var result = eventRepository.save(event);
|
||||
return eventMapper.toDto(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EventDto updateStatus(Long id, EventStatus status) {
|
||||
Event event = eventRepository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Event.class, "id", id));
|
||||
|
||||
// Only update the status field
|
||||
event.setStatus(status);
|
||||
if (status == EventStatus.CHECK_IN) {
|
||||
event.setCheckInAt(Timestamp.from(Instant.now()));
|
||||
}
|
||||
|
||||
final var result = eventRepository.save(event);
|
||||
return eventMapper.toDto(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue