feat: 添加了社团相关功能(查找社团)
This commit is contained in:
parent
99df89efbc
commit
bf23cc4c9c
26
src/main/java/org/mmga/clubs/controller/ClubController.java
Normal file
26
src/main/java/org/mmga/clubs/controller/ClubController.java
Normal file
@ -0,0 +1,26 @@
|
||||
package org.mmga.clubs.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.mmga.clubs.entities.BaseResponse;
|
||||
import org.mmga.clubs.entities.club.ClubInformation;
|
||||
import org.mmga.clubs.service.ClubService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/club")
|
||||
@Tag(name = "社团", description = "社团相关接口")
|
||||
public class ClubController {
|
||||
private final ClubService clubService;
|
||||
@Autowired
|
||||
public ClubController(ClubService clubService) {
|
||||
this.clubService = clubService;
|
||||
}
|
||||
@GetMapping("/")
|
||||
public BaseResponse<ClubInformation> getClub(@RequestParam("id") int clubId){
|
||||
return clubService.getClubInformationById(clubId);
|
||||
}
|
||||
}
|
@ -3,7 +3,10 @@ package org.mmga.clubs.dao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.mmga.clubs.entities.ClubUserAuthVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ClubUserAuthDao {
|
||||
ClubUserAuthVo getClubUserAuthVoByUserId(int userId);
|
||||
List<ClubUserAuthVo> getUsersByClubId(int clubId);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.mmga.clubs.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.mmga.clubs.entities.user.UserRegResponseVo;
|
||||
import org.mmga.clubs.entities.user.UserSimpleInformation;
|
||||
import org.mmga.clubs.entities.user.UserVo;
|
||||
|
||||
import java.util.List;
|
||||
@ -20,4 +21,6 @@ public interface UserDao {
|
||||
void changePasswordAdmin(int id, String password);
|
||||
void changeAuth(int id, int authId);
|
||||
void changeAvatar(int id, String sha);
|
||||
|
||||
UserSimpleInformation getUserSimpleInformation(int userId);
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package org.mmga.clubs.entities.club;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.mmga.clubs.entities.user.ClubUserSimpleInformation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "社团详细详细")
|
||||
public class ClubInformation {
|
||||
@Schema(description = "社团ID")
|
||||
private int id;
|
||||
@Schema(description = "社团名称")
|
||||
private String name;
|
||||
@Schema(description = "社团简介")
|
||||
private String commit;
|
||||
@Schema(description = "社团用户信息")
|
||||
private List<ClubUserSimpleInformation> users;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.mmga.clubs.entities.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Schema(description = "社团用户简单信息")
|
||||
public class ClubUserSimpleInformation extends UserSimpleInformation{
|
||||
@Schema(description = "社团ID")
|
||||
private int clubId;
|
||||
@Schema(description = "社团职务名称")
|
||||
private String clubAuthName;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.mmga.clubs.entities.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "用户基础信息")
|
||||
public class UserSimpleInformation {
|
||||
@Schema(description = "用户ID")
|
||||
private int id;
|
||||
@Schema(description = "用户名")
|
||||
private String name;
|
||||
@Schema(description = "用户头像SHA1")
|
||||
private String avatar;
|
||||
}
|
@ -2,23 +2,33 @@ package org.mmga.clubs.service;
|
||||
|
||||
import org.mmga.clubs.dao.ClubDao;
|
||||
import org.mmga.clubs.dao.ClubUserAuthDao;
|
||||
import org.mmga.clubs.entities.BaseResponse;
|
||||
import org.mmga.clubs.entities.ClubUserAuthVo;
|
||||
import org.mmga.clubs.entities.auth.Auth;
|
||||
import org.mmga.clubs.entities.club.Club;
|
||||
import org.mmga.clubs.entities.club.ClubInformation;
|
||||
import org.mmga.clubs.entities.club.ClubVo;
|
||||
import org.mmga.clubs.entities.user.ClubUserSimpleInformation;
|
||||
import org.mmga.clubs.entities.user.UserSimpleInformation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ClubService {
|
||||
private final ClubUserAuthDao clubUserAuthDao;
|
||||
private final ClubDao clubDao;
|
||||
private final AuthService authService;
|
||||
private final UserService userService;
|
||||
|
||||
@Autowired
|
||||
public ClubService(ClubUserAuthDao clubUserAuthDao, ClubDao clubDao, AuthService authService){
|
||||
public ClubService(ClubUserAuthDao clubUserAuthDao, ClubDao clubDao, AuthService authService, @Lazy UserService userService){
|
||||
this.clubDao = clubDao;
|
||||
this.clubUserAuthDao = clubUserAuthDao;
|
||||
this.authService = authService;
|
||||
this.userService = userService;
|
||||
}
|
||||
public Club getClubWithoutAuthById(int id){
|
||||
ClubVo clubById = this.clubDao.getClubById(id);
|
||||
@ -39,4 +49,29 @@ public class ClubService {
|
||||
clubById.setAuth(auth);
|
||||
return clubById;
|
||||
}
|
||||
private List<ClubUserSimpleInformation> getUserInformationByClubId(int clubId){
|
||||
List<ClubUserAuthVo> usersByClubId = this.clubUserAuthDao.getUsersByClubId(clubId);
|
||||
return usersByClubId.stream().map(this::packageInformation).toList();
|
||||
}
|
||||
private ClubUserSimpleInformation packageInformation(ClubUserAuthVo clubUserAuthVo){
|
||||
int i = clubUserAuthVo.authId();
|
||||
String authName = i != -1 ? authService.getAuthById(i).getName() : "社员";
|
||||
UserSimpleInformation userSimpleInformation = userService.getUserSimpleInformation(clubUserAuthVo.userId());
|
||||
ClubUserSimpleInformation clubUserSimpleInformation = new ClubUserSimpleInformation();
|
||||
clubUserSimpleInformation.setId(userSimpleInformation.getId());
|
||||
clubUserSimpleInformation.setName(userSimpleInformation.getName());
|
||||
clubUserSimpleInformation.setAvatar(userSimpleInformation.getAvatar());
|
||||
clubUserSimpleInformation.setClubId(clubUserAuthVo.clubId());
|
||||
clubUserSimpleInformation.setClubAuthName(authName);
|
||||
return clubUserSimpleInformation;
|
||||
}
|
||||
public BaseResponse<ClubInformation> getClubInformationById(int clubId) {
|
||||
Club clubWithoutAuthById = getClubWithoutAuthById(clubId);
|
||||
ClubInformation clubInformation = new ClubInformation();
|
||||
clubInformation.setId(clubWithoutAuthById.getId());
|
||||
clubInformation.setName(clubWithoutAuthById.getName());
|
||||
clubInformation.setCommit(clubWithoutAuthById.getCommit());
|
||||
clubInformation.setUsers(this.getUserInformationByClubId(clubId));
|
||||
return BaseResponse.success(clubInformation);
|
||||
}
|
||||
}
|
||||
|
@ -230,4 +230,8 @@ public class UserService {
|
||||
fileInputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public UserSimpleInformation getUserSimpleInformation(int userId) {
|
||||
return userDao.getUserSimpleInformation(userId);
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,7 @@
|
||||
<select id="getClubUserAuthVoByUserId" resultType="org.mmga.clubs.entities.ClubUserAuthVo">
|
||||
select * from `club_user_auth` where `user_id` = #{userId};
|
||||
</select>
|
||||
<select id="getUsersByClubId" resultType="org.mmga.clubs.entities.ClubUserAuthVo">
|
||||
select * from `club_user_auth` where `club_id` = #{clubId};
|
||||
</select>
|
||||
</mapper>
|
@ -36,4 +36,7 @@
|
||||
<select id="queryTotalUserCount" resultType="java.lang.Long">
|
||||
select count(*) from `user`;
|
||||
</select>
|
||||
<select id="getUserSimpleInformation" resultType="org.mmga.clubs.entities.user.UserSimpleInformation">
|
||||
select `id`, `name`, `avatar` from `user` where `id` = #{userId};
|
||||
</select>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user