Skip to content
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 @@ -49,6 +49,7 @@ public void updateLastOpened(UserDocumentId userDocumentId, Long workspaceId, St
}

@Override
@Transactional
public void createInitialRecordsForWorkspaceUsers(List<User> usersInWorkspace, Documentable document) {

// 저장할 엔티티 리스트 생성
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.haru.api.domain.snsEvent.dto.SnsEventRequestDTO;
import com.haru.api.domain.snsEvent.dto.SnsEventResponseDTO;
import com.haru.api.domain.snsEvent.entity.SnsEvent;
import com.haru.api.domain.snsEvent.entity.enums.Format;
import com.haru.api.domain.snsEvent.entity.enums.ListType;
import com.haru.api.domain.snsEvent.service.SnsEventCommandService;
import com.haru.api.domain.snsEvent.service.SnsEventQueryService;
import com.haru.api.domain.user.security.jwt.SecurityUtil;
import com.haru.api.domain.user.entity.User;
import com.haru.api.domain.workspace.entity.Workspace;
import com.haru.api.global.annotation.AuthSnsEvent;
import com.haru.api.global.annotation.AuthUser;
import com.haru.api.global.annotation.AuthWorkspace;
import com.haru.api.global.apiPayload.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -31,10 +34,12 @@ public class SnsEventController {
@PostMapping("/{workspaceId}")
public ApiResponse<SnsEventResponseDTO.CreateSnsEventResponse> instagramOauthRedirectUri(
@PathVariable String workspaceId,
@RequestBody SnsEventRequestDTO.CreateSnsRequest request
@RequestBody SnsEventRequestDTO.CreateSnsRequest request,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthWorkspace Workspace workspace
) {
return ApiResponse.onSuccess(
snsEventCommandService.createSnsEvent(Long.parseLong(workspaceId), request)
snsEventCommandService.createSnsEvent(user, workspace, request)
);
}

Expand All @@ -58,11 +63,12 @@ public ApiResponse<?> instagramRedirectUri(
@PostMapping("/{workspaceId}/link-instagram")
public ApiResponse<SnsEventResponseDTO.LinkInstagramAccountResponse> linkInstagramAccount(
@RequestHeader("code") String code,
@PathVariable String workspaceId
@PathVariable String workspaceId,
@Parameter(hidden = true) @AuthWorkspace Workspace workspace
) {
System.out.println("Received accessToken: " + code);
return ApiResponse.onSuccess(
snsEventCommandService.getInstagramAccessTokenAndAccount(code, Long.parseLong(workspaceId))
snsEventCommandService.getInstagramAccessTokenAndAccount(code, workspace)
);
}

Expand All @@ -73,11 +79,13 @@ public ApiResponse<SnsEventResponseDTO.LinkInstagramAccountResponse> linkInstagr
)
@GetMapping("/{workspaceId}/list")
public ApiResponse<SnsEventResponseDTO.GetSnsEventListRequest> getSnsEventList(
@PathVariable String workspaceId
@PathVariable String workspaceId,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthWorkspace Workspace workspace
) {
Long userId = SecurityUtil.getCurrentUserId();

return ApiResponse.onSuccess(
snsEventQueryService.getSnsEventList(userId, Long.parseLong(workspaceId))
snsEventQueryService.getSnsEventList(user, workspace)
);
}

Expand All @@ -86,28 +94,37 @@ public ApiResponse<SnsEventResponseDTO.GetSnsEventListRequest> getSnsEventList(
description = "# [v1.0 (2025-08-05)](https://www.notion.so/2265da7802c580e8b883e3e4481fd61d?v=2265da7802c5816ab095000cc1ddadca&p=22a5da7802c580d3bed7c57de0b88492&pm=s)" +
" SNS 이벤트명 수정 API입니다. Header에 access token을 넣고 Path Variable에는 snsEvnetId를 Request Body에 SNS 이벤트 수정 정보(title)를 담아 요청해주세요."
)
@PatchMapping("/{snsEvnetId}")
@PatchMapping("/{snsEventId}")
public ApiResponse<?> updateSnsEventTitle(
@PathVariable String snsEvnetId,
@RequestBody SnsEventRequestDTO.UpdateSnsEventRequest request
@PathVariable String snsEventId,
@RequestBody SnsEventRequestDTO.UpdateSnsEventRequest request,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthSnsEvent SnsEvent snsEvent
) {
Long userId = SecurityUtil.getCurrentUserId();
snsEventCommandService.updateSnsEventTitle(userId, Long.parseLong(snsEvnetId), request);

snsEventCommandService.updateSnsEventTitle(user, snsEvent, request);

return ApiResponse.onSuccess("");

}

@Operation(
summary = "SNS 이벤트 삭제 API [v1.0 (2025-08-05)]",
description = "# [v1.0 (2025-08-05)](https://www.notion.so/2265da7802c580e8b883e3e4481fd61d?v=2265da7802c5816ab095000cc1ddadca&p=2265da7802c5809b84d3d8c09f95c36b&pm=s)" +
" SNS 이벤트 삭제 API입니다. Header에 access token을 넣고 Path Variable에는 삭제할 SNS Event의 snsEvnetId를 담아 요청해주세요."
)
@DeleteMapping("/{snsEvnetId}")
@DeleteMapping("/{snsEventId}")
public ApiResponse<?> deleteSnsEvent(
@PathVariable String snsEvnetId
@PathVariable String snsEventId,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthSnsEvent SnsEvent snsEvent

) {
Long userId = SecurityUtil.getCurrentUserId();
snsEventCommandService.deleteSnsEvent(userId, Long.parseLong(snsEvnetId));

snsEventCommandService.deleteSnsEvent(user, snsEvent);

return ApiResponse.onSuccess("");

}

@Operation(
Expand All @@ -117,11 +134,12 @@ public ApiResponse<?> deleteSnsEvent(
)
@GetMapping("/{snsEventId}")
public ApiResponse<SnsEventResponseDTO.GetSnsEventRequest> getSnsEvent(
@PathVariable String snsEventId
@PathVariable String snsEventId,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthSnsEvent SnsEvent snsEvent
) {
Long userId = SecurityUtil.getCurrentUserId();
return ApiResponse.onSuccess(
snsEventQueryService.getSnsEvent(userId, Long.parseLong(snsEventId))
snsEventQueryService.getSnsEvent(user, snsEvent)
);
}

Expand All @@ -134,27 +152,18 @@ public ApiResponse<SnsEventResponseDTO.GetSnsEventRequest> getSnsEvent(
public ApiResponse<SnsEventResponseDTO.ListDownLoadLinkResponse> downloadList(
@PathVariable String snsEventId,
@RequestParam ListType listType,
@RequestParam Format format
@RequestParam Format format,
@Parameter(hidden = true) @AuthUser User user,
@Parameter(hidden = true) @AuthSnsEvent SnsEvent snsEvent
) {
Long userId = SecurityUtil.getCurrentUserId();
return ApiResponse.onSuccess(
snsEventCommandService.downloadList(
userId,
Long.parseLong(snsEventId),
user,
snsEvent,
listType,
format
)
);

// String listTypefileName = listType == ListType.PARTICIPANT ? "참여자" : "당첨자";
// String filename = format == Format.PDF ? listTypefileName + ".pdf" : listTypefileName + ".docx";
// String contentType = format == Format.PDF
// ? MediaType.APPLICATION_PDF_VALUE
// : "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
//
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
// .contentType(MediaType.parseMediaType(contentType))
// .body(fileBytes);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.haru.api.domain.snsEvent.dto;

import com.haru.api.global.common.entity.TitleHolder;
import lombok.*;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -33,7 +34,7 @@ public static class SnsCondition {
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class UpdateSnsEventRequest {
public static class UpdateSnsEventRequest implements TitleHolder {
private String title;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ public class SnsEvent extends BaseEntity implements Documentable {
@Column(nullable = false, length = 100)
private String title;

@Column(length = 255)
private String snsLink;

@Column(length = 200)
private String snsLinkTitle;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User creator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Repository
public interface SnsEventRepository extends JpaRepository<SnsEvent, Long> {
Expand All @@ -22,4 +23,11 @@ public interface SnsEventRepository extends JpaRepository<SnsEvent, Long> {
"WHERE mt.workspace.id = :workspaceId " +
"AND mt.createdAt BETWEEN :startDate AND :endDate")
List<SnsEvent> findAllDocumentForCalendars(Long workspaceId, LocalDateTime startDate, LocalDateTime endDate);

@Query("SELECT se FROM SnsEvent se " +
"WHERE se.id = :snsEventId AND EXISTS (" +
" SELECT 1 FROM UserWorkspace uw " +
" WHERE uw.user.id = :userId AND uw.workspace.id = se.workspace.id" +
")")
Optional<SnsEvent> findSnsEventByIdIfUserHasAccess(Long userId, Long snsEventId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.haru.api.domain.snsEvent.dto.SnsEventRequestDTO;
import com.haru.api.domain.snsEvent.dto.SnsEventResponseDTO;
import com.haru.api.domain.snsEvent.entity.SnsEvent;
import com.haru.api.domain.snsEvent.entity.enums.Format;
import com.haru.api.domain.snsEvent.entity.enums.ListType;
import com.haru.api.domain.user.entity.User;
import com.haru.api.domain.workspace.entity.Workspace;

public interface SnsEventCommandService {
SnsEventResponseDTO.CreateSnsEventResponse createSnsEvent(Long workspaceId, SnsEventRequestDTO.CreateSnsRequest request);
SnsEventResponseDTO.CreateSnsEventResponse createSnsEvent(User user, Workspace workspace, SnsEventRequestDTO.CreateSnsRequest request);

SnsEventResponseDTO.LinkInstagramAccountResponse getInstagramAccessTokenAndAccount(String code, Long workspaceId);
SnsEventResponseDTO.LinkInstagramAccountResponse getInstagramAccessTokenAndAccount(String code, Workspace workspace);

void updateSnsEventTitle(Long userId, Long snsEventId, SnsEventRequestDTO.UpdateSnsEventRequest request);
void updateSnsEventTitle(User user, SnsEvent snsEvent, SnsEventRequestDTO.UpdateSnsEventRequest request);

void deleteSnsEvent(Long userId, Long snsEventId);
void deleteSnsEvent(User user, SnsEvent snsEvent);

SnsEventResponseDTO.ListDownLoadLinkResponse downloadList(Long userId, Long snsEventId, ListType listType, Format format);
SnsEventResponseDTO.ListDownLoadLinkResponse downloadList(User user, SnsEvent snsEvent, ListType listType, Format format);
}
Loading