-
Notifications
You must be signed in to change notification settings - Fork 0
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 #21 from CodingWasabi/feature-19/createGroup
[FEAT] 파티 생성
- Loading branch information
Showing
17 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
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: 4 additions & 0 deletions
4
src/main/java/com/codingwasabi/trti/domain/location/repository/LocationRepository.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,7 +1,11 @@ | ||
package com.codingwasabi.trti.domain.location.repository; | ||
|
||
import com.codingwasabi.trti.domain.location.model.City; | ||
import com.codingwasabi.trti.domain.location.model.Location; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface LocationRepository extends JpaRepository<Location, Long> { | ||
Optional<Location> findByCity(City city); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/codingwasabi/trti/domain/member/MemberService.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,8 +1,12 @@ | ||
package com.codingwasabi.trti.domain.member; | ||
|
||
import com.codingwasabi.trti.domain.member.model.entity.Member; | ||
import com.codingwasabi.trti.domain.member.model.request.RequestExistMemberDto; | ||
import com.codingwasabi.trti.domain.member.model.response.ResponseExistMemberDto; | ||
import com.codingwasabi.trti.domain.member.model.response.ResponseMyInfoDto; | ||
|
||
public interface MemberService { | ||
ResponseMyInfoDto getMemberInfo(Member member); | ||
|
||
ResponseExistMemberDto existMember(RequestExistMemberDto requestDto); | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/codingwasabi/trti/domain/member/model/request/RequestExistMemberDto.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,12 @@ | ||
package com.codingwasabi.trti.domain.member.model.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RequestExistMemberDto { | ||
private String email; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/codingwasabi/trti/domain/member/model/response/ResponseExistMemberDto.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,16 @@ | ||
package com.codingwasabi.trti.domain.member.model.response; | ||
|
||
import com.codingwasabi.trti.domain.member.model.entity.Member; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseExistMemberDto { | ||
private String nickname; | ||
private Long id; | ||
|
||
public static ResponseExistMemberDto from(Member member) { | ||
return new ResponseExistMemberDto(member.getNickname(), member.getId()); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/codingwasabi/trti/domain/party/PartyAPI.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,4 +1,9 @@ | ||
package com.codingwasabi.trti.domain.party; | ||
|
||
import com.codingwasabi.trti.config.auth.security.MemberAdaptor; | ||
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface PartyAPI { | ||
ResponseEntity<?> createParty(MemberAdaptor memberAdaptor, RequestCreatePartyDto requestDto); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/codingwasabi/trti/domain/party/PartyService.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,4 +1,9 @@ | ||
package com.codingwasabi.trti.domain.party; | ||
|
||
import com.codingwasabi.trti.domain.member.model.entity.Member; | ||
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto; | ||
import com.codingwasabi.trti.domain.party.model.response.ResponseCreatePartyDto; | ||
|
||
public interface PartyService { | ||
ResponseCreatePartyDto create(Member member, RequestCreatePartyDto requestDto); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyController.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,6 +1,27 @@ | ||
package com.codingwasabi.trti.domain.party.implementation; | ||
|
||
import com.codingwasabi.trti.config.auth.security.MemberAdaptor; | ||
import com.codingwasabi.trti.domain.party.PartyAPI; | ||
import com.codingwasabi.trti.domain.party.PartyService; | ||
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
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.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/group") | ||
public class PartyController implements PartyAPI { | ||
private final PartyService partyService; | ||
|
||
@Override | ||
@PostMapping | ||
public ResponseEntity<?> createParty(@AuthenticationPrincipal MemberAdaptor memberAdaptor, | ||
@RequestBody RequestCreatePartyDto requestDto) { | ||
return ResponseEntity.ok(partyService.create(memberAdaptor.getMember(), requestDto)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyServiceImpl.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,6 +1,60 @@ | ||
package com.codingwasabi.trti.domain.party.implementation; | ||
|
||
import com.codingwasabi.trti.domain.location.model.City; | ||
import com.codingwasabi.trti.domain.location.repository.LocationRepository; | ||
import com.codingwasabi.trti.domain.member.model.entity.Member; | ||
import com.codingwasabi.trti.domain.member.repository.MemberRepository; | ||
import com.codingwasabi.trti.domain.memberInParty.model.MemberInParty; | ||
import com.codingwasabi.trti.domain.memberInParty.repository.MemberInPartyRepository; | ||
import com.codingwasabi.trti.domain.party.PartyService; | ||
import com.codingwasabi.trti.domain.party.model.Party; | ||
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto; | ||
import com.codingwasabi.trti.domain.party.model.response.ResponseCreatePartyDto; | ||
import com.codingwasabi.trti.domain.party.repository.PartyRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PartyServiceImpl implements PartyService { | ||
private final PartyRepository partyRepository; | ||
private final MemberInPartyRepository memberInPartyRepository; | ||
private final MemberRepository memberRepository; | ||
private final LocationRepository locationRepository; | ||
|
||
@Override | ||
@Transactional | ||
public ResponseCreatePartyDto create(Member member, RequestCreatePartyDto requestDto) { | ||
Party party = requestDto.getEntityFrom(); | ||
|
||
setPartyCaptain(member, party); | ||
setPartyCity(requestDto, party); | ||
partyRepository.save(party); | ||
|
||
putMemberInParty(party, requestDto.getMembers()); | ||
|
||
return ResponseCreatePartyDto.from(party); | ||
} | ||
|
||
private void setPartyCaptain(Member member, Party party) { | ||
party.setCaptain(member); | ||
} | ||
|
||
private void setPartyCity(RequestCreatePartyDto requestDto, Party party) { | ||
City.parseName(requestDto.getLocation()); | ||
party.setLocation(locationRepository | ||
.findByCity(City.parseName(requestDto.getLocation())) | ||
.orElseThrow(() -> new IllegalArgumentException("[ERROR] 도시의 정보가 존재하지 않습니다."))); | ||
} | ||
|
||
private void putMemberInParty(Party party, List<Long> memberIdList) { | ||
memberIdList.stream() | ||
.map((id) -> memberRepository | ||
.findById(id) | ||
.orElseThrow(() -> new IllegalArgumentException("[ERROR] 존재하지 않는 회원의 id가 입력되었습니다."))) | ||
.forEach((member) -> memberInPartyRepository.save(MemberInParty.of(party, member))); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/codingwasabi/trti/domain/party/model/request/RequestCreatePartyDto.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,29 @@ | ||
package com.codingwasabi.trti.domain.party.model.request; | ||
|
||
import com.codingwasabi.trti.domain.location.model.Location; | ||
import com.codingwasabi.trti.domain.party.model.Party; | ||
import jdk.javadoc.doclet.Taglet; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class RequestCreatePartyDto { | ||
private String title; | ||
private String image; | ||
private String location; | ||
private List<Long> members; | ||
private String[] period; | ||
|
||
public Party getEntityFrom() { | ||
return Party.builder() | ||
.title(title) | ||
.imageLink(image) | ||
.startDate(LocalDate.parse(period[0])) | ||
.endDate(LocalDate.parse(period[1])) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/codingwasabi/trti/domain/party/model/response/ResponseCreatePartyDto.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,15 @@ | ||
package com.codingwasabi.trti.domain.party.model.response; | ||
|
||
import com.codingwasabi.trti.domain.party.model.Party; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ResponseCreatePartyDto { | ||
private Long id; | ||
|
||
public static ResponseCreatePartyDto from(Party party) { | ||
return new ResponseCreatePartyDto(party.getId()); | ||
} | ||
} |
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