Skip to content
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

[FEAT] 워크스페이스 설정 로직 #193

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.memberteammanager.controller.dto.request.UpdateTeamMemberNameRequest;
import com.tiki.server.memberteammanager.service.MemberTeamManagerService;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamInformGetResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -25,12 +25,12 @@ public class MemberTeamController {
private final MemberTeamManagerService memberTeamManagerService;

@GetMapping("/teams/{teamId}/members/position")
public ResponseEntity<SuccessResponse<MemberTeamPositionGetResponse>> getMemberTeamPosition(
public ResponseEntity<SuccessResponse<MemberTeamInformGetResponse>> getMemberTeamInform(
final Principal principal,
@PathVariable final long teamId
) {
long memberId = Long.parseLong(principal.getName());
MemberTeamPositionGetResponse response = memberTeamManagerService.getPosition(memberId, teamId);
MemberTeamInformGetResponse response = memberTeamManagerService.getMemberTeamInform(memberId, teamId);
return ResponseEntity.ok().body(success(GET_POSITION.getMessage(), response));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성공메세지랑 api 메소드명이랑 매치가 안되는 거 같아요!

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.tiki.server.note.adapter.NoteFinder;
import com.tiki.server.note.entity.Note;
import com.tiki.server.team.exception.TeamException;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamPositionGetResponse;
import com.tiki.server.memberteammanager.service.dto.response.MemberTeamInformGetResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -44,9 +44,9 @@ public void leaveTeam(final long memberId, final long teamId) {
memberTeamManagerDeleter.delete(memberTeamManager);
}

public MemberTeamPositionGetResponse getPosition(final long memberId, final long teamId) {
public MemberTeamInformGetResponse getMemberTeamInform(final long memberId, final long teamId) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
return MemberTeamPositionGetResponse.from(memberTeamManager.getPosition());
return MemberTeamInformGetResponse.from(memberTeamManager.getPosition(), memberTeamManager.getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터가 두 개이므로, of로 하면 좋을 거 같아요.
또한 MemberTeamManager 자체를 파라미터로 넘겨도 좋을 거 같아요.

}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tiki.server.memberteammanager.service.dto.response;

import com.tiki.server.common.entity.Position;

public record MemberTeamInformGetResponse(
Position position,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonnull, Notnull 같은 널 방지 들어가면 좋을 거 같아요.

String name
) {
public static MemberTeamInformGetResponse from(final Position position, final String name) {
return new MemberTeamInformGetResponse(position, name);
}
}

This file was deleted.

28 changes: 13 additions & 15 deletions src/main/java/com/tiki/server/team/controller/TeamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import java.security.Principal;

import com.tiki.server.common.dto.BaseResponse;
import com.tiki.server.team.controller.dto.request.UpdateTeamIconRequest;
import com.tiki.server.team.controller.dto.request.UpdateTeamNameRequest;
import com.tiki.server.team.controller.dto.request.UpdateTeamMemberAndTeamInformRequest;
import com.tiki.server.team.dto.request.UpdateTeamMemberAndTeamInformServiceRequest;
import com.tiki.server.team.dto.response.CategoriesGetResponse;
import com.tiki.server.team.dto.response.TeamsGetResponse;

import com.tiki.server.team.service.dto.response.TeamInformGetResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -68,26 +69,23 @@ public ResponseEntity<BaseResponse> deleteTeam(
return ResponseEntity.noContent().build();
}

@PatchMapping("/{teamId}/name")
public ResponseEntity<BaseResponse> updateTeamName(
final Principal principal,
@PathVariable final long teamId,
@RequestBody final UpdateTeamNameRequest request
@GetMapping("/{teamId}/inform")
public ResponseEntity<SuccessResponse<TeamInformGetResponse>> getTeamName(
@PathVariable final long teamId
) {
long memberId = Long.parseLong(principal.getName());
teamService.updateTeamName(memberId, teamId, request.newTeamName());
return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_NAME.getMessage()));
TeamInformGetResponse response = teamService.getTeamInform(teamId);
return ResponseEntity.ok().body(success(SUCCESS_GET_CATEGORIES.getMessage(), response));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

팀 이름을 가져오는 api와 맞는 성공메세지명을 사용하면 좋을 거 같아요.

}

@PatchMapping("/{teamId}/icon")
public ResponseEntity<BaseResponse> updateIconImage(
@PatchMapping("/{teamId}/inform")
public ResponseEntity<BaseResponse> updateTeamAndTeamMemberInform(
final Principal principal,
@PathVariable final long teamId,
@RequestBody final UpdateTeamIconRequest request
@RequestBody final UpdateTeamMemberAndTeamInformRequest request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

행위가 뒤에 오는 dto명이면 더 좋을 거 같아요.
ex. TeamMemberAndTeamInformUpdateRequest

) {
long memberId = Long.parseLong(principal.getName());
teamService.updateIconImage(memberId, teamId, request.iconImageUrl());
return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_ICON.getMessage()));
teamService.updateTeamAndTeamMemberInform(memberId, teamId, UpdateTeamMemberAndTeamInformServiceRequest.from(request));
return ResponseEntity.ok(success(SUCCESS_UPDATE_TEAM_NAME.getMessage()));
}

@PatchMapping("/{teamId}/member/{targetId}/admin")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tiki.server.team.controller.dto.request;

import jakarta.validation.constraints.NotNull;

public record UpdateTeamMemberAndTeamInformRequest(
@NotNull String teamMemberName,
@NotNull String teamName,
@NotNull String teamUrl
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tiki.server.team.dto.request;

import com.tiki.server.team.controller.dto.request.UpdateTeamMemberAndTeamInformRequest;
import jakarta.validation.constraints.NotNull;

public record UpdateTeamMemberAndTeamInformServiceRequest(
@NotNull String teamMemberName,
@NotNull String teamName,
@NotNull String teamIconUrl
) {
public static UpdateTeamMemberAndTeamInformServiceRequest from(UpdateTeamMemberAndTeamInformRequest request) {
return new UpdateTeamMemberAndTeamInformServiceRequest(
request.teamMemberName(),
request.teamName(),
request.teamUrl()
);
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/tiki/server/team/entity/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -60,15 +62,20 @@ public static Team of(TeamCreateRequest request, University univ) {
.build();
}

public void updateName(final String name) {
public void updateInform(final String name, final String iconImageUrl) {
updateTeamName(name);
updateIconImageUrl(iconImageUrl);
}

private void updateTeamName(final String name) {
if (!canChangeName()) {
throw new TeamException(TOO_SHORT_PERIOD);
}
this.name = name;
this.namingUpdatedAt = LocalDate.now();
}

public void setIconImageUrl(final String url) {
private void updateIconImageUrl(final String url) {
this.iconImageUrl = url;
}

Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/tiki/server/team/service/TeamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder;
import com.tiki.server.team.adapter.TeamDeleter;
import com.tiki.server.team.adapter.TeamFinder;
import com.tiki.server.team.dto.request.UpdateTeamMemberAndTeamInformServiceRequest;
import com.tiki.server.team.dto.response.CategoriesGetResponse;
import com.tiki.server.team.dto.response.TeamsGetResponse;

import com.tiki.server.team.service.dto.response.TeamInformGetResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -29,7 +31,6 @@
import com.tiki.server.team.dto.response.TeamCreateResponse;
import com.tiki.server.team.entity.Category;
import com.tiki.server.team.entity.Team;
import com.tiki.server.team.exception.TeamException;
import com.tiki.server.team.vo.TeamVO;
import com.tiki.server.timeblock.adapter.TimeBlockDeleter;

Expand Down Expand Up @@ -83,23 +84,26 @@ public void deleteTeam(final long memberId, final long teamId) {
teamDeleter.deleteById(teamId);
}

private Team createTeam(final TeamCreateRequest request, final University univ) {
return Team.of(request, univ);
public TeamInformGetResponse getTeamInform(final long teamId) {
Team team = teamFinder.findById(teamId);
return TeamInformGetResponse.from(team.getName(), team.getUniv(), team.getIconImageUrl());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터가 적으면 적을 수록 좋은 코드라는 리뷰를 다른 프로젝트에서 받아서 Team 자체를 파라미터로 넘겨도 좋을 거 같아요! 물론 지금도 좋습니다.

}

@Transactional
public void updateTeamName(final long memberId, final long teamId, final String newTeamName) {
checkIsAdmin(memberId, teamId);
Team team = teamFinder.findById(teamId);
team.updateName(newTeamName);
private Team createTeam(final TeamCreateRequest request, final University univ) {
return Team.of(request, univ);
}

@Transactional
public void updateIconImage(final long memberId, final long teamId, final String iconImageUrl) {
checkIsAdmin(memberId, teamId);
public void updateTeamAndTeamMemberInform(
final long memberId,
final long teamId,
final UpdateTeamMemberAndTeamInformServiceRequest request
) {
MemberTeamManager memberTeamManager = checkIsAdmin(memberId, teamId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkIsAdmin을 통해 ADMIN도 검사하고 멤버팀매니저도 받아오는데 개인적으로 메소드가 두 일을 한다고 생각합니다!
두 로직을 분리해도 좋을 거 같아요!

memberTeamManager.updateName(request.teamMemberName());
Team team = teamFinder.findById(teamId);
deleteIconUrl(team);
team.setIconImageUrl(iconImageUrl);
team.updateInform(request.teamName(), request.teamIconUrl());
updateIconUrlS3(team, request.teamIconUrl());
}

@Transactional
Expand All @@ -114,8 +118,8 @@ private MemberTeamManager createMemberTeamManager(final Member member, final Tea
return MemberTeamManager.of(member, team, position);
}

private void deleteIconUrl(final Team team) {
if (!team.isDefaultImage()) {
private void updateIconUrlS3(final Team team, final String iconUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s3라는 이름이 안 들어가도 괜찮을거 같아요. 만약 추후에 s3를 이용하지 않게된다면 메소드 네이밍을 바꿔야 한다고 생각하기 때문입니다! 만약 들어가는게 좋은거 같다면 updateIconS3Url이 더 나을 거 같아요.

if (!team.isDefaultImage() && !team.getImageUrl().equals(iconUrl)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iconUrl 동등성 검사 로직을 team으로 위임해도 좋을 거 같아요.

s3Handler.deleteFile(team.getIconImageUrl());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tiki.server.team.service.dto.response;

import com.tiki.server.common.entity.University;

public record TeamInformGetResponse(
String teamName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

널 방지 로직 들어가면 좋을 거 같아요.

University university,
String teamIconUrl
) {

public static TeamInformGetResponse from(final String teamName, final University university, final String teamIconUrl) {
return new TeamInformGetResponse(teamName, university, teamIconUrl);
}
}
Loading