From df3210cfba2f40cdbd099f4aae2430fb94c649b5 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 5 Dec 2024 01:16:00 +0300 Subject: [PATCH] Rename Member.Id to Member.UserId --- .../java/su/foxogram/services/MessagesService.java | 5 +++-- .../java/su/foxogram/dtos/response/MemberDTO.java | 4 ++-- .../java/su/foxogram/dtos/response/MessagesDTO.java | 2 +- .../src/main/java/su/foxogram/models/Member.java | 12 ++++++------ .../su/foxogram/repositories/MemberRepository.java | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/foxogram-api/src/main/java/su/foxogram/services/MessagesService.java b/foxogram-api/src/main/java/su/foxogram/services/MessagesService.java index 5acbdf1..98affc3 100644 --- a/foxogram-api/src/main/java/su/foxogram/services/MessagesService.java +++ b/foxogram-api/src/main/java/su/foxogram/services/MessagesService.java @@ -65,7 +65,7 @@ public void deleteMessage(String id, Member member, Channel channel) throws Mess Message message = messageRepository.findByChannelAndId(channel, id); if (message == null) throw new MessageNotFoundException(); - if (!Objects.equals(message.getAuthor().getId(), member.getId()) || member.hasAnyPermission(MemberConstants.Permissions.ADMIN, MemberConstants.Permissions.MANAGE_MESSAGES)) + if (!Objects.equals(message.getAuthor().getUserId(), member.getUserId()) || member.hasAnyPermission(MemberConstants.Permissions.ADMIN, MemberConstants.Permissions.MANAGE_MESSAGES)) throw new MissingPermissionsException(); messageRepository.delete(message); @@ -77,7 +77,8 @@ public Message editMessage(String id, Channel channel, Member member, MessageCre String content = body.getContent(); if (message == null) throw new MessageNotFoundException(); - if (!Objects.equals(message.getAuthor().getId(), member.getId())) throw new MissingPermissionsException(); + if (!Objects.equals(message.getAuthor().getUserId(), member.getUserId())) + throw new MissingPermissionsException(); message.setContent(content); messageRepository.save(message); diff --git a/foxogram-common/src/main/java/su/foxogram/dtos/response/MemberDTO.java b/foxogram-common/src/main/java/su/foxogram/dtos/response/MemberDTO.java index ea2bd3b..4be4b99 100644 --- a/foxogram-common/src/main/java/su/foxogram/dtos/response/MemberDTO.java +++ b/foxogram-common/src/main/java/su/foxogram/dtos/response/MemberDTO.java @@ -7,14 +7,14 @@ @Getter @Setter public class MemberDTO { - private String id; + private String userId; private String channelId; private long permissions; public MemberDTO(Member member) { - this.id = member.getId(); + this.userId = member.getUserId(); this.channelId = member.getChannel().getId(); this.permissions = member.getPermissions(); } diff --git a/foxogram-common/src/main/java/su/foxogram/dtos/response/MessagesDTO.java b/foxogram-common/src/main/java/su/foxogram/dtos/response/MessagesDTO.java index a076a40..a2177dc 100644 --- a/foxogram-common/src/main/java/su/foxogram/dtos/response/MessagesDTO.java +++ b/foxogram-common/src/main/java/su/foxogram/dtos/response/MessagesDTO.java @@ -13,7 +13,7 @@ public class MessagesDTO { public MessagesDTO(List messages) { for (Message message : messages) { - this.messages.add(new MessageDTO(message.getId(), message.getContent(), message.getAuthor().getId(), message.getChannel().getId(), message.getAttachments())); + this.messages.add(new MessageDTO(message.getId(), message.getContent(), message.getAuthor().getUserId(), message.getChannel().getId(), message.getAttachments())); } } } diff --git a/foxogram-common/src/main/java/su/foxogram/models/Member.java b/foxogram-common/src/main/java/su/foxogram/models/Member.java index 2fd24f8..de26696 100644 --- a/foxogram-common/src/main/java/su/foxogram/models/Member.java +++ b/foxogram-common/src/main/java/su/foxogram/models/Member.java @@ -9,7 +9,7 @@ @Getter @Entity @Table(name = "members", indexes = { - @Index(name = "idx_member_user_channel_id", columnList = "id, channel") + @Index(name = "idx_member_user_channel_id", columnList = "user_id, channel") }) public class Member { @Column() @@ -17,7 +17,7 @@ public class Member { @MapsId @ManyToOne - @JoinColumn(name = "id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @ManyToOne @@ -25,18 +25,18 @@ public class Member { private Channel channel; @Id - private String id; + private String userId; public Member() { } - public Member(String id) { - this.id = id; + public Member(String userId) { + this.userId = userId; } public Member(User user, Channel channel, long permissions) { - this.id = user.getId(); + this.userId = user.getId(); this.user = user; this.channel = channel; this.permissions = permissions; diff --git a/foxogram-common/src/main/java/su/foxogram/repositories/MemberRepository.java b/foxogram-common/src/main/java/su/foxogram/repositories/MemberRepository.java index 42e8559..45d9c20 100644 --- a/foxogram-common/src/main/java/su/foxogram/repositories/MemberRepository.java +++ b/foxogram-common/src/main/java/su/foxogram/repositories/MemberRepository.java @@ -12,7 +12,7 @@ @Repository public interface MemberRepository extends CrudRepository { - @Query(value = "SELECT m FROM Member m WHERE m.channel = :ch AND m.id = :id") + @Query(value = "SELECT m FROM Member m WHERE m.channel = :ch AND m.user.id = :id") Member findByChannelAndId(@Param("ch") Channel channel, @Param("id") String id); List findAllByChannel(Channel channel);