-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Onion-City/feat/clubJoinApi
유저 클럽 가입 신청 구현 및 예외처리
- Loading branch information
Showing
26 changed files
with
242 additions
and
57 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/GDG/whatssue/domain/attendance/entity/MemberAttendanceResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/java/GDG/whatssue/domain/club/repository/ClubRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package GDG.whatssue.domain.club.repository; | ||
|
||
import GDG.whatssue.domain.club.entity.Club; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ClubRepository extends JpaRepository<Club, Long> { | ||
|
||
Optional<Club> findByClubCode(String clubCode); | ||
boolean existsByClubCode(String clubCode); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/GDG/whatssue/domain/member/controller/ClubMemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package GDG.whatssue.domain.member.controller; | ||
|
||
import GDG.whatssue.domain.member.exception.ClubMemberErrorCode; | ||
import GDG.whatssue.domain.member.service.ClubMemberService; | ||
import GDG.whatssue.global.error.CommonException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.util.PatternMatchUtils; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class ClubMemberController { | ||
|
||
private final ClubMemberService clubMemberService; | ||
|
||
@PostMapping("/join/{clubCode}") | ||
public ResponseEntity joinClub(@PathVariable(name = "clubCode") String clubCode) { | ||
//현재 로그인 id parameter로 받아오기 TODO | ||
Long userId = 1L; | ||
|
||
boolean checkClubCode = Pattern.matches("[0-9]{6}", clubCode); | ||
|
||
if (checkClubCode) { | ||
clubMemberService.addClubJoinRequest(userId, clubCode); | ||
return new ResponseEntity("ok", HttpStatus.OK); | ||
} else { | ||
throw new CommonException(ClubMemberErrorCode.INVALID_CLUB_CODE_ERROR); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...atssue/domain/club/entity/ClubMember.java → ...ssue/domain/member/entity/ClubMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/GDG/whatssue/domain/member/exception/ClubMemberErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package GDG.whatssue.domain.member.exception; | ||
|
||
import GDG.whatssue.global.error.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ClubMemberErrorCode implements ErrorCode { | ||
|
||
CLUB_NOT_FOUND_ERROR(HttpStatus.BAD_REQUEST, "No Club With That Club Code"), | ||
INVALID_CLUB_CODE_ERROR(HttpStatus.BAD_REQUEST, "Invalid Club Code Pattern [******]"), | ||
DUPLICATE_CLUB_JOIN_ERROR(HttpStatus.BAD_REQUEST, "Club That Has Already Joined"); | ||
|
||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...repository/ClubJoinRequestRepository.java → ...repository/ClubJoinRequestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...club/repository/ClubMemberRepository.java → ...mber/repository/ClubMemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/GDG/whatssue/domain/member/service/ClubMemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package GDG.whatssue.domain.member.service; | ||
|
||
import GDG.whatssue.domain.club.entity.Club; | ||
import GDG.whatssue.domain.club.repository.ClubRepository; | ||
import GDG.whatssue.domain.member.entity.ClubJoinRequest; | ||
import GDG.whatssue.domain.member.exception.ClubMemberErrorCode; | ||
import GDG.whatssue.domain.member.repository.ClubJoinRequestRepository; | ||
import GDG.whatssue.domain.user.entity.User; | ||
import GDG.whatssue.domain.user.repository.UserRepository; | ||
import GDG.whatssue.global.error.CommonException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ClubMemberService { | ||
|
||
private final UserRepository userRepository; | ||
private final ClubRepository clubRepository; | ||
private final ClubJoinRequestRepository clubJoinRequestRepository; | ||
|
||
public void addClubJoinRequest(Long userId, String clubCode) { | ||
Club club = clubRepository.findByClubCode(clubCode) | ||
.orElseThrow(() -> new CommonException(ClubMemberErrorCode.CLUB_NOT_FOUND_ERROR)); | ||
|
||
User loginUser = userRepository.findById(userId).get(); | ||
|
||
checkJoinDuplicate(loginUser, club); | ||
|
||
ClubJoinRequest newClubJoinRequest = ClubJoinRequest.builder() | ||
.club(club).user(loginUser).build(); | ||
|
||
clubJoinRequestRepository.save(newClubJoinRequest); | ||
} | ||
|
||
private void checkJoinDuplicate(User loginUser, Club club) { | ||
boolean result = clubJoinRequestRepository.findAll() | ||
.stream() | ||
.anyMatch(r -> r.getClub().equals(club) && r.getUser().equals(loginUser)); | ||
|
||
if (result) { | ||
throw new CommonException(ClubMemberErrorCode.DUPLICATE_CLUB_JOIN_ERROR); | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...controller/OfficialAbsenceController.java → ...controller/OfficialAbsenceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...est/dto/OfficialAbsenceAddRequestDto.java → ...nce/dto/OfficialAbsenceAddRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...est/dto/OfficialAbsenceGetRequestDto.java → ...nce/dto/OfficialAbsenceGetRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...equest/entity/OfficialAbsenceRequest.java → ...bsence/entity/OfficialAbsenceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ory/OfficialAbsenceRequestRepository.java → ...ory/OfficialAbsenceRequestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
...quest/service/OfficialAbsenceService.java → ...sence/service/OfficialAbsenceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.