Refactor createAppeal in AppealMapper to void return type, adjust AppealController to remove redundant UUID handling. Optimize AppealDataMapper to use UUID.randomUUID().
This commit is contained in:
parent
eaee31ab2b
commit
f026f24263
|
|
@ -46,11 +46,8 @@ public class AppealController implements AppealsApi {
|
||||||
log.debug("Loading history by id");
|
log.debug("Loading history by id");
|
||||||
try {
|
try {
|
||||||
Appeal appeal = mapper.minecraftAppealDtoToAppeal(minecraftAppealDto);
|
Appeal appeal = mapper.minecraftAppealDtoToAppeal(minecraftAppealDto);
|
||||||
UUID appealId = sqlSession.getMapper(AppealMapper.class)
|
sqlSession.getMapper(AppealMapper.class).createAppeal(appeal);
|
||||||
.createAppeal(appeal);
|
appealCompletableFuture.complete(appeal);
|
||||||
Appeal finalAppeal = new Appeal(appealId, appeal.uuid(), appeal.username(), appeal.reason(),
|
|
||||||
appeal.createdAt(), appeal.sendAt(), appeal.email(), appeal.assignedTo());
|
|
||||||
appealCompletableFuture.complete(finalAppeal);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to load history count", e);
|
log.error("Failed to load history count", e);
|
||||||
appealCompletableFuture.completeExceptionally(e);
|
appealCompletableFuture.completeExceptionally(e);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import com.alttd.altitudeweb.database.web_db.forms.Appeal;
|
||||||
import com.alttd.altitudeweb.model.MinecraftAppealDto;
|
import com.alttd.altitudeweb.model.MinecraftAppealDto;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AppealDataMapper {
|
public class AppealDataMapper {
|
||||||
public MinecraftAppealDto appealToMinecraftAppealDto(Appeal appeal) {
|
public MinecraftAppealDto appealToMinecraftAppealDto(Appeal appeal) {
|
||||||
|
|
@ -17,7 +19,7 @@ public class AppealDataMapper {
|
||||||
|
|
||||||
public Appeal minecraftAppealDtoToAppeal(MinecraftAppealDto minecraftAppealDto) {
|
public Appeal minecraftAppealDtoToAppeal(MinecraftAppealDto minecraftAppealDto) {
|
||||||
return new Appeal(
|
return new Appeal(
|
||||||
null,
|
UUID.randomUUID(),
|
||||||
minecraftAppealDto.getUuid(),
|
minecraftAppealDto.getUuid(),
|
||||||
minecraftAppealDto.getUsername(),
|
minecraftAppealDto.getUsername(),
|
||||||
minecraftAppealDto.getAppeal(),
|
minecraftAppealDto.getAppeal(),
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
package com.alttd.altitudeweb.database.web_db.forms;
|
package com.alttd.altitudeweb.database.web_db.forms;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Options;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface AppealMapper {
|
public interface AppealMapper {
|
||||||
|
|
||||||
|
|
@ -14,8 +12,7 @@ public interface AppealMapper {
|
||||||
INSERT INTO appeals (uuid, username, reason, created_at, send_at, e_mail, assigned_to)
|
INSERT INTO appeals (uuid, username, reason, created_at, send_at, e_mail, assigned_to)
|
||||||
VALUES (#{uuid}, #{username}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
|
VALUES (#{uuid}, #{username}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
|
||||||
""")
|
""")
|
||||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
void createAppeal(Appeal appeal);
|
||||||
UUID createAppeal(Appeal appeal);
|
|
||||||
|
|
||||||
@Update("""
|
@Update("""
|
||||||
UPDATE appeals
|
UPDATE appeals
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user