-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#12] teams / 팀 생성 · 조회 · 수정 · 삭제 로직 구현 #21
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
base: develop
Are you sure you want to change the base?
Changes from all commits
de77605
783222f
52c94e6
dd7f019
2123226
a018f8b
7ed3b4c
5ffa94c
cf36c27
ecb0434
a41abec
44db484
c72d1b8
9a5fa60
d94bc04
c2c7c25
bea7734
3475cff
05ff93b
67a4b98
56ef939
fb28b2b
1381f4f
f78ea49
84336af
607c7c6
29f225f
3f2e473
50b744d
c07b861
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,78 @@ | ||
| package com.beat_it.team.controller | ||
|
|
||
| import com.beat_it.team.dto.TeamCreateRequest | ||
| import com.beat_it.team.dto.TeamCreateResponse | ||
| import com.beat_it.team.dto.TeamDetailResponse | ||
| import com.beat_it.team.dto.TeamDetailUpdateRequest | ||
| import com.beat_it.team.dto.TeamDetailUpdateResponse | ||
| import com.beat_it.team.service.TeamService | ||
| import com.beat_it.global.response.BasicResponse | ||
| import org.springframework.http.HttpStatus | ||
| import org.springframework.http.ResponseEntity | ||
| import org.springframework.web.bind.annotation.* | ||
| import java.util.UUID | ||
| import io.swagger.v3.oas.annotations.Parameter | ||
|
|
||
| @RestController | ||
| @RequestMapping("/teams") | ||
| class TeamController( | ||
| private val teamService: TeamService | ||
| ) { | ||
|
|
||
| @PostMapping | ||
| fun createTeam( | ||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-User-Public-Id") userPublicId: UUID, | ||
|
|
||
| @RequestBody request: TeamCreateRequest | ||
| ): ResponseEntity<BasicResponse<TeamCreateResponse>> { | ||
|
|
||
| val responseData = teamService.createTeam(userPublicId, request) | ||
|
|
||
| return ResponseEntity | ||
| .status(HttpStatus.CREATED) | ||
| .body(BasicResponse.success(responseData, HttpStatus.CREATED, "팀 생성에 성공했습니다.")) | ||
| } | ||
|
|
||
| @PatchMapping | ||
| fun updateTeamDetail( | ||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-User-Public-Id") userPublicId: UUID, | ||
|
|
||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-Team-Public-Id") teamPublicId: UUID, | ||
|
Collaborator
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. team id로 변경해주세요! |
||
|
|
||
| @RequestBody request: TeamDetailUpdateRequest, | ||
| ): ResponseEntity<BasicResponse<TeamDetailUpdateResponse>> { | ||
| val responseData = teamService.updateTeamDetail(teamPublicId, userPublicId, request) | ||
| return ResponseEntity.ok(BasicResponse.success(responseData, HttpStatus.OK, "팀 상세 내용이 수정되었습니다.")) | ||
| } | ||
|
|
||
| @DeleteMapping | ||
| fun deleteTeam( | ||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-User-Public-Id") userPublicId: UUID, | ||
|
|
||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-Team-Public-Id") teamPublicId: UUID, | ||
|
|
||
| ): ResponseEntity<BasicResponse<Nothing>> { | ||
| teamService.deleteTeam(teamPublicId, userPublicId) | ||
| return ResponseEntity.ok( | ||
| BasicResponse.success(HttpStatus.OK,"팀이 성공적으로 삭제되었습니다.") | ||
| ) | ||
| } | ||
|
|
||
| @GetMapping | ||
| fun getTeamDetail( | ||
| @Parameter(hidden = true) | ||
| @RequestHeader("X-Team-Public-Id") teamPublicId: UUID, | ||
|
|
||
| ): ResponseEntity<BasicResponse<TeamDetailResponse>> { | ||
| val responseData = teamService.getTeamDetail(teamPublicId) | ||
| return ResponseEntity.ok( | ||
| BasicResponse.success(responseData, HttpStatus.OK,"팀 상세 내용 조회에 성공했습니다.") | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.beat_it.team.dto | ||
|
|
||
| import com.beat_it.team.entity.enum.TeamType | ||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import io.swagger.v3.oas.annotations.media.Schema | ||
| import java.time.LocalDate | ||
| import java.time.OffsetDateTime | ||
|
|
||
| data class TeamCreateRequest( | ||
| val teamName: String, | ||
| val description: String?, | ||
| val teamType: TeamType, | ||
| val establishedOn: LocalDate?, | ||
| val profileImageUrl: String?, | ||
| ) |
|
Contributor
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. JsonProperty로 invite_code 처럼 스네이크코드로 하면 responseBody를 스네이크코드로 받을텐데?!!
Collaborator
Author
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. 아하 그러면 Response와 Request 모두 수정해둘게요!! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.beat_it.team.dto | ||
|
|
||
| import com.beat_it.team.entity.enum.TeamType | ||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import java.time.OffsetDateTime | ||
|
|
||
| data class TeamCreateResponse( | ||
| val teamId: Long, | ||
| val teamName: String, | ||
| val description: String?, | ||
| val inviteCode: String, | ||
| val teamType: TeamType, | ||
| val teamRole: String, | ||
| val createdAt: OffsetDateTime, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.beat_it.team.dto | ||
|
|
||
| import com.beat_it.team.entity.enum.PlatformCode | ||
| import java.time.LocalDate | ||
| import java.time.OffsetDateTime | ||
|
|
||
| data class TeamDetailResponse( | ||
| val teamId: Long? = null, | ||
| val profileImageUrl: String?, | ||
| val teamName: String, | ||
| val description: String?, | ||
| val establishedOn: LocalDate?, | ||
| val inviteCode: String, | ||
| val memberCount: Int, | ||
| val createdAt: OffsetDateTime, | ||
| val updatedAt: OffsetDateTime, | ||
| val links: List<LinksResponse>, | ||
| val parts: List<PartsResponse>, | ||
| val archiveCount: Int, | ||
| val cloudItemCount: Int, | ||
| ) | ||
|
|
||
| data class LinksResponse( | ||
| val teamLinkId: Long, | ||
| val platformCode: PlatformCode, | ||
| val linkUrl: String, | ||
| ) | ||
|
|
||
| data class PartsResponse( | ||
| val teamPartId: Long, | ||
| val partName: String, | ||
| val displayOrder: Int, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.beat_it.team.dto | ||
|
|
||
| import com.beat_it.team.entity.enum.PlatformCode | ||
| import com.beat_it.team.entity.enum.TeamType | ||
| import java.time.LocalDate | ||
|
|
||
| data class TeamDetailUpdateRequest( | ||
| val teamName: String? = null, | ||
| val description: String? = null, | ||
| val teamType: TeamType? = null, | ||
| val establishedOn: LocalDate? = null, | ||
| val profileImageUrl: String? = null, | ||
| val links: List<TeamLinksRequest>? = null, | ||
| ) | ||
|
|
||
| data class TeamLinksRequest( | ||
| val platformCode: PlatformCode, | ||
| val linkUrl: String, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.beat_it.team.dto | ||
|
|
||
| import java.time.LocalDate | ||
| import java.time.OffsetDateTime | ||
|
|
||
| data class TeamDetailUpdateResponse( | ||
| val teamId: Long, | ||
| val teamName: String, | ||
| val description: String?, | ||
| val establishedOn: LocalDate?, | ||
| val updatedAt: OffsetDateTime, | ||
| val links: List<LinksResponse>? = null, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.beat_it.team.entity | ||
|
|
||
| import com.beat_it.global.entity.BaseUpdatedTimeEntity | ||
| import com.beat_it.team.entity.enum.PlatformCode | ||
| import com.beat_it.team.entity.enum.TeamRole | ||
| import io.swagger.v3.oas.annotations.links.Link | ||
| import jakarta.persistence.* | ||
| import java.time.OffsetDateTime | ||
|
|
||
| @Entity | ||
| @Table(name = "team_links") | ||
| class TeamLinks( | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name="team_link_id", nullable = false) | ||
| val teamLinkId: Long? = null, | ||
|
|
||
| //TODO: 팀 ID 연결하기 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "team_id", nullable = false) | ||
| val team: Teams, | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name="platform_code",nullable = false) | ||
| var platformCode: PlatformCode = PlatformCode.CUSTOM, | ||
|
|
||
| @Column(name="link_url",nullable = false) | ||
| var linkUrl: String = "", | ||
|
|
||
| // @Column(name="update_at",nullable = false) | ||
| // var updateAt: OffsetDateTime = OffsetDateTime.now(), | ||
| // | ||
| // @Column(name="create_at",nullable = false) | ||
| // val createdAt: OffsetDateTime = OffsetDateTime.now(), | ||
|
|
||
| ) : BaseUpdatedTimeEntity() { | ||
| fun updateLink(platformCode: PlatformCode, linkUrl: String) { | ||
| this.platformCode = platformCode | ||
| this.linkUrl = linkUrl | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.beat_it.team.entity | ||
|
|
||
| import com.beat_it.global.entity.BaseUpdatedTimeEntity | ||
| import com.beat_it.team.entity.enum.TeamRole | ||
| import jakarta.persistence.* | ||
| import java.time.OffsetDateTime | ||
|
|
||
| @Entity | ||
| @Table(name = "team_membership") | ||
| class TeamMemberships( | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "team_membership_id") | ||
| val teamMembershipId: Long? = null, | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "team_id", nullable = false) | ||
| val team: Teams, | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| val userId: Long, | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "team_role", nullable = false) | ||
| var teamRole: TeamRole = TeamRole.MEMBER, | ||
|
|
||
| @Column(name = "left_at", nullable = true) | ||
| var leftAt: OffsetDateTime? = null, | ||
| ) : BaseUpdatedTimeEntity() { | ||
|
|
||
| fun updateTeamRole(teamRole: TeamRole) { | ||
| this.teamRole = teamRole | ||
| } | ||
|
|
||
| fun leaveTeam() { | ||
| this.leftAt = OffsetDateTime.now() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.beat_it.team.entity | ||
|
|
||
| import com.beat_it.global.entity.BaseUpdatedTimeEntity | ||
| import com.beat_it.team.entity.enum.TeamRole | ||
| import jakarta.persistence.* | ||
| import java.time.OffsetDateTime | ||
|
|
||
| @Entity | ||
| @Table(name = "team_parts") | ||
| class TeamParts( | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name="team_part_id", nullable = false) | ||
| val teamPartId: Long? = null, | ||
|
|
||
| //TODO: 팀 ID 연결하기 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "team_id", nullable = false) | ||
| val team: Teams, | ||
|
|
||
| @Column(name="part_name", nullable = false) | ||
| var partName: String = "", | ||
|
|
||
| @Column(name="display_order", nullable = false) | ||
| var displayOrder: Int = 0, | ||
|
|
||
| @Column(name="is_active", nullable = false) | ||
| var isActive: Boolean = true, | ||
|
|
||
| // @Column(name="update_at", nullable = false) | ||
| // var updateAt: OffsetDateTime = OffsetDateTime.now(), | ||
| // | ||
| // @Column(name="create_at", nullable = false) | ||
| // val createdAt: OffsetDateTime = OffsetDateTime.now(), | ||
|
|
||
| ) : BaseUpdatedTimeEntity() { | ||
| // TODO: 파트를 추가하는 함수를 넣어야 함. | ||
| fun updateTeamPart( | ||
| partName: String, | ||
| displayOrder: Int, | ||
| ) { | ||
| this.partName = partName | ||
| this.displayOrder = displayOrder | ||
| } | ||
|
|
||
| fun deactivateTeamPart() { | ||
| this.isActive = false | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.beat_it.team.entity | ||
|
|
||
| import jakarta.persistence.* | ||
| import java.time.OffsetDateTime | ||
|
|
||
| @Entity | ||
| @Table(name = "team_settings") | ||
| class TeamSettings( | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name="team_settings_id") | ||
| val teamSettingId: Long? = null, | ||
|
|
||
| //TODO: 팀 ID 연결하기 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "team_id", nullable = false) | ||
| val team: Teams, | ||
|
|
||
| @Column(name="max_storage", nullable = false) | ||
| var maxStorage: Int = 10, | ||
|
|
||
| @Column(name="used_storage", nullable = false) | ||
| var usedStorage: Int = 0, | ||
|
|
||
| @Column(name="update_at", nullable = false) | ||
| var updateAt: OffsetDateTime = OffsetDateTime.now(), | ||
| ) |
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.
user id로 변경해주세요!
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.
@AuthenticationPrincipal 어노테이션으로 JWT토큰 이용한 userId 가져오기 로직으로 해주세요!