我和群众站一队-alpha冲刺第3日

我和群众站一队 2024-11-04 22:40:11

冲刺日记三:

这个作业属于哪个课程https://bbs.csdn.net/forums/2401_CS_SE_FZU
这个作业要求在哪里https://bbs.csdn.net/topics/619397949
这个作业的目标CodeArt团队实战总结
其他参考文献CSDN,博客园

目录

  • 冲刺日记三:
  • 一、项目进展
  • 二、存在的问题/遇到的困难及接下来的安排
  • 三、站立式会议照片
  • 四、今日完成度相关照片
  • 五、心得体会

一、项目进展

222200315张俊腾
进展一:完成了创建dto_rescue文件夹 完成LeaderboardEntry类和RescueInfoDetail类的代码实现

img

222200309孙阳
进展一:完成“获取用户奖牌接口”,新增了 medalController,dto_medal,MedalRespository,medalService文件

package com.bafang.service;

import com.bafang.dto.Response.Response;
import com.bafang.dto.dto_medal.MedalDetail;
import com.bafang.dto.dto_user.UserDetail;
import com.bafang.entity.entity_user.User;
import com.bafang.repository.MedalRepository;
import com.bafang.repository.UserRepository;
import com.bafang.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.MalformedJwtException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
public class MedalService {
    @Autowired
    private MedalRepository medalRepository;

    @Autowired
    private UserRepository userRepository;

    public Response<List<MedalDetail>> GetUserMedal(Long uid, String token) {

        // 检查令牌
        Claims claims;
        try {
            claims = JwtUtil.extractClaims(token);
        } catch (MalformedJwtException e) {
            return new Response<>(400, "无效的令牌格式", null);
        } catch (ExpiredJwtException e) {
            return new Response<>(401, "令牌已过期", null);
        } catch (IllegalArgumentException e) {
            return new Response<>(400, "令牌不能为空", null);
        } catch (JwtException e) {
            return new Response<>(401, "无效的令牌", null);
        } catch (Exception e) {
            return new Response<>(500, "服务器内部错误", null);
        }

        Optional<User> optUser=userRepository.findById(uid);
        if(optUser.isEmpty()){
            return new Response<>(401, "用户不存在", null);
        }
        else {
            return new Response<>(200,"success",medalRepository.findByUid(uid).stream()
                    .map(medal -> {
                        return new MedalDetail(
                                medal.getId(),
                                medal.getUid(),
                                medal.getMedalType(),
                                medal.getCreatedAt(),
                                medal.getUpdatedAt(),
                                medal.getDeletedAt()
                        );
                    })
                    .collect(Collectors.toList()));
        }

    }
}

222200304卢君豪
进展一:“获取我的求助信息”service部分的实现

package com.bafang.service;

        import com.bafang.dto.Response.Response;
        import com.bafang.dto.dto_help.HelpRequestInfo;
        import com.bafang.repository.HelpRequestRepository;
        import com.bafang.repository.UserRepository;
        import com.bafang.util.JwtUtil;
        import io.jsonwebtoken.Claims;
        import io.jsonwebtoken.ExpiredJwtException;
        import io.jsonwebtoken.JwtException;
        import io.jsonwebtoken.MalformedJwtException;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;

        import java.util.List;

        @Service
        public class HelpRequestService {
            @Autowired
            private HelpRequestRepository helpRequestRepository;

            @Autowired
            private UserRepository userRepository;

            public Response<List<HelpRequestInfo>> getUserHelpRequestInfo(Long uid, String token) {
                Claims claims;
                try {
                    claims = JwtUtil.extractClaims(token);
                } catch (MalformedJwtException e) {
                    return new Response<>(400, "无效的令牌格式", null);
                } catch (ExpiredJwtException e) {
                    return new Response<>(401, "令牌已过期", null);
                } catch (IllegalArgumentException e) {
                    return new Response<>(400, "令牌不能为空", null);
                } catch (JwtException e) {
                    return new Response<>(401, "无效的令牌", null);
                } catch (Exception e) {
                    return new Response<>(500, "服务器内部错误", null);
                }

                Long userId = Long.parseLong(claims.getSubject());
                if(!userRepository.existsById(userId)) {
                    return new Response<>(401, "用户无效", null);
                }

                if (!userRepository.existsById(uid)) {
                    return new Response<>(401, "用户不存在", null);
                }

                List<HelpRequestInfo> helpRequestInfoList = helpRequestRepository.findByUid(uid);
                return new Response<>(200, "success", helpRequestInfoList);
            }
        }

222200310李怡涵
进展一: - 获取用户实况接口

public Response<List<UserLiveList>> getUserLive(Long uid, String token){
        Claims claims;
        try {
            claims = JwtUtil.extractClaims(token);
        } catch (MalformedJwtException e) {
            return new Response<>(400, "无效的令牌格式", null);
        } catch (ExpiredJwtException e) {
            return new Response<>(401, "令牌已过期", null);
        } catch (IllegalArgumentException e) {
            return new Response<>(400, "令牌不能为空", null);
        } catch (JwtException e) {
            return new Response<>(401, "无效的令牌", null);
        } catch (Exception e) {
            return new Response<>(500, "服务器内部错误", null);
        }
        long userId = Long.parseLong(claims.getSubject());
        Optional<User> gettingUser = userRepository.findById(userId);
        if(gettingUser.isEmpty()) {
            return new Response<>(401, "用户无效", null);
        }

        List<LiveInfo> wholeLiveList = liveInfoRepository.findByUid(uid);
        List<UserLiveList> liveList = wholeLiveList.stream().map(LiveInfo->new UserLiveList(LiveInfo.getId(),LiveInfo.getUid(), LiveInfo.getLocation(), LiveInfo.getWeatherCondition(),
                LiveInfo.getRoadCondition(), LiveInfo.getUtilitiesInfo(),LiveInfo.getLevel(),LiveInfo.getIntroduction(),LiveInfo.getExpiryAt())).collect(Collectors.toList());

        if (liveList.isEmpty()){
            return new Response<>(400, "用户实况为空", null);
        }

        return new Response<>(200, "success", liveList);
    }

222200311李梓玄
进展一:实现地图拖拽选点获取位置,实现搜索附近地址选择

img

222200328夏振
进展一:新增token拦截器,所有接口使用统一用拦截器验证令牌
222200401丁昌彪
进展一: 基本完成了求助历史功能
222200312杨年申
进展一:完成UserController.register及其Request的搭建

@PostMapping("/register")
                public ResultResponse<UserLogin> register(@ModelAttribute RegisterRequest registerRequest) {
                    return userService.register(registerRequest);
                }
public class RegisterRequest {
                private String username;
                private String password;

                // Getter 和 Setter
                public String getUsername() {
                    return username;
                }

                public void setUsername(String username) {
                    this.username = username;
                }

                public String getPassword() {
                    return password;
                }

                public void setPassword(String password) {
                    this.password = password;
                }
            }

进展二:完善register的Service

 public ResultResponse<UserLogin> register(RegisterRequest registerRequest) {
                // 检查用户名是否已经存在
                if (userRepository.existsByUsername(registerRequest.getUsername())) {
                    return new ResultResponse<>(400, "Username already exists", null);
                }

                // 创建并保存新用户
                User user = new User();
                user.setUsername(registerRequest.getUsername());
                user.setPassword(passwordEncoder.encode(registerRequest.getPassword()));  // 使用加密后的密码

                userRepository.save(user);
                // 生成JWT令牌
                String token = JwtUtil.generateToken(user.getId());

                return new ResultResponse<>(200, "success", new UserLogin(user.getId(), user.getUsername(), token));
            }

222200230梁蕴潆
进展一:编写冲刺日记
进展二:开始用vue编写相关部分

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    aids: []
  },
  mutations: {
    SET_AIDS(state, aids) {
      state.aids = aids
    },
    ADD_AID(state, aid) {
      state.aids.push(aid)
    }
  },
  actions: {
    fetchAids({ commit }) {
      // 这里应该是API调用,现在我们用静态数据代替
      const aids = [
        { id: 1, message: '需要食物和水', location: 'A市' },
        { id: 2, message: '需要医疗援助', location: 'B市' }
      ]
      commit('SET_AIDS', aids)
    },
    addAid({ commit }, aid) {
      commit('ADD_AID', aid)
    }
  }
})

二、存在的问题/遇到的困难及接下来的安排

成员存在的问题/遇到的困难接下来的安排
222200315张俊腾问题:问题:如何合理设计 LeaderboardEntry 类中的字段以便后续扩展和排序操作,以及 RescueInfoDetail 类中字段的类型选择是否满足后续业务需求。- 解答:通过查看数据库设计,确定了 LeaderboardEntry 类中应包含用户 ID、用户名、救援次数必要字段。

img

img

开发RescueService的核心逻辑,包括接取求助的实现。
222200309孙阳不理解token是干什么用的,但看了同学们的代码示例后学习了token的意义和用法打算测试“获取用户奖牌接口,”开始编写“更新用户消息”的接口代码
222200304卢君豪- 问题、困难1,对token还没有完全的理解- 解答,先照着别人的代码写再说实现“发起求助”部分的dto、controller的创建
222200310李怡涵entity中的类与dto中的类的转化问题.经搜索学习得知,利用List liveList = wholeLiveList.stream().map(LiveInfo->new UserLiveList(LiveInfo.getId(),LiveInfo.getUid(), LiveInfo.getLocation(), LiveInfo.getWeatherCondition(), LiveInfo.getRoadCondition(), LiveInfo.getUtilitiesInfo(),LiveInfo.getLevel(),LiveInfo.getIntroduction(),LiveInfo.getExpiryAt())).collect(Collectors.toList()); 进行转换。后端完成 上传实况信息接口
222200311李梓玄无,但是高德地图的免费额度已经被造完了(高德真抠)

img

- 上传实况信息、发起求助的界面设计和代码 - 上传实况信息、发起求助接口对接
222200328夏振刚开始没懂拦截器怎么添加不必验证的接口接下来还是把我剩下没完成的功能设计实现,并总结今天完成的内容
222200401丁昌彪问题:没有及时pull,导致合并fork时和别人的代码发生冲突解决办法:克隆最新仓库,手动复制粘贴新代码到指定位置1. 完善求助历史功能2. 完成我的实况功能
222200312杨年申问题、困难1- - 用户提交的注册信息(如用户名、密码)需要进行验证,以确保输入的有效性。- 解答- - 用户名唯一性检测,使用密码加密工具(如 BCrypt)对用户密码进行加密,确保存储在数据库中的密码是安全的。- 问题、困难2 - - 注册过程涉及多个数据库操作(如插入用户、创建用户角色等),需要保证原子性。- 解答- - 使用 @Transactional 注解,确保在整个注册过程中所有操作要么全部成功,要么全部失败,避免数据不一致。安排实现一个接口getUserInfo
222200230梁蕴潆继续编写有关灾难互助平台vue框架

三、站立式会议照片

img

四、今日完成度相关照片

成员相关图片
222200315张俊腾

img

222200309孙阳

img

222200304卢君豪

img

222200310李怡涵

img

222200311李梓玄

img

222200328夏振

img

222200401丁昌彪

img

222200312杨年申

img

222200230梁蕴潆

img

五、心得体会

成员心得体会
222200315张俊腾在设计 DTO 时,通过团队讨论和文档查阅,不仅能确保字段设计合理,还能为后续的扩展做好准备。尤其是在解决字段类型选择的过程中,发现选择合适的数据类型(如 LocalDateTime)对于处理复杂的多时区环境和长期维护有很大帮助。注重这些细节使得开发过程更高效,避免未来可能的重构。
222200309孙阳代码编写要专心,否则只会永远debug
222200304卢君豪非常好的学习,使我对token一知半解
222200310李怡涵学习了entity中的类与dto中的类的转化相关知识
222200311李梓玄阅读kotlin源码使我大脑宕机,虽然实现了功能但是shi山痕迹愈发明显,考虑优化一下
222200328夏振感谢项目使我获得提升,谢谢
222200401丁昌彪切记先pull在push,否则冲突不好处理。
222200312杨年申参数验证的重要性:对用户输入的严格验证可以有效减少后端逻辑的负担,防止无效或恶意输入导致的错误。良好的输入验证不仅提高了系统的稳定性,也能提升用户体验。- 关注用户体验:在注册过程中,提供清晰的提示信息,如注册成功、失败原因等,能极大提升用户体验。考虑到用户可能的操作错误,提供友好的错误反馈可以帮助用户更顺利地完成注册。
222200230梁蕴潆参与项目让我获得提升,学到很多新知识。
...全文
124 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

113

社区成员

发帖
与我相关
我的任务
社区描述
202401_CS_SE_FZU
软件工程 高校
社区管理员
  • FZU_SE_TeacherL
  • 助教_林日臻
  • 防震水泥
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧