Skip to content

Commit

Permalink
Merge pull request #136 from IT-Cotato/develop
Browse files Browse the repository at this point in the history
[Main] V2.2024.08.23.02
  • Loading branch information
Youthhing authored Aug 22, 2024
2 parents abfa188 + 0f35afc commit 1d8fc9f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ResponseEntity<Void> updateAttendance(@RequestBody @Valid UpdateAttendanc
@Operation(summary = "세션 시간 반환 API")
@GetMapping("/info")
public ResponseEntity<AttendanceTimeResponse> findAttendanceTimeInfo(@RequestParam("sessionId") Long sessionId) {
return ResponseEntity.status(HttpStatus.OK).body(attendanceService.findAttendanceTimeInfo(sessionId));
return ResponseEntity.status(HttpStatus.OK).body(attendanceService.getAttendanceDetailInfo(sessionId));
}

@Operation(summary = "회원 출결사항 기간 단위 조회 API")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.cotato.csquiz.api.attendance.dto;

import java.time.LocalDateTime;
import java.time.LocalTime;
import org.cotato.csquiz.domain.attendance.embedded.Location;
import org.cotato.csquiz.domain.attendance.entity.Attendance;

public record AttendanceTimeResponse(
Long sessionId,
LocalTime attendanceDeadLine,
LocalTime lateDeadLine
LocalTime lateDeadLine,
Location location
) {
public static AttendanceTimeResponse of(Long sessionId, LocalDateTime attendanceDeadLine, LocalDateTime lateDeadLine) {

public static AttendanceTimeResponse from(Attendance attendance) {
return new AttendanceTimeResponse(
sessionId,
attendanceDeadLine.toLocalTime(),
lateDeadLine.toLocalTime()
attendance.getSessionId(),
attendance.getAttendanceDeadLine().toLocalTime(),
attendance.getLateDeadLine().toLocalTime(),
attendance.getLocation()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public record ProjectSummaryResponse(
String introduction,
Long generationId,
Integer generationNumber,
String logoUrl
String logoUrl,
String githubUrl,
String behanceUrl,
String projectUrl
) {
public static ProjectSummaryResponse of(Project project, Integer generationNumber, ProjectImage projectImage) {
return new ProjectSummaryResponse(
Expand All @@ -18,7 +21,10 @@ public static ProjectSummaryResponse of(Project project, Integer generationNumbe
project.getIntroduction(),
project.getGenerationId(),
generationNumber,
projectImage != null ? projectImage.getS3Info().getUrl() : null
projectImage != null ? projectImage.getS3Info().getUrl() : null,
project.getGithubUrl(),
project.getBehanceUrl(),
project.getProjectUrl()
);
}
}
57 changes: 29 additions & 28 deletions src/main/java/org/cotato/csquiz/common/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,43 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.cors();
http.exceptionHandling(exception ->
exception.accessDeniedHandler(customAccessDeniedHandler));
exception.accessDeniedHandler(customAccessDeniedHandler));
http.csrf().disable()
.formLogin().disable()
.addFilter(new JwtAuthenticationFilter(authenticationManager, jwtTokenProvider, refreshTokenRepository))
.addFilterBefore(jwtAuthorizationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JwtExceptionFilter(), JwtAuthorizationFilter.class)
.addFilter(corsFilter)
.authorizeHttpRequests(request -> request
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.requestMatchers("/v1/api/admin/**").hasRole("ADMIN")
.requestMatchers(WHITE_LIST).permitAll()
.requestMatchers("/v1/api/education/result/**").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/education/from").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/education/status", "GET"))
.hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/education", "GET")).authenticated()
.requestMatchers("/v1/api/education/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/generation/**").hasAnyRole("ADMIN")
.requestMatchers("/v1/api/mypage/**").hasAnyRole("MEMBER", "OLD_MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/cs-admin/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/adds").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/**").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/record/reply").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/record/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/session/cs-on").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/session", "GET")).authenticated()
.requestMatchers("/v1/api/session/**").hasAnyRole("ADMIN")
.requestMatchers("/v2/api/attendance/records").hasAnyRole("ADMIN")
.requestMatchers("/v2/api/attendance").hasAnyRole("ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/socket/token", "POST"))
.hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.requestMatchers("/v1/api/admin/**").hasRole("ADMIN")
.requestMatchers(WHITE_LIST).permitAll()
.requestMatchers("/v1/api/education/result/**").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/education/from").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/education/status", "GET"))
.hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/education", "GET")).authenticated()
.requestMatchers("/v1/api/education/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/generation/**").hasAnyRole("ADMIN")
.requestMatchers("/v1/api/mypage/**").hasAnyRole("MEMBER", "OLD_MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/cs-admin/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/adds").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/quiz/**").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/record/reply").hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
.requestMatchers("/v1/api/record/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers("/v1/api/session/cs-on").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/session", "GET")).authenticated()
.requestMatchers("/v1/api/session/**").hasAnyRole("ADMIN")
.requestMatchers("/v2/api/attendance/records").hasAnyRole("ADMIN")
.requestMatchers("/v2/api/attendance").hasAnyRole("ADMIN")
.requestMatchers(new AntPathRequestMatcher("/v1/api/socket/token", "POST"))
.hasAnyRole("MEMBER", "EDUCATION", "ADMIN")
// .requestMatchers("/v2/api/events/attendances").hasAnyRole("MEMBER", "ADMIN", "EDUCATION")
.requestMatchers("/v1/api/socket/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers(HttpMethod.POST, "/v2/api/projects").hasRole("ADMIN")
.requestMatchers(HttpMethod.GET, "/v2/api/projects/**").permitAll()
.anyRequest().authenticated()
.requestMatchers("/v1/api/socket/**").hasAnyRole("EDUCATION", "ADMIN")
.requestMatchers(HttpMethod.POST, "/v2/api/projects").hasRole("ADMIN")
.requestMatchers(HttpMethod.POST, "v2/api/projects/images").hasRole("ADMIN")
.requestMatchers(HttpMethod.GET, "/v2/api/projects/**").permitAll()
.anyRequest().authenticated()
);
return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import jodd.net.HttpMethod;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.cotato.csquiz.common.config.jwt.JwtTokenProvider;
import org.cotato.csquiz.domain.auth.entity.Member;
import org.cotato.csquiz.common.error.exception.FilterAuthenticationException;
import org.cotato.csquiz.domain.auth.repository.MemberRepository;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.filter.OncePerRequestFilter;

@Slf4j
Expand All @@ -33,8 +32,11 @@ public class JwtAuthorizationFilter extends OncePerRequestFilter {
private static final String GENERATION_PATH = "/v1/api/generation";
private static final String SESSION_PATH = "/v1/api/session";
private static final String POLICIES_PATH = "/v2/api/policies";
private static final String PROJECTS_LIST = "/v2/api/projects";
private static final String PROJECT_DETAIL = "/v2/api/projects/{projectId:\\d+}";

private final JwtTokenProvider jwtTokenProvider;
private static final AntPathMatcher pathMatcher = new AntPathMatcher();

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Expand Down Expand Up @@ -68,6 +70,9 @@ protected boolean shouldNotFilter(HttpServletRequest request) {
return path.startsWith(AUTH_PATH) || path.equals(LOGIN_PATH)
|| path.startsWith(SWAGGER_PATH) || path.equals(SWAGGER_FAVICON)
|| path.startsWith(SWAGGER_PATH_3) || path.startsWith(WS)
|| path.equals(GENERATION_PATH) || path.equals(SESSION_PATH) || path.equals(POLICIES_PATH);
|| path.equals(GENERATION_PATH) || path.equals(SESSION_PATH)
|| path.equals(POLICIES_PATH)
|| path.equals(PROJECTS_LIST) && HttpMethod.GET.name().equals(request.getMethod())
|| pathMatcher.match(PROJECT_DETAIL, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public AttendancesResponse findAttendancesByGenerationId(final Long generationId
}

@Transactional(readOnly = true)
public AttendanceTimeResponse findAttendanceTimeInfo(Long sessionId) {
Attendance findAttendance = attendanceRepository.findBySessionId(sessionId)
public AttendanceTimeResponse getAttendanceDetailInfo(final Long sessionId) {
Attendance attendance = attendanceRepository.findBySessionId(sessionId)
.orElseThrow(() -> new EntityNotFoundException("해당 출석을 찾을 수 없습니다"));

return AttendanceTimeResponse.of(sessionId,
findAttendance.getAttendanceDeadLine(),
findAttendance.getLateDeadLine());
return AttendanceTimeResponse.from(attendance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.cotato.csquiz.api.project.dto.ProjectImageRequest;
import org.cotato.csquiz.common.entity.S3Info;
import org.cotato.csquiz.common.error.exception.ImageException;
import org.cotato.csquiz.common.s3.S3Uploader;
import org.cotato.csquiz.domain.generation.entity.Project;
import org.cotato.csquiz.domain.generation.entity.ProjectImage;
import org.cotato.csquiz.domain.generation.repository.ProjectImageRepository;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cotato.csquiz.domain.generation.service;

import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.cotato.csquiz.api.project.dto.ProjectMemberRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public void updateSession(UpdateSessionRequest request) {

public void updateSessionDate(Session session, LocalDate newDate, AttendanceDeadLineDto newDeadline) {
Attendance findAttendance = attendanceRepository.findBySessionId(session.getId())
.orElseThrow(() -> new EntityNotFoundException("해당 세션의 출석이 존재하지 않습니다"));
.orElseGet(() -> Attendance.builder()
.session(session)
.build());


// 날짜가 바뀌지 않았고, 출결 시간이 모두 동일한 경우
Expand All @@ -144,6 +146,7 @@ public void updateSessionDate(Session session, LocalDate newDate, AttendanceDead
LocalDateTime newLateDeadline = LocalDateTime.of(newDate, newDeadline.lateDeadLine());
findAttendance.updateDeadLine(newAttendanceDeadline, newLateDeadline);

attendanceRepository.save(findAttendance);
attendanceRecordService.updateAttendanceStatus(findAttendance);
}

Expand Down

0 comments on commit 1d8fc9f

Please sign in to comment.