-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
모임 상태 및 찜, 참여 기능 추가 #171
모임 상태 및 찜, 참여 기능 추가 #171
Changes from all commits
d5b3ab4
5bb735d
647b0bc
d588f7d
96c862c
320d2fe
d66de5e
5261fb7
10706c3
308502d
2111e00
6c7807c
5b9aab9
c00be06
f77c825
4aaa5a2
3087ebb
dcc33be
473acba
32a8411
82b190d
43fac8d
d3d1794
339621e
c21540b
d6f7aab
723427d
76218b2
baf0b21
e0a6d69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mouda.backend.chamyo.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.chamyo.dto.response.ChamyoFindAllResponses; | ||
import mouda.backend.chamyo.dto.request.MoimChamyoRequest; | ||
import mouda.backend.chamyo.dto.response.MoimRoleFindResponse; | ||
import mouda.backend.chamyo.service.ChamyoService; | ||
import mouda.backend.common.RestResponse; | ||
import mouda.backend.config.argumentresolver.LoginMember; | ||
import mouda.backend.member.domain.Member; | ||
|
||
@RestController | ||
@RequestMapping("/v1/chamyo") | ||
@RequiredArgsConstructor | ||
public class ChamyoController implements ChamyoSwagger { | ||
|
||
private final ChamyoService chamyoService; | ||
|
||
@Override | ||
@GetMapping("/me") | ||
public ResponseEntity<RestResponse<MoimRoleFindResponse>> findMoimRoleByMember( | ||
@RequestParam Long moimId, @LoginMember Member member | ||
) { | ||
MoimRoleFindResponse moimRoleFindResponse = chamyoService.findMoimRole(moimId, member); | ||
|
||
return ResponseEntity.ok().body(new RestResponse<>(moimRoleFindResponse)); | ||
} | ||
|
||
@Override | ||
@GetMapping("/all") | ||
public ResponseEntity<RestResponse<ChamyoFindAllResponses>> findAllChamyoByMoim(@RequestParam Long moimId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
기본값이 required=true라서 없으면 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 😀 그럼 핸들링해서 400 에러를 보내는 과정도 필요하겠네요. |
||
ChamyoFindAllResponses chamyoFindAllResponses = chamyoService.findAllChamyo(moimId); | ||
|
||
return ResponseEntity.ok().body(new RestResponse<>(chamyoFindAllResponses)); | ||
} | ||
|
||
@Override | ||
@PostMapping | ||
public ResponseEntity<Void> chamyoMoim(@Valid @RequestBody MoimChamyoRequest request, @LoginMember Member member) { | ||
chamyoService.chamyoMoim(request, member); | ||
|
||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package mouda.backend.chamyo.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import jakarta.validation.Valid; | ||
import mouda.backend.chamyo.dto.response.ChamyoFindAllResponses; | ||
import mouda.backend.chamyo.dto.request.MoimChamyoRequest; | ||
import mouda.backend.chamyo.dto.response.MoimRoleFindResponse; | ||
import mouda.backend.common.RestResponse; | ||
import mouda.backend.config.argumentresolver.LoginMember; | ||
import mouda.backend.member.domain.Member; | ||
|
||
public interface ChamyoSwagger { | ||
|
||
@Operation(summary = "모임 참여 여부 조회", description = "현재 로그인된 회원의 모임 참여 여부를 조회합니다.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "모임 참여 여부 조회 성공") | ||
}) | ||
ResponseEntity<RestResponse<MoimRoleFindResponse>> findMoimRoleByMember(@RequestParam Long moimId, | ||
@LoginMember Member member); | ||
|
||
@Operation(summary = "모든 모임 참여자 조회", description = "모임에 참여한 모든 회원을 조회합니다.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "모든 모임 참여자 조회 성공") | ||
}) | ||
ResponseEntity<RestResponse<ChamyoFindAllResponses>> findAllChamyoByMoim(@RequestParam Long moimId); | ||
|
||
@Operation(summary = "모임 참여", description = "모임에 참여합니다.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "모임 참여 성공") | ||
}) | ||
ResponseEntity<Void> chamyoMoim(@Valid @RequestBody MoimChamyoRequest request, @LoginMember Member member); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
@Getter | ||
public enum MoimRole { | ||
DEFAULT | ||
MOIMER, MOIMEE, NON_MOIMEE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package mouda.backend.chamyo.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
public record MoimChamyoRequest( | ||
@NotNull @Positive | ||
Long moimId | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mouda.backend.chamyo.dto.response; | ||
|
||
import lombok.Builder; | ||
import mouda.backend.chamyo.domain.Chamyo; | ||
|
||
@Builder | ||
public record ChamyoFindAllResponse( | ||
String nickname, | ||
String profile, | ||
String role | ||
) { | ||
|
||
public static ChamyoFindAllResponse toResponse(Chamyo chamyo) { | ||
return ChamyoFindAllResponse.builder() | ||
.nickname(chamyo.getMember().getNickname()) | ||
.profile("") | ||
.role(chamyo.getMoimRole().name()) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mouda.backend.chamyo.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record ChamyoFindAllResponses( | ||
List<ChamyoFindAllResponse> chamyos | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package mouda.backend.chamyo.dto.response; | ||
|
||
public record MoimRoleFindResponse( | ||
String role | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mouda.backend.chamyo.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ChamyoErrorMessage { | ||
|
||
MOIM_NOT_FOUND("참여하려는 모임이 존재하지 않습니다."), | ||
MOIM_ALREADY_JOINED("이미 참여한 모임입니다."), | ||
MOIM_FULL("최대 인원 수를 초과했습니다."), | ||
MOIMING_CANCLED("취소된 모임입니다."), | ||
MOIMING_COMPLETE("모집이 완료된 모임입니다."); | ||
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MOIM이라는 접두사랑 MOIMING이라는 접두사는 무슨 차이가 있는 지 궁금합니다 😀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
MOIM은 모임 그 자체를, MOIMING은 모집 중이라는 행위를 표현하려는 의도였어요 ㅎㅎ |
||
|
||
private final String message; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mouda.backend.chamyo.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import mouda.backend.exception.MoudaException; | ||
|
||
public class ChamyoException extends MoudaException { | ||
|
||
public ChamyoException(HttpStatus httpStatus, ChamyoErrorMessage chamyoErrorMessage) { | ||
super(httpStatus, chamyoErrorMessage.getMessage()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mouda.backend.chamyo.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import mouda.backend.chamyo.domain.Chamyo; | ||
import mouda.backend.member.domain.Member; | ||
import mouda.backend.moim.domain.Moim; | ||
|
||
public interface ChamyoRepository extends JpaRepository<Chamyo, Long> { | ||
|
||
Optional<Chamyo> findByMoimIdAndMemberId(Long moimId, Long id); | ||
|
||
List<Chamyo> findAllByMoimId(Long moimId); | ||
|
||
int countByMoim(Moim moim); | ||
|
||
boolean existsByMoimAndMember(Moim moim, Member member); | ||
|
||
void deleteAllByMoimId(Long moimId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package mouda.backend.chamyo.service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.chamyo.domain.Chamyo; | ||
import mouda.backend.chamyo.domain.MoimRole; | ||
import mouda.backend.chamyo.dto.response.ChamyoFindAllResponse; | ||
import mouda.backend.chamyo.dto.response.ChamyoFindAllResponses; | ||
import mouda.backend.chamyo.dto.request.MoimChamyoRequest; | ||
import mouda.backend.chamyo.dto.response.MoimRoleFindResponse; | ||
import mouda.backend.chamyo.exception.ChamyoErrorMessage; | ||
import mouda.backend.chamyo.exception.ChamyoException; | ||
import mouda.backend.chamyo.repository.ChamyoRepository; | ||
import mouda.backend.member.domain.Member; | ||
import mouda.backend.moim.domain.Moim; | ||
import mouda.backend.moim.domain.MoimStatus; | ||
import mouda.backend.moim.repository.MoimRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ChamyoService { | ||
|
||
private final ChamyoRepository chamyoRepository; | ||
private final MoimRepository moimRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public MoimRoleFindResponse findMoimRole(Long moimId, Member member) { | ||
Optional<Chamyo> chamyoOptional = chamyoRepository.findByMoimIdAndMemberId(moimId, member.getId()); | ||
|
||
MoimRole moimRole = chamyoOptional.map(Chamyo::getMoimRole).orElse(MoimRole.NON_MOIMEE); | ||
|
||
return new MoimRoleFindResponse(moimRole.name()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ChamyoFindAllResponses findAllChamyo(Long moimId) { | ||
List<ChamyoFindAllResponse> responses = chamyoRepository.findAllByMoimId(moimId).stream() | ||
.map(ChamyoFindAllResponse::toResponse) | ||
.toList(); | ||
|
||
return new ChamyoFindAllResponses(responses); | ||
} | ||
|
||
public void chamyoMoim(MoimChamyoRequest request, Member member) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 주석은 혹시 일부러 하신 건가요 ? 아니면 실수로 남겨놓은 건가요? 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋ 수정할게요..ㅋㅋㅋㅋㅋㅋ 어제 마지막 부분만 못하고 갔거든요 |
||
Moim moim = moimRepository.findById(request.moimId()) | ||
.orElseThrow(() -> new ChamyoException(HttpStatus.NOT_FOUND, ChamyoErrorMessage.MOIM_NOT_FOUND)); | ||
validateCanChamyoMoim(moim, member); | ||
|
||
Chamyo chamyo = Chamyo.builder() | ||
.moim(moim) | ||
.member(member) | ||
.moimRole(MoimRole.MOIMEE) | ||
.build(); | ||
chamyoRepository.save(chamyo); | ||
|
||
int currentPeople = chamyoRepository.countByMoim(moim); | ||
if (currentPeople >= moim.getMaxPeople()) { | ||
moimRepository.updateMoimStatusById(moim.getId(), MoimStatus.COMPLETED); | ||
} | ||
} | ||
|
||
private void validateCanChamyoMoim(Moim moim, Member member) { | ||
int currentPeople = chamyoRepository.countByMoim(moim); | ||
if (currentPeople >= moim.getMaxPeople()) { | ||
throw new ChamyoException(HttpStatus.BAD_REQUEST, ChamyoErrorMessage.MOIM_FULL); | ||
} | ||
if (moim.getMoimStatus() == MoimStatus.CANCELED) { | ||
throw new ChamyoException(HttpStatus.BAD_REQUEST, ChamyoErrorMessage.MOIMING_CANCLED); | ||
} | ||
if (moim.getMoimStatus() == MoimStatus.COMPLETED) { | ||
throw new ChamyoException(HttpStatus.BAD_REQUEST, ChamyoErrorMessage.MOIMING_COMPLETE); | ||
} | ||
if (chamyoRepository.existsByMoimAndMember(moim, member)) { | ||
throw new ChamyoException(HttpStatus.BAD_REQUEST, ChamyoErrorMessage.MOIM_ALREADY_JOINED); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 로그인한 사용자의 권한을 불러오는 거군요 .. !
/chamyo/me
보다는chamyo/role
는 어떨까요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프론트 처리를 위해 role을 반환하도록 했지만 사실상
참여 여부 조회
에 사용되고 있습니다 ㅎㅎ 어찌됐든 Role에 미참여자도 포함된 만큼 상의 후 처리해볼게용!