-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f45211
commit da00c13
Showing
8 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/twtw/backend/domain/group/dto/request/MakeGroupDto.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,13 @@ | ||
package com.twtw.backend.domain.group.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class MakeGroupDto { | ||
private String name; | ||
private String groupImage; | ||
} |
2 changes: 1 addition & 1 deletion
2
...ackend/domain/group/dto/GroupInfoDto.java → ...main/group/dto/response/GroupInfoDto.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
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/twtw/backend/domain/group/mapper/GroupMapper.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,18 @@ | ||
package com.twtw.backend.domain.group.mapper; | ||
|
||
import com.twtw.backend.domain.group.dto.request.MakeGroupDto; | ||
import com.twtw.backend.domain.group.entity.Group; | ||
import com.twtw.backend.domain.group.entity.GroupMember; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class GroupMapper { | ||
public GroupMember connectGroupMember(Group group, Member member){ | ||
return new GroupMember(group,member); | ||
} | ||
|
||
public Group toGroupEntity(MakeGroupDto groupDto){ | ||
return new Group(groupDto.getName(),groupDto.getGroupImage()); | ||
} | ||
} |
49 changes: 47 additions & 2 deletions
49
backend/src/main/java/com/twtw/backend/domain/group/service/GroupService.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,14 +1,59 @@ | ||
package com.twtw.backend.domain.group.service; | ||
|
||
import com.twtw.backend.domain.group.dto.request.MakeGroupDto; | ||
import com.twtw.backend.domain.group.entity.Group; | ||
import com.twtw.backend.domain.group.entity.GroupMember; | ||
import com.twtw.backend.domain.group.mapper.GroupMapper; | ||
import com.twtw.backend.domain.group.repository.GroupMemberRepository; | ||
import com.twtw.backend.domain.group.repository.GroupRepository; | ||
|
||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.domain.member.service.AuthService; | ||
import com.twtw.backend.domain.member.service.MemberService; | ||
import com.twtw.backend.global.exception.EntityNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
public class GroupService { | ||
private final GroupRepository groupRepository; | ||
|
||
public GroupService(GroupRepository groupRepository) { | ||
private final GroupMemberRepository groupMemberRepository; | ||
private final AuthService authService; | ||
private final GroupMapper groupMapper; | ||
private final MemberService memberService; | ||
public GroupService(GroupRepository groupRepository,GroupMemberRepository groupMemberRepository,AuthService authService,GroupMapper groupMapper,MemberService memberService) { | ||
this.groupRepository = groupRepository; | ||
this.groupMemberRepository = groupMemberRepository; | ||
this.authService = authService; | ||
this.groupMapper = groupMapper; | ||
this.memberService = memberService; | ||
} | ||
|
||
@Transactional | ||
public void makeGroup(MakeGroupDto groupDto){ | ||
Member member = this.authService.getMemberByJwt(); | ||
Group group = this.groupMapper.toGroupEntity(groupDto); | ||
|
||
GroupMember groupMember = this.groupMapper.connectGroupMember(group,member); | ||
|
||
groupMemberRepository.save(groupMember); | ||
} | ||
@Transactional | ||
public void joinGroup(UUID groupId){ | ||
Member member = this.authService.getMemberByJwt(); | ||
Group group = this.groupRepository.findById(groupId).orElseThrow(EntityNotFoundException::new); | ||
|
||
GroupMember groupMember = this.groupMapper.connectGroupMember(group,member); | ||
|
||
groupMemberRepository.save(groupMember); | ||
} | ||
|
||
|
||
public void removeGroup(UUID groupId){ | ||
// TODO() | ||
} | ||
|
||
|
||
} |
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: 3 additions & 1 deletion
4
backend/src/test/java/com/twtw/backend/BackendApplicationTests.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,13 +1,15 @@ | ||
package com.twtw.backend; | ||
|
||
import com.twtw.backend.domain.group.service.GroupService; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
class BackendApplicationTests { | ||
|
||
@Test | ||
void contextLoads() {} | ||
} |