-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from gooiman/feat/메모수정
Feat 메모수정
- Loading branch information
Showing
10 changed files
with
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,70 @@ | ||
CREATE DATABASE gooiman; | ||
CREATE DATABASE gooiman; | ||
|
||
drop table if exists memo; | ||
drop table if exists users; | ||
drop table if exists page; | ||
|
||
CREATE TABLE page | ||
( | ||
page_id BINARY(16) NOT NULL PRIMARY KEY, | ||
page_name VARCHAR(255) NOT NULL | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4; | ||
|
||
|
||
CREATE TABLE users | ||
( | ||
user_id BINARY(16) NOT NULL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
password VARCHAR(255) NOT NULL, | ||
page_id BINARY(16), | ||
CONSTRAINT fk_users_page FOREIGN KEY (page_id) REFERENCES page (page_id) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4; | ||
|
||
|
||
CREATE TABLE memo | ||
( | ||
memo_id BINARY(16) NOT NULL PRIMARY KEY, | ||
category VARCHAR(255), | ||
sub_category VARCHAR(255), | ||
title VARCHAR(255) NOT NULL, | ||
content TEXT, | ||
page_id BINARY(16), | ||
user_id BINARY(16), | ||
CONSTRAINT fk_memo_page FOREIGN KEY (page_id) REFERENCES page (page_id), | ||
CONSTRAINT fk_memo_user FOREIGN KEY (user_id) REFERENCES users (user_id) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4; | ||
|
||
-- page 더미 | ||
INSERT INTO page (page_id, page_name) | ||
VALUES (UUID_TO_BIN('dbdfa00c-4292-48c2-92b4-97c643e6dd5a'), 'page1'); | ||
-- (UUID_TO_BIN('dbee3cdf-20e1-4ddb-a510-3cf5909f875c'), 'page2'), | ||
-- (UUID_TO_BIN('1cf08322-da12-4838-a1ea-3e45ffc701a6'), 'page3'); | ||
|
||
-- user1 더미 추가 | ||
INSERT INTO users (user_id, name, password, page_id) | ||
VALUES (UUID_TO_BIN('382afa8a-79d2-4fe8-9f61-2c4db816ee3a'), 'user1', '1234', | ||
UUID_TO_BIN('dbdfa00c-4292-48c2-92b4-97c643e6dd5a')); | ||
-- (UUID_TO_BIN('082e940e-cd05-49b1-b5e5-e62eeb3a478b'), 'Bob', 'password456', NULL), | ||
-- (UUID_TO_BIN('41f69597-45d2-4732-8c4b-68775cbf7468'), 'Charlie', 'password789', NULL); | ||
|
||
-- user1의 memo 추가 | ||
INSERT INTO memo (memo_id, category, sub_category, title, content, page_id, user_id) | ||
VALUES (UUID_TO_BIN('24a4aea3-eb63-475c-b9e3-212d58986980'), 'category1', 'sub_category1', 'title1', | ||
'content1.', UUID_TO_BIN('dbdfa00c-4292-48c2-92b4-97c643e6dd5a'), | ||
UUID_TO_BIN('382afa8a-79d2-4fe8-9f61-2c4db816ee3a')), | ||
(UUID_TO_BIN('4bb960d6-4dc1-4b31-a3c7-333c5bd589d2'), 'category1', 'sub_category2', 'title2', | ||
'content2', UUID_TO_BIN('dbdfa00c-4292-48c2-92b4-97c643e6dd5a'), | ||
UUID_TO_BIN('382afa8a-79d2-4fe8-9f61-2c4db816ee3a')), | ||
(UUID_TO_BIN('cfda99e4-2d9f-4188-9498-4dea0bdb9011'), 'category1', 'sub_category3', 'title3', | ||
'3', UUID_TO_BIN('dbdfa00c-4292-48c2-92b4-97c643e6dd5a'), | ||
UUID_TO_BIN('382afa8a-79d2-4fe8-9f61-2c4db816ee3a')); | ||
|
||
select * | ||
from page; | ||
select * | ||
from users; | ||
select * | ||
from memo; |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/dev/gooiman/server/memo/application/dto/UpdateMemoRequestDto.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,9 @@ | ||
package dev.gooiman.server.memo.application.dto; | ||
|
||
public record UpdateMemoRequestDto(String title, | ||
String content, | ||
String author, | ||
String category, | ||
String subCategory) { | ||
|
||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/gooiman/server/user/application/UserService.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,22 @@ | ||
package dev.gooiman.server.user.application; | ||
|
||
import dev.gooiman.server.common.exception.CommonException; | ||
import dev.gooiman.server.common.exception.ErrorCode; | ||
import dev.gooiman.server.user.repository.UserRepository; | ||
import dev.gooiman.server.user.repository.entity.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public User getUserByName(String name) { | ||
return userRepository.findByName(name) | ||
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_USER)); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/dev/gooiman/server/user/repository/UserRepository.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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package dev.gooiman.server.user.repository; | ||
|
||
import dev.gooiman.server.user.repository.entity.User; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface UserRepository extends JpaRepository<User, UUID> { | ||
|
||
@Query("select u from User u" | ||
+ " where u.name=:name") | ||
Optional<User> findByName(@Param("name") String name); | ||
// Optional<User> findByPageAndName(String pageId, String name); | ||
} |
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