Skip to content

Commit

Permalink
Release: v1.2.0
Browse files Browse the repository at this point in the history
Release: v1.2.0
  • Loading branch information
zionhann authored Mar 9, 2024
2 parents 6a84e9c + f551a14 commit c7a286a
Show file tree
Hide file tree
Showing 78 changed files with 2,569 additions and 2,320 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'
implementation 'commons-io:commons-io:2.15.1'
implementation 'org.apache.commons:commons-csv:1.10.0'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile("dev")
@Profile({"dev", "test"})
@Configuration
public class SwaggerConfig {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/handong/csee/histudy/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WebConfig implements WebMvcConfigurer {
private final JwtService jwtService;

@Value("${custom.origin.allowed}")
private String client;
private String[] clients;

@Value("${custom.path-patterns.exclude}")
private String[] excludePathPatterns;
Expand All @@ -41,7 +41,7 @@ public void addInterceptors(InterceptorRegistry registry) {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns(client)
.allowedOriginPatterns(clients)
.allowedMethods("GET", "POST", "DELETE", "PATCH")
.allowCredentials(true);
}
Expand Down
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 @@ -10,75 +10,60 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Tag(name = "강의 관리 API")
@RestController
@RequestMapping("/api/courses")
@RequiredArgsConstructor
public class CourseController {

private final CourseService courseService;
private final CourseService courseService;

@SecurityRequirement(name = "ADMIN")
@Operation(summary = "강의 목록 업로드")
@PostMapping
public ResponseEntity<String> importCourses(
@RequestParam("file") MultipartFile file,
@RequestAttribute Claims claims) throws IOException {
if (Role.isAuthorized(claims, Role.ADMIN)) {
if (file.isEmpty()) {
return ResponseEntity
.status(HttpStatus.NOT_ACCEPTABLE)
.body("Empty file");
} else {
String status = courseService.uploadFile(file);
if (status.equals("FAILED"))
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Failed in server");
else
return ResponseEntity.ok(status);
}
}
throw new ForbiddenException();
@SecurityRequirement(name = "ADMIN")
@Operation(summary = "강의 목록 업로드")
@PostMapping(consumes = {"multipart/form-data"})
public ResponseEntity<Void> importCourses(
@RequestParam("file") MultipartFile file, @RequestAttribute Claims claims)
throws IOException {
if (Role.isAuthorized(claims, Role.ADMIN)) {
if (file.isEmpty()) {
return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).build();
}
courseService.readCourseCSV(file);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
throw new ForbiddenException();
}

@SecurityRequirement(name = "ADMIN")
@Operation(summary = "강의 삭제")
@PostMapping("/delete")
public int deleteCourse(
@RequestBody CourseIdDto dto,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
return courseService.deleteCourse(dto);
}
throw new ForbiddenException();
@SecurityRequirement(name = "ADMIN")
@Operation(summary = "강의 삭제")
@PostMapping("/delete")
public int deleteCourse(@RequestBody CourseIdDto dto, @RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN)) {
return courseService.deleteCourse(dto);
}
throw new ForbiddenException();
}

@SecurityRequirements({
@SecurityRequirement(name = "ADMIN"),
@SecurityRequirement(name = "USER")
})
@Operation(summary = "강의 목록 조회")
@GetMapping
public ResponseEntity<CourseDto> getCourses(
@RequestParam(name = "search", required = false) String keyword,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN, Role.USER)) {
List<CourseDto.CourseInfo> courses = (keyword == null)
? courseService.getCourses()
: courseService.search(keyword);
@SecurityRequirements({@SecurityRequirement(name = "ADMIN"), @SecurityRequirement(name = "USER")})
@Operation(summary = "강의 목록 조회")
@GetMapping
public ResponseEntity<CourseDto> getCourses(
@RequestParam(name = "search", required = false) String keyword,
@RequestAttribute Claims claims) {
if (Role.isAuthorized(claims, Role.ADMIN, Role.USER)) {
List<CourseDto.CourseInfo> courses =
(keyword == null) ? courseService.getCurrentCourses() : courseService.search(keyword);

return ResponseEntity.ok(new CourseDto(courses));
}
throw new ForbiddenException();
return ResponseEntity.ok(new CourseDto(courses));
}
throw new ForbiddenException();
}
}
Loading

0 comments on commit c7a286a

Please sign in to comment.