完成部分帖子相关功能,同时完善了一些用户功能
Change-Id: Ie9d22bcceec197930d48f578d8b9a749ce7a3382
diff --git a/src/main/java/com/pt/controller/AdminController.java b/src/main/java/com/pt/controller/AdminController.java
new file mode 100644
index 0000000..1ddfc92
--- /dev/null
+++ b/src/main/java/com/pt/controller/AdminController.java
@@ -0,0 +1,41 @@
+package com.pt.controller;
+
+import com.pt.constant.Constants;
+import com.pt.entity.Admin;
+import com.pt.repository.AdminRepository;
+import com.pt.service.AdminService;
+import com.pt.utils.JWTUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.http.ResponseEntity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/admin")
+@CrossOrigin(origins = "*")
+public class AdminController {
+
+ @Autowired
+ private AdminService adminService;
+
+ @PostMapping("/login")
+ public ResponseEntity<?> loginAdmin(@RequestParam("username") String username,
+ @RequestParam("password") String password) {
+ Map<String, Object> ans = new HashMap<>();
+ Admin admin = adminService.findByUsernameAndPassword(username, password);
+ if (admin != null) {
+ ans.put("result", "Login successful");
+ ans.put("token", JWTUtils.generateToken(username, Constants.UserRole.ADMIN, (int)1.2e8));
+ return ResponseEntity.ok().body(ans);
+ } else {
+ ans.put("result", "Invalid username or password");
+ return ResponseEntity.badRequest().body(ans);
+ }
+ }
+}