Skip to content

Commit

Permalink
refactor: event - collect stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann authored Feb 27, 2024
1 parent 7af19b9 commit 5eb6e3a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ddingdong-dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ on:
push:
branches:
- develop # develop에 push될 때 실행

pull_request:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ public SecurityFilterChain filterChain(HttpSecurity http, JwtAuthService authSer
http
.authorizeHttpRequests()
.antMatchers(API_PREFIX + "/auth/**",
API_PREFIX + "/qr-stamps/**")

.permitAll()
API_PREFIX + "/event/**")
.permitAll()
.antMatchers(GET,
API_PREFIX + "/clubs/**",
API_PREFIX + "/notices/**",
API_PREFIX + "/event/**",
API_PREFIX + "/banners/**")
.permitAll()
.antMatchers(API_PREFIX + "/admin/**").hasRole("ADMIN")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/server/qr-stamps")
@RequestMapping("/server/events")
@RequiredArgsConstructor
public class QrStampController {

private final QrStampService qrStampService;

@PostMapping("/collect")
public void collectStamp(@RequestBody CollectStampRequest request) {
@PostMapping("/stamps")
public String collectStamp(@RequestBody CollectStampRequest request) {
LocalDateTime collectedAt = LocalDateTime.now();
qrStampService.collectStamp(request, collectedAt);
return qrStampService.collectStamp(request, collectedAt);
}

@GetMapping()
@GetMapping("/stmaps")
public CollectionResultResponse getCollectionResult(@RequestParam String studentName, @RequestParam String studentNumber) {
return qrStampService.getCollectionResult(studentName, studentNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class CollectStampRequest {

private String studentName;

private String department;

@Size(min = 8, max = 8, message = "학번은 8자리입니다.")
private String studentNumber;

Expand All @@ -20,6 +22,7 @@ public class CollectStampRequest {
public StampHistory toStampHistoryEntity() {
return StampHistory.builder()
.studentName(this.studentName)
.department(this.department)
.studentNumber(this.studentNumber).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ddingdong.ddingdongBE.domain.qrstamp.entity;

import com.amazonaws.services.kms.model.NotFoundException;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -8,8 +9,51 @@
@RequiredArgsConstructor
public enum ClubStamp {

COW("카우", "COW"),
TEST("테스트", "TEST");
너나들이("너나들이", "EVENTNNDE"),
키비탄("키비탄", "EVENTKBT"),
RCY("RCY", "EVENTRCY"),
PTPI("PTPI", "EVENTPTPI"),
인액터스("인액터스 ", "EVENTIACT"),
COW("COW", "EVENTCOW"),
비주얼("비주얼", "EVENTVISUAL"),
SK_루키("SK루키", "EVENTSKROOKIE"),
명지챌린저스("명지챌린저스", "EVENTMC"),
농어민후생연구회_흙("농어민후생연구회 흙", "EVENTSOIL"),
흑풍("흑풍", "EVENTBLACK"),
통해("통해", "EVENTTH"),
MGH("MGH", "EVENTMGH"),
화이트홀스("화이트홀스", "EVENTWH"),
주리랑("주리랑", "EVENTJURI"),
극예술연구회_알("극예술연구회 알", "EVENTAL"),
그림패시만화("그림패시만화", "EVENTPIC"),
포토랩("포토랩", "EVENTPHO"),
디비전("디비전", "EVENTDIV"),
코아("코아 ", "EVENTCOA "),
씨네메이션("씨네메이션", "EVENTCINE"),
실로암("실로암", "EVENTSIL"),
CCC("ccc", "EVENTCCC"),
CFM("Cfm", "EVENTCFM"),
UBF("UBF", "EVENTUBF"),
BB("BB", "EVENTBB"),
씨네필("씨네필", "EVENTFIL"),
에뚜알("에뚜알", "EVENTALL"),
DEPTH("DEPth", "EVENTDEPTH"),
IVF("IVF", "EVENTIVF"),
명월("명월 ", "EVENTMON"),
나라오르다("나라오르다", "EVENTFLY"),
굴렁쇠("굴렁쇠", "EVENTBIKE"),
나이너스("나이너스", "EVENTBASE"),
FC_명지("FC명지", "EVENTFC"),
삼박자("삼박자", "EVENTSAM"),
무릉도원("무릉도원", "EVENTKAL"),
오버행("오버행", "EVENTHANG"),
MJTA("MJTA", "EVENTMJTA"),
콕콕콕("콕콕콕", "EVENTCOK"),
바다이야기("바다이야기", "EVENTSEA"),
파인("파인", "EVENTFINE"),
TIME("TIME", "EVENTTIME"),
명지서법("명지서법", "EVENTWORD"),
MIRS("MIRS", "EVENTMIRS");

private final String name;
private final String code;
Expand All @@ -18,6 +62,6 @@ public static ClubStamp getByClubCode(String code) {
return Arrays.stream(ClubStamp.values())
.filter(clubStamp -> clubStamp.getCode().equals(code))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("동아리 코드를 확인해주세요."));
.orElseThrow(() -> new NotFoundException("동아리 코드를 확인해주세요."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,31 @@ public class StampHistory extends BaseEntity {

private LocalDateTime completedAt;

private String department;

private String certificationImageUrl;

@Builder
private StampHistory(Long id, String studentName, String studentNumber, LocalDateTime completedAt) {

private StampHistory(Long id, String studentName, String department, String studentNumber,
LocalDateTime completedAt, String certificationImageUrl) {
this.id = id;
this.studentName = studentName;
this.department = department;
this.studentNumber = studentNumber;
this.completedAt = completedAt;
this.certificationImageUrl = certificationImageUrl;
}

public void collectStamp(ClubStamp clubStamp, LocalDateTime collectedAt) {
this.collectedStamps.put(clubStamp, collectedAt);
if (this.collectedStamps.size() == ClubStamp.values().length) {
if (this.collectedStamps.size() == 10) {
this.completedAt = LocalDateTime.now();
}
}

public boolean isCompleted() {
return this.collectedStamps.size() >= 10;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ public class QrStampService {
private final StampHistoryRepository stampHistoryRepository;

@Transactional
public void collectStamp(CollectStampRequest request, LocalDateTime collectedAt) {
public String collectStamp(CollectStampRequest request, LocalDateTime collectedAt) {
StampHistory stampHistory = stampHistoryRepository.findStampHistoryByStudentNameAndStudentNumber(
request.getStudentName(),
request.getStudentNumber())
.orElse(request.toStampHistoryEntity());

if (stampHistory.isCompleted()) {
return "10개의 벚꽃을 모두 채우셨습니다. 이벤트 응모를 완료해주세요!";
}
ClubStamp clubStamp = ClubStamp.getByClubCode(request.getClubCode());
stampHistory.collectStamp(clubStamp, collectedAt);

stampHistoryRepository.save(stampHistory);
return "ok";
}

public CollectionResultResponse getCollectionResult(String studentNumber, String studentName) {
Expand All @@ -44,8 +47,6 @@ public CollectionResultResponse getCollectionResult(String studentNumber, String
.map(stamp -> CollectedStampsResponse.of(stamp.getName(),
stampHistory.getCollectedStamps().get(stamp)))
.toList();
boolean isCompleted = stampHistory.getCollectedStamps().size() == ClubStamp.values().length;
return CollectionResultResponse.of(isCompleted, collectedStampsResponse);
return CollectionResultResponse.of(stampHistory.isCompleted(), collectedStampsResponse);
}

}

0 comments on commit 5eb6e3a

Please sign in to comment.