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

fix: 프로필 업데이트 시, Id를 토큰으로 대체 #352

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.web.bind.annotation.RestController;

import com.sponus.coredomain.domain.common.ApiResponse;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.organization.club.dto.ClubGetResponse;
import com.sponus.sponusbe.domain.organization.club.dto.ClubUpdateRequest;
import com.sponus.sponusbe.domain.organization.club.service.ClubService;
Expand All @@ -28,11 +30,11 @@ public ApiResponse<ClubGetResponse> getClub(@PathVariable Long clubId) {
return ApiResponse.onSuccess(clubService.getClub(clubId));
}

@PatchMapping("/{clubId}")
@PatchMapping("/me")
public ApiResponse<Void> updateClub(
@PathVariable Long clubId,
@AuthOrganization Organization authOrganization,
@Valid @RequestBody ClubUpdateRequest request) {
clubService.updateClub(clubId, request);
clubService.updateClub(authOrganization.getId(), request);
return ApiResponse.onSuccess(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.web.bind.annotation.RestController;

import com.sponus.coredomain.domain.common.ApiResponse;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.organization.company.dto.CompanyGetResponse;
import com.sponus.sponusbe.domain.organization.company.dto.CompanyUpdateRequest;
import com.sponus.sponusbe.domain.organization.company.service.CompanyService;
Expand All @@ -28,11 +30,12 @@ public ApiResponse<CompanyGetResponse> getCompany(@PathVariable Long companyId)
return ApiResponse.onSuccess(companyService.getCompany(companyId));
}

@PatchMapping("/{companyId}")
@PatchMapping("/me")
public ApiResponse<Void> updateCompany(
@PathVariable Long companyId,
@Valid @RequestBody CompanyUpdateRequest request) {
companyService.updateCompany(companyId, request);
@AuthOrganization Organization authOrganization,
@Valid @RequestBody CompanyUpdateRequest request
) {
companyService.updateCompany(authOrganization.getId(), request);
return ApiResponse.onSuccess(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.enums.OrganizationType;
import com.sponus.coreinfrasecurity.annotation.AuthOrganization;
import com.sponus.sponusbe.domain.organization.club.service.ClubService;
import com.sponus.sponusbe.domain.organization.company.dto.OrganizationGetResponse;
import com.sponus.sponusbe.domain.organization.company.service.CompanyService;
import com.sponus.sponusbe.domain.organization.dto.request.OrganizationCreateRequest;
import com.sponus.sponusbe.domain.organization.dto.request.OrganizationSearchRequest;
import com.sponus.sponusbe.domain.organization.dto.request.PageCondition;
Expand All @@ -37,6 +39,8 @@
@RequiredArgsConstructor
public class OrganizationController {
private final OrganizationService organizationService;
private final ClubService clubService;
private final CompanyService companyService;

@PostMapping("/join")
public ApiResponse<Long> join(@RequestBody OrganizationCreateRequest request) {
Expand All @@ -52,11 +56,21 @@ public ApiResponse<PageResponse<OrganizationGetResponse>> getOrganizations(
organizationService.getOrganizations(authOrganization, pageCondition, organizationType));
}

@PostMapping(value = "/{organizationId}/profileImage", consumes = "multipart/form-data")
@GetMapping("/me")
public ApiResponse<?> getMyProfile(
@AuthOrganization Organization authOrganization) {
if (authOrganization.isClub()) {
return ApiResponse.onSuccess(clubService.getClub(authOrganization.getId()));
} else {
return ApiResponse.onSuccess(companyService.getCompany(authOrganization.getId()));
}
}

@PostMapping(value = "/me/profileImage", consumes = "multipart/form-data")
public ApiResponse<OrganizationImageUploadResponse> uploadProfileImage(
@PathVariable Long organizationId,
@AuthOrganization Organization organization,
@RequestPart(name = "profileImage") MultipartFile file) {
return ApiResponse.onSuccess(organizationService.uploadProfileImage(organizationId, file));
return ApiResponse.onSuccess(organizationService.uploadProfileImage(organization.getId(), file));
}

@GetMapping("/exists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ public void deleteOrganization(Long organizationId) {
organization.delete();
}

private Organization findOrganizationById(Long organizationId) {
return organizationRepository.findById(organizationId)
.orElseThrow(() -> new OrganizationException(OrganizationErrorCode.ORGANIZATION_NOT_FOUND));
}

public PageResponse<OrganizationGetResponse> getOrganizations(
Organization authOrganization,
PageCondition pageCondition,
Expand Down Expand Up @@ -163,4 +158,9 @@ public void deleteAllSearchKeyword(Long organizationId) {
searchHistory.getKeywords().clear();
searchHistoryRepository.save(searchHistory);
}

private Organization findOrganizationById(Long organizationId) {
return organizationRepository.findById(organizationId)
.orElseThrow(() -> new OrganizationException(OrganizationErrorCode.ORGANIZATION_NOT_FOUND));
}
}
6 changes: 3 additions & 3 deletions core/core-infra-db/src/main/resources/application-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ spring:
jpa:
database: mysql
hibernate:
ddl-auto: create-drop
ddl-auto: create
open-in-view: false
show-sql: true
# generate-ddl: true
# defer-datasource-initialization: true
# generate-ddl: false
# defer-datasource-initialization: false
#
# sql:
# init:
Expand Down
Loading