Skip to content

Commit

Permalink
Merge pull request #150 from HGU-WALAB/HISTUDY-149
Browse files Browse the repository at this point in the history
�학기별 스터디그룹 관리
  • Loading branch information
zionhann authored Mar 9, 2024
2 parents 6991a9c + 4b59aed commit f551a14
Show file tree
Hide file tree
Showing 71 changed files with 2,056 additions and 1,938 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -55,7 +56,6 @@ public ResponseEntity<TeamReportDto> getTeamReports(
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
TeamReportDto res = teamService.getTeamReports(id, claims.getSubject());

return ResponseEntity.ok(res);
}
throw new ForbiddenException();
Expand All @@ -80,9 +80,10 @@ public ResponseEntity<List<UserDto.UserInfo>> getAppliedUsers(@RequestAttribute

@Operation(summary = "그룹 매칭")
@PostMapping("/team-match")
public ResponseEntity<TeamDto.MatchResults> matchTeam(@RequestAttribute Claims claims) {
public ResponseEntity<Void> matchTeam(@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
return ResponseEntity.ok(teamService.matchTeam());
teamService.matchTeam();
return ResponseEntity.status(HttpStatus.CREATED).build();
}
throw new ForbiddenException();
}
Expand All @@ -106,19 +107,20 @@ public ResponseEntity<List<UserDto.UserInfo>> getUnmatchedUsers(@RequestAttribut

@Operation(summary = "특정 유저 지원폼 삭제")
@DeleteMapping("/form")
public UserDto.UserInfo deleteForm(@RequestParam String sid, @RequestAttribute Claims claims) {
public void deleteForm(@RequestParam String sid, @RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
return userService.deleteUserForm(sid);
userService.deleteUserForm(sid);
return;
}
throw new ForbiddenException();
}

@Operation(summary = "유저 정보 수정")
@PostMapping("/edit-user")
public UserDto.UserInfo editUser(
@RequestBody UserDto.UserEdit form, @RequestAttribute Claims claims) {
public void editUser(@RequestBody UserDto.UserEdit form, @RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
return userService.editUser(form);
userService.editUser(form);
return;
}
throw new ForbiddenException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import edu.handong.csee.histudy.controller.form.ApplyForm;
import edu.handong.csee.histudy.controller.form.ApplyFormV2;
import edu.handong.csee.histudy.domain.Friendship;
import edu.handong.csee.histudy.domain.Role;
import edu.handong.csee.histudy.domain.User;
import edu.handong.csee.histudy.domain.UserCourse;
import edu.handong.csee.histudy.domain.*;
import edu.handong.csee.histudy.dto.ApplyFormDto;
import edu.handong.csee.histudy.dto.CourseDto;
import edu.handong.csee.histudy.dto.UserDto;
Expand All @@ -15,79 +12,71 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Comparator;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;

@Tag(name = "스터디 신청 API")
@SecurityRequirement(name = "USER")
@RestController
@RequiredArgsConstructor
public class ApplyFormController {

private final UserService userService;
private final UserService userService;

/**
* 스터디 신청 정보를 등록하는 API
*
* @param form 신청 정보(같이 하고 싶은 학생 목록, 강의 목록)
* @param claims 토큰 페이로드
* @return 신청 내역
* @see #applyForStudy(ApplyFormV2, Claims)
* @deprecated 신청한 학생 목록을 보낼 때
* 더 이상 학번 정보를 보낼 수 없기 때문에 사용하지 않음
*/
@Operation(summary = "스터디 신청")
@Deprecated
@PostMapping("/api/forms")
public ResponseEntity<ApplyFormDto> applyForStudy(
@RequestBody ApplyForm form,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.USER)) {
return ResponseEntity.ok(userService.apply(form, claims.getSubject()));
}
throw new ForbiddenException();
/**
* 스터디 신청 정보를 등록하는 API
*
* @param form 신청 정보(같이 하고 싶은 학생 목록, 강의 목록)
* @param claims 토큰 페이로드
* @return 신청 내역
* @see #applyForStudy(ApplyFormV2, Claims)
* @deprecated 신청한 학생 목록을 보낼 때 더 이상 학번 정보를 보낼 수 없기 때문에 사용하지 않음
*/
@Operation(summary = "스터디 신청")
@Deprecated
@PostMapping("/api/forms")
public ResponseEntity<ApplyFormDto> applyForStudy(
@RequestBody ApplyForm form, @RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.USER)) {
return ResponseEntity.ok(userService.apply(form, claims.getSubject()));
}
throw new ForbiddenException();
}

/**
* 스터디 신청 정보를 등록하는 API (v2)
*
* <p>스터디 신청 단계에서 같이할 학생과 강의를 선택하여
* 신청 정보를 등록한다.
*
* @param form 신청 정보(같이 하고 싶은 학생 목록, 강의 목록)
* @param claims 토큰 페이로드
* @return 신청 내역
*/
@Operation(summary = "스터디 신청")
@PostMapping("/api/v2/forms")
public ResponseEntity<ApplyFormDto> applyForStudy(
@RequestBody ApplyFormV2 form,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.USER)) {
User appliedUser = userService.apply(
form.getFriendIds(), form.getCourseIds(),
claims.getSubject());
/**
* 스터디 신청 정보를 등록하는 API (v2)
*
* <p>스터디 신청 단계에서 같이할 학생과 강의를 선택하여 신청 정보를 등록한다.
*
* @param form 신청 정보(같이 하고 싶은 학생 목록, 강의 목록)
* @param claims 토큰 페이로드
* @return 신청 내역
*/
@Operation(summary = "스터디 신청")
@PostMapping("/api/v2/forms")
public ResponseEntity<ApplyFormDto> applyForStudy(
@RequestBody ApplyFormV2 form, @RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.USER)) {
StudyApplicant submittedForm =
userService.apply(form.getFriendIds(), form.getCourseIds(), claims.getSubject());

return ResponseEntity.ok(
new ApplyFormDto(
appliedUser.getSentRequests()
.stream()
.map(Friendship::getReceived)
.map(UserDto.UserBasicWithMasking::new)
.toList(),
appliedUser.getCourseSelections()
.stream()
.sorted(Comparator.comparing(UserCourse::getPriority))
.map(UserCourse::getCourse)
.map(CourseDto.CourseInfo::new)
.toList()));
}
throw new ForbiddenException();
return ResponseEntity.ok(
new ApplyFormDto(
submittedForm.getPartnerRequests().stream()
.map(StudyPartnerRequest::getReceiver)
.map(UserDto.UserBasicWithMasking::new)
.toList(),
submittedForm.getPreferredCourses().stream()
.sorted(Comparator.comparing(PreferredCourse::getPriority))
.map(PreferredCourse::getCourse)
.map(CourseDto.CourseInfo::new)
.toList()));
}
throw new ForbiddenException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import edu.handong.csee.histudy.controller.form.ReportForm;
import edu.handong.csee.histudy.domain.Role;
import edu.handong.csee.histudy.domain.StudyGroup;
import edu.handong.csee.histudy.dto.CourseDto;
import edu.handong.csee.histudy.dto.ReportDto;
import edu.handong.csee.histudy.dto.UserDto;
import edu.handong.csee.histudy.exception.ForbiddenException;
import edu.handong.csee.histudy.exception.UserNotFoundException;
import edu.handong.csee.histudy.repository.AcademicTermRepository;
import edu.handong.csee.histudy.repository.StudyGroupRepository;
import edu.handong.csee.histudy.repository.UserRepository;
import edu.handong.csee.histudy.service.CourseService;
import edu.handong.csee.histudy.service.ImageService;
Expand Down Expand Up @@ -43,6 +43,8 @@ public class TeamController {
private final TeamService teamService;
private final ImageService imageService;
private final UserRepository userRepository;
private final AcademicTermRepository academicTermRepository;
private final StudyGroupRepository studyGroupRepository;

@Operation(summary = "그룹 스터디 보고서 생성")
@PostMapping("/reports")
Expand Down Expand Up @@ -149,13 +151,7 @@ public ResponseEntity<Map<String, String>> uploadImage(
@RequestParam MultipartFile image,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.MEMBER)) {
StudyGroup studyGroup =
userRepository
.findUserByEmail(claims.getSubject())
.orElseThrow(UserNotFoundException::new)
.getStudyGroup();

String filename = imageService.getImagePaths(image, studyGroup.getTag(), reportIdOr);
String filename = imageService.getImagePaths(claims.getSubject(), image, reportIdOr);
Map<String, String> response = Map.of("imagePath", filename);
return ResponseEntity.ok(response);
}
Expand Down
Loading

0 comments on commit f551a14

Please sign in to comment.