Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
[fix](PinController.java): fix API named getPinPermission and searchPin
Browse files Browse the repository at this point in the history
  • Loading branch information
SisyphusDu committed Apr 15, 2023
1 parent 831ff36 commit e03d85a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/example/backend/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf().disable()
// 设置白名单
.authorizeHttpRequests()
.requestMatchers("/auth/**")
.requestMatchers("/auth/**", "/map/**", "/service/**",
"/forum/**", "/photo/**", "/ps-rel/**", "/user/**")
.permitAll()
// 保护剩余请求
.anyRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public CommonResult insertPin(@RequestBody Pin pin) {
}

@RequestMapping("/pin_search")
public CommonResult searchPin(@RequestBody Text text) {
ArrayList<Pin> pins = pinService.searchPin(text.getSearchContext());
public CommonResult searchPin(@RequestBody Text text, @RequestParam(name = "id") Integer id) {
ArrayList<Pin> pins = pinService.searchPin(text.getSearchContext(), id);
if (pins == null || pins.size() == 0)
return CommonResult.failed("搜索不到包含字段 '" + text.getSearchContext() + "' 的数据");
SearchInfo searchInfo = new SearchInfo();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/example/backend/domain/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class Pin implements Serializable {
*/
private String phone;

/**
* 地点联系电话
*/
private String visibility;

/**
* 用户id,个人用户创建pin为私有的,管理员创建pin为公开的
*/
Expand Down Expand Up @@ -100,6 +105,10 @@ public String getPhone() {
return phone;
}

public String getVisibility() {
return visibility;
}

public Integer getUser_id() {
return user_id;
}
Expand Down Expand Up @@ -140,6 +149,10 @@ public void setPhone(String phone) {
this.phone = phone;
}

public void setVisibility(String visibility) {
this.visibility = visibility;
}

public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/backend/mapper/PinMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public interface PinMapper extends BaseMapper<Pin> {
int insertAll(Pin pin);

ArrayList<Pin> searchAll(String searchContext);
ArrayList<Pin> searchAll(String searchContext, Integer id);

int updateAll(Pin pin);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/backend/service/PinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface PinService extends IService<Pin> {

int insertPin(Pin pin);

ArrayList<Pin> searchPin(String searchContext);
ArrayList<Pin> searchPin(String searchContext, Integer id);

int updatePin(Pin pin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public int insertPin(Pin pin) {
}

@Override
public ArrayList<Pin> searchPin(String searchContext) {
ArrayList<Pin> pins = pinMapper.searchAll(searchContext);
public ArrayList<Pin> searchPin(String searchContext, Integer id) {
ArrayList<Pin> pins = pinMapper.searchAll(searchContext, id);
return pins;
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/resources/mapper/PinMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<result property="type" column="p_type" jdbcType="INTEGER"/>
<result property="openTime" column="p_openTime" jdbcType="VARCHAR"/>
<result property="phone" column="p_phone" jdbcType="VARCHAR"/>
<result property="visibility" column="p_visibility" jdbcType="INTEGER"/>
<result property="user_id" column="u_id" jdbcType="INTEGER"/>
<result property="photo_id" column="ph_id" jdbcType="INTEGER"/>
<result property="forum_id" column="f_id" jdbcType="INTEGER"/>
Expand All @@ -20,27 +21,31 @@
<sql id="Base_Column_List">
p_id,p_name,p_pos,
p_brief,p_type,p_openTime,
p_phone,u_id,ph_id,
p_visibility,p_phone,u_id,ph_id,
f_id
</sql>
<insert id="insertAll">
insert into pin
(p_id,p_name,p_pos,p_brief,p_type,p_openTime,p_phone,u_id,ph_id,f_id)
(p_id,p_name,p_pos,p_brief,p_type,p_openTime,p_phone,p_visibility,u_id,ph_id,f_id)
values (#{id,jdbcType=NUMERIC}, #{name,jdbcType=VARCHAR}, #{position,jdbcType=VARCHAR},
#{brief,jdbcType=VARCHAR}, #{type,jdbcType=NUMERIC}, #{openTime,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{user_id,jdbcType=NUMERIC}, #{photo_id,jdbcType=NUMERIC},
#{forum_id,jdbcType=NUMERIC})
#{phone,jdbcType=VARCHAR}, #{visibility,jdbcType=NUMERIC}, #{user_id,jdbcType=NUMERIC},
#{photo_id,jdbcType=NUMERIC}, #{forum_id,jdbcType=NUMERIC})
</insert>
<update id="updateAll">
update pin
set p_name=#{name}, p_pos=#{position}, p_brief=#{brief},
p_type=#{type}, p_openTime=#{openTime}, p_phone=#{phone}
p_type=#{type}, p_openTime=#{openTime}, p_phone=#{phone},
p_visibility=#{visibility}
where p_id=#{id}
</update>
<select id="searchAll" resultType="com.example.backend.domain.Pin" resultMap="BaseResultMap">
select * from pin where 1 = 0
<if test='searchContext != "null" and searchContext != ""'>
or p_name like '%${searchContext}%' or p_brief like '%${searchContext}%'
or p_name like '%${searchContext}%' and p_visibility = 1
or p_brief like '%${searchContext}%' and p_visibility = 1
or p_name like '%${searchContext}%' and u_id = #{id}
or p_brief like '%${searchContext}%' and u_id = #{id}
</if>
</select>
<select id="getPinById" resultType="com.example.backend.domain.Pin" resultMap="BaseResultMap">
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/sql/createPinTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE `buaa_map`.`pin` (
`p_type` INT NOT NULL COMMENT '地图钉Tag' ,
`p_openTime` VARCHAR(100) NOT NULL COMMENT '地点开放时间' ,
`p_phone` VARCHAR(100) NOT NULL COMMENT '地点联系电话' ,
`p_visibility` INT NOT NULL COMMENT '0代表私人,1代表公开' ,
`u_id` INT NOT NULL COMMENT '用户id,个人用户创建pin为私有的,管理员创建pin为公开的' ,
`ph_id` INT NOT NULL COMMENT '地图钉相关照片组id' ,
`f_id` INT NOT NULL COMMENT '地图钉相关论坛id' ,
Expand Down

0 comments on commit e03d85a

Please sign in to comment.