Skip to content

Commit

Permalink
Merge pull request #233 from softeerbootcamp4th/dev
Browse files Browse the repository at this point in the history
merge to main
  • Loading branch information
k000927 authored Aug 25, 2024
2 parents daef2de + e684461 commit a9956ac
Show file tree
Hide file tree
Showing 116 changed files with 5,368 additions and 1,551 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
/.idea/
/Server/out/
/Server/src/main/resources/application-local.yml
/Server/logs/
/logs/

7 changes: 5 additions & 2 deletions Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0")
runtimeOnly 'com.h2database:h2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand All @@ -49,6 +48,10 @@ dependencies {
annotationProcessor('org.projectlombok:lombok')
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3'

// prometheus
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableAspectJAutoProxy
@EnableScheduling
@EnableCaching
public class CasperEventApplication {

public static void main(String[] args) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package JGS.CasperEvent.domain.event.controller.eventController;


import JGS.CasperEvent.domain.event.dto.ResponseDto.TotalEventDateResponseDto;
import JGS.CasperEvent.domain.event.dto.response.TotalEventDateResponseDto;
import JGS.CasperEvent.domain.event.service.eventService.EventService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,6 +20,8 @@ public class EventController {
@GetMapping("/total")
public ResponseEntity<TotalEventDateResponseDto> getTotalEventDate() {
TotalEventDateResponseDto totalEventDateResponseDto = eventService.getTotalEventDate();
return ResponseEntity.ok(totalEventDateResponseDto);
return ResponseEntity
.status(HttpStatus.OK)
.body(totalEventDateResponseDto);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package JGS.CasperEvent.domain.event.controller.eventController;

import JGS.CasperEvent.domain.event.dto.RequestDto.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryEventResponseDto;
import JGS.CasperEvent.domain.event.dto.ResponseDto.lotteryEventResponseDto.LotteryParticipantResponseDto;
import JGS.CasperEvent.domain.event.service.redisService.RedisService;
import JGS.CasperEvent.domain.event.dto.request.lotteryEventDto.CasperBotRequestDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.CasperBotResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventParticipantResponseDto;
import JGS.CasperEvent.domain.event.dto.response.lottery.LotteryEventResponseDto;
import JGS.CasperEvent.domain.event.service.redisService.LotteryEventRedisService;
import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService;
import JGS.CasperEvent.global.entity.BaseUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,56 +21,73 @@
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.nio.file.attribute.UserPrincipalNotFoundException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@Tag(name = "추첨 이벤트 API", description = "추첨 이벤트 (Lottery Event) 관련 API 목록입니다.")
@RestController
@RequestMapping("/event/lottery")
public class LotteryEventController {

private final LotteryEventService lotteryEventService;
private final RedisService redisService;
private final LotteryEventRedisService lotteryEventRedisService;

@Autowired
public LotteryEventController(LotteryEventService lotteryEventService, RedisService redisService) {
public LotteryEventController(LotteryEventService lotteryEventService, LotteryEventRedisService lotteryEventRedisService) {
this.lotteryEventService = lotteryEventService;
this.redisService = redisService;
this.lotteryEventRedisService = lotteryEventRedisService;
}

// 추첨 이벤트 조회 API
@Operation(summary = "추첨 이벤트 조회", description = "현재 진행 중인 추첨 이벤트의 정보를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Lottery event retrieval successful"),
@ApiResponse(responseCode = "404", description = "No lottery event found in the database"),
@ApiResponse(responseCode = "409", description = "More than one lottery event exists in the database")
})
@GetMapping
public ResponseEntity<LotteryEventResponseDto> getLotteryEvent(){
public ResponseEntity<LotteryEventResponseDto> getLotteryEvent() {
return ResponseEntity
.status(HttpStatus.OK)
.body(lotteryEventService.getLotteryEvent());
}

// 캐스퍼 봇 생성 API
@Operation(summary = "캐스퍼 봇 생성", description = "새로운 캐스퍼 봇을 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Casper bot creation successful"),
@ApiResponse(responseCode = "404", description = "No lottery event found in the database"),
@ApiResponse(responseCode = "409", description = "More than one lottery event exists in the database")
})
@PostMapping("/casperBot")
public ResponseEntity<CasperBotResponseDto> postCasperBot(
HttpServletRequest request,
@RequestBody @Valid CasperBotRequestDto postCasperBot) throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
@RequestBody @Valid CasperBotRequestDto postCasperBot) {
BaseUser user = (BaseUser) request.getAttribute("user");
return ResponseEntity
.status(HttpStatus.CREATED)
.body(lotteryEventService.postCasperBot(user, postCasperBot));
}

// 응모 여부 조회 API
@Operation(summary = "응모 여부 조회", description = "현재 사용자의 응모 여부를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Application status retrieval successful"),
@ApiResponse(responseCode = "404", description = "User has not applied")
})
@GetMapping("/applied")
public ResponseEntity<LotteryParticipantResponseDto> GetLotteryParticipant(HttpServletRequest request) throws UserPrincipalNotFoundException {
public ResponseEntity<LotteryEventParticipantResponseDto> getLotteryParticipant(HttpServletRequest request) {
BaseUser user = (BaseUser) request.getAttribute("user");
return ResponseEntity
.status(HttpStatus.OK)
.body(lotteryEventService.getLotteryParticipant(user));
}

// 최근 100개 캐스퍼 봇 조회
@Operation(summary = "최근 100개 캐스퍼 봇 조회", description = "최근에 생성된 100개의 캐스퍼 봇을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Recent Casper bots retrieval successful")
})
@GetMapping("/caspers")
public ResponseEntity<List<CasperBotResponseDto>> getCasperBots() {
return ResponseEntity.status(HttpStatus.OK)
.body(redisService.getRecentData());
.body(lotteryEventRedisService.getRecentData());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package JGS.CasperEvent.domain.event.controller.eventController;


import JGS.CasperEvent.domain.event.dto.ResponseDto.rushEventResponseDto.*;
import JGS.CasperEvent.domain.event.dto.response.rush.RushEventListResponseDto;
import JGS.CasperEvent.domain.event.dto.response.rush.RushEventOptionResponseDto;
import JGS.CasperEvent.domain.event.dto.response.rush.RushEventResponseDto;
import JGS.CasperEvent.domain.event.dto.response.rush.RushEventResultResponseDto;
import JGS.CasperEvent.domain.event.service.eventService.RushEventService;
import JGS.CasperEvent.global.entity.BaseUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "선착순 이벤트 API", description = "선착순 이벤트 (Rush Event) 관련 API 목록입니다.")
@RestController
@RequestMapping("/event/rush")
public class RushEventController {
Expand All @@ -17,62 +26,93 @@ public RushEventController(RushEventService rushEventService) {
this.rushEventService = rushEventService;
}

// 전체 선착순 이벤트 조회
@Operation(summary = "메인화면 선착순 이벤트 리스트 조회", description = "메인화면에 들어갈 선착순 이벤트 6개와 서버 시간 등을 조회합니다.")
@ApiResponse(responseCode = "200", description = "Successfully retrieved the list of rush events.")
@GetMapping
public ResponseEntity<RushEventListResponseDto> getRushEventListAndServerTime() {
return ResponseEntity.ok(rushEventService.getAllRushEvents());
return ResponseEntity
.status(HttpStatus.OK)
.body(rushEventService.getAllRushEvents());
}

// 밸런스 게임 참여 여부 조회
@Operation(summary = "응모 여부 체크", description = "해당 유저가 오늘의 이벤트에 응모했는지 여부를 조회합니다.")
@ApiResponse(responseCode = "200", description = "Successfully checked user participation.")
@GetMapping("/applied")
public ResponseEntity<Boolean> checkUserParticipationInRushEvent(HttpServletRequest httpServletRequest) {
BaseUser user = (BaseUser) httpServletRequest.getAttribute("user");
return ResponseEntity.ok(rushEventService.isExists(user.getId()));
return ResponseEntity
.status(HttpStatus.OK)
.body(rushEventService.isExists(user.getPhoneNumber()));
}

// 밸런스 게임 응모
@Operation(summary = "선착순 이벤트 응모", description = "해당 유저가 오늘의 이벤트에 응모합니다. optionId 값이 필요합니다. optionId 값이 1이면 왼쪽 선택지, 2이면 오른쪽 선택지에 응모합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Successfully applied for the rush event."),
@ApiResponse(responseCode = "400", description = "Invalid option ID provided."),
@ApiResponse(responseCode = "401", description = "Unauthorized to apply for the event.")
})
@PostMapping("/options/{optionId}/apply")
public ResponseEntity<Void> applyRushEvent(HttpServletRequest httpServletRequest, @PathVariable("optionId") int optionId) {
BaseUser user = (BaseUser) httpServletRequest.getAttribute("user");
rushEventService.apply(user, optionId);

return ResponseEntity.noContent().build();
return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.build();
}

// 밸런스 게임 비율 조회
@Operation(summary = "실시간 응모 비율 조회", description = "실시간으로 변경되는 응모 비율을 조회합니다.")
@ApiResponse(responseCode = "200", description = "Successfully retrieved the balance rate.")
@GetMapping("/balance")
public ResponseEntity<RushEventRateResponseDto> rushEventRate(HttpServletRequest httpServletRequest) {
public ResponseEntity<RushEventResultResponseDto> rushEventRate(HttpServletRequest httpServletRequest) {
BaseUser user = (BaseUser) httpServletRequest.getAttribute("user");
RushEventRateResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(user);
return ResponseEntity.ok(rushEventRateResponseDto);
RushEventResultResponseDto rushEventRateResponseDto = rushEventService.getRushEventRate(user);
return ResponseEntity
.status(HttpStatus.OK)
.body(rushEventRateResponseDto);
}

// 밸런스 게임 결과 조회
@Operation(summary = "선착순 이벤트 결과를 조회합니다.", description = "이벤트가 끝나고 나서 최종 결과를 조회합니다.")
@ApiResponse(responseCode = "200", description = "Successfully retrieved the rush event result.")
@GetMapping("/result")
public ResponseEntity<RushEventResultResponseDto> rushEventResult(HttpServletRequest httpServletRequest) {
BaseUser user = (BaseUser) httpServletRequest.getAttribute("user");
RushEventResultResponseDto result = rushEventService.getRushEventResult(user);
return ResponseEntity.ok(result);
return ResponseEntity
.status(HttpStatus.OK)
.body(result);
}

// 레디스에 오늘의 이벤트 등록 테스트 api
@Operation(summary = "오늘의 이벤트를 초기화합니다.", description = "오늘의 이벤트를 전부 초기화하고, 응모 여부도 전부 초기화합니다.")
@ApiResponse(responseCode = "204", description = "Successfully set today's event in Redis.")
@GetMapping("/today/test")
public ResponseEntity<Void> setTodayEvent() {
rushEventService.setTodayEventToRedis();
return ResponseEntity.noContent().build();
rushEventService.setRushEvents();
return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.build();
}

// 오늘의 이벤트 선택지 조회
@Operation(summary = "오늘의 이벤트 옵션을 조회합니다.", description = "이벤트 참여자가 이벤트에 진입했을 때 보여질 옵션 선택지 정보를 조회합니다.")
@ApiResponse(responseCode = "200", description = "Successfully retrieved today's rush event options.")
@GetMapping("/today")
public ResponseEntity<MainRushEventOptionsResponseDto> getTodayEvent() {
MainRushEventOptionsResponseDto mainRushEventOptionsResponseDto = rushEventService.getTodayRushEventOptions();
return ResponseEntity.ok(mainRushEventOptionsResponseDto);
public ResponseEntity<RushEventResponseDto> getTodayEvent() {
RushEventResponseDto mainRushEventOptionsResponseDto = rushEventService.getTodayRushEventOptions();
return ResponseEntity
.status(HttpStatus.OK)
.body(mainRushEventOptionsResponseDto);
}

// 옵션 선택 결과 조회
@Operation(summary = "옵션의 결과 Text를 조회합니다.", description = "유저가 응모를 했을 때 보여질 옵션의 상세 Text를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully retrieved the option result."),
@ApiResponse(responseCode = "400", description = "Invalid option ID provided.")
})
@GetMapping("/options/{optionId}/result")
public ResponseEntity<ResultRushEventOptionResponseDto> getResultOption(@PathVariable("optionId") int optionId) {
ResultRushEventOptionResponseDto resultRushEventOptionResponseDto = rushEventService.getRushEventOptionResult(optionId);
return ResponseEntity.ok(resultRushEventOptionResponseDto);
public ResponseEntity<RushEventOptionResponseDto> getResultOption(@PathVariable("optionId") int optionId) {
RushEventOptionResponseDto resultRushEventOptionResponseDto = rushEventService.getRushEventOptionResult(optionId);
return ResponseEntity
.status(HttpStatus.OK)
.body(resultRushEventOptionResponseDto);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a9956ac

Please sign in to comment.