-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created club page and implemented api endpoints
- Loading branch information
Showing
16 changed files
with
651 additions
and
10 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
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
134 changes: 134 additions & 0 deletions
134
src/main/java/com/runningmate/backend/club/controller/ClubController.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,134 @@ | ||
package com.runningmate.backend.club.controller; | ||
|
||
import com.runningmate.backend.club.dto.*; | ||
import com.runningmate.backend.club.service.ClubService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/club") | ||
@RequiredArgsConstructor | ||
public class ClubController { | ||
/*TODO: join club(check already in), leave club(owner can't leave), delete club, change owner, | ||
remove member, update title/description, get club info, create new schedule, update schedule | ||
*/ | ||
private final ClubService clubService; | ||
|
||
@PostMapping | ||
@ResponseStatus(value = HttpStatus.CREATED) | ||
public ClubResponseDto createNewClub(@RequestBody ClubRequestDto clubRequestDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
ClubResponseDto clubResponseDto = clubService.createClub(clubRequestDto, userDetails.getUsername()); | ||
return clubResponseDto; | ||
} | ||
|
||
@GetMapping("/{clubId}") | ||
@ResponseStatus(value = HttpStatus.OK) | ||
public ClubResponseDto getClub(@PathVariable(name = "clubId") UUID clubId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.getClub(clubId); | ||
} | ||
|
||
@GetMapping("/{clubId}/schedules") | ||
@ResponseStatus(value = HttpStatus.OK) | ||
public ListClubScheduleEntityResponseDto getClubSchedules(@PathVariable(name = "clubId") UUID clubId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.getClubSchedules(clubId, userDetails.getUsername()); | ||
} | ||
|
||
@PostMapping("/{clubId}/schedules") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ClubScheduleEntityResponseDto createClubSchedule(@PathVariable(name = "clubId") UUID clubId, | ||
@Valid @RequestBody CreateOrUpdateClubScheduleRequestDto requestDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.createClubSchedule(requestDto, clubId, userDetails.getUsername()); | ||
} | ||
|
||
@PutMapping("/{clubId}/schedules/{scheduleId}") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ClubScheduleEntityResponseDto updateClubSchedule(@PathVariable(name = "clubId") UUID clubId, | ||
@Valid @RequestBody CreateOrUpdateClubScheduleRequestDto requestDto, | ||
@PathVariable(name = "scheduleId") Long scheduleId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.updateClubSchedule(requestDto, clubId, scheduleId, userDetails.getUsername()); | ||
} | ||
|
||
@DeleteMapping("/{clubId}/schedules/{scheduleId}") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public void removeClubSchedule(@PathVariable(name = "clubId") UUID clubId, | ||
@PathVariable(name = "scheduleId") Long scheduleId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
clubService.removeClubSchedule(clubId, scheduleId, userDetails.getUsername()); | ||
} | ||
|
||
@DeleteMapping("/{clubId}/delete") | ||
@ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
public void removeClub(@PathVariable(name = "clubId") UUID clubId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
clubService.removeClub(clubId, userDetails.getUsername()); | ||
} | ||
|
||
@PutMapping("/{clubId}/members/{memberId}/role") | ||
@ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
public void changeMemberRole(@PathVariable(name = "clubId") UUID clubId, | ||
@PathVariable(name = "memberId") Long memberId, | ||
@Valid @RequestBody ChangeRoleRequestDto changeRoleDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
clubService.changeMemberRole(changeRoleDto, clubId, memberId, userDetails.getUsername()); | ||
} | ||
|
||
@DeleteMapping("/{clubId}/members/{membersId}") | ||
@ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
public void removeMemberFromClub(@PathVariable(name = "clubId") UUID clubId, | ||
@PathVariable(name = "memberId") Long memberId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
clubService.removeMemberFromClub(clubId, memberId, userDetails.getUsername()); | ||
} | ||
|
||
@PostMapping("/{clubId}/join") | ||
@ResponseStatus(value = HttpStatus.CREATED) | ||
public ClubResponseDto joinClub(@PathVariable(name = "clubId") UUID clubId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
ClubResponseDto clubResponseDto = clubService.addUserToClub(clubId, userDetails.getUsername()); | ||
return clubResponseDto; | ||
} | ||
|
||
@DeleteMapping("/{clubId}/leave") | ||
@ResponseStatus(value = HttpStatus.OK) | ||
public ClubResponseDto leaveClub(@PathVariable(name = "clubId") UUID clubId, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
ClubResponseDto clubResponseDto = clubService.removeSelfFromClub(clubId, userDetails.getUsername()); | ||
return clubResponseDto; | ||
} | ||
|
||
@PutMapping("/{clubId}/title-description") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ClubResponseDto updateTitleAndDescription(@PathVariable(name = "clubId") UUID clubId, | ||
@Valid @RequestBody UpdateTitleDescriptionRequestDto updateDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.updateTitleAndDescription(clubId, updateDto, userDetails.getUsername()); | ||
} | ||
|
||
|
||
@PutMapping("/{clubId}/profile-pic") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ClubResponseDto updateProfilePic(@PathVariable(name = "clubId") UUID clubId, | ||
@Valid @RequestBody UploadImageRequestDto newImageDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.updateProfilePic(clubId, newImageDto.getNewImageUrl(), userDetails.getUsername()); | ||
} | ||
|
||
@PutMapping("/{clubId}/background-pic") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ClubResponseDto updateBackgroundPic(@PathVariable(name = "clubId") UUID clubId, | ||
@Valid @RequestBody UploadImageRequestDto newImageDto, | ||
@AuthenticationPrincipal UserDetails userDetails) { | ||
return clubService.updateBackgroundPic(clubId, newImageDto.getNewImageUrl(), userDetails.getUsername()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/runningmate/backend/club/dto/ChangeRoleRequestDto.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.runningmate.backend.club.dto; | ||
|
||
import com.runningmate.backend.club.ClubRole; | ||
import com.runningmate.backend.validation.ValidEnum; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ChangeRoleRequestDto { | ||
@NotNull(message = "New role must not be null") | ||
@ValidEnum(enumClass = ClubRole.class, message = "Invalid role. Allowed roles are MEMBER, OWNER, MODERATOR.") | ||
private ClubRole clubRole; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/runningmate/backend/club/dto/ClubRequestDto.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,36 @@ | ||
package com.runningmate.backend.club.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.runningmate.backend.club.Club; | ||
import com.runningmate.backend.route.dto.CoordinateDto; | ||
import com.runningmate.backend.utils.PointCreator; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.*; | ||
import org.locationtech.jts.geom.Point; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ClubRequestDto { | ||
@NotEmpty(message = "Title must not be empty or null") | ||
@Size(max = 100, message = "Title must not exceed 100 characters") | ||
private String title; | ||
|
||
@NotEmpty(message = "Detail must not be empty or null") | ||
@Size(max = 500, message = "Detail must not exceed 500 characters") | ||
private String description; | ||
|
||
@NotNull(message = "Location must not be null") | ||
private CoordinateDto location; | ||
|
||
public Club toEntity() { | ||
return Club.builder() | ||
.title(this.title) | ||
.description(this.description) | ||
.location(PointCreator.createPoint(this.location.getLongitude(), this.location.getLatitude())) | ||
.build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/runningmate/backend/club/dto/ClubResponseDto.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,48 @@ | ||
package com.runningmate.backend.club.dto; | ||
|
||
import com.runningmate.backend.club.Club; | ||
import com.runningmate.backend.club.ClubMemberEntity; | ||
import com.runningmate.backend.member.dto.MemberDto; | ||
import com.runningmate.backend.route.dto.CoordinateDto; | ||
import com.runningmate.backend.schedule.Schedule; | ||
import com.runningmate.backend.utils.PointCreator; | ||
import lombok.*; | ||
import org.locationtech.jts.geom.Point; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ClubResponseDto { | ||
private UUID id; | ||
private String title; | ||
private String description; | ||
private CoordinateDto location; | ||
private String profilePic; | ||
private String backgroundPic; | ||
private List<MemberDto> clubMembers; | ||
private List<ClubScheduleEntityResponseDto> schedules; | ||
|
||
public static ClubResponseDto fromEntity(Club club) { | ||
return ClubResponseDto.builder() | ||
.id(club.getId()) | ||
.title(club.getTitle()) | ||
.description(club.getDescription()) | ||
.location(PointCreator.toCoordinateDto(club.getLocation())) | ||
.profilePic(club.getProfile_pic()) | ||
.backgroundPic(club.getBackground_pic()) | ||
.clubMembers(club.getMembers().stream() | ||
.map(ClubMemberEntity::getMember) | ||
.map(MemberDto::fromEntity) | ||
.collect(Collectors.toList())) | ||
.schedules(club.getSchedules().stream() | ||
.map(clubScheduleEntity -> ClubScheduleEntityResponseDto.fromEntity(clubScheduleEntity)) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/runningmate/backend/club/dto/ClubScheduleEntityResponseDto.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,25 @@ | ||
package com.runningmate.backend.club.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.runningmate.backend.club.ClubScheduleEntity; | ||
import com.runningmate.backend.schedule.dto.ScheduleResponseDto; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ClubScheduleEntityResponseDto { | ||
private Long id; | ||
@JsonUnwrapped | ||
private ScheduleResponseDto schedule; | ||
|
||
public static ClubScheduleEntityResponseDto fromEntity(ClubScheduleEntity clubScheduleEntity) { | ||
return ClubScheduleEntityResponseDto.builder() | ||
.id(clubScheduleEntity.getId()) | ||
.schedule(ScheduleResponseDto.fromEntity(clubScheduleEntity.getSchedule())) | ||
.build(); | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/runningmate/backend/club/dto/CreateOrUpdateClubScheduleRequestDto.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.runningmate.backend.club.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.runningmate.backend.schedule.dto.CreateOrUpdateScheduleRequestDto; | ||
import lombok.*; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class CreateOrUpdateClubScheduleRequestDto{ | ||
@JsonUnwrapped | ||
private CreateOrUpdateScheduleRequestDto createOrUpdateScheduleRequestDto; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/runningmate/backend/club/dto/ListClubScheduleEntityResponseDto.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,14 @@ | ||
package com.runningmate.backend.club.dto; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ListClubScheduleEntityResponseDto { | ||
private List<ClubScheduleEntityResponseDto> clubScheduleEntityResponseDtos; | ||
} |
Oops, something went wrong.