Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/gooiman/Gooiman_server i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
koosco committed Sep 28, 2024
2 parents 17db2b6 + 4f87699 commit 7faebb9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package dev.gooiman.server.auth.application;

import dev.gooiman.server.common.exception.CommonException;
import dev.gooiman.server.common.exception.ErrorCode;
import dev.gooiman.server.auth.repository.UserRepository;
import dev.gooiman.server.auth.repository.entity.User;
import dev.gooiman.server.common.exception.CommonException;
import dev.gooiman.server.common.exception.ErrorCode;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -15,8 +16,8 @@ public class UserService {

private final UserRepository userRepository;

public User getUserByName(String name) {
return userRepository.findByName(name)
public User getUserByNameAndPageId(String name, UUID pageId) {
return userRepository.findByNameAndPage_PageId(name, pageId)
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public MemoDto[] listMemo(UUID pageId, String category) {
@Transactional
public CommonSuccessDto updateMemo(UUID memoId, @RequestBody UpdateMemoRequestDto dto) {
Memo memo = findMemo(memoId);
User user = userService.getUserByName(dto.author());
pageService.updatePageUpdateTime(memo.getPage());
if (!user.getUserId().equals(memo.getUserID())) {
User user = userService.getUserByNameAndPageId(dto.author(), memo.getPageId());
if (!user.getUserId().equals(memo.getUserId())) {
throw new CommonException(ErrorCode.NOT_MATCH_USER);
}
pageService.updatePageUpdateTime(memo.getPage());

memo.updateInfo(dto.title(), dto.content(), dto.category(), dto.subCategory(), dto.color(),
user);
Expand All @@ -74,7 +74,7 @@ public CommonSuccessDto deleteMemo(UUID memoId) {

@Transactional
public CommonIdResponseDto createMemo(CreateMemoRequestDto dto) {
User user = userService.getUserByName(dto.author());
User user = userService.getUserByNameAndPageId(dto.author(), dto.pageId());
Page page = pageService.getPageById(dto.pageId());
pageService.updatePageUpdateTime(page);
Memo memo = new Memo(dto.category(), dto.subCategory(), dto.title(), dto.color(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface MemoRepository extends JpaRepository<Memo, UUID> {

List<Memo> findMemosByPage_PageId(UUID pageId);

@Query("select m.title, m.category, m.subCategory from Memo m where m.page.pageId = :pageId")
@Query("select m.title as title, m.category as category, m.subCategory as subCategory from Memo m where m.page.pageId = :pageId")
List<MemoSummariesView> getMemoSummaries(@Param("pageId") UUID pageId);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.gooiman.server.memo.repository.entity;

import dev.gooiman.server.page.repository.entity.Page;
import dev.gooiman.server.auth.repository.entity.User;
import dev.gooiman.server.page.repository.entity.Page;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -51,7 +51,10 @@ public class Memo {
private User user;

@Column(name = "USER_ID", insertable = false, updatable = false)
private UUID userID;
private UUID userId;

@Column(name = "PAGE_ID", insertable = false, updatable = false)
private UUID pageId;

public String getUsername() {
return user.getName();
Expand Down

0 comments on commit 7faebb9

Please sign in to comment.