Add qp to chat service

This commit is contained in:
Adam
2019-01-05 10:15:36 -05:00
parent 5192a28cec
commit b65018ae84
4 changed files with 88 additions and 6 deletions

View File

@@ -48,7 +48,7 @@ public class ChatController
private ChatService chatService;
@PostMapping("/kc")
public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc)
public void submitKc(@RequestParam String name, @RequestParam String boss, @RequestParam int kc)
{
if (kc <= 0)
{
@@ -60,7 +60,7 @@ public class ChatController
}
@GetMapping("/kc")
public int get(@RequestParam String name, @RequestParam String boss)
public int getKc(@RequestParam String name, @RequestParam String boss)
{
Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss));
if (kc == null)
@@ -78,4 +78,26 @@ public class ChatController
}
return kc;
}
@PostMapping("/qp")
public void submitQp(@RequestParam String name, @RequestParam int qp)
{
if (qp < 0)
{
return;
}
chatService.setQp(name, qp);
}
@GetMapping("/qp")
public int getKc(@RequestParam String name)
{
Integer kc = chatService.getQp(name);
if (kc == null)
{
throw new NotFoundException();
}
return kc;
}
}

View File

@@ -60,4 +60,22 @@ public class ChatService
jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc));
}
}
public Integer getQp(String name)
{
String value;
try (Jedis jedis = jedisPool.getResource())
{
value = jedis.get("qp." + name);
}
return value == null ? null : Integer.parseInt(value);
}
public void setQp(String name, int qp)
{
try (Jedis jedis = jedisPool.getResource())
{
jedis.setex("qp." + name, (int) EXPIRE.getSeconds(), Integer.toString(qp));
}
}
}