Skip to content

Commit acbfccb

Browse files
Feat: [FN-68][FN-69][FN-70][FN-71][FN-72] 그룹 가입 신청
Feat: [FN-68][FN-69][FN-70][FN-71][FN-72] 그룹 가입 신청
2 parents 0dce162 + 133ae96 commit acbfccb

27 files changed

Lines changed: 917 additions & 39 deletions

src/main/java/project/flipnote/group/controller/GroupController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class GroupController {
2323

2424
@PostMapping("")
2525
public ResponseEntity<GroupCreateResponse> create(
26-
@AuthenticationPrincipal AuthPrinciple userAuth,
26+
@AuthenticationPrincipal AuthPrinciple authPrinciple,
2727
@Valid @RequestBody GroupCreateRequest req) {
28-
GroupCreateResponse res = groupService.create(userAuth, req);
28+
GroupCreateResponse res = groupService.create(authPrinciple, req);
2929
return ResponseEntity.status(HttpStatus.CREATED).body(res);
3030
}
3131
}

src/main/java/project/flipnote/group/entity/GroupPermission.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package project.flipnote.group.entity;
22

3-
import jakarta.persistence.Column;
4-
import jakarta.persistence.Entity;
5-
import jakarta.persistence.GeneratedValue;
6-
import jakarta.persistence.GenerationType;
7-
import jakarta.persistence.Id;
8-
import jakarta.persistence.Table;
3+
import jakarta.persistence.*;
94
import lombok.AccessLevel;
105
import lombok.Builder;
116
import lombok.Getter;
@@ -23,11 +18,12 @@ public class GroupPermission {
2318
@GeneratedValue(strategy = GenerationType.IDENTITY)
2419
private Long id;
2520

21+
@Enumerated(EnumType.STRING)
2622
@Column(nullable = false, length = 50, unique = true)
27-
private String name;
23+
private GroupPermissionStatus name;
2824

2925
@Builder
30-
private GroupPermission(String name) {
26+
private GroupPermission(GroupPermissionStatus name) {
3127
this.name = name;
3228
}
3329
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package project.flipnote.group.entity;
2+
3+
public enum GroupPermissionStatus {
4+
INVITE, KICK, JOIN_REQUEST_MANAGE
5+
}

src/main/java/project/flipnote/group/entity/GroupRole.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/project/flipnote/group/entity/GroupRolePermission.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class GroupRolePermission {
3030

3131
@Enumerated(EnumType.STRING)
3232
@Column(name = "role", nullable = false)
33-
private GroupRole role;
33+
private GroupMemberRole role;
3434

3535
@Builder
36-
private GroupRolePermission(Group group, GroupPermission groupPermission, GroupRole role) {
36+
private GroupRolePermission(Group group, GroupPermission groupPermission, GroupMemberRole role) {
3737
this.group = group;
3838
this.groupPermission = groupPermission;
3939
this.role = role;

src/main/java/project/flipnote/group/exception/GroupErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@Getter
1111
@RequiredArgsConstructor
1212
public enum GroupErrorCode implements ErrorCode {
13+
GROUP_NOT_FOUND(HttpStatus.NOT_FOUND, "GROUP_002", "그룹이 존재하지 않습니다."),
1314
INVALID_MAX_MEMBER(HttpStatus.BAD_REQUEST, "GROUP_001", "최대 인원 수는 1 이상 100 이하여야 합니다.");
1415

1516
private final HttpStatus httpStatus;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package project.flipnote.group.model;
2+
3+
import org.hibernate.validator.constraints.URL;
4+
5+
import jakarta.validation.constraints.Max;
6+
import jakarta.validation.constraints.Min;
7+
import jakarta.validation.constraints.NotBlank;
8+
import jakarta.validation.constraints.NotEmpty;
9+
import jakarta.validation.constraints.NotNull;
10+
import jakarta.validation.constraints.Size;
11+
import project.flipnote.group.entity.Category;
12+
13+
public class GroupCreateDto {
14+
public record Request(
15+
@NotBlank
16+
@Size(max = 50)
17+
String name,
18+
19+
@NotNull
20+
Category category,
21+
22+
@NotBlank
23+
String description,
24+
25+
@NotNull
26+
Boolean applicationRequired,
27+
28+
@NotNull
29+
Boolean publicVisible,
30+
31+
@NotNull
32+
@Min(1)
33+
@Max(100)
34+
Integer maxMember,
35+
36+
@URL
37+
String image
38+
) {
39+
}
40+
41+
public record Response(
42+
Long groupId
43+
){
44+
public static Response from(Long groupId) {
45+
return new Response(groupId);
46+
}
47+
}
48+
}

src/main/java/project/flipnote/group/repository/GroupMemberRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
import org.springframework.data.jpa.repository.JpaRepository;
44

5+
import project.flipnote.group.entity.Group;
6+
57
import org.springframework.stereotype.Repository;
68
import project.flipnote.group.entity.GroupMember;
9+
import project.flipnote.user.entity.UserProfile;
10+
11+
import java.util.Optional;
712

813
@Repository
914
public interface GroupMemberRepository extends JpaRepository<GroupMember, Long> {
15+
Optional<GroupMember> findByGroupAndUser(Group group, UserProfile userProfile);
16+
17+
long countByGroup_Id(Long groupId);
18+
1019
}

src/main/java/project/flipnote/group/repository/GroupPermissionRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.springframework.stereotype.Repository;
55

66
import project.flipnote.group.entity.GroupPermission;
7+
import project.flipnote.group.entity.GroupPermissionStatus;
78

89
@Repository
910
public interface GroupPermissionRepository extends JpaRepository<GroupPermission, Long> {
11+
GroupPermission findByName(GroupPermissionStatus name);
1012
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
package project.flipnote.group.repository;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Lock;
5+
import org.springframework.data.jpa.repository.Query;
46
import org.springframework.stereotype.Repository;
57

8+
import jakarta.persistence.LockModeType;
69
import project.flipnote.group.entity.Group;
10+
import project.flipnote.group.entity.GroupMember;
11+
12+
import java.util.List;
13+
import java.util.Optional;
714

815
@Repository
916
public interface GroupRepository extends JpaRepository<Group, Long> {
17+
Optional<Group> findById(Long groupId);
18+
19+
@Lock(LockModeType.PESSIMISTIC_WRITE)
20+
@Query("select g from Group g where g.id = :id")
21+
Optional<Group> findByIdForUpdate(Long groupId);
1022
}

0 commit comments

Comments
 (0)