Skip to content

Commit 0adab9d

Browse files
authored
[deploy] 배포 진행합니다! (#188)
2 parents b27fcdb + 75c1258 commit 0adab9d

File tree

10 files changed

+352
-32
lines changed

10 files changed

+352
-32
lines changed

README.md

+246-1
Large diffs are not rendered by default.

src/main/java/com/ggang/be/api/facade/GroupRequestFacade.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ public class GroupRequestFacade {
2424
private final UserService userService;
2525
private final LocationValidator locationValidator;
2626
private final TitleValidator titleValidator;
27-
private final IntroductionValidator introductionValidator;
2827

2928
public void validateRegisterRequest(Long userId, RegisterGongbaekRequest dto) {
3029
TimeValidator.isTimeValid(dto.startTime(), dto.endTime());
3130
isDateValid(dto);
3231
isWeekDateRight(dto);
3332
titleValidator.isGroupTitleValid(dto.groupTitle());
3433
locationValidator.isLocationValid(dto.location());
35-
introductionValidator.isIntroductionValid(dto.introduction());
34+
IntroductionValidator.isIntroductionValid(dto.introduction());
3635
isValidCoverImg(dto);
3736
isValidMaxPeople(dto);
3837

src/main/java/com/ggang/be/api/facade/SignupFacade.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
import com.ggang.be.api.exception.GongBaekException;
55
import com.ggang.be.api.lectureTimeSlot.service.LectureTimeSlotService;
66
import com.ggang.be.api.school.service.SchoolService;
7+
import com.ggang.be.api.user.NicknameValidator;
78
import com.ggang.be.api.user.dto.SignupRequest;
89
import com.ggang.be.api.user.dto.SignupResponse;
910
import com.ggang.be.api.user.service.UserService;
1011
import com.ggang.be.api.user.vo.TimeTableVo;
12+
import com.ggang.be.domain.group.IntroductionValidator;
1113
import com.ggang.be.domain.school.SchoolEntity;
1214
import com.ggang.be.domain.timslot.lectureTimeSlot.vo.LectureTimeSlotVo;
1315
import com.ggang.be.domain.user.UserEntity;
1416
import com.ggang.be.domain.user.dto.SaveUserSignUp;
1517
import com.ggang.be.global.jwt.JwtService;
18+
import com.ggang.be.global.util.TimeValidator;
1619
import lombok.RequiredArgsConstructor;
1720
import org.springframework.stereotype.Component;
1821
import org.springframework.transaction.annotation.Transactional;
@@ -34,9 +37,6 @@ public void duplicateCheckNickname(final String nickname) {
3437

3538
@Transactional
3639
public SignupResponse signup(SignupRequest request) {
37-
38-
duplicateUserCheck(request);
39-
4040
SchoolEntity schoolEntityByName = schoolService.findSchoolEntityByName(request.schoolName());
4141

4242
SaveUserSignUp saveUserSignUp = SignupRequest.toSaveUserSignUp(request, schoolEntityByName);
@@ -52,14 +52,6 @@ public SignupResponse signup(SignupRequest request) {
5252
return madeSignupResponse(userEntity);
5353
}
5454

55-
private void duplicateUserCheck(SignupRequest request) {
56-
try{
57-
duplicateCheckNickname(request.nickname());
58-
} catch (GongBaekException e) {
59-
throw new GongBaekException(ResponseError.USERNAME_ALREADY_EXISTS);
60-
}
61-
}
62-
6355
private SignupResponse madeSignupResponse(final UserEntity userEntity) {
6456
Long userId = userEntity.getId();
6557
String accessToken = jwtService.createAccessToken(userId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.ggang.be.api.facade;
2+
3+
import com.ggang.be.api.common.ResponseError;
4+
import com.ggang.be.api.exception.GongBaekException;
5+
import com.ggang.be.api.user.NicknameValidator;
6+
import com.ggang.be.api.user.dto.SignupRequest;
7+
import com.ggang.be.api.user.service.UserService;
8+
import com.ggang.be.domain.group.IntroductionValidator;
9+
import com.ggang.be.global.annotation.Facade;
10+
import com.ggang.be.global.util.TimeValidator;
11+
import lombok.RequiredArgsConstructor;
12+
13+
@Facade
14+
@RequiredArgsConstructor
15+
public class SignupRequestFacade {
16+
17+
private final UserService userService;
18+
19+
public void validateSignupRequest(SignupRequest request) {
20+
userService.duplicateCheckNickname(request.nickname());
21+
IntroductionValidator.isIntroductionValid(request.introduction());
22+
NicknameValidator.validate(request.nickname());
23+
TimeValidator.hasDuplicateInfo(request.timeTable());
24+
TimeValidator.isTimeVoValidTime(request.timeTable());
25+
26+
isValidSchoolGrade(request.schoolGrade());
27+
TimeValidator.isYearAfterNow(request.enterYear());
28+
}
29+
30+
private void isValidSchoolGrade(Integer schoolGrade) {
31+
if (schoolGrade < 1 || schoolGrade > 4) {
32+
throw new GongBaekException(ResponseError.BAD_REQUEST);
33+
}
34+
}
35+
36+
37+
}

src/main/java/com/ggang/be/api/user/NicknameValidator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class NicknameValidator {
1313

1414
public static void validate(String nickname){
1515
if(!LengthValidator.rangelengthCheck(nickname, MIN_LENGTH, MAX_LENGTH))
16-
throw new GongBaekException(ResponseError.INVALID_INPUT_LENGTH);
16+
throw new GongBaekException(ResponseError.BAD_REQUEST);
1717
if(!koreanPattern.matcher(nickname).find())
18-
throw new GongBaekException(ResponseError.INVALID_INPUT_NICKNAME);
18+
throw new GongBaekException(ResponseError.BAD_REQUEST);
1919
}
2020
}

src/main/java/com/ggang/be/api/user/controller/UserController.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.ggang.be.api.common.ResponseSuccess;
77
import com.ggang.be.api.exception.GongBaekException;
88
import com.ggang.be.api.facade.SignupFacade;
9+
import com.ggang.be.api.facade.SignupRequestFacade;
910
import com.ggang.be.api.user.NicknameValidator;
1011
import com.ggang.be.api.user.dto.SignupRequest;
1112
import com.ggang.be.api.user.dto.SignupResponse;
@@ -28,6 +29,7 @@
2829
public class UserController {
2930
private final UserService userService;
3031
private final SignupFacade signupFacade;
32+
private final SignupRequestFacade signupRequestFacade;
3133
private final JwtService jwtService;
3234

3335
private final static int INTRODUCTION_MIN_LENGTH = 20;
@@ -49,6 +51,7 @@ public ResponseEntity<ApiResponse<Void>> validateNickname(@RequestParam final St
4951

5052
@PostMapping("/user/signup")
5153
public ResponseEntity<ApiResponse<SignupResponse>> signup(@RequestBody final SignupRequest request){
54+
signupRequestFacade.validateSignupRequest(request);
5255
return ResponseBuilder.created(signupFacade.signup(request));
5356
}
5457

src/main/java/com/ggang/be/api/user/vo/TimeTableVo.java

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.ggang.be.domain.constant.WeekDay;
44
import com.ggang.be.domain.timslot.lectureTimeSlot.vo.LectureTimeSlotVo;
5+
import java.util.Objects;
6+
import lombok.EqualsAndHashCode;
57

68
public record TimeTableVo(WeekDay weekDay,
79
Double startTime,
@@ -14,4 +16,21 @@ public static LectureTimeSlotVo toLectureTimeSlotVo(final TimeTableVo timeTableV
1416
timeTableVo.endTime()
1517
);
1618
}
19+
20+
@Override
21+
public boolean equals(Object o) {
22+
if (this == o) {
23+
return true;
24+
}
25+
if (!(o instanceof TimeTableVo that)) {
26+
return false;
27+
}
28+
return Objects.equals(endTime, that.endTime) && weekDay == that.weekDay
29+
&& Objects.equals(startTime, that.startTime);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(weekDay, startTime, endTime);
35+
}
1736
}

src/main/java/com/ggang/be/domain/group/IntroductionValidator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import lombok.extern.slf4j.Slf4j;
77
import org.springframework.stereotype.Component;
88

9-
@Component
109
@Slf4j
1110
public class IntroductionValidator {
12-
public void isIntroductionValid(String introduction) {
11+
public static void isIntroductionValid(String introduction) {
1312
log.info("now value is : {}", introduction);
1413
if(!LengthValidator.rangelengthCheck(introduction, 20, 100)) {
1514
log.error("소개글 길이 검증에 실패하였습니다.");

src/main/java/com/ggang/be/global/util/TimeValidator.java

+36-10
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,69 @@
22

33
import com.ggang.be.api.common.ResponseError;
44
import com.ggang.be.api.exception.GongBaekException;
5+
import com.ggang.be.api.user.vo.TimeTableVo;
56
import com.ggang.be.domain.constant.WeekDay;
6-
import lombok.extern.slf4j.Slf4j;
7-
87
import java.time.LocalDate;
8+
import java.util.List;
9+
import lombok.extern.slf4j.Slf4j;
910

1011
@Slf4j
1112
public class TimeValidator {
12-
public static void isWeekDateRight(WeekDay writeWeekDay, LocalDate writeDate) {
13+
14+
public static void isWeekDateRight(WeekDay writeWeekDay, LocalDate writeDate) {
1315
WeekDay realWeekDay = WeekDay.fromDayOfWeek(writeDate.getDayOfWeek());
14-
if(!realWeekDay.equals(writeWeekDay)) {
16+
if (!realWeekDay.equals(writeWeekDay)) {
1517
log.error("weekDate and weekDay is not same");
1618
throw new GongBaekException(ResponseError.BAD_REQUEST);
1719
}
1820
}
1921

20-
public static void isTimeValid(double startTime, double endTime){
21-
if((startTime < 9 || startTime >= 18) && (endTime > 18 || endTime <= 9)) {
22+
public static void isTimeValid(double startTime, double endTime) {
23+
if ((startTime < 9 || startTime >= 18) || (endTime > 18 || endTime <= 9)) {
2224
log.error("startTime {} or endTime {} is not valid", startTime, endTime);
2325
throw new GongBaekException(ResponseError.BAD_REQUEST);
2426
}
25-
if(startTime >= endTime) {
27+
if (startTime >= endTime) {
2628
log.error("startTime or endTime is not valid");
2729
throw new GongBaekException(ResponseError.BAD_REQUEST);
2830
}
2931
}
3032

31-
public static void isDateBeforeNow(LocalDate writeDate){
32-
if(writeDate.isBefore(LocalDate.now())) {
33+
public static void isYearAfterNow(int year) {
34+
if (year > LocalDate.now().getYear()) {
35+
log.error("year {} is after now {}", year, LocalDate.now().getYear());
36+
throw new GongBaekException(ResponseError.BAD_REQUEST);
37+
}
38+
}
39+
40+
public static void isDateBeforeNow(LocalDate writeDate) {
41+
if (writeDate.isBefore(LocalDate.now())) {
3342
log.error("writeDate {} is before now {}", writeDate, LocalDate.now());
3443
throw new GongBaekException(ResponseError.BAD_REQUEST);
3544
}
3645
}
3746

3847
public static void isSameDate(LocalDate date, LocalDate otherDate) {
39-
if(!date.equals(otherDate)) {
48+
if (!date.equals(otherDate)) {
4049
log.error("localDate {} and otherDate {} is not same", date, otherDate);
4150
throw new GongBaekException(ResponseError.BAD_REQUEST);
4251
}
4352
}
53+
54+
public static void hasDuplicateInfo(List<TimeTableVo> timeTableVos) {
55+
long size = timeTableVos.size();
56+
long count = timeTableVos.stream().distinct().count();
57+
58+
if (size != count) {
59+
log.error("timeTableVo has duplicate info");
60+
throw new GongBaekException(ResponseError.BAD_REQUEST);
61+
}
62+
}
63+
64+
public static void isTimeVoValidTime(List<TimeTableVo> timeTableVos) {
65+
timeTableVos.forEach(
66+
timeTableVo -> isTimeValid(timeTableVo.startTime(),
67+
timeTableVo.endTime())
68+
);
69+
}
4470
}

src/test/java/com/ggang/be/api/user/NicknameValidatorTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class NicknameValidatorTest {
1616
//when && then
1717
Assertions.assertThatThrownBy(() -> NicknameValidator.validate(name))
1818
.isInstanceOf(GongBaekException.class)
19-
.hasMessageContaining("닉네임은 한글로만 입력 가능합니다.")
20-
.hasFieldOrPropertyWithValue("responseError", ResponseError.INVALID_INPUT_NICKNAME);
19+
.hasMessageContaining("유효하지 않은 요청입니다.")
20+
.hasFieldOrPropertyWithValue("responseError", ResponseError.BAD_REQUEST);
2121
}
2222

2323

@@ -28,8 +28,8 @@ class NicknameValidatorTest {
2828
//when && then
2929
Assertions.assertThatThrownBy(() -> NicknameValidator.validate(name))
3030
.isInstanceOf(GongBaekException.class)
31-
.hasMessageContaining("입력된 글자수가 허용된 범위를 벗어났습니다.")
32-
.hasFieldOrPropertyWithValue("responseError", ResponseError.INVALID_INPUT_LENGTH);
31+
.hasMessageContaining("유효하지 않은 요청입니다.")
32+
.hasFieldOrPropertyWithValue("responseError", ResponseError.BAD_REQUEST);
3333
}
3434

3535
@ParameterizedTest

0 commit comments

Comments
 (0)