Skip to content

Commit

Permalink
Merge pull request #52 from softeerbootcamp4th/feature/#45-rush-event…
Browse files Browse the repository at this point in the history
…-apply-check

Feature/#45 rush event apply check
  • Loading branch information
k000927 authored Aug 6, 2024
2 parents 4199523 + 05835c5 commit fa62f5c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 79 deletions.
4 changes: 3 additions & 1 deletion Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ dependencies {
implementation 'org.projectlombok:lombok'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")}
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
annotationProcessor('org.projectlombok:lombok')

}

tasks.named('test') {
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventListAndServerTimeResponse;
import JGS.CasperEvent.domain.event.service.eventService.RushEventService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -22,10 +23,10 @@ public ResponseEntity<RushEventListAndServerTimeResponse> getRushEventListAndSer
}

// 밸런스 게임 참여 여부 조회
// @GetMapping("/{eventId}/applied")
// public ResponseEntity<Boolean> checkUserParticipationInRushEvent(@PathVariable Long eventId,
// @CookieValue String userData) {
//
// return ResponseEntity.ok(rushEventService.isExists(eventId, userData));
// }
@GetMapping("/{eventId}/applied")
public ResponseEntity<Boolean> checkUserParticipationInRushEvent(HttpServletRequest httpServletRequest, @PathVariable("eventId") Long eventId) {

String userId = httpServletRequest.getAttribute("userId").toString();
return ResponseEntity.ok(rushEventService.isExists(eventId, userId));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package JGS.CasperEvent.domain.event.repository.participantsRepository;

import JGS.CasperEvent.domain.event.entity.participants.RushParticipants;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface RushParticipantsRepository {
public interface RushParticipantsRepository extends JpaRepository<RushParticipants, String> {
@Query("SELECT CASE WHEN COUNT(rp) > 0 THEN TRUE ELSE FALSE END " +
"FROM RushParticipants rp " +
"WHERE rp.rushEvent.rushEventId = :eventId AND rp.id = :userId")
boolean existsByRushEventIdAndUserId(@Param("eventId") Long eventId, @Param("userId") String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import JGS.CasperEvent.domain.event.entity.admin.Admin;
import JGS.CasperEvent.domain.event.repository.AdminRepository;
import JGS.CasperEvent.global.enums.CustomErrorCode;
import JGS.CasperEvent.global.enums.Role;
import JGS.CasperEvent.global.error.exception.CustomException;
import JGS.CasperEvent.global.error.exception.ErrorCode;
import JGS.CasperEvent.global.jwt.dto.AdminLoginDto;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand Down Expand Up @@ -33,7 +33,7 @@ public String postAdmin(String body) {

Admin admin = adminRepository.findById(adminId).orElse(null);

if (admin != null) throw new CustomException("이미 등록된 ID입니다.", ErrorCode.ACCESS_DENIED);
if (admin != null) throw new CustomException("이미 등록된 ID입니다.", CustomErrorCode.CONFLICT);
adminRepository.save(new Admin(adminId, password, Role.ADMIN));

return "admin Created";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import JGS.CasperEvent.domain.event.dto.ResponseDto.RushEventListAndServerTimeResponse;
import JGS.CasperEvent.domain.event.entity.event.RushEvent;
import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository;
import JGS.CasperEvent.domain.event.repository.participantsRepository.RushParticipantsRepository;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RushEventService {

private final RushEventRepository rushEventRepository;
private final RushParticipantsRepository rushParticipantsRepository;

public RushEventService(RushEventRepository rushEventRepository) {
public RushEventService(RushEventRepository rushEventRepository, RushParticipantsRepository rushParticipantsRepository) {
this.rushEventRepository = rushEventRepository;
this.rushParticipantsRepository = rushParticipantsRepository;
}

public RushEventListAndServerTimeResponse getAllRushEvents() {
Expand All @@ -29,10 +31,7 @@ public RushEventListAndServerTimeResponse getAllRushEvents() {
return new RushEventListAndServerTimeResponse(rushEventDtoList, LocalDateTime.now());
}

// public boolean isExists(Long eventId, String userData) {
// RushEvent rushEvent = findByIdOrElseThrow(rushEventRepository, eventId, CustomErrorCode.NO_RUSH_EVENT);
//
//
// }

public boolean isExists(Long eventId, String userId) {
return rushParticipantsRepository.existsByRushEventIdAndUserId(eventId, userId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@RequiredArgsConstructor
public class JwtAuthorizationFilter implements Filter {

private final String[] whiteListUris = new String[]{"/event/auth", "/event/rush", "/event/lottery/caspers", "/admin/join", "/admin/auth"};
private final String[] whiteListUris = new String[]{"/event/auth", "/event/rush", "/event/lottery/caspers", "/admin/join", "/admin/auth", "/h2", "/h2/*", "/swagger-ui/*", "/v3/api-docs", "/v3/api-docs/*"};
private final String[] blackListUris = new String[]{"/event/rush/*"};

private final JwtProvider jwtProvider;
Expand Down Expand Up @@ -54,6 +54,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
BaseUser user = getAuthenticateUser(token);
verifyAuthorization(requestUri, user);
log.info("값 : {}", user.getId());
httpServletRequest.setAttribute("userId", user.getId());
chain.doFilter(request, response);
} catch (JsonParseException e) {
log.error("JsonParseException");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Claims getClaims(String token) {


public Date getExpireDateAccessToken() {
long expireTimeMils = 1000 * 60 * 60;
long expireTimeMils = 1000L * 60 * 60 * 24 * 365;
return new Date(System.currentTimeMillis() + expireTimeMils);
}

Expand Down

0 comments on commit fa62f5c

Please sign in to comment.