-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: [FN-297] 그룹 생성 API 구현 #4
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
Changes from all commits
97b8cb6
474c07f
d0ad202
c185220
19fcda1
7312a74
887e71b
9144f33
717b49c
2123161
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,50 @@ | ||
| package flipnote.group.adapter.in.web; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestHeader; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import flipnote.group.api.dto.request.CreateGroupRequestDto; | ||
| import flipnote.group.api.dto.response.CreateGroupResponseDto; | ||
| import flipnote.group.application.port.in.CreateGroupUseCase; | ||
| import flipnote.group.application.port.in.command.CreateGroupCommand; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/v1/groups") | ||
| public class GroupController { | ||
|
|
||
| private final CreateGroupUseCase createGroupUseCase; | ||
|
|
||
| /** | ||
| * 그룹 생성 API | ||
| * @param userId | ||
| * @param req | ||
| * @return | ||
| */ | ||
| @PostMapping("") | ||
| public ResponseEntity<CreateGroupResponseDto> createGroup( | ||
| @RequestHeader("X-USER-ID") Long userId, | ||
| @RequestBody @Valid CreateGroupRequestDto req) { | ||
|
|
||
| CreateGroupCommand cmd = new CreateGroupCommand( | ||
| req.name(), | ||
| req.category(), | ||
| req.description(), | ||
| req.joinPolicy(), | ||
| req.visibility(), | ||
| req.maxMember(), | ||
| req.imageRefId() | ||
| ); | ||
|
|
||
| var result = createGroupUseCase.create(cmd, userId); | ||
| CreateGroupResponseDto res = CreateGroupResponseDto.from(result.groupId()); | ||
| return ResponseEntity.ok(res); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||
| package flipnote.group.adapter.out.entity; | ||||
|
|
||||
| import flipnote.group.application.port.in.command.CreateGroupCommand; | ||||
|
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. 사용되지 않는 import:
♻️ 제안-import flipnote.group.application.port.in.command.CreateGroupCommand;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| import flipnote.group.domain.model.BaseEntity; | ||||
| import flipnote.group.domain.model.group.Category; | ||||
| import flipnote.group.domain.model.group.JoinPolicy; | ||||
| import flipnote.group.domain.model.group.Visibility; | ||||
| import jakarta.persistence.Column; | ||||
| import jakarta.persistence.Entity; | ||||
| import jakarta.persistence.EnumType; | ||||
| import jakarta.persistence.Enumerated; | ||||
| import jakarta.persistence.GeneratedValue; | ||||
| import jakarta.persistence.GenerationType; | ||||
| import jakarta.persistence.Id; | ||||
| import jakarta.persistence.Table; | ||||
| import lombok.AccessLevel; | ||||
| import lombok.Builder; | ||||
| import lombok.Getter; | ||||
| import lombok.NoArgsConstructor; | ||||
|
|
||||
| @Getter | ||||
| @Entity | ||||
| @Table(name = "app_groups") | ||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||
| public class GroupEntity extends BaseEntity { | ||||
|
|
||||
| @Id | ||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||
| private Long id; | ||||
|
|
||||
| @Column(nullable = false, length = 50) | ||||
| private String name; | ||||
|
|
||||
| @Enumerated(EnumType.STRING) | ||||
| @Column(nullable = false) | ||||
| private Category category; | ||||
|
|
||||
| @Column(nullable = false) | ||||
| private String description; | ||||
|
|
||||
| @Enumerated(EnumType.STRING) | ||||
| @Column(nullable = false) | ||||
| private JoinPolicy joinPolicy; | ||||
|
|
||||
| @Enumerated(EnumType.STRING) | ||||
| @Column(nullable = false) | ||||
| private Visibility visibility; | ||||
|
|
||||
| @Column(nullable = false) | ||||
| private Integer maxMember; | ||||
|
|
||||
| private Long imageRefId; | ||||
|
|
||||
| @Column(nullable = false) | ||||
| private Integer memberCount; | ||||
|
|
||||
| @Builder | ||||
| private GroupEntity(String name, Category category, String description, JoinPolicy joinPolicy, Visibility visibility, | ||||
| Integer maxMember, Long imageRefId, Integer memberCount) { | ||||
| this.name = name; | ||||
| this.category = category; | ||||
| this.description = description; | ||||
| this.joinPolicy = joinPolicy; | ||||
| this.visibility = visibility; | ||||
| this.maxMember = maxMember; | ||||
| this.imageRefId = imageRefId; | ||||
| this.memberCount = memberCount; | ||||
| } | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package flipnote.group.adapter.out.entity; | ||
|
|
||
| import flipnote.group.domain.model.BaseEntity; | ||
| import flipnote.group.domain.model.member.GroupMemberRole; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.persistence.UniqueConstraint; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @Table( | ||
| name = "group_members", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "uk_group_members_group_user", | ||
| columnNames = {"group_id", "user_id"} | ||
| ) | ||
| } | ||
| ) | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class GroupMemberEntity extends BaseEntity { | ||
stoneTiger0912 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "group_id", nullable = false) | ||
| private Long groupId; | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| private Long userId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| private GroupMemberRole role; | ||
|
|
||
| @Builder | ||
| private GroupMemberEntity(Long groupId, Long userId, GroupMemberRole role) { | ||
| this.groupId = groupId; | ||
| this.userId = userId; | ||
| this.role = (role != null) ? role : GroupMemberRole.MEMBER; | ||
| } | ||
|
|
||
| /** | ||
| * 오너인 경우 | ||
| * @param groupId | ||
| * @param userId | ||
| * @return | ||
| */ | ||
| public static GroupMemberEntity createOwner(Long groupId, Long userId) { | ||
| return GroupMemberEntity.builder() | ||
| .groupId(groupId) | ||
| .userId(userId) | ||
| .role(GroupMemberRole.OWNER) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * 오너가 아닌 경우 | ||
| * @param groupId | ||
| * @param userId | ||
| * @return | ||
| */ | ||
| public static GroupMemberEntity join(Long groupId, Long userId) { | ||
| return GroupMemberEntity.builder() | ||
| .groupId(groupId) | ||
| .userId(userId) | ||
| .role(GroupMemberRole.MEMBER) | ||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package flipnote.group.adapter.out.persistence; | ||
|
|
||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import flipnote.group.adapter.out.persistence.mapper.GroupMemberMapper; | ||
| import flipnote.group.application.port.out.GroupMemberRepositoryPort; | ||
| import flipnote.group.domain.model.member.GroupMemberRole; | ||
| import flipnote.group.infrastructure.persistence.jpa.GroupMemberRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class GroupMemberRepositoryAdapter implements GroupMemberRepositoryPort { | ||
|
|
||
| private final GroupMemberRepository groupMemberRepository; | ||
|
|
||
| /** | ||
| * 오너일 경우 | ||
| * @param groupId | ||
| * @param userId | ||
| */ | ||
| @Override | ||
| public void saveOwner(Long groupId, Long userId) { | ||
| groupMemberRepository.save(GroupMemberMapper.createOwner(groupId, userId)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package flipnote.group.adapter.out.persistence; | ||
|
|
||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import flipnote.group.adapter.out.entity.GroupEntity; | ||
| import flipnote.group.adapter.out.persistence.mapper.GroupMapper; | ||
| import flipnote.group.application.port.out.GroupRepositoryPort; | ||
| import flipnote.group.domain.model.group.Group; | ||
| import flipnote.group.infrastructure.persistence.jpa.GroupRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class GroupRepositoryAdapter implements GroupRepositoryPort { | ||
|
|
||
| private final GroupRepository groupRepository; | ||
|
|
||
| @Override | ||
| public Long saveNewGroup(Group group) { | ||
| GroupEntity entity = GroupMapper.createNewEntity(group); | ||
| return groupRepository.save(entity).getId(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package flipnote.group.adapter.out.persistence.mapper; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import flipnote.group.adapter.out.entity.GroupEntity; | ||
| import flipnote.group.domain.model.group.Group; | ||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Component | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class GroupMapper { | ||
|
|
||
| /** | ||
| * 새로운 엔티티 생성 | ||
| * @param domain | ||
| * @return | ||
| */ | ||
| public static GroupEntity createNewEntity(Group domain) { | ||
| return GroupEntity.builder() | ||
| .name(domain.getName()) | ||
| .category(domain.getCategory()) | ||
| .description(domain.getDescription()) | ||
| .joinPolicy(domain.getJoinPolicy()) | ||
| .visibility(domain.getVisibility()) | ||
| .maxMember(domain.getMaxMember()) | ||
| .imageRefId(domain.getImageRefId()) | ||
| .memberCount(domain.getMemberCount()) | ||
| .build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package flipnote.group.adapter.out.persistence.mapper; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import flipnote.group.adapter.out.entity.GroupMemberEntity; | ||
| import flipnote.group.domain.model.member.GroupMemberRole; | ||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Component | ||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class GroupMemberMapper { | ||
| public static GroupMemberEntity createOwner(Long groupId, Long userId) { | ||
| return GroupMemberEntity.builder() | ||
| .groupId(groupId) | ||
| .userId(userId) | ||
| .role(GroupMemberRole.OWNER) | ||
| .build(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.