Add party name retrieval: implemented PartyMapper for database queries, updated ChatService with new getPartyName method, and extended /chat/party/{id}/name API endpoint.
This commit is contained in:
parent
8931bdc30d
commit
79a62e9ce9
|
|
@ -40,4 +40,17 @@ public class ChatController implements ChatApi {
|
|||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<String> getPartyName(String id) {
|
||||
int partyId;
|
||||
try {
|
||||
partyId = Integer.parseInt(id);
|
||||
} catch (NumberFormatException e) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
return chatService.getPartyName(partyId)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package com.alttd.altitudeweb.services.chat;
|
|||
|
||||
import com.alttd.altitudeweb.controllers.chat.ChatMessage;
|
||||
import com.alttd.altitudeweb.controllers.chat.ChatMessageMapper;
|
||||
import com.alttd.altitudeweb.controllers.chat.ChatMessageType;
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.chat.ChatLogMapper;
|
||||
import com.alttd.altitudeweb.database.chat.NicknameMapper;
|
||||
import com.alttd.altitudeweb.database.chat.PartyMapper;
|
||||
import com.alttd.altitudeweb.database.luckperms.UUIDUsernameMapper;
|
||||
import com.alttd.altitudeweb.model.PermissionClaimDto;
|
||||
import com.alttd.altitudeweb.model.PlayerNameDto;
|
||||
|
|
@ -163,4 +163,9 @@ public class ChatService {
|
|||
return Optional.of(playerNameDto);
|
||||
}
|
||||
|
||||
public Optional<String> getPartyName(int id) {
|
||||
return Connection.getConnection(Databases.CHAT)
|
||||
.runQueryWithResult(sqlSession -> sqlSession.getMapper(PartyMapper.class).getPartyName(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.alttd.altitudeweb.database.chat;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PartyMapper {
|
||||
|
||||
@Select("""
|
||||
SELECT party_name FROM parties
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
Optional<String> getPartyName(@Param("id") int id);
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package com.alttd.altitudeweb.setup;
|
|||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.chat.ChatLogMapper;
|
||||
import com.alttd.altitudeweb.database.chat.NicknameMapper;
|
||||
import com.alttd.altitudeweb.database.votingplugin.VotingPluginUsersMapper;
|
||||
import com.alttd.altitudeweb.database.chat.PartyMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
|
|
@ -14,6 +14,7 @@ public class InitializeChat {
|
|||
Connection.getConnection(Databases.CHAT, (configuration) -> {
|
||||
configuration.addMapper(ChatLogMapper.class);
|
||||
configuration.addMapper(NicknameMapper.class);
|
||||
configuration.addMapper(PartyMapper.class);
|
||||
}).join();
|
||||
log.debug("Initialized Chat");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,30 @@ paths:
|
|||
$ref: "#/components/schemas/PlayerName"
|
||||
"404":
|
||||
description: Player not found
|
||||
|
||||
/chat/party/{id}/name:
|
||||
get:
|
||||
tags:
|
||||
- chat
|
||||
summary: Gets the name, of the party based on the id
|
||||
operationId: getPartyName
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: The party name
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: Invalid ID
|
||||
"404":
|
||||
description: Party not found
|
||||
components:
|
||||
schemas:
|
||||
PlayerName:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user