Skip to content

Commit

Permalink
Rename Member.Id to Member.UserId
Browse files Browse the repository at this point in the history
  • Loading branch information
krabiworld committed Dec 4, 2024
1 parent 240b78c commit df3210c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MessagesDTO {

public MessagesDTO(List<Message> 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()));
}
}
}
12 changes: 6 additions & 6 deletions foxogram-common/src/main/java/su/foxogram/models/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@
@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()
public long permissions;

@MapsId
@ManyToOne
@JoinColumn(name = "id", nullable = false)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@ManyToOne
@JoinColumn(name = "channel", nullable = false)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Repository
public interface MemberRepository extends CrudRepository<Member, String> {
@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<Member> findAllByChannel(Channel channel);
Expand Down

0 comments on commit df3210c

Please sign in to comment.