Skip to content

Commit

Permalink
Merge pull request #33 from SQUAD-D/feature#18/image-update
Browse files Browse the repository at this point in the history
test
  • Loading branch information
songhaechan authored Jun 18, 2024
2 parents 133b112 + e33a3dc commit c34dcc3
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 98 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-quartz:2.7.5'
implementation 'org.apache.commons:commons-collections4:4.0'
implementation group: 'com.github.javafaker', name: 'javafaker', version: '1.0.2'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation("org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2")
}

tasks.named('test') {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/squad/board/repository/BoardMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

@Mapper
public interface BoardMapper {

// 게시글 저장
void save(Board board);

void saveAll(List<Board> boards);

// 상세게시글 조회 [member join for nickname]
BoardDetailResponse findByIdWithNickName(Long boardId);

Expand Down
209 changes: 112 additions & 97 deletions src/main/resources/mapper/BoardMapper.xml
Original file line number Diff line number Diff line change
@@ -1,111 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="squad.board.repository.BoardMapper">
<insert id="save" useGeneratedKeys="true" keyColumn="board_id" keyProperty="boardId"
parameterType="squad.board.domain.board.Board">
insert into board(member_id, title, content, created_date, modified_date)
values (#{memberId}, #{title}, #{content}, #{createdDate}, #{modifiedDate})
</insert>
<insert id="save" useGeneratedKeys="true" keyColumn="board_id" keyProperty="boardId"
parameterType="squad.board.domain.board.Board">
insert into board(member_id, title, content, created_date, modified_date)
values (#{memberId}, #{title}, #{content}, #{createdDate}, #{modifiedDate})
</insert>

<select id="findAllWithNickName" resultType="squad.board.dto.board.BoardResponse">
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
<if test='memberId != null'>
where b.member_id = #{memberId}
</if>
order by created_date desc
limit #{size} offset #{offset}
</select>
<insert id="saveAll" keyColumn="board_id" keyProperty="boardId"
parameterType="squad.board.domain.board.Board">
insert into board(member_id, title, content, created_date, modified_date)
values
<foreach collection="list" item="boards" separator=",">
(#{boards.memberId},
#{boards.title},
#{boards.content},
NULL,
NULL
)
</foreach>
</insert>

<select id="findByKeyWord">
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
<if test='searchType=="content"'>
where match(content) against(#{keyWord})
</if>
<if test='searchType=="title"'>
where match(title) against(#{keyWord})
</if>
<if test='searchType=="titleAndContent"'>
where match(content) against(#{keyWord})
union
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
where match(title) against(#{keyWord})
</if>
order by created_date desc
limit #{size} offset #{offset};
</select>
<select id="findAllWithNickName" resultType="squad.board.dto.board.BoardResponse">
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
<if test='memberId != null'>
where b.member_id = #{memberId}
</if>
order by created_date desc
limit #{size} offset #{offset}
</select>

<select id="countBoards">
select count(*)
from board b
<if test='memberId != null'>
where b.member_id = #{memberId}
</if>
</select>
<select id="findByKeyWord">
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
<if test='searchType=="content"'>
where match(content) against(#{keyWord})
</if>
<if test='searchType=="title"'>
where match(title) against(#{keyWord})
</if>
<if test='searchType=="titleAndContent"'>
where match(content) against(#{keyWord})
union
select b.board_id,
b.title,
b.content,
m.nick_name,
b.created_date
from board b
join member m
on b.member_id = m.member_id
where match(title) against(#{keyWord})
</if>
order by created_date desc
limit #{size} offset #{offset};
</select>

<select id="countByKeyWord">
select count(*)
<if test='searchType=="content"'>
from (select * from board where match(content) against(#{keyWord})) as `b*`;
</if>
<if test='searchType=="title"'>
from (select * from board where match(title) against(#{keyWord})) as `b*`;
</if>
<if test='searchType=="titleAndContent"'>
from (select * from board where match(title) against(#{keyWord})
union
select * from board where match(content) against(#{keyWord})) as `b*`;
</if>
</select>
<select id="countBoards">
select count(*)
from board b
<if test='memberId != null'>
where b.member_id = #{memberId}
</if>
</select>

<select id="findByIdWithNickName" resultType="squad.board.dto.board.BoardDetailResponse" parameterType="long">
select b.board_id, b.title, b.content, m.nick_name, b.created_date, b.modified_date
from board b
join member m
on b.member_id = m.member_id
where b.board_id = #{boardId}
</select>
<select id="countByKeyWord">
select count(*)
<if test='searchType=="content"'>
from (select * from board where match(content) against(#{keyWord})) as `b*`;
</if>
<if test='searchType=="title"'>
from (select * from board where match(title) against(#{keyWord})) as `b*`;
</if>
<if test='searchType=="titleAndContent"'>
from (select * from board where match(title) against(#{keyWord})
union
select * from board where match(content) against(#{keyWord})) as `b*`;
</if>
</select>

<delete id="deleteById">
delete
from board
where board_id = #{boardId}
</delete>
<select id="findByIdWithNickName" resultType="squad.board.dto.board.BoardDetailResponse"
parameterType="long">
select b.board_id, b.title, b.content, m.nick_name, b.created_date, b.modified_date
from board b
join member m
on b.member_id = m.member_id
where b.board_id = #{boardId}
</select>

<select id="findById" resultType="Board">
select *
from board
where board_id = #{boardId}
</select>
<delete id="deleteById">
delete
from board
where board_id = #{boardId}
</delete>

<update id="updateById">
update board
set title = #{dto.title},
content = #{dto.content},
modified_date = #{modifiedDate}
where board_id = #{boardId}
</update>
<select id="findById" resultType="Board">
select *
from board
where board_id = #{boardId}
</select>

<update id="updateById">
update board
set title = #{dto.title},
content = #{dto.content},
modified_date = #{modifiedDate}
where board_id = #{boardId}
</update>
</mapper>
2 changes: 1 addition & 1 deletion src/main/resources/static/js/board/url.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const homeUrl = 'https://haechan.store'
const homeUrl = 'http://13.125.17.239:80'
// const homeUrl = 'http://localhost:8080'

0 comments on commit c34dcc3

Please sign in to comment.